{"id":28312823,"url":"https://github.com/mrzstack/chat-backend","last_synced_at":"2025-06-24T20:11:43.955Z","repository":{"id":258216938,"uuid":"873631326","full_name":"mrzstack/chat-backend","owner":"mrzstack","description":"Real-Time Chat Application (Server)","archived":false,"fork":false,"pushed_at":"2024-10-17T05:41:40.000Z","size":577,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T04:42:19.869Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrzstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-16T13:42:42.000Z","updated_at":"2024-10-17T05:41:43.000Z","dependencies_parsed_at":"2024-10-19T00:15:40.720Z","dependency_job_id":null,"html_url":"https://github.com/mrzstack/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/mrzstack/chat-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrzstack%2Fchat-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrzstack%2Fchat-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrzstack%2Fchat-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrzstack%2Fchat-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrzstack","download_url":"https://codeload.github.com/mrzstack/chat-backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrzstack%2Fchat-backend/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261314159,"owners_count":23140021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2025-05-24T17:11:22.018Z","updated_at":"2025-06-24T20:11:43.946Z","avatar_url":"https://github.com/mrzstack.png","language":"JavaScript","readme":"# Real-Time Chat Application (Server)\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## Features\n\n- **Real-time Communication**: Users can send and receive messages in real-time using Socket.IO.\n- **File Sharing**: Efficient file uploads/downloads with Node.js streams and buffers.\n- **User Authentication**: Secure user login and registration using JWT (JSON Web Tokens).\n- **Persistent Chat History**: MongoDB stores chat messages, user data, and file metadata for future retrieval.\n- **Scalability**: The application is designed for horizontal scaling and optimized for concurrent users.\n\n## Technologies Used\n\n- **Node.js**: JavaScript runtime for building server-side logic.\n- **Express**: Fast web framework for Node.js.\n- **Socket.IO**: Enables real-time, bidirectional communication between server and client.\n- **MongoDB**: NoSQL database used for chat storage and user management.\n- **JWT**: Secure user authentication using JSON Web Tokens.\n- **Streams \u0026 Buffers**: Handle large file uploads/downloads without blocking the server.\n\n## Project Structure\n\n```bash\n.\n├── .env\n├── .env.example\n├── .gitignore\n├── app.js\n├── config\n│   ├── db.js\n│   └── jwtConfig.js\n├── controllers\n│   ├── authController.js\n│   ├── chatController.js\n│   └── chatRoomController.js\n├── middleware\n│   └── authMiddleware.js\n├── models\n│   ├── ChatMessage.js\n│   ├── ChatRoom.js\n│   └── User.js\n├── routes\n│   ├── authRoutes.js\n│   ├── chatRoomRoutes.js\n│   ├── chatRoutes.js\n│   \n├── services\n│   └── socketService.js\n├── socket.js\n├── swagger.js\n├── uploads\n├── utils\n│   ├── logger.js\n│   └── responseFormatter.js\n├── seeder.js\n└── tests\n    ├── auth.test.js\n    └── chat.test.js\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\nTo execute tests for authentication and chat functionality, use the following command:\n\n```bash\nnpm test\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## Error Handling\n\nThe application includes robust error handling for:\n\n- Invalid JWT tokens\n- Database connection errors\n- File upload/download issues\n- User authentication failures\n\n## Future Improvements\n\n- **Private Messaging**: Implement direct messaging between individual users.\n- **Group Chats**: Allow for group chat rooms with multiple participants.\n- **Notifications**: Add real-time notifications for new messages or file uploads.\n- **OAuth Integration**: Implement social logins via Google, Facebook, etc.\n- **Admin Dashboard**: Build a dashboard for managing users, chat rooms, and file uploads.\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)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrzstack%2Fchat-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrzstack%2Fchat-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrzstack%2Fchat-backend/lists"}