A production-ready, full-stack real-time chat application built with Django, Django Channels, React, and TypeScript.
- Real-time messaging - Instant message delivery using WebSockets
- JWT Authentication - Secure authentication with access and refresh tokens
- Typing indicators - See when others are typing in real-time
- Online/Offline status - Track user presence
- Message history - Persistent message storage with pagination
- Direct messages - One-on-one conversations
- Group chats - Multi-user chat rooms
- Read receipts - Know when messages are read
- Message editing/deletion - Edit or delete your messages
- Reply to messages - Quote and reply to specific messages
- Responsive design - Works on desktop and mobile
- Django 5.0 - Web framework
- Django Channels - WebSocket support
- Django REST Framework - REST API
- Simple JWT - JWT authentication
- PostgreSQL - Primary database
- Redis - WebSocket channel layer & caching
- Daphne - ASGI server
- React 18 - UI library
- TypeScript - Type safety
- Vite - Build tool
- Tailwind CSS - Styling
- Zustand - State management
- React Hook Form - Form handling
- Zod - Schema validation
- Docker & Docker Compose - Containerization
- Nginx - Reverse proxy
- GitHub Actions - CI/CD (optional)
Real-Time-Chat-App/
βββ backend/
β βββ accounts/ # User authentication & profiles
β βββ chat/ # Chat functionality & WebSockets
β βββ chat_project/ # Django project settings
β βββ Dockerfile
β βββ requirements.txt
βββ frontend/
β βββ src/
β β βββ api/ # API client & services
β β βββ components/ # React components
β β βββ pages/ # Page components
β β βββ stores/ # Zustand stores
β β βββ services/ # WebSocket service
β β βββ types/ # TypeScript types
β βββ Dockerfile
β βββ package.json
βββ nginx/ # Nginx configuration
βββ docker-compose.yml
βββ README.md
- Docker & Docker Compose
- Node.js 18+ (for local development)
- Python 3.11+ (for local development)
- Redis (for local development)
- Clone the repository
git clone <repository-url>
cd Real-Time-Chat-App- Create environment file
cp .env.example .env
# Edit .env with your settings- Start the application
docker-compose up -d- Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000/api/
- Admin: http://localhost:8000/admin/
- Create virtual environment
cd backend
python -m venv venv
source venv/bin/activate # Linux/Mac
# or: venv\Scripts\activate # Windows- Install dependencies
pip install -r requirements.txt- Set up environment
cp .env.example .env
# Edit .env with your settings- Run migrations
python manage.py migrate- Create superuser
python manage.py createsuperuser- Start Redis (required for WebSockets)
redis-server- Run development server
python manage.py runserver
# or with Daphne for WebSockets:
daphne -b 0.0.0.0 -p 8000 chat_project.asgi:application- Install dependencies
cd frontend
npm install- Set up environment
cp .env.example .env- Start development server
npm run dev| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register/ |
Register new user |
| POST | /api/auth/login/ |
Login user |
| POST | /api/auth/logout/ |
Logout user |
| POST | /api/auth/refresh/ |
Refresh access token |
| GET | /api/auth/profile/ |
Get user profile |
| PATCH | /api/auth/profile/ |
Update profile |
| POST | /api/auth/password/change/ |
Change password |
| GET | /api/auth/users/ |
Search users |
| GET | /api/auth/users/online/ |
Get online users |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/chat/rooms/ |
List chat rooms |
| POST | /api/chat/rooms/ |
Create chat room |
| GET | /api/chat/rooms/{id}/ |
Get room details |
| DELETE | /api/chat/rooms/{id}/ |
Leave/delete room |
| GET | /api/chat/rooms/{id}/messages/ |
Get messages |
| POST | /api/chat/rooms/{id}/messages/ |
Send message |
| PATCH | /api/chat/rooms/{id}/messages/{mid}/ |
Edit message |
| DELETE | /api/chat/rooms/{id}/messages/{mid}/ |
Delete message |
| POST | /api/chat/direct/ |
Create direct message |
| POST | /api/chat/rooms/{id}/read/ |
Mark as read |
// Send message
{ type: 'message', content: 'Hello!', reply_to: null }
// Typing indicator
{ type: 'typing', is_typing: true }
// Mark as read
{ type: 'read' }
// Edit message
{ type: 'edit', message_id: 'uuid', content: 'Updated content' }
// Delete message
{ type: 'delete', message_id: 'uuid' }// New message
{ type: 'message', message: { id, sender, content, created_at, ... } }
// Typing indicator
{ type: 'typing', user_id: 1, username: 'john', is_typing: true }
// Read receipt
{ type: 'read', user_id: 1, username: 'john', read_at: 'ISO-date' }
// Message edited
{ type: 'edit', message: { id, content, is_edited: true, ... } }
// Message deleted
{ type: 'delete', message_id: 'uuid' }
// User status
{ type: 'status', user_id: 1, username: 'john', is_online: true }| Variable | Description | Default |
|---|---|---|
DJANGO_ENV |
Environment (development/production) | development |
DJANGO_SECRET_KEY |
Secret key for Django | - |
DB_NAME |
PostgreSQL database name | chat_db |
DB_USER |
PostgreSQL username | chat_user |
DB_PASSWORD |
PostgreSQL password | - |
DB_HOST |
PostgreSQL host | localhost |
REDIS_HOST |
Redis host | localhost |
ALLOWED_HOSTS |
Comma-separated allowed hosts | localhost |
CORS_ALLOWED_ORIGINS |
Comma-separated CORS origins | - |
| Variable | Description | Default |
|---|---|---|
VITE_API_URL |
Backend API URL | /api |
VITE_WS_HOST |
WebSocket host | localhost:8000 |
# Start all services including Nginx
docker-compose --profile production up -d- Set strong
DJANGO_SECRET_KEY - Use strong database passwords
- Enable HTTPS with SSL certificates
- Set appropriate
ALLOWED_HOSTS - Configure CORS properly
- Enable rate limiting
- Set up monitoring and logging
- Configure backup strategy
cd backend
pytestcd frontend
npm run type-check- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
For support, please open an issue in the repository.