This repository contains the source code for a real-time chat application that supports user authentication, dynamic messaging, and efficient database management. The project comprises both a frontend and a backend system. Additionally, a separate repository handles database cleanup tasks via a cron job.
-
Real-Time Messaging:
- Users can send and receive messages in real-time.
- Old messages are retrieved from the database for seamless conversations.
-
User Management:
- Dynamic user connections and disconnections are handled efficiently.
- Integration with a separate cron job repository ensures expired users (accounts older than 24 hours) are automatically removed.
-
Search and Navigation:
- Users can search for connections dynamically.
- The selected connection scrolls into view for easy navigation.
-
Data Integrity:
- Automatic cleanup of expired users and associated conversations using a separate cron job system.
- Frontend: (Hosted on vercel)
- React.js
- CSS for styling
- WebSocket API for real-time communication
- Backend: (Hosted on render)
- Django (Python)
- WebSockets (via Django Channels) for real-time communication
- MongoDB for database management
- Redis for session and state management
- Database Cleanup:
- MongoDB queries for user and conversation cleanup
- Cron job in a separate repository
.
├── frontend/ # React-based frontend
│ ├── components/ # Reusable React components
│ ├── styles/ # CSS files for styling
│ └── App.js # Main React application
├── backend/ # Django-based backend
│ ├── settings.py # Django settings
│ ├── urls.py # URL routing
│ ├── views.py # API views
│ ├── consumers.py # WebSocket handlers
│ └── models.py # Database models
├── cron-job/ # Separate repository for cleanup
│ └── cleanup_script.js # Handles expired user cleanup
└── README.md # Project documentation
-
Sidebar:
- Allows toggling of the search bar and logout.
- Search is placed at the top, and logout is placed at the bottom for easy access.
-
Header:
- Displays user-specific information.
- Supports dynamic search functionality.
-
ListOfConnections:
- Displays a list of user connections.
- Automatically scrolls to the selected connection.
-
ChatWindow:
- Displays messages with a typing effect for the header.
- Handles message sending and retrieval.
- Shows the online/offline status of the selected user using WebSocket communication.
- Custom CSS ensures a responsive and user-friendly interface.
- Animations and hover effects improve interactivity.
-
Django APIs:
- REST APIs to handle user connections and search.
- Integration with MongoDB for persistent storage.
-
WebSocket Communication:
- Real-time messaging between users using Django Channels.
- Active user tracking and message handling.
-
MongoDB Integration:
- Stores user and conversation data.
- Ensures data consistency across sessions.
-
Redis Integration:
- Tracks online users using Redis data structures.
- Caches messages for efficient retrieval.
-
Error Handling:
- Comprehensive error logging and handling to ensure smooth operation.
The cron job is managed in a separate repository and is responsible for removing expired users (accounts older than 24 hours) and cleaning up related data.
- Identify Expired Users:
- Queries the
users
collection for accounts older than 24 hours.
- Queries the
- Remove Expired Users:
- Deletes expired user records from the database.
- Update Connections:
- Removes references to expired users from other users' connection lists.
- Delete Conversations:
- Deletes chat records involving expired users.
The cron job repository can be found here.
- Run the cleanup script periodically using a scheduler (e.g.,
cron
or third-party services).
Create a .env
file in the root directory of both the backend and cron job repositories and define the following variables:
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/<dbname>
REDIS_HOST=<your-redis-host>
REDIS_PORT=<your-redis-port>
REDIS_PASSWORD=<your-redis-password>
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/<dbname>
- Python
- Node.js
- MongoDB
- Redis
- Navigate to the backend directory:
cd backend
- Install dependencies:
pip install -r requirements.txt
- Run migrations:
python manage.py migrate
- Start the server:
python manage.py runserver
- Navigate to the frontend directory:
cd frontend
- Install dependencies:
npm install
- Start the React development server:
npm start
- Navigate to the cron-job repository directory:
cd cron-job
- Install dependencies:
npm install
- Run the cleanup script manually (for testing):
node cleanup_script.js
- Schedule the script using
cron
or another scheduler for periodic execution.
- Start the backend server.
- Start the frontend server.
- Access the application in your browser (default:
http://localhost:3000
). - Use the app to chat, search connections, and view online/offline status.
- Integrate a delete button to delete the account instantly.
- Add options allowing users to choose the duration for holding their account.
- Add support for message notifications.
- Implement group chats.
- Optimize the frontend for mobile devices.
- Enhance search functionality with fuzzy matching.
This project is licensed under the MIT License. See the LICENSE file for details.
- React.js for the frontend framework.
- Django and Django Pymango for backend APIs.
- MongoDB for robust database management.
- Redis for efficient session and state management.
For further assistance, feel free to raise an issue or contribute to the repository!