# jawherkl/nodejs-microservices architecture

> Architecture diagram of the GitHub repository jawherkl/nodejs-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jawherkl/nodejs-microservices
- Repository: https://github.com/jawherkl/nodejs-microservices

## Overview

##### Project type and purpose
- This is a Node.js microservices e-commerce system (Order & Inventory)
- Purpose: demonstrate a production-ready, modular architecture with single-responsibility services, event-driven communication, and containerized deployment

##### File structure
- Monorepo with one folder per microservice plus an API gateway
– api-gateway: NestJS/Express entry point, routing, JWT guard
– user-service, order-service: NestJS services using PostgreSQL (entities, modules, controllers, services)
– product-service, inventory-service, notification-service: ExpressJS services using MongoDB (models, controllers, routes)
– event listeners (order-event-listener, product-event-listener): standalone consumers reading from RabbitMQ
- Shared docker-compose.yml orchestrates all containers (services, databases, message broker)
- Each service has its own Dockerfile, lint/config files, and test suites
- Config files indicate use of TypeScript for NestJS services and JavaScript for ExpressJS services

##### README for additional insights
- REST between API Gateway and services
- RabbitMQ events connect services (order_created, stock updates, notifications)
- Each service’s tech stack, DB, and responsibilities spelled out

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        UI["UI / Frontend"]:::external
        Mobile["Mobile App"]:::external
    end

    %% Application Layer
    subgraph "Application Layer"
        API["API Gateway\n(NestJS)"]:::gateway
        US["User Service\n(NestJS)"]:::service
        OR["Order Service\n(NestJS)"]:::service
        PR["Product Service\n(ExpressJS)"]:::service
        IN["Inventory Service\n(ExpressJS)"]:::service
        NT["Notification Service\n(ExpressJS)"]:::service
    end

    %% Messaging Layer
    subgraph "Messaging Layer"
        MQ["RabbitMQ / NATS"]:::broker
        OEL["Order Event Listener"]:::listener
        PEL["Product Event Listener"]:::listener
    end

    %% Database Layer
    subgraph "Database Layer"
        PG["PostgreSQL\n(Users & Orders)"]:::db
        MG["MongoDB\n(Products, Inventory, Notifications)"]:::db
    end

    %% Orchestration
    subgraph "Orchestration"
        Docker["Docker Compose"]:::orchestration
    end

    %% Connections
    UI -->|"REST"| API
    Mobile -->|"REST"| API

    API -->|"REST"| US
    API -->|"REST"| OR
    API -->|"REST"| PR
    API -->|"REST"| IN
    API -->|"REST"| NT

    OR -->|"emit order_created"| MQ
    PR -->|"emit stock_changed"| MQ
    IN -->|"emit inventory_updated"| MQ
    MQ -->|"consume order_created"| OEL
    MQ -->|"consume stock_changed"| PEL

    US -.->|"DB"| PG
    OR -.->|"DB"| PG
    PR -.->|"DB"| MG
    IN -.->|"DB"| MG
    NT -.->|"DB"| MG

    Docker -.-> API
    Docker -.-> US
    Docker -.-> OR
    Docker -.-> PR
    Docker -.-> IN
    Docker -.-> NT
    Docker -.-> MQ
    Docker -.-> PG
    Docker -.-> MG
    Docker -.-> OEL
    Docker -.-> PEL

    %% Click Events
    click API "https://github.com/jawherkl/nodejs-microservices/tree/main/api-gateway/"
    click US "https://github.com/jawherkl/nodejs-microservices/tree/main/user-service/"
    click OR "https://github.com/jawherkl/nodejs-microservices/tree/main/order-service/"
    click PR "https://github.com/jawherkl/nodejs-microservices/tree/main/product-service/"
    click IN "https://github.com/jawherkl/nodejs-microservices/tree/main/inventory-service/"
    click NT "https://github.com/jawherkl/nodejs-microservices/tree/main/notification-service/"
    click OEL "https://github.com/jawherkl/nodejs-microservices/tree/main/order-event-listener/"
    click PEL "https://github.com/jawherkl/nodejs-microservices/tree/main/product-event-listener/"
    click Docker "https://github.com/jawherkl/nodejs-microservices/blob/main/docker-compose.yml"

    %% Styles
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px;
    classDef gateway fill:#9f6,stroke:#333,stroke-width:1px;
    classDef service fill:#9f6,stroke:#333,stroke-width:1px;
    classDef broker fill:#f96,stroke:#333,stroke-width:1px;
    classDef listener fill:#dddddd,stroke:#333,stroke-width:1px;
    classDef db fill:#69f,stroke:#333,stroke-width:1px;
    classDef orchestration fill:#fcf,stroke:#333,stroke-width:1px;
```
