# pablorg9/node-ms-ddd-template architecture

> Architecture diagram of the GitHub repository pablorg9/node-ms-ddd-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pablorg9/node-ms-ddd-template
- Repository: https://github.com/pablorg9/node-ms-ddd-template

## Overview

##### Project type and purpose
- This is a backend microservice: a User Management API built in Node.js/TypeScript.
- It follows Domain-Driven Design (DDD) with clear separation of layers and uses Inversify for dependency injection and express for HTTP routing.
- Its responsibility is to expose HTTP endpoints for user operations, orchestrate application logic, enforce domain rules, and persist user data.

##### File structure
- Top-level files: Dockerfiles, pm2.json, tsconfig.json, package.json – show build and deployment.
- src/
- application/services → use-case level orchestration (UserAppService).
- domain/entities, domain/services, domain/repositories → core business model, logic, and repository interfaces.
- infrastructure/api → HTTP server (Server.ts), controllers (UserController), middlewares, validators.
- infrastructure/repositories → concrete repository (UserRepository) talking to a datastore.
- setup/DependencyContainer, Symbols, Envs → Inversify DI configuration, environment loading, shared interfaces, and HTTP utils.

##### README for additional insights
- Confirms four layers: domain, application, infrastructure, setup.
- Stresses DDD concepts: Entities, Value Objects, Services, Repositories.
- Points out technologies: TypeScript, Inversify, Express, PM2, Docker.

##### Elements
- API Server
- UserController
- Validation & Middleware
- UserAppService
- UserService
- IUserRepository interface
- UserRepository
- Database
- DependencyContainer
- HTTP flow: Client → Server → Controller → AppService → DomainService → Repository → Database → back up the chain
- DI bindings: DependencyContainer → Controller, Services, Repositories
- Blue for API/infrastructure components
- Green for Application layer
- Yellow for Domain layer
- Grey for Setup/DI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Setup / DI Layer
    subgraph "Setup & Bootstrapping"
        DC["DependencyContainer"]:::setup
        SYM["Symbols Registry"]:::setup
        ENVS["Environment Loader"]:::setup
        DTO["IUserDTO"]:::setup
        HTTPUTIL["HTTP Utilities"]:::setup
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        SERVER["Express Server"]:::api
        CM["CommonMiddleware"]:::api
        EM["ErrorMiddleware"]:::api
        VALHELP["Validation Helper"]:::api
        USERVAL["UserValidators"]:::api
        CONT["UserController"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        UAS["UserAppService"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        USRV["UserService"]:::domain
        UENT["User Entity"]:::domain
        IUR["IUserRepository"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        UR["UserRepository"]:::infra
        DB[(Database)]:::db
    end

    %% Flow of HTTP Request
    Client(("Client")):::external
    Client -->|HTTP Request| SERVER
    SERVER -->|apply| CM
    SERVER -->|apply| EM
    SERVER -->|route to| USERVAL
    USERVAL -->|validate| VALHELP
    USERVAL -->|then| CONT
    CM --> CONT
    EM --> CONT

    %% Controller to Application
    CONT -->|calls| UAS

    %% Application to Domain
    UAS -->|uses| USRV
    UAS -->|requires| IUR

    %% Domain to Infrastructure
    USRV -->|calls| IUR
    IUR -->|bound to| UR

    %% Repository to Database
    UR -->|queries| DB

    %% Dependency Injection Bindings
    DC -->|binds| CONT
    DC -->|binds| UAS
    DC -->|binds| USRV
    DC -->|binds| UR
    DC -->|uses| SYM
    DC -->|loads| ENVS
    DC -->|provides| DTO
    DC -->|provides| HTTPUTIL

    %% Click Events
    click SERVER "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/api/Server.ts"
    click CM "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/api/middlewares/CommonMiddleware.ts"
    click EM "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/api/middlewares/ErrorMiddleware.ts"
    click USERVAL "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/api/validators/UserValidators.ts"
    click VALHELP "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/api/validators/Validation.ts"
    click CONT "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/api/controllers/UserController.ts"
    click UAS "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/application/services/UserAppService.ts"
    click UENT "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/domain/entities/User.ts"
    click USRV "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/domain/services/UserService.ts"
    click IUR "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/domain/repositories/IUserRepository.ts"
    click UR "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/infrastructure/repositories/UserRepository.ts"
    click DC "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/setup/DependencyContainer.ts"
    click SYM "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/setup/Symbols.ts"
    click ENVS "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/setup/Envs.ts"
    click DTO "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/setup/interfaces/DTOs/IUserDTO.ts"
    click HTTPUTIL "https://github.com/pablorg9/node-ms-ddd-template/blob/main/src/setup/utils/Http.ts"

    %% Styles
    classDef api fill:#D0E8FF,stroke:#0066CC,color:#003366
    classDef app fill:#DFF2BF,stroke:#4F8A10,color:#4F8A10
    classDef domain fill:#FFF2CC,stroke:#B8860B,color:#8B6508
    classDef infra fill:#F0D9FF,stroke:#800080,color:#4B0082
    classDef db fill:#CCCCCC,stroke:#666666,color:#333333
    classDef setup fill:#E8E8E8,stroke:#999999,color:#666666
    classDef external fill:#FFFFFF,stroke:#000000,color:#000000,stroke-dasharray: 5 5
```
