Skip to content

Latest commit

 

History

History
134 lines (108 loc) · 4.99 KB

File metadata and controls

134 lines (108 loc) · 4.99 KB

System Architecture

Overview

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.

Key Features

  • 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.

High-Level Design (Container Diagram)

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
Loading

Component Breakdown

1. API Gateway (/services/api-gateway)

  • Role: The single entry point for all client requests.
  • Key Responsibilities:
    • Dynamic Routing: Automatically routes /api/users/* -> User Service, etc. based on services.js.
    • Authentication: Validates JWTs and injects x-user-id headers for downstream services.
    • Protection: Implements global rate limiting via Redis.
    • Proxying: Uses a custom, lightweight Axios proxy for control and error handling.

2. User Service (/services/user-service)

  • Role: Identifies and manages users.
  • Key Responsibilities:
    • User Registration & Login.
    • JWT Token Generation.
    • Profile Management.

3. Task Service (/services/task-service)

  • 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.

4. Notification Service (/services/notification-service)

  • 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.

Infrastructure

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

Data Flow Example: "Create Task"

  1. Client sends POST /api/tasks/upload to Nginx.
  2. Nginx forwards to API Gateway.
  3. Gateway:
    • Checks Rate Limit in Redis.
    • Validates JWT (Auth).
    • Proxies request to Task Service.
  4. Task Service:
    • Saves Task to MongoDB.
    • Publishes task_created event to RabbitMQ.
    • Returns 201 Created to Gateway -> Client.
  5. RabbitMQ routes message to task_created queue.
  6. Notification Service picks up message and saves a new Notification to MongoDB.

Directory Structure

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