A real-time chat application built with Django Channels, featuring WebSocket communication, user authentication, and message persistence.
- Real-time Messaging: Instant message delivery using Django Channels and WebSockets
- User Authentication: Sign up, login, and logout functionality
- Chat Rooms: Create and join multiple chat rooms with unique slugs
- Message Persistence: Messages stored in Redis for session persistence
- Rate Limiting: Prevents spam with configurable message limits (10 messages per minute, 1 second between messages)
- Responsive UI: Clean, modern interface for seamless communication
- Docker Support: Complete containerized setup with PostgreSQL and Redis
- Backend: Django 5.2.7, Django Channels
- Database: PostgreSQL
- Cache/Message Broker: Redis
- WebSockets: Django Channels with Redis Channel Layer
- Frontend: HTML, CSS, JavaScript
- Containerization: Docker & Docker Compose
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/ericknavarro97/realtime-django-chat.git cd realtime-django-chat -
Start the application:
docker compose up --build
-
Access the application: Open your browser and navigate to
http://localhost:8000
- Sign Up: Create a new account or log in with existing credentials
- Create Chat Room: Enter a chat room name to create a new room
- Join Chat: Click on any existing chat room to join the conversation
- Start Chatting: Send messages that appear instantly to all participants
- accounts: User authentication (signup, login, logout)
- chats: Chat room management and real-time messaging
- config: Django project settings and configuration
- services: Redis service layer for message persistence
- utilities: Common abstract models and utilities
- ChatConsumer: WebSocket consumer handling real-time message broadcasting
- RedisService: Manages message storage and retrieval from Redis
- Rate Limiting: Prevents abuse with configurable message limits
- BaseAbstract: Common model base with UUID primary keys and timestamps
# Build and run containers
docker compose up --build
# Run in background
docker compose up -d
# Run tests
docker compose exec django python manage.py test
# Create superuser
docker compose exec django python manage.py createsuperuser
# Run migrations
docker compose exec django python manage.py migrate
# Collect static files
docker compose exec django python manage.py collectstaticGET/POST /- Chat room list and creationGET /<chat_slug>/- Individual chat roomPOST /signup/- User registrationPOST /login/- User loginPOST /logout/- User logoutWS /ws/<chat_name>/- WebSocket endpoint for real-time messaging
The application uses environment variables for configuration. Key settings include:
- Database: PostgreSQL connection parameters
- Redis: Host and port for caching and channel layer
- Django: Secret key, debug mode, allowed hosts
- Implement chat deletion (admin only)
- Add more comprehensive error handling and user feedback
- Environment variables configuration with
.envfile - Improve cache cleanup mechanisms
- Add user presence indicators
- Implement private messaging
- Add message history pagination
- Email notifications for new messages
- File/image sharing capabilities
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
docker compose exec django python manage.py test - Submit a pull request
This project is open source and available under the MIT License.