A production-ready, real-time chat application built with modern web technologies, demonstrating enterprise-grade architecture patterns for handling thousands of concurrent users.
This scalable chat application showcases how to build a robust, real-time messaging system capable of handling high-traffic scenarios while maintaining low latency and reliable message delivery. The architecture is designed with cloud deployment and horizontal scaling in mind.
- Real-time Communication: WebSocket-based messaging with Socket.IO
- Scalable Architecture: Modular backend design ready for horizontal scaling
- Message Reliability: Queue-based message processing for fault tolerance
- Security: JWT authentication and basic message encryption
- Modern UI: Responsive React interface with beautiful animations
- Load Testing: Built-in tools for performance benchmarking
- Node.js with Express.js - Event-driven server architecture
- Socket.IO - WebSocket communication for real-time messaging
- SQLite - Database (easily replaceable with PostgreSQL/MongoDB for production)
- Redis-compatible Queue - Message queuing system (in-memory for demo)
- JWT - Secure authentication
- bcryptjs - Password hashing
- Crypto-js - Message encryption
- React 18 - Modern UI library with hooks
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling
- Lucide React - Beautiful icons
- Socket.IO Client - Real-time communication
- date-fns - Date formatting utilities
- Vite - Fast development server and build tool
- ESLint - Code linting
- Load Testing - Custom Node.js load testing script
- Node.js 16+
- npm or yarn
-
Clone and install dependencies
npm install
-
Start the development servers
npm run dev
This starts both the backend server (port 3001) and frontend dev server (port 5173).
-
Open your browser Navigate to
http://localhost:5173to access the chat application.
- Create an account - Register with any username/email/password
- Join the General room - You'll be automatically added to the default room
- Start chatting - Send messages and see real-time updates
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β React Client βββββΊβ WebSocket βββββΊβ Message Queue β
β (Frontend) β β Server β β (Redis-like) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Database β
β (SQLite/PG) β
ββββββββββββββββββββ
- SocketHandler - Manages WebSocket connections and real-time events
- ChatService - Handles message processing and room management
- AuthService - JWT-based authentication and user management
- MessageQueue - Ensures reliable message delivery and scaling
- DatabaseManager - Data persistence and retrieval
- User sends message via React UI
- Socket.IO client emits to server
- Server validates and stores message in database
- Message published to queue for reliability
- Queue broadcasts to all connected clients in room
- Real-time UI updates across all connected users
- Instant message delivery via WebSockets
- Typing indicators showing when users are composing messages
- Online/offline status indicators
- Message read receipts and delivery confirmation
- Responsive Design - Works seamlessly on desktop and mobile
- Dark Theme - Easy on the eyes with modern aesthetics
- Smooth Animations - Polished micro-interactions
- Auto-scroll - Messages automatically scroll to latest
- Message Timestamps - Smart time formatting (Today, Yesterday, etc.)
- JWT Authentication - Secure, stateless user sessions
- Message Encryption - Basic encryption for message security
- Connection Recovery - Automatic reconnection on network issues
- Rate Limiting - Built-in protection against spam
- Error Handling - Graceful degradation and error recovery
Run the built-in load test to simulate concurrent users:
# Test with 50 users for 60 seconds, 0.5 messages/user/second
npm run test:load
# Custom test parameters: users, duration(s), message-rate
node tests/loadTest.js 100 120 1.0The load tester tracks:
- Concurrent Users - Number of simultaneous connections
- Messages/Second - Real-time message throughput
- Delivery Rate - Percentage of messages successfully delivered
- Connection Success - User connection success rate
- Error Rate - Failed operations and network errors
- 100 concurrent users - ~50 messages/second sustained
- Message latency - <200ms average delivery time
- Memory usage - ~100MB for 100 users (optimized for scaling)
- CPU usage - <20% on modern hardware
# Backend Dockerfile example
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY backend/ .
EXPOSE 3001
CMD ["node", "server.js"]# Horizontal scaling example
apiVersion: apps/v1
kind: Deployment
metadata:
name: chat-backend
spec:
replicas: 3 # Scale to 3 instances
selector:
matchLabels:
app: chat-backend
template:
spec:
containers:
- name: chat-backend
image: chat-app:latest
ports:
- containerPort: 3001- Database: Replace SQLite with PostgreSQL/MongoDB with connection pooling
- Message Queue: Use Redis Cluster or Apache Kafka for high availability
- Load Balancing: Deploy behind nginx or AWS ALB with sticky sessions
- Caching: Add Redis for session storage and message caching
- Monitoring: Integrate Prometheus/Grafana for metrics and alerting
- Security: Add rate limiting, DDoS protection, and enhanced encryption
- JWT Authentication - Secure, stateless authentication tokens
- Password Hashing - bcrypt with salt for secure password storage
- Message Encryption - AES encryption for message content
- Input Validation - Server-side validation for all user inputs
- CORS Configuration - Proper cross-origin resource sharing setup
- SQL Injection Prevention - Parameterized queries for database safety
This application demonstrates solutions for:
- Customer Support Chat - Real-time customer service systems
- Team Collaboration - Internal communication platforms
- Gaming Chat - In-game messaging systems
- Social Platforms - Community chat features
- Live Events - Real-time audience interaction
- Educational Platforms - Classroom discussion tools
- File and image sharing with drag-drop upload
- Voice and video calling integration
- Message reactions and emoji responses
- Advanced user roles and permissions
- Message search and filtering
- Push notifications for mobile apps
- End-to-end encryption with key exchange
- Message threading and replies
- Custom chat themes and personalization
- Analytics dashboard for chat metrics
- Redis Cluster integration for distributed caching
- Apache Kafka for enterprise message queuing
- MongoDB sharding for horizontal data scaling
- CDN integration for file sharing
- Microservices architecture with API Gateway
- Auto-scaling based on concurrent user metrics
Contributions are welcome! This project demonstrates enterprise patterns and is perfect for:
- System Design Practice - Learn distributed systems concepts
- Portfolio Projects - Showcase full-stack development skills
- Interview Preparation - Demonstrate scalable architecture knowledge
- Open Source Contributions - Add features and improvements
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Socket.IO - For excellent WebSocket library and documentation
- React Team - For the powerful UI framework
- Tailwind CSS - For the utility-first CSS framework
- Node.js Community - For the rich ecosystem of packages
- Open Source Contributors - For the amazing tools and libraries
If you encounter any issues or have questions:
- Check the Issues page for existing solutions
- Create a new issue with detailed description
- Include steps to reproduce and system information
- Tag with appropriate labels (bug, enhancement, question)
Happy Coding! π
