A real-time group chat web application built with Django, Django Channels, WebSockets, Redis, and modern web technologies. This application enables seamless real-time communication with advanced features like AI-powered chat summarization, online user tracking, and responsive design.
- Real-time messaging using WebSockets and Django Channels
- Room-based chat system with unique room codes
- User authentication and session management
- Message persistence with SQLite database
- Online user tracking with Redis caching
- Chat history - last 20 messages loaded on join
- System notifications for user join/leave events
- Chat Summarization using Google's Generative AI (Gemini)
- Intelligent conversation analysis and insights
- Modern, responsive UI with custom CSS styling
- Clean navigation with branded header
- Real-time user presence indicators
- Smooth animations and transitions
- Mobile-friendly design
- Django 5.2.4 - Web framework
- Django Channels 4.3.0 - WebSocket support
- Redis - Channel layer and caching
- SQLite - Database (easily configurable for PostgreSQL/MySQL)
- ASGI - Asynchronous server gateway interface
- HTML5 with Django templates
- Custom CSS with modern styling
- JavaScript for WebSocket client-side handling
- Responsive design principles
- LangChain 0.3.27 - AI framework
- Google Generative AI - Chat summarization
- LangSmith - AI observability
Group-Chat-Django-Channels/
├── groupchat/ # Main Django project
│ ├── groupchat/ # Project settings
│ │ ├── settings.py # Django configuration
│ │ ├── asgi.py # ASGI configuration
│ │ ├── urls.py # Main URL routing
│ │ └── wsgi.py # WSGI configuration
│ ├── chat/ # Chat application
│ │ ├── models.py # Room and Message models
│ │ ├── views.py # HTTP views and AI features
│ │ ├── consumers.py # WebSocket consumers
│ │ ├── routing.py # WebSocket URL routing
│ │ ├── urls.py # HTTP URL patterns
│ │ ├── templates/ # HTML templates
│ │ │ └── chat/
│ │ │ ├── home.html # Landing page
│ │ │ └── chatroom.html # Chat interface
│ │ └── static/ # CSS and static files
│ ├── db.sqlite3 # SQLite database
│ ├── manage.py # Django management script
│ └── .env # Environment variables
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
└── README.md # This file
- Python 3.8+
- Redis server
- Git
git clone <repository-url>
cd Group-Chat-Django-Channelspython -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activatecd groupchat
pip install -r ../requirements.txtCreate a .env file in the groupchat directory:
SECRET_KEY=your-secret-key-here
DEBUG=True
GOOGLE_API_KEY=your-google-ai-api-key # For AI featurespython manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser # Optional: for admin accessOption A: Using Docker (Recommended)
docker run -p 6379:6379 -d redis:latestOption B: Native Installation
- Windows: Download from Redis Windows
- Linux:
sudo apt-get install redis-server
# Using Daphne (Production-ready ASGI server)
daphne groupchat.asgi:application
# Or using Django development server (Development only)
python manage.py runserverOpen your browser and navigate to:
- Development:
http://127.0.0.1:8000 - Daphne:
http://127.0.0.1:8000
- Visit the home page
- Click "Create Room"
- Enter your username
- A unique room code will be generated automatically
- Share the room code with others
- Visit the home page
- Click "Join Room"
- Enter the room code and your username
- Start chatting in real-time!
- Use the summarization endpoint:
/summarize/?room_code=YOUR_ROOM_CODE - Get AI-powered insights and summaries of your chat conversations
The application uses Redis for:
- Channel Layer: WebSocket message routing
- User Presence: Online user tracking
- Caching: Performance optimization
Default Redis settings in settings.py:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}By default, the application uses SQLite. To use PostgreSQL or MySQL:
- Install the appropriate database adapter
- Update
DATABASESinsettings.py - Run migrations
To enable AI-powered chat summarization:
- Get a Google AI API key from Google AI Studio
- Add it to your
.envfile asGOOGLE_API_KEY - The summarization endpoint will be available at
/summarize/
- Room: Manages chat rooms with unique codes
- Message: Stores chat messages with timestamps
- ChatConsumer: Handles WebSocket connections
- Real-time message broadcasting
- User join/leave notifications
- Message history loading
- Home view: Landing page with room creation/joining
- Chat room view: Main chat interface
- AI summarization: LangChain-powered chat analysis
- Online user tracking: Redis-based presence system
- Database changes: Update models, create migrations
- WebSocket features: Modify
ChatConsumerclass - HTTP endpoints: Add views and URL patterns
- Frontend: Update templates and static files
- Redis channel layer for efficient message routing
- Connection pooling for database operations
- Async/await patterns for non-blocking operations
- Message history limiting (last 20 messages)
- User presence caching with TTL
- Set
DEBUG = False - Configure
ALLOWED_HOSTS - Use PostgreSQL/MySQL instead of SQLite
- Set up Redis with persistence
- Configure HTTPS/WSS
- Set up proper logging
- Use environment variables for secrets
- Configure static file serving
# Example Dockerfile structure
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["daphne", "groupchat.asgi:application"]- Fork the repository
- Create a 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
Connection: ws://localhost:8000/ws/chat/{room_code}/?username={username}
Message Format:
{
"username": "user123",
"message": "Hello, world!",
"timestamp": "2024-01-01 12:00:00"
}GET /- Home pageGET /chat/{room_code}/- Chat room interfaceGET /summarize/?room_code={code}- AI chat summarization
*⭐ If you found this project helpful, please give it a star!