A robust, scalable backend server for the Msgbits real-time messaging platform, built with Express.js and TypeScript. Features secure communication, distributed processing, comprehensive logging, and efficient file handling.
- Features
- Demo
- Screenshots
- Tech Stack
- Architecture
- Installation
- Development
- Deployment
- API Documentation
- Contributing
- License
- Support
-
Real-Time Communication
- Socket.IO with Redis adapter for scalable real-time messaging
- WebRTC signaling server for audio/video calls
- Message queuing with BullMQ for reliable message delivery
- Real-time user status tracking
-
File Management
- Secure file uploads with chunked streaming
- On-the-fly file encryption/decryption
- Support for EC2 filesystem and S3 storage
- Efficient media handling
-
Authentication & Security
- JWT-based authentication
- OAuth integration (Google, Facebook, GitHub)
- Email verification with Nodemailer
- Rate limiting and request validation
-
Logging & Monitoring
- Comprehensive logging with Winston and Morgan
- Production logs stored in both filesystem and database
- Request tracking and error monitoring
Experience the application live at: Live Demo
Clean, modern landing page showcasing key features and user benefits
Secure login interface with multiple authentication options and OTP verification
Feature-rich chat interface with intuitive navigation and real-time status updates
High-quality video conferencing with up to 4 participants and easy-to-use controls
Comprehensive file sharing interface with image preview, shared media gallery, and chat room details panel
Advanced group management interface with member controls and admin privileges
Real-time group chat interface with member list and shared media gallery
Four distinct theme options for personalized user experience
-
Distributed Architecture
- Stateless server design using Redis for temporary state
- MongoDB for persistent data storage
- Node.js cluster support for horizontal scaling
-
Performance Optimization
- Redis caching layer
- Efficient database queries
- Optimized file streaming
- Message broker for async operations
- Core Framework: Express.js, TypeScript
- Database: MongoDB
- Caching: Redis
- Message Queue: BullMQ
- File Processing: Busboy
- Email Service: Nodemailer
- Documentation: Swagger
- Logging: Winston, Morgan
- Validation: Zod
- Real-time: Socket.IO
βββββββββββββββ
β Client β
ββββββββ¬βββββββ
β
ββββββββΌβββββββ
βLoad Balancerβ
ββββββββ¬βββββββ
β
ββββββββββββββββββββ¬β΄β¬βββββββββββββββββββ
β β β β
βββββββΌβββββ βββββββΌββΌβββββ βββββββΌβββββ
β Express.jsβ β Express.js β β Express.jsβ
β Server β β Server β β Server β
βββββββ¬βββββ βββββββ¬βββββββ βββββββ¬βββββ
β β β
ββββββββββββ΄ββββββββββββββββββΌβββββββββββββββββββββ΄βββββββββββ
β β β
ββββββΌβββββ βββββββΌββββββ ββββββΌβββββ
β Redis β β MongoDB β β S3 β
βββββββββββ βββββββββββββ βββββββββββ
- Clone the repository:
git clone https://github.com/kr-ashwani/msgbits_backend.git
cd msgbits-backend- Install dependencies:
npm install- Create
.envfile:
MONGODB_URI_PROD = mongodb_prod_uri
MONGODB_URI_DEV = mongodb_dev_uri
NODE_ENV = node_environment
MONGODB_URI_LOG = mongodb_log_uri
REDIS_PORT = redis_port
REDIS_HOST = redis_host
REFRESH_TOKEN_SECRET_KEY_PROD = prod_refresh_token
REFRESH_TOKEN_SECRET_KEY_DEV = dev_refresh_token
REFRESH_TOKEN_EXP_TIME = refresh_token_exp_time
SMTP_SERVICE = smtp_service
SMTP_PORT = smtp_port
SMTP_SECURE = smtp_secure
SMTP_USER = smtp_user
SMTP_PASS = smtp_password
CLIENT_URL = client_url
SELF_URL = self_url
GITHUB_OAUTH_CLIENT_ID = github_oauth_client_id
GITHUB_OAUTH_CLIENT_SECRET = github_oauth_client_id
REDIRECT_CLIENT_URL = client_redirect_url
GOOGLE_CLIENT_ID = google_oauth_client_id
UPLOAD_FILES_TO_S3 = upload_to_s3
AWS_REGION = aws_region
AWS_ACCESS_KEY_ID = aws_access_key
AWS_SECRET_ACCESS_KEY = aws_secret_key
S3_BUCKET = s3_bucket
ENCRYPTION_KEY = enc_key
SOCKETUI_USERNAME = socket_ui_username
SOCKETUI_PASSWORD = socket_ui_password- Start development server:
npm run devsrc/
βββ config/ # Configuration files
βββ controllers/ # Route controllers
βββ middleware/ # Custom middleware
βββ models/ # Database models
βββ routes/ # API routes
βββ services/ # Business logic
βββ utils/ # Utility functions
βββ validators/ # Zod schemas
- Use TypeScript strict mode
- Implement proper error handling
- Write comprehensive tests
- Follow consistent coding style
- Document API endpoints
- Log important events
The application uses GitHub Actions for automated deployment to EC2:
-
On push to main branch:
- Build is triggered
- Tests are run
- Docker image is created and pushed to registry
- New image is deployed to EC2
-
Production Environment:
- Running on EC2 instance
- Redis container for caching and session management
- Environment variables loaded from production config
- Automated SSL certificate renewal
-
Monitoring:
- Application logs stored on EC2 and database
- Error tracking and alerting
- Resource utilization monitoring
- Horizontal scaling using Node.js cluster
- Redis for session storage across instances
- Load balancer distribution
- Auto-scaling based on metrics
API documentation available at /api-docs when running the server, featuring:
- Complete endpoint documentation
- Request/response schemas
- Authentication details
- Example requests
- Error responses
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
- Email: support@msgbits.com
- Discord: Join our community