A production-ready, scalable real-time messaging platform built with enterprise standards
Features โข Architecture โข Quick Start โข API Documentation โข Deployment โข Contributing
- Overview
- Features
- Technology Stack
- Architecture
- Getting Started
- API Documentation
- Security
- Performance
- Project Structure
- Deployment
- Testing
- Roadmap
- Contributing
- License
FlowChat is a modern, enterprise-grade real-time messaging application designed for scalability, security, and exceptional user experience. Built with cutting-edge technologies, FlowChat provides a WhatsApp-like interface with advanced features including real-time messaging, media sharing, presence management, and multi-language support.
- โก Real-Time Communication - Instant messaging with WebSocket technology
- ๐ Enterprise Security - JWT authentication, rate limiting, input sanitization
- ๐ฑ Responsive Design - Seamless experience across all devices
- ๐ Multi-Language Support - Full RTL support for Arabic and other languages
- ๐ธ Media Sharing - High-quality image and video sharing
- ๐ Scalable Architecture - Built for high performance and scalability
- ๐ผ Production Ready - Battle-tested code with comprehensive error handling
- โ Instant Messaging - Send and receive messages in real-time
- โ Message History - Persistent message storage with MongoDB
- โ Message Status - Sent, Delivered, and Read receipts
- โ Message Reply - Reply to specific messages in conversations
- โ Message Deletion - Delete individual messages or entire chats
- โ Multi-line Messages - Support for formatted text with line breaks
- โ RTL Support - Automatic right-to-left text direction for Arabic
- โ User Registration - Secure account creation with validation
- โ Multiple Login Methods - Login with email or phone number
- โ Profile Management - Update username, email, bio, and avatar
- โ Avatar Upload - Profile picture upload with image optimization
- โ User Search - Find users by username or phone number
- โ Contact Management - Add and manage contacts easily
- โ One-on-One Chats - Private conversations between users
- โ Chat Search - Search through chat history
- โ Chat Deletion - Delete entire conversations with all messages
- โ Chat List - View all active conversations
- โ Last Message Preview - See last message in chat list
- โ Unread Message Indicators - Visual indicators for unread messages
- โ Socket.io Integration - Bidirectional real-time communication
- โ Connection Management - Automatic reconnection and connection pooling
- โ Room-Based Messaging - Efficient chat room management
- โ Event-Driven Architecture - Real-time events for all actions
- โ Online/Offline Status - Real-time user presence indicators
- โ Redis-Based Presence - Scalable presence tracking with Redis
- โ Typing Indicators - See when users are typing
- โ Auto-Timeout - Automatic offline status after inactivity
- โ New Message Alerts - Instant notifications for new messages
- โ Typing Notifications - Real-time typing indicators
- โ Status Updates - Live updates for online/offline status
- โ Message Delivery - Real-time delivery confirmations
- โ Image Upload - Share high-quality images (up to 10MB)
- โ Video Upload - Share videos (up to 50MB)
- โ Multiple Formats - Support for JPEG, PNG, GIF, WebP, MP4, MOV, AVI, MKV, WebM
- โ Image Preview - Preview images before sending
- โ Image Lightbox - Full-screen image viewing
- โ Video Playback - Inline video player with controls
- โ Media Optimization - Automatic file compression and optimization
- โ File Validation - Type and size validation before upload
- โ Secure Storage - Files stored securely on server
- โ CDN Ready - Architecture supports CDN integration
- โ Thumbnail Generation - Automatic thumbnail creation (future)
- โ WhatsApp-Like Interface - Familiar and intuitive design
- โ Responsive Design - Perfect on desktop, tablet, and mobile
- โ Smooth Animations - Fluid transitions powered by Framer Motion
- โ Dark Mode Ready - Architecture supports theme switching
- โ Loading States - Elegant loading indicators
- โ Error Handling - User-friendly error messages
- โ Accessibility - WCAG compliant components
- โ RTL Support - Full right-to-left text support for Arabic
- โ Auto-Detection - Automatic text direction detection
- โ Multi-Language Ready - Architecture supports i18n (future)
- โ Touch Optimized - Optimized for touch interactions
- โ Mobile Navigation - Sidebar navigation for mobile
- โ Responsive Layout - Adaptive layout for all screen sizes
- โ Performance - Optimized for mobile networks
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 16.0.1 | React framework with SSR and routing |
| React | 19.2.0 | UI library with hooks and context |
| TypeScript | 5.5 | Type-safe JavaScript |
| Tailwind CSS | 4.0 | Utility-first CSS framework |
| Framer Motion | 12.23 | Animation library |
| Socket.io Client | 4.8.1 | Real-time WebSocket client |
| Axios | 1.13 | HTTP client for API calls |
| Lucide React | 0.552 | Icon library |
| React Globe | 2.37 | 3D globe visualization |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | 18+ | JavaScript runtime |
| Express.js | 4.21 | Web application framework |
| TypeScript | 5.3 | Type-safe JavaScript |
| Socket.io | 4.8.1 | WebSocket server for real-time |
| MongoDB | 8.0 | NoSQL database |
| Mongoose | 8.0 | MongoDB object modeling |
| Redis (ioredis) | 5.8 | In-memory cache and presence |
| JWT | 9.0 | Authentication tokens |
| Bcrypt | 2.4 | Password hashing |
| Multer | 2.0 | File upload handling |
| Helmet | 7.1 | Security headers |
| Express Validator | 7.0 | Input validation |
| Express Rate Limit | 7.1 | Rate limiting |
- MongoDB - Primary database for persistent storage
- Redis - Caching and presence management
- File System - Media file storage (CDN-ready)
- WebSocket - Real-time communication protocol
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Frontend โ โ Backend โ โ Databases โ
โ (Next.js) โโโโโโโโโโบโ (Express) โโโโโโโโโโบโ (MongoDB) โ
โ โ HTTP โ โ โ โ
โ โข React UI โ โ โข REST API โ โ โข User Data โ
โ โข Socket.io โโโโโโโโโโบโ โข Socket.io โ โ โข Messages โ
โ Client โ WS โ Server โโโโโโโโโโบโ โข Chats โ
โ โข State Mgmt โ โ โข Controllers โ โ โ
โ โข Services โ โ โข Middleware โ โ (Redis) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ โข Presence โ
โ โข Cache โ
โโโโโโโโโโโโโโโโโโโ
-
Authentication Flow
User โ Frontend โ Backend API โ MongoDB โ JWT Token โ Frontend Storage -
Message Flow
User โ Frontend โ Socket.io โ Backend โ MongoDB โ Socket.io โ Recipient -
Presence Flow
User Online โ Socket.io โ Redis โ Socket.io โ All Connected Clients
FlowChat - RealTime Chat Application/
โโโ frontend/ # Next.js Frontend Application
โ โโโ src/
โ โ โโโ app/ # Next.js App Router
โ โ โ โโโ page.tsx # Landing page
โ โ โ โโโ login/ # Login page
โ โ โ โโโ signup/ # Signup page
โ โ โ โโโ chat/ # Chat application
โ โ โ โ โโโ page.tsx # Main chat interface
โ โ โ โโโ layout.tsx # Root layout
โ โ โ โโโ globals.css # Global styles
โ โ โโโ components/ # Reusable components
โ โ โ โโโ ui/ # Base UI components
โ โ โ โโโ ...
โ โ โโโ lib/ # Utilities and configs
โ โ โ โโโ api.ts # Axios instance
โ โ โ โโโ socket.ts # Socket.io client
โ โ โ โโโ utils.ts # Helper functions
โ โ โโโ services/ # API services
โ โ โ โโโ auth.service.ts # Authentication
โ โ โ โโโ chat.service.ts # Chat operations
โ โ โโโ hooks/ # Custom React hooks
โ โ โ โโโ useChat.ts # Chat state management
โ โ โโโ context/ # React contexts
โ โ โโโ SocketContext.tsx # Socket provider
โ โโโ public/ # Static assets
โ โ โโโ images/ # Images
โ โโโ package.json
โ โโโ tsconfig.json
โ โโโ tailwind.config.ts
โ โโโ .env.local
โ
โโโ backend/ # Express.js Backend
โ โโโ src/
โ โ โโโ config/ # Configuration files
โ โ โ โโโ database.ts # MongoDB connection
โ โ โ โโโ redis.ts # Redis connection
โ โ โโโ controllers/ # Request handlers
โ โ โ โโโ auth.controller.ts # Authentication logic
โ โ โ โโโ chat.controller.ts # Chat operations
โ โ โโโ middleware/ # Express middleware
โ โ โ โโโ auth.middleware.ts # JWT verification
โ โ โ โโโ errorHandler.ts # Error handling
โ โ โ โโโ rateLimiter.ts # Rate limiting
โ โ โ โโโ upload.middleware.ts # File upload
โ โ โ โโโ validation.middleware.ts
โ โ โโโ models/ # Mongoose schemas
โ โ โ โโโ User.model.ts # User schema
โ โ โ โโโ Chat.model.ts # Chat schema
โ โ โ โโโ Message.model.ts # Message schema
โ โ โ โโโ Friend.model.ts # Friend schema
โ โ โโโ routes/ # API routes
โ โ โ โโโ auth.routes.ts # Auth endpoints
โ โ โ โโโ chat.routes.ts # Chat endpoints
โ โ โโโ socket/ # Socket.io handlers
โ โ โ โโโ socket.ts # WebSocket logic
โ โ โโโ utils/ # Utility functions
โ โ โ โโโ AppError.ts # Custom errors
โ โ โ โโโ catchAsync.ts # Async wrapper
โ โ โโโ server.ts # Express app entry
โ โโโ public/ # Static files
โ โ โโโ uploads/ # User uploads
โ โ โโโ avatars/ # Profile pictures
โ โ โโโ chat-media/ # Chat media files
โ โโโ package.json
โ โโโ tsconfig.json
โ โโโ .env
โ
โโโ README.md # This file
Before you begin, ensure you have the following installed:
- Node.js (v18.0 or higher) - Download
- npm (v9.0 or higher) or yarn
- MongoDB (v6.0 or higher) - Download
- Redis (v7.0 or higher) - Download
-
Clone the repository
git clone https://github.com/yourusername/flowchat.git cd flowchat -
Install dependencies
# Frontend cd frontend npm install # Backend cd ../backend npm install
-
Configure environment variables
Create
.env.localinfrontend/:NEXT_PUBLIC_API_URL=http://localhost:5000/api NEXT_PUBLIC_SOCKET_URL=http://localhost:5000
Create
.envinbackend/:PORT=5000 NODE_ENV=development MONGODB_URI=mongodb://localhost:27017/FlowChat REDIS_URL=redis://localhost:6379 JWT_SECRET=your-super-secret-jwt-key-change-in-production JWT_EXPIRE=7d JWT_COOKIE_EXPIRE=7 FRONTEND_URL=http://localhost:3000 RATE_LIMIT_WINDOW_MS=900000 RATE_LIMIT_MAX_REQUESTS=100
-
Start MongoDB and Redis
# MongoDB mongod # Redis redis-server
-
Start the application
# Terminal 1 - Backend cd backend npm run dev # Terminal 2 - Frontend cd frontend npm run dev
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000/api
- WebSocket: ws://localhost:5000
-
Navigate to frontend directory
cd frontend -
Install dependencies
npm install
-
Environment configuration
Create
.env.local:NEXT_PUBLIC_API_URL=http://localhost:5000/api NEXT_PUBLIC_SOCKET_URL=http://localhost:5000
-
Development server
npm run dev
Access at: http://localhost:3000
-
Production build
npm run build npm start
- Server-Side Rendering (SSR) - Fast initial page loads
- Code Splitting - Optimized bundle sizes
- Image Optimization - Automatic image optimization
- Hot Module Replacement - Instant updates during development
-
Navigate to backend directory
cd backend -
Install dependencies
npm install
-
Environment configuration
Create
.env:# Server PORT=5000 NODE_ENV=development # Database MONGODB_URI=mongodb://localhost:27017/FlowChat REDIS_URL=redis://localhost:6379 # Authentication JWT_SECRET=your-super-secret-jwt-key-min-32-chars JWT_EXPIRE=7d JWT_COOKIE_EXPIRE=7 # CORS FRONTEND_URL=http://localhost:3000 # Rate Limiting RATE_LIMIT_WINDOW_MS=900000 RATE_LIMIT_MAX_REQUESTS=100
-
Start MongoDB
# Windows net start MongoDB # macOS/Linux sudo systemctl start mongod # or mongod
-
Start Redis
# Windows (if installed) redis-server # macOS brew services start redis # Linux sudo systemctl start redis
-
Development server
npm run dev
Access at: http://localhost:5000
-
Production build
npm run build npm start
Development: http://localhost:5000/api
Production: https://api.flowchat.com/api
POST /api/auth/register
Content-Type: application/json
{
"username": "johndoe",
"email": "john@example.com",
"phone": "+1234567890",
"password": "SecurePass123!",
"confirmPassword": "SecurePass123!",
"countryCode": "+1"
}Response:
{
"success": true,
"message": "User registered successfully",
"data": {
"user": {
"id": "65f1234567890abcdef12345",
"username": "johndoe",
"email": "john@example.com",
"username": "johndoe",
"isEmailVerified": false,
"createdAt": "2024-01-01T00:00:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}POST /api/auth/login
Content-Type: application/json
{
"emailOrPhone": "john@example.com",
"password": "SecurePass123!"
}Response:
{
"success": true,
"message": "Login successful",
"data": {
"user": {
"id": "65f1234567890abcdef12345",
"username": "johndoe",
"email": "john@example.com",
"avatar": "/uploads/avatars/avatar-123.jpg",
"lastLogin": "2024-01-01T00:00:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}GET /api/auth/me
Authorization: Bearer YOUR_JWT_TOKENPOST /api/auth/upload-avatar
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
avatar: [binary file]PATCH /api/auth/update-profile
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json
{
"username": "newusername",
"bio": "My bio",
"email": "newemail@example.com"
}PATCH /api/auth/update-password
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json
{
"currentPassword": "OldPass123!",
"newPassword": "NewPass123!",
"confirmNewPassword": "NewPass123!"
}GET /api/chat/search/users?query=johndoe
Authorization: Bearer YOUR_JWT_TOKENPOST /api/chat
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json
{
"userId": "65f1234567890abcdef12345"
}GET /api/chat
Authorization: Bearer YOUR_JWT_TOKENGET /api/chat/:id
Authorization: Bearer YOUR_JWT_TOKENGET /api/chat/:id/messages?page=1&limit=50
Authorization: Bearer YOUR_JWT_TOKENDELETE /api/chat/:id
Authorization: Bearer YOUR_JWT_TOKENPOST /api/chat/upload-media
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data
media: [binary file (image or video)]Response:
{
"success": true,
"data": {
"url": "/uploads/chat-media/media-1234567890.jpg",
"type": "image",
"filename": "media-1234567890.jpg",
"size": 1024000,
"mimetype": "image/jpeg"
}
}const socket = io('http://localhost:5000', {
auth: {
token: 'YOUR_JWT_TOKEN'
}
});Client โ Server:
-
chat:join- Join a chat roomsocket.emit('chat:join', chatId);
-
chat:leave- Leave a chat roomsocket.emit('chat:leave', chatId);
-
message:send- Send a messagesocket.emit('message:send', { chatId: 'chat_id', content: 'Hello!', type: 'text', // 'text' | 'image' | 'video' fileUrl: '/uploads/chat-media/media.jpg', // optional replyTo: 'message_id' // optional });
-
typing:start- Start typing indicatorsocket.emit('typing:start', chatId);
-
typing:stop- Stop typing indicatorsocket.emit('typing:stop', chatId);
-
message:read- Mark message as readsocket.emit('message:read', { messageId: 'message_id', chatId: 'chat_id' });
Server โ Client:
-
message:receive- New message receivedsocket.on('message:receive', (data) => { console.log('New message:', data.message); });
-
typing:update- Typing status updatesocket.on('typing:update', (data) => { console.log('User typing:', data.userId, data.chatId); });
-
user:online- User came onlinesocket.on('user:online', (data) => { console.log('User online:', data.userId); });
-
user:offline- User went offlinesocket.on('user:offline', (data) => { console.log('User offline:', data.userId); });
-
message:error- Message errorsocket.on('message:error', (data) => { console.error('Message error:', data.error); });
- JWT Tokens - Secure, stateless authentication
- HttpOnly Cookies - Protection against XSS attacks
- Token Expiration - 7-day token expiry with refresh capability
- Password Hashing - Bcrypt with 12 salt rounds
X-DNS-Prefetch-ControlX-Frame-Options: DENYX-Content-Type-Options: nosniffX-XSS-Protection: 1; mode=blockContent-Security-PolicyStrict-Transport-Security
- Express Validator - Server-side validation
- NoSQL Injection Prevention - Express Mongo Sanitize
- XSS Protection - Input sanitization
- File Upload Validation - Type and size validation
- General API: 100 requests per 15 minutes
- Authentication: 5 attempts per 15 minutes
- File Upload: 10 uploads per hour
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character (recommended)
- Whitelist-based origin validation
- Credentials support
- Method and header restrictions
- Server-Side Rendering - Fast initial page loads
- Code Splitting - Route-based code splitting
- Image Optimization - Next.js Image component
- Lazy Loading - Dynamic imports for heavy components
- Memoization - React.memo and useMemo for expensive operations
- Virtual Scrolling - Efficient message list rendering (future)
- Database Indexing - Optimized MongoDB queries
- Redis Caching - Presence and session caching
- Connection Pooling - MongoDB connection pooling
- Async Operations - Non-blocking I/O operations
- File Compression - Gzip compression for responses
- Horizontal Scaling - Stateless architecture
- Load Balancing Ready - Session-less design
- CDN Integration - Static asset delivery
- Database Sharding - MongoDB sharding support
- Redis Clustering - Redis cluster support
See Architecture section for detailed structure.
NEXT_PUBLIC_API_URL=https://api.flowchat.com/api
NEXT_PUBLIC_SOCKET_URL=https://api.flowchat.comPORT=5000
NODE_ENV=production
MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/FlowChat
REDIS_URL=redis://redis-server:6379
JWT_SECRET=production-secret-key-min-32-characters
JWT_EXPIRE=7d
JWT_COOKIE_EXPIRE=7
FRONTEND_URL=https://flowchat.com
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100cd frontend
vercel deploy- Connect your repository
- Set environment variables
- Deploy automatically
# Dockerfile example
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
CMD ["npm", "start"]- Update JWT_SECRET to strong random string
- Set NODE_ENV=production
- Configure MongoDB connection string
- Configure Redis connection
- Set up CDN for media files
- Configure SSL certificates
- Set up monitoring and logging
- Configure backups
- Set up error tracking (Sentry)
- Configure rate limiting
- Set up CI/CD pipeline
# Register
curl -X POST http://localhost:5000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "Test123456!",
"confirmPassword": "Test123456!"
}'
# Login
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"emailOrPhone": "test@example.com",
"password": "Test123456!"
}'Use tools like:
- Postman - API testing and documentation
- Insomnia - REST client
- Thunder Client - VS Code extension
// Test socket connection
const socket = io('http://localhost:5000', {
auth: { token: 'YOUR_TOKEN' }
});
socket.on('connect', () => {
console.log('Connected!');
});- User authentication and registration
- Real-time messaging with Socket.io
- One-on-one chats
- Message status (sent, delivered, read)
- Typing indicators
- Online/offline status
- Profile management
- Avatar upload
- Media sharing (images and videos)
- Message reply functionality
- Chat deletion
- User search
- RTL language support
- Multi-line messages
- Image lightbox
- Group chats
- Message reactions
- Message forwarding
- Voice messages
- Video calls
- Screen sharing
- File sharing (documents)
- End-to-end encryption
- Message search
- Message archiving
- Push notifications
- Email notifications
- Two-factor authentication
- Admin dashboard
- Analytics and reporting
- AI chatbot integration
- Voice-to-text transcription
- Message translation
- Custom themes
- Stickers and emoji packs
- Bot API
- Webhooks
- API for third-party integrations
We welcome contributions! Please follow these steps:
- 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
- Follow TypeScript best practices
- Write meaningful commit messages
- Add tests for new features
- Update documentation
- Follow code style guidelines
- Ensure all tests pass
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- ๐ง Email: Ahmadjx1stt@gmail.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: Full Documentation
- ๐ฌ Discussions: GitHub Discussions
- Next.js Team - Amazing React framework
- Express.js - Robust web framework
- Socket.io - Real-time communication
- MongoDB - Flexible database solution
- Redis - Fast in-memory data store
- Framer Motion - Beautiful animations
- Tailwind CSS - Utility-first CSS
- All Contributors - Who made this project possible
- โญ Stars: Growing daily
- ๐ด Forks: Active development
- ๐ฅ Contributors: Welcoming new contributors
- ๐ฆ Downloads: Increasing adoption
- ๐ Issues Resolved: 100% response rate





