# andrea-acampora/nestjs-ddd-devops architecture

> Architecture diagram of the GitHub repository andrea-acampora/nestjs-ddd-devops, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andrea-acampora/nestjs-ddd-devops
- Repository: https://github.com/andrea-acampora/nestjs-ddd-devops

## Overview

##### Main Components
- • Entry Point & Global Configuration: Highlight files such as src/main.ts and the configuration folders (src/config and environment files). This layer sets up the global pipes (validation, versioning) and starts the NestJS application.
- • Modules/Bounded Contexts: Represent each module (auth, communication, health, user) as a separate component. Each module further adheres to layering according to Clean Architecture (Domain, Application/Use Case, Infrastructure).
– Domain Layer: Entities, value objects, domain events, and repository interfaces (for example, in src/modules/user/domain).
– Application/Use-Case Layer: Use cases, command and query handlers, and application services (e.g., src/modules/auth/application, src/modules/user/application).
– Infrastructure Layer: Database mappers, repository implementations, communication gateways (GraphQL resolvers, REST controllers, etc.).
- • Shared/Library Components: Include reusable libraries (src/libs) where you find common constructs like ddd building blocks, API helpers, exceptions, pipes, and decorators. These are integral to multiple modules.
- • Database and Persistence: Include the configuration directories, migration scripts (src/config/database/migrations), and Mikro-ORM settings. Mark PostgreSQL as the underlying persistence engine (paired with Docker and docker-compose).
- • DevOps & CI/CD Tools: Indicate CI/CD pipelines (GitHub workflows in .github/workflows), Dockerfiles, docker-compose.yml, and environment management (env dist/test files).

##### Relationships and Interactions
- Dependency injection – for instance, each module’s services rely on infrastructure implementations and domain repository interfaces.
- Interaction with external systems such as the PostgreSQL database (via Mikro-ORM) and external DevOps pipelines (CI/CD workflows triggering Docker builds and deployments).

##### Architectural Patterns and Design Principles
- That the overall architecture is a Modular Monolith with clean boundaries between bounded contexts.
- Use of Domain-Driven Design patterns such as Aggregates, Repositories, Domain Services, and Domain Events.
- Mention that functional programming principles (immutability, pure functions, type safety via TypeScript) are integrated particularly in lower-level (utility/DDD) libraries.
- CI/CD and DevOps practices that automate testing, building, and deployment using Docker and GitHub Actions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External clients and DevOps
    Client["External Clients"]:::external
    CI_CD["CI/CD Pipelines"]:::devops
    Dockerfile["Dockerfile"]:::devops
    DockerCompose["docker-compose.yml"]:::devops

    %% Entry Point & Global Configuration
    subgraph "Entry & Global Configuration"
        Entry["Entry Point"]:::entry
        Config["Global Configuration"]:::entry
        Env_Files["Environment Files"]:::entry
    end

    %% Modules
    subgraph "Modules"
        %% Auth Module
        subgraph "Auth Module"
            Auth_API["Auth API"]:::api
            Auth_App["Auth Application"]:::application
            Auth_Dom["Auth Domain"]:::domain
            Auth_Infra["Auth Infrastructure"]:::infrastructure
        end

        %% Communication Module
        subgraph "Communication Module"
            Com_Module["Communication Module"]:::api
            Com_App["Communication Application"]:::application
            Com_Infra["Communication Infrastructure"]:::infrastructure
        end

        %% Health Module
        subgraph "Health Module"
            Health_API["Health API"]:::api
            Health_Module["Health Module"]:::infrastructure
        end

        %% User Module
        subgraph "User Module"
            User_API["User API"]:::api
            User_App["User Application"]:::application
            User_Dom["User Domain"]:::domain
            User_Infra["User Infrastructure"]:::infrastructure
            User_Module["User Module"]:::infrastructure
        end
    end

    %% Shared / Library Components
    Shared["Shared Libraries"]:::shared

    %% Database & Persistence
    subgraph "Database & Persistence"
        DB["PostgreSQL DB"]:::database
        DB_Config["Database Config & Migrations"]:::database
        DB_Mikro["MikroORM Config"]:::database
        DB_Help["Database Helpers"]:::database
    end

    %% Connections: External Clients to Entry Point
    Client -->|"HTTP Request"| Entry
    Entry -->|"Initialize"| Config
    Config -->|"Loads Env"| Env_Files

    %% DevOps triggering deployments into Entry
    CI_CD -->|"Triggers deployment"| Entry
    Dockerfile -->|"Defines build"| DockerCompose

    %% Entry flows into Modules (API Layer)
    Config -->|"Routes requests to"| Auth_API
    Config -->|"Routes requests to"| Com_Module
    Config -->|"Routes requests to"| Health_API
    Config -->|"Routes requests to"| User_API

    %% Auth Module flow
    Auth_API -->|"Calls"| Auth_App
    Auth_App -->|"Executes"| Auth_Dom
    Auth_App -->|"Uses"| Auth_Infra

    %% Communication Module flow
    Com_Module -->|"Calls"| Com_App
    Com_App -->|"Executes"| Com_Infra

    %% Health Module flow
    Health_API -->|"Triggers"| Health_Module

    %% User Module flow
    User_API -->|"Calls"| User_App
    User_App -->|"Executes"| User_Dom
    User_App -->|"Uses"| User_Infra
    User_App -->|"Manages"| User_Module

    %% Infrastructure to Database connectivity
    Auth_Infra -->|"Persists"| DB
    Com_Infra -->|"Persists (if needed)"| DB
    User_Infra -->|"Persists"| DB

    %% Modules using Shared Libraries
    Auth_App ---|"Utilizes"| Shared
    Com_App ---|"Utilizes"| Shared
    User_App ---|"Utilizes"| Shared
    Health_Module ---|"Utilizes"| Shared

    %% Cross-module interaction (example: Auth to User)
    Auth_Dom ---|"Domain event"| User_Dom

    %% Database configuration details
    DB_Config --> DB
    DB_Mikro --> DB_Config
    DB_Help --> DB

    %% Click Events for Entry & Global Configuration
    click Entry "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/src/main.ts"
    click Config "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/config"
    click Env_Files "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/.env.dist"

    %% Click Events for Auth Module
    click Auth_App "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/auth/application"
    click Auth_Infra "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/auth/infrastructure"
    click Auth_API "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/auth/api"
    click Auth_Dom "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/auth"

    %% Click Events for Communication Module
    click Com_App "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/communication/application"
    click Com_Infra "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/communication/infrastructure/email"
    click Com_Module "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/src/modules/communication/communication.module.ts"

    %% Click Events for Health Module
    click Health_API "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/health/api/rest/controller"
    click Health_Module "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/src/modules/health/health.module.ts"

    %% Click Events for User Module
    click User_API "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/user/api"
    click User_App "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/user/application"
    click User_Dom "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/user/domain"
    click User_Infra "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/modules/user/infrastructure"
    click User_Module "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/src/modules/user/user.module.ts"

    %% Click Events for Shared / Library Components
    click Shared "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/libs"

    %% Click Events for Database & Persistence
    click DB_Config "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/config/database"
    click DB_Mikro "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/src/config/database/mikro-orm.config.ts"
    click DB_Help "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/src/libs/database"

    %% Click Events for DevOps & CI/CD Tools
    click CI_CD "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/.github/workflows"
    click Dockerfile "https://github.com/andrea-acampora/nestjs-ddd-devops/tree/main/Dockerfile"
    click DockerCompose "https://github.com/andrea-acampora/nestjs-ddd-devops/blob/main/docker-compose.yml"

    %% Styles
    classDef entry fill:#f2d7d5,stroke:#922B21,stroke-width:2px;
    classDef api fill:#d5f5e3,stroke:#1E8449,stroke-width:2px;
    classDef application fill:#fcf3cf,stroke:#B7950B,stroke-width:2px;
    classDef domain fill:#d6eaf8,stroke:#2471A3,stroke-width:2px;
    classDef infrastructure fill:#fdebd0,stroke:#CA6F1E,stroke-width:2px;
    classDef shared fill:#ebdef0,stroke:#6C3483,stroke-width:2px;
    classDef database fill:#d6dbdf,stroke:#566573,stroke-width:2px;
    classDef devops fill:#fadbd8,stroke:#922B21,stroke-width:2px;
    classDef external fill:#e8f8f5,stroke:#117864,stroke-width:2px;
```
