A full-stack realtime messaging platform built with Django, Django Channels, WebSockets, and Redis. This project demonstrates how to design and implement a distributed, event-driven system inside a traditional web framework.
⚡ Not just a chat demo — this project showcases realtime architecture, connection lifecycle management, presence tracking, and scalable message broadcasting.
- Instant message delivery using WebSockets
- No page reloads, no polling
- Message validation and persistence before broadcast
- Live online user tracking per room
- Updates triggered by connection lifecycle (connect/disconnect)
- Realtime presence synchronization across all clients
- One-to-one private chat rooms
- Membership-based access control
- Dynamic room creation
- Redis-backed channel layer
- Supports multiple ASGI workers
- Designed for horizontal scaling
- Global chat dropdown
- Private chat index
- Conversation-aware UI
This application is built as a distributed realtime system, not just a Django app.
Browser
│
│ WebSocket
▼
Django Channels Consumer
│
├── Validation Layer (Django Forms)
├── Persistence Layer (PostgreSQL)
└── Broadcast Layer (Redis Channel Layer)
│
▼
Other Connected Clients
The system operates across two communication planes:
| Layer | Purpose |
|---|---|
| HTTP | Page rendering, authentication, room creation |
| WebSocket | Live events (messages, presence, updates) |
| Technology | Purpose |
|---|---|
| Django | Core web framework |
| Django Channels | WebSocket support & event routing |
| ASGI | Enables long-lived connections and async handling |
| Redis | Distributed channel layer backend |
| PostgreSQL | Persistent storage for users, rooms, messages |
| Alpine.js | Reactive frontend updates |
| Tailwind CSS | UI styling |
Each client connection is managed by a Consumer, which handles:
connect()→ join room, update presencereceive()→ validate, save, broadcast messagesdisconnect()→ cleanup presence
The WebSocket connection carries multiple event types:
{ "event": "message", "message": {...} }
{ "event": "online_count", "online_count": 4 }A custom event protocol enables multiplexed realtime communication over a single socket.
The channel layer acts as a message bus:
- Routes events between consumers
- Synchronizes state across multiple server workers
- Enables horizontal scaling
Presence is modeled as shared state, not just events:
- Stored in the database
- Updated on connection lifecycle
- Broadcast to all clients in the room
WebSocket consumers enforce:
- Authentication
- Room-level authorization
- Private room membership validation
a_rtchat/
│
├── consumers.py # WebSocket connection controllers
├── models.py # Chat rooms, messages, presence
├── views.py # HTTP layer for room bootstrap
├── queries.py # Chat relationship data access
├── serializers.py # Transport formatting
├── context_processors.py # Global chat data injection
│
templates/
├── chat.html # Chat interface
└── partials/ # Chat dropdown & UI components
pip install -r requirements.txtredis-serverpython manage.py migratedaphne a_core.asgi:applicationThis project demonstrates practical experience with:
- Realtime system design
- Distributed event-driven architecture
- WebSocket lifecycle management
- Scalable Django deployment patterns
- Separation of concerns across layers
- Designing communication protocols
Modern applications like Slack, Discord, and collaborative tools rely on the same architectural patterns demonstrated here:
- Persistent connections
- Message buses
- Presence tracking
- Event multiplexing
- Distributed coordination
This project shows the ability to build these systems from the ground up.
Built as part of advanced exploration into realtime web architecture and scalable backend systems.