{"id":17712590,"url":"https://github.com/jmrashed/chat-backend","last_synced_at":"2026-04-30T20:33:49.262Z","repository":{"id":258216938,"uuid":"873631326","full_name":"jmrashed/chat-backend","owner":"jmrashed","description":"This is the server-side of a real-time chat application with file-sharing capabilities. Built using Node.js, Express, Socket.IO, and MongoDB","archived":false,"fork":false,"pushed_at":"2025-10-07T18:17:54.000Z","size":1746,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-30T20:33:47.963Z","etag":null,"topics":["api","express","mongodb"],"latest_commit_sha":null,"homepage":"https://chat.rasheduzzaman.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmrashed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-16T13:42:42.000Z","updated_at":"2025-10-14T15:57:16.000Z","dependencies_parsed_at":"2024-10-19T00:15:40.720Z","dependency_job_id":null,"html_url":"https://github.com/jmrashed/chat-backend","commit_stats":null,"previous_names":["jmrashed/chat-backend","mrzstack/chat-backend"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jmrashed/chat-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmrashed%2Fchat-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmrashed%2Fchat-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmrashed%2Fchat-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmrashed%2Fchat-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmrashed","download_url":"https://codeload.github.com/jmrashed/chat-backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmrashed%2Fchat-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32476682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","express","mongodb"],"created_at":"2024-10-25T09:05:40.376Z","updated_at":"2026-04-30T20:33:49.256Z","avatar_url":"https://github.com/jmrashed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Real-Time Chat Application (Server)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)\n[![Express.js](https://img.shields.io/badge/Express.js-4.19.2-000000)](https://expressjs.com/)\n[![Socket.IO](https://img.shields.io/badge/Socket.IO-4.8.1-010101)](https://socket.io/)\n[![MongoDB](https://img.shields.io/badge/MongoDB-7.0.14-47A248)](https://www.mongodb.com/)\n[![Mongoose](https://img.shields.io/badge/Mongoose-8.7.0-880000)](https://mongoosejs.com/)\n[![JWT](https://img.shields.io/badge/JWT-9.0.2-000000)](https://jwt.io/)\n[![Bcrypt](https://img.shields.io/badge/Bcrypt-5.1.1-3178C6)](https://www.npmjs.com/package/bcrypt)\n[![Joi](https://img.shields.io/badge/Joi-17.13.3-blue)](https://joi.dev/)\n[![Jest](https://img.shields.io/badge/Jest-29.7.0-C21325)](https://jestjs.io/)\n[![Docker](https://img.shields.io/badge/Docker-Ready-2496ED)](https://www.docker.com/)\n[![API](https://img.shields.io/badge/API-RESTful-FF6C37)](https://restfulapi.net/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)\n[![GitHub Stars](https://img.shields.io/github/stars/jmrashed/chat-backend?style=social)](https://github.com/jmrashed/chat-backend/stargazers)\n[![GitHub Forks](https://img.shields.io/github/forks/jmrashed/chat-backend?style=social)](https://github.com/jmrashed/chat-backend/network/members)\n\nThis is the server-side of a real-time chat application with file-sharing capabilities. Built using **Node.js**, **Express**, **Socket.IO**, and **MongoDB**, it allows users to join chat rooms, send/receive real-time messages, and share files using Node.js streams and buffers. User authentication, chat history, and file metadata are stored securely in MongoDB.\n\n## Related Repositories\n\n**Frontend Client**: For the complete chat application experience, you'll also need the frontend client. Check out the [Chat Frontend Repository](https://github.com/jmrashed/chat-frontend) which provides:\n- Modern Next.js React interface\n- Real-time UI updates\n- Responsive design\n- Optimized performance\n- Socket.IO client integration\n\n## Features\n\n### Core Messaging\n- **Real-time Communication**: Users can send and receive messages in real-time using Socket.IO\n- **Message Reactions**: React to messages with emojis, real-time reaction updates\n- **Message Editing/Deletion**: Edit sent messages and soft delete with permissions\n- **Message Threads/Replies**: Reply to specific messages and create threaded conversations\n- **Mentions**: @mention functionality with real-time notifications\n- **Message Status**: Sent, delivered, and read status indicators\n- **Typing Indicators**: Real-time \"user is typing\" notifications\n- **Message Search**: Full-text search within chat history with pagination\n- **Pinned Messages**: Pin important messages to chat rooms\n- **Starred Messages**: Personal message bookmarking system\n\n### File \u0026 Media\n- **File Sharing**: Efficient file uploads/downloads with Node.js streams and buffers\n- **File Metadata**: Store and retrieve file information with messages\n\n### Authentication \u0026 Security\n- **User Authentication**: Secure JWT-based login and registration\n- **Permission System**: Role-based access control for message operations\n- **Input Validation**: Comprehensive Joi-based validation\n- **Rate Limiting**: Configurable rate limits for different endpoints\n\n### Data \u0026 Performance\n- **Persistent Storage**: MongoDB with optimized schemas and indexing\n- **Real-time Updates**: Socket.IO events for all messaging features\n- **Scalability**: Horizontal scaling support with concurrent user optimization\n- **Comprehensive Testing**: 80%+ coverage with unit, integration, and performance tests\n\n## Technologies Used\n\n- **Node.js**: JavaScript runtime for building server-side logic\n- **Express**: Fast web framework for Node.js with RESTful API design\n- **Socket.IO**: Real-time, bidirectional communication with comprehensive event handling\n- **MongoDB**: NoSQL database with optimized schemas for chat features\n- **Mongoose**: ODM for MongoDB with advanced querying and population\n- **JWT**: Secure user authentication using JSON Web Tokens\n- **Joi**: Schema validation for all API endpoints\n- **Bcrypt**: Password hashing and security\n- **Multer**: File upload handling with stream processing\n- **Jest**: Comprehensive testing framework\n\n## Project Structure\n\n```bash\n.\n├── .env.example\n├── .gitignore\n├── LICENSE\n├── package.json\n├── README.md\n├── API.md\n├── CHANGELOG.md\n├── CONTRIBUTING.md\n├── CODE_OF_CONDUCT.md\n├── SECURITY.md\n├── swagger.js\n├── seeder.js\n├── .github/\n│   ├── ISSUE_TEMPLATE/\n│   │   ├── bug_report.md\n│   │   ├── feature_request.md\n│   │   └── question.md\n│   └── PULL_REQUEST_TEMPLATE.md\n├── src/\n│   ├── app.js\n│   ├── config/\n│   │   ├── database.js\n│   │   ├── environment.js\n│   │   ├── jwtConfig.js\n│   │   └── socket.js\n│   ├── controllers/\n│   │   ├── authController.js\n│   │   ├── chatController.js\n│   │   ├── chatRoomController.js\n│   │   └── fileController.js\n│   ├── middleware/\n│   │   ├── authMiddleware.js\n│   │   ├── errorHandler.js\n│   │   └── rateLimiter.js\n│   ├── models/\n│   │   ├── ChatRoom.js\n│   │   ├── File.js\n│   │   ├── Message.js\n│   │   └── User.js\n│   ├── routes/\n│   │   ├── authRoutes.js\n│   │   ├── chatRoomRoutes.js\n│   │   └── chatRoutes.js\n│   ├── services/\n│   │   ├── authService.js\n│   │   ├── chatService.js\n│   │   ├── fileService.js\n│   │   ├── messageService.js\n│   │   └── socketService.js\n│   ├── utils/\n│   │   ├── fileUpload.js\n│   │   ├── logger.js\n│   │   └── responseFormatter.js\n│   └── validations/\n│       ├── auth.js\n│       ├── chatRoom.js\n│       ├── file.js\n│       └── message.js\n├── tests/\n│   ├── auth.test.js\n│   ├── chat.test.js\n│   ├── chatRoom.test.js\n│   ├── fileUpload.test.js\n│   ├── integration.test.js\n│   ├── message.test.js\n│   └── performance.test.js\n├── uploads/\n└── views/\n    ├── layouts/\n    └── *.ejs\n```\n \n\n## Installation\n\n### Prerequisites\n\n- **Node.js** (version 14 or above)\n- **MongoDB** (locally or cloud-hosted)\n- **Docker** (optional, for containerized deployment)\n\n### Step-by-Step Setup\n\n1. **Clone the repository:**\n\n    ```bash\n    git clone https://github.com/jmrashed/chat-backend.git\n    cd chat-backend\n    ```\n\n2. **Install dependencies:**\n\n    ```bash\n    npm install\n    ```\n\n3. **Create a `.env` file:**\n\n    In the root of the project directory, create a `.env` file with the following content:\n\n    ```env\n    PORT=3000\n    MONGODB_URI=mongodb://localhost:27017/realtime-chat-app\n    JWT_SECRET=your_secret_key\n    ```\n\n4. **Start MongoDB:**\n\n    Make sure MongoDB is running locally or connect to your cloud MongoDB instance.\n\n    ```bash\n    mongod\n    ```\n\n5. **Run the server:**\n\n    Start the application with:\n\n    ```bash\n    npm start\n    ```\n\n6. **Access the Application:**\n\n    Open your browser and navigate to `http://localhost:3000`.\n\n## Running Tests\n\nComprehensive test suite covering unit, integration, and performance tests:\n\n```bash\n# Run all tests\nnpm test\n\n# Run specific test suites\nnpm run test:unit          # Unit tests (auth, chat rooms, messages, files)\nnpm run test:integration   # Integration tests (full API flows)\nnpm run test:performance   # Performance tests (load testing)\nnpm run test:coverage      # Generate coverage report\nnpm run test:watch         # Watch mode for development\n```\n\n## Docker Setup\n\nTo run the server in a Docker container:\n\n1. **Build the Docker image:**\n\n    ```bash\n    docker build -t realtime-chat-app-server .\n    ```\n\n2. **Run the Docker container:**\n\n    ```bash\n    docker run -d -p 3000:3000 realtime-chat-app-server\n    ```\n\n3. **Access the Application:**\n\n    Navigate to `http://localhost:3000` to use the chat application.\n\n## API Documentation\n\nFor API documentation, you can explore the endpoints through Postman or Swagger:\n\n- **Postman Documentation**: [Postman Collection](your-postman-link)\n- **Swagger UI**: Available locally at `/api-docs` after starting the server.\n\n## Scalability and Optimization\n\n- **Horizontal Scaling**: Cluster the app or use multiple instances behind a load balancer.\n- **Redis**: Use Redis to handle session management and WebSocket scaling with Socket.IO.\n- **Database Indexing**: Ensure MongoDB collections are indexed for optimal query performance.\n- **Rate Limiting**: Implement rate limiting to control API usage and prevent server overload.\n\n## Quality Assurance\n\n### Error Handling\nRobust error handling throughout the application:\n- Invalid JWT tokens and authentication failures\n- Database connection and query errors\n- File upload/download issues and validation\n- Input validation with detailed error messages\n- Consistent error response format\n\n### Testing\n- **Unit Tests**: Individual component testing (auth, rooms, messages, files)\n- **Integration Tests**: Full API workflow testing\n- **Performance Tests**: Load testing and concurrent user simulation\n- **Coverage**: 80%+ test coverage with detailed reports\n\n### Security\n- Rate limiting on all endpoints (configurable per endpoint type)\n- Input validation and sanitization\n- File type and size restrictions\n- Environment-specific CORS configuration\n- Secure password hashing with bcrypt\n\n### Code Quality\n- JSDoc documentation for all functions\n- Consistent error handling patterns\n- Environment-specific configurations\n- Clean, maintainable code structure\n\n## API Endpoints\n\n### Messages\n- `POST /api/chat/messages` - Send message with optional reply/mentions\n- `GET /api/chat/messages/:room` - Get messages with pagination\n- `PUT /api/chat/messages/:id` - Edit message (owner only)\n- `DELETE /api/chat/messages/:id` - Soft delete message (owner only)\n- `GET /api/chat/messages/search` - Search messages with filters\n\n### Reactions\n- `POST /api/chat/messages/:id/react` - Add emoji reaction\n- `DELETE /api/chat/messages/:id/react/:reactionId` - Remove reaction\n\n### Message Status\n- `PUT /api/chat/messages/:id/read` - Mark message as read\n- `PUT /api/chat/messages/:id/pin` - Pin/unpin message\n\n### Favorites\n- `POST /api/chat/favorites` - Add message to favorites\n- `DELETE /api/chat/favorites/:messageId` - Remove from favorites\n- `GET /api/chat/favorites` - Get user's favorite messages\n\n### Socket Events\n- `sendMessage`, `receiveMessage`, `receiveReply`\n- `addReaction`, `removeReaction`, `reactionAdded`, `reactionRemoved`\n- `editMessage`, `deleteMessage`, `messageEdited`, `messageDeleted`\n- `markAsRead`, `messageRead`, `messageDelivered`\n- `typingStart`, `typingStop`, `userTyping`, `userStoppedTyping`\n- `pinMessage`, `messagePinned`, `messageUnpinned`\n- `mention` - Real-time mention notifications\n\n## Future Improvements\n\n- **Push Notifications**: Mobile and web push notifications for mentions\n- **Voice Messages**: Audio message recording and playback\n- **Message Encryption**: End-to-end encryption for sensitive conversations\n- **Advanced Search**: Search by date range, file type, user, etc.\n- **Message Templates**: Quick reply templates and saved responses\n- **Admin Dashboard**: Comprehensive admin panel for user and content management\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE). \n\n\n ## Screenshots\n\nHere are some screenshots of the project:\n\n### Screenshot 1\n![Screenshot 1](docs/1.png)\n\n## 👨💻 Author\n\n**Md Rasheduzzaman**  \nFull-Stack Software Engineer \u0026 Technical Project Manager  \n\nBuilding scalable, secure \u0026 AI-powered SaaS platforms across ERP, HRMS, CRM, LMS, and E-commerce domains.  \nOver 10 years of experience leading full-stack teams, cloud infrastructure, and enterprise-grade software delivery.\n\n**🌐 Portfolio:** [jmrashed.github.io](https://jmrashed.github.io/)  \n**✉️ Email:** [jmrashed@gmail.com](mailto:jmrashed@gmail.com)  \n**💼 LinkedIn:** [linkedin.com/in/jmrashed](https://www.linkedin.com/in/jmrashed/)  \n**📝 Blog:** [medium.com/@jmrashed](https://medium.com/@jmrashed)  \n**💻 GitHub:** [github.com/jmrashed](https://github.com/jmrashed)\n\n---\n\n\u003e *\"Need a Reliable Software Partner? I build scalable, secure \u0026 modern solutions for startups and enterprises.\"*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmrashed%2Fchat-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmrashed%2Fchat-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmrashed%2Fchat-backend/lists"}