This project is an Event-Driven Microservices Architecture built with Node.js. It is designed for high scalability, fault tolerance, and clear separation of concerns.
- Centralized API Gateway: Handles routing, rate-limiting, and authentication termination.
- Event-Driven Communication: Services communicate asynchronously via RabbitMQ.
- Containerized Infrastructure: Fully Dockerized with Nginx, Redis, and RabbitMQ.
- Production-Grade Persistence: MongoDB for data and Redis AOF for robust caching.
graph TD
User((User / Client))
subgraph "Infrastructure Layer"
Nginx[Nginx Load Balancer]
RabbitMQ[RabbitMQ Message Broker]
Redis[Redis (Cache & Rate Limit)]
end
subgraph "Microservices Layer"
Gateway[API Gateway]
UserService[User Service]
TaskService[Task Service]
NotifyService[Notification Service]
end
%% Edge Definitions
User -->|HTTPS Request| Nginx
Nginx -->|Reverse Proxy| Gateway
Gateway -->|Rate Check| Redis
Gateway -->|Forward Auth| UserService
Gateway -->|Forward Requests| TaskService
Gateway -->|Forward Requests| NotifyService
UserService -->|Read/Write| Mongo
TaskService -->|Read/Write| Mongo
NotifyService -->|Read/Write| Mongo
TaskService -.->|Publish: task_created| RabbitMQ
RabbitMQ -.->|Consume: task_created| NotifyService
- Role: The single entry point for all client requests.
- Key Responsibilities:
- Dynamic Routing: Automatically routes
/api/users/*-> User Service, etc. based onservices.js. - Authentication: Validates JWTs and injects
x-user-idheaders for downstream services. - Protection: Implements global rate limiting via Redis.
- Proxying: Uses a custom, lightweight Axios proxy for control and error handling.
- Dynamic Routing: Automatically routes
- Role: Identifies and manages users.
- Key Responsibilities:
- User Registration & Login.
- JWT Token Generation.
- Profile Management.
- Role: Core business logic for managing tasks.
- Key Responsibilities:
- CRUD operations for Tasks.
- Producer: Publishes events (
task_created,task_updated,task_deleted) to RabbitMQ. - Ensures data persistence in MongoDB before broadcasting events.
- Role: Handles user alerts and history.
- Key Responsibilities:
- Consumer: Listens to RabbitMQ queues (
task_created, etc.). - Persists notifications to MongoDB for historical access.
- Provides APIs for users to fetch their latest notifications.
- Consumer: Listens to RabbitMQ queues (
| Component | Technology | Usage | Configuration |
|---|---|---|---|
| Reverse Proxy | Nginx | Entry point, handles SSL (future), static compression. | infra/nginx |
| Load Balancer | Nginx [Upstream] | As of now Nginx's Upstream is serving as Load Balancer | infra/nginx |
| Message Broker | RabbitMQ | Asynchronous decoupling between Task and Notification services. | infra/rabbitmq (Custom Image) |
| Cache / Limits | Redis 7 | Distributed rate limiting and potential session caching. | infra/redis (Custom Image) |
| Database | MongoDB(Atlas) | Primary persistent store for all services. | External URI |
- Client sends
POST /api/tasks/uploadto Nginx. - Nginx forwards to API Gateway.
- Gateway:
- Checks Rate Limit in Redis.
- Validates JWT (Auth).
- Proxies request to Task Service.
- Task Service:
- Saves Task to MongoDB.
- Publishes
task_createdevent to RabbitMQ. - Returns
201 Createdto Gateway -> Client.
- RabbitMQ routes message to
task_createdqueue. - Notification Service picks up message and saves a new Notification to MongoDB.
backend-platform/
├── infra/ # Infrastructure Configuration
│ ├── nginx/ # Custom Nginx Load Balancer
│ ├── rabbitmq/ # RabbitMQ Custom Image (3.13)
│ └── redis/ # Redis Custom Image (7.0)
│
├── services/ # Microservices Code source
│ ├── api-gateway/ # Express Gateway & Proxy
│ ├── user-service/ # User Logic
│ ├── task-service/ # Task Logic (Producer)
│ └── notification-service/ # Notification Logic (Consumer)
│
├── scripts/ # Dev & Ops Automation
│ ├── dev.sh / .ps1 # Start entire stack
│ └── clean-docker.sh # Reset environment
│
└── docker-compose.yml # Orchestration