A modern, real-time chat application built with React and Django, featuring WebSocket connections for instant messaging and live user presence tracking.
- Real-time Messaging: Instant message delivery using WebSockets
- User Authentication: Secure login/logout with JWT tokens
- Live User Status: See who's online/offline in real-time
- Responsive Design: Works seamlessly on desktop and mobile devices
- User Management: User registration, profile management, and admin panel
- Message History: Persistent chat messages with database storage
- Online Filtering: Toggle to show only online users
- Modern UI: Clean, intuitive interface built with Tailwind CSS
- React 19 - Modern UI library with latest features
- Vite - Fast build tool and development server
- Tailwind CSS - Utility-first CSS framework
- Zustand - Lightweight state management
- React Router - Client-side routing
- Axios - HTTP client for API calls
- React Hot Toast - Beautiful notifications
- Lucide React - Modern icon library
- Django 5.2 - Python web framework
- Django REST Framework - API development
- Django Channels - WebSocket support
- Redis - Message broker for WebSockets
- JWT Authentication - Secure token-based auth
- SQLite - Default database (easily configurable)
- CORS Headers - Cross-origin resource sharing
- Cloudinary - Media file management (optional)
Before running this application, make sure you have:
- Node.js (v18.0.0 or higher)
- npm (v9.0.0 or higher)
- Python (3.8 or higher)
- pip (Python package manager)
- Redis Server (for WebSocket functionality)
git clone https://github.com/Andhar7/chat_app_mini.git
cd chat_app_mininpm run install:allThis installs both frontend (npm) and backend (pip) dependencies.
npm run migratenpm run createsuperusernpm run devThis starts both the Django backend and React frontend simultaneously.
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- Django Admin: http://localhost:8000/admin
chat_app_mini/
├── backend/ # Django backend
│ ├── accounts/ # User authentication app
│ ├── chat/ # Django project settings
│ ├── chat_messages/ # Chat functionality app
│ ├── manage.py # Django management script
│ └── requirements.txt # Python dependencies
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Page components
│ │ ├── store/ # Zustand state management
│ │ ├── lib/ # Utility functions
│ │ └── App.jsx # Main app component
│ ├── public/ # Static assets
│ └── package.json # Frontend dependencies
├── package.json # Root package.json with scripts
└── README.md # This file
# Start both frontend and backend servers
npm run dev
# Start only frontend (React + Vite)
npm run dev:frontend
# Start only backend (Django)
npm run dev:backend# Install all dependencies (frontend + backend)
npm run install:all
# Install only frontend dependencies
npm run install:frontend
# Install only backend dependencies
npm run install:backend# Build frontend for production
npm run build
# Build frontend (alternative)
npm run build:frontend# Run frontend linting
npm run lint
# Run backend tests
npm run test:backend# Apply database migrations
npm run migrate
# Create new migrations
npm run makemigrations
# Create Django superuser
npm run createsuperuser
# Collect static files (production)
npm run collectstaticThe backend uses environment variables for configuration. Create a .env file in the backend/ directory:
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
REDIS_URL=redis://localhost:6379The frontend automatically connects to the backend at http://localhost:8000. For production, update the API base URL in the frontend configuration.
POST /api/accounts/register/- User registrationPOST /api/accounts/login/- User loginPOST /api/accounts/logout/- User logoutGET /api/accounts/profile/- Get user profile
GET /api/chat/messages/- Get chat messagesPOST /api/chat/messages/- Send new messageGET /api/chat/users/- Get all usersGET /api/chat/online-users/- Get online users
ws://localhost:8000/ws/chat/- Real-time chat connectionws://localhost:8000/ws/presence/- User presence tracking
- JWT Authentication: Secure token-based authentication
- CORS Protection: Configured cross-origin resource sharing
- Input Validation: Django REST framework serializers
- SQL Injection Protection: Django ORM prevents SQL injection
- XSS Protection: React's built-in XSS protection
- Build the frontend:
npm run build:frontend
- Deploy the
frontend/distfolder to your hosting service (Netlify, Vercel, etc.)
- Set up production environment variables
- Collect static files:
npm run collectstatic
- Apply migrations:
npm run migrate
- Deploy to your hosting service (Heroku, DigitalOcean, AWS, etc.)
# Run Django tests
npm run test:backend
# Run specific test
cd backend && python manage.py test accounts.tests.TestUserModelThe frontend uses ESLint for code quality:
npm run lint:frontend- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Run tests:
npm run test:backend && npm run lint - Commit changes:
git commit -m 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
1. WebSocket Connection Failed
- Ensure Redis server is running:
redis-server - Check if backend is running on port 8000
2. CORS Errors
- Verify
django-cors-headersis installed - Check CORS settings in
backend/chat/settings.py
3. Database Migration Errors
# Reset migrations if needed
cd backend
rm -rf */migrations/
python manage.py makemigrations accounts chat_messages
python manage.py migrate4. Frontend Build Errors
- Clear node_modules and reinstall:
cd frontend rm -rf node_modules package-lock.json npm install
5. Python Dependencies Issues
- Use a virtual environment:
cd backend python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
This project is licensed under the MIT License - see the LICENSE file for details.
Created with ❤️ by Andhar7
- Django and React communities for excellent documentation
- Contributors to the open-source libraries used in this project
- WebSocket technology for enabling real-time communication
Note: This is a mini chat application designed for learning and development purposes. For production use, consider additional security measures, scalability optimizations, and comprehensive testing.