https://github.com/valentinocarmonas/realtimechat
A Real Time Chat API project
https://github.com/valentinocarmonas/realtimechat
docker expressjs jwt mongodb mvc-pattern nodejs real-time-chat socket-io tdd-javascript
Last synced: 5 months ago
JSON representation
A Real Time Chat API project
- Host: GitHub
- URL: https://github.com/valentinocarmonas/realtimechat
- Owner: ValentinoCarmonaS
- License: mit
- Created: 2025-05-06T17:54:36.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-05-06T19:22:29.000Z (5 months ago)
- Last Synced: 2025-05-06T19:32:19.112Z (5 months ago)
- Topics: docker, expressjs, jwt, mongodb, mvc-pattern, nodejs, real-time-chat, socket-io, tdd-javascript
- Language: JavaScript
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Real-Time Chat System

[](https://codecov.io/gh/ValentinoCarmonaS/RealTimeChat)A **real-time chat application** built with **Node.js**, **Express**, **Socket.IO**, and **MongoDB**, enabling multiple users to send and receive messages instantly in a shared chat room. It implements the **MVC** pattern, featuring a minimal frontend, persistent message storage, and easy deployment.
## π Features
- **Real-Time Messaging**: Send and receive messages instantly using WebSockets.
- **Persistence**: Store messages in MongoDB for chat history.
- **Notifications**: Alerts for user connections and disconnections.
- **Minimal Interface**: Simple frontend with HTML, CSS, and JavaScript.
- **Testing**: Comprehensive automated tests with Jest and Supertest (93.75% branch coverage).
- **Docker**: Containerized setup for easy deployment.## π Prerequisites
- **Node.js** v16+
- **MongoDB Atlas** or a local MongoDB instance
- **Docker** and **Docker Compose** (optional, for containerized setup)
- Modern web browser (Chrome, Firefox, etc.)## π οΈ Installation
1. Clone the repository:
```bash
git clone https://github.com/ValentinoCarmonaS/RealTimeChat.git
cd RealTimeChat
```2. Install dependencies:
```bash
npm install
```3. Create a `.env` file in the root directory with:
```bash
PORT=3000
MONGODB_URI=mongodb+srv://:@cluster0.mongodb.net/realtime-chat?retryWrites=true&w=majority
```## βΆοΈ Running the Application
- **Locally**:
```bash
npm start
```The application will be available at `http://localhost:3000`.
- **With Docker**:
```bash
make build
make up
```Stop containers with:
```bash
make down
```## π§ͺ Testing
Run tests with Docker:
```bash
make test
```Or run tests with npm:
```bash
npm test
```- Tests cover user connections, message sending and storage, and WebSocket event logic.
- Coverage: 93.75% branches, 98.64% statements.
- View detailed reports in `coverage/lcov-report/index.html`.## π Main Functionalities
- **User Connection**: Users enter a username and join a shared chat room.
- **Messages**: Messages are sent in real-time, stored in MongoDB, and displayed with the senderβs username.
- **History**: Retrieve historical messages when a new user connects.
- **Notifications**: Alerts when a user connects or disconnects.### Example Interaction
```
User enters their name: "Ana"
Ana sends: "Hello, how are you?"
All users see: "Ana: Hello, how are you?" (stored in MongoDB)
Ana disconnects, all users see: "Ana has disconnected"
```For more details, refer to the [technical specification](docs/spec.md).
## ποΈ Project Structure
```
RealTimeChat/
βββ backend/
β βββ src/
β β βββ config/ # Environment and database setup
β β βββ controllers/ # Business logic for WebSockets and messages
β β βββ middlewares/ # Validation and error handling
β β βββ models/ # MongoDB schemas for messages
β β βββ routes/ # HTTP routes for frontend and auxiliary endpoints
β β βββ sockets/ # WebSocket-specific logic
β β βββ tests/ # Unit and integration tests
β β βββ app.js # Express application setup
βββ frontend/
β βββ index.html # Main interface
β βββ styles.css # Basic styles
β βββ script.js # Frontend logic
βββ .env # Environment variables
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
βββ Makefile # Automation scripts
βββ package.json # Dependencies and scripts
```## π License
[MIT](LICENSE)