# diaz-adrianz/nestjs-typeorm-ts architecture

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

- Interactive diagram: https://gitdiagram.com/diaz-adrianz/nestjs-typeorm-ts
- Repository: https://github.com/diaz-adrianz/nestjs-typeorm-ts

## Overview

##### Main Components
- NestJS Application – the overarching container hosting all functionalities.
- Controllers – each module (e.g., Auth, Payments, Notifications, Permissions, Roles, and Users) has its own controller handling the incoming HTTP requests.
- Services – underlying business logic for each module, showing dependency injection flows from controllers.
- Modules – groups of related controllers and services which encapsulate a feature set.
- Database Layer – represented by TypeORM, with entities (e.g., user.entity, payment.entity, notification.entity) and migrations, seeding processes.
- External Integrations – include components for Redis (caching), Firebase, Minio (file storage), Mail service, and Xendit (payment gateway).

##### Relationships and Interactions
- How a controller calls its corresponding service to handle logic.
- That these services often interact with the database layer (via TypeORM) to query or persist data.
- Authentication flow with JWT strategies, guards, and decorators that secure routes.
- Interactions with external services (for example, the mail service calls an SMTP server, or Minio services for file uploads).

##### Architectural Patterns and Design Principles
- Modular structure inherent to NestJS (each core module is isolated into its own folder under “src/core”).
- How cross-cutting concerns (logging, caching, validation, exception filters, interceptors) are handled via dedicated custom modules (in “src/lib”, “src/decorators”, “src/filters”, etc.).
- Use of dependency injection to enable clean separation of concerns.

##### Technologies, Frameworks, and Libraries
- NestJS as the application framework.
- TypeORM for ORM-based database connectivity and migrations.
- JWT for authentication.
- Redis (likely used for caching, although integration files for cache are in “src/lib/cache”).
- Tools for file uploads and external file storage like Minio.
- Integrations with external services (Firebase and Xendit).
- Winston for logging (as seen in “src/lib/logger”).
- Email service implemented with modules in “src/lib/mail”.

##### Additional Elements
- Configuration and utility modules (like config files under “src/config” and utilities under “src/utils”) as supporting components, indicating that they are used by various parts of the application.
- “src/lib” directory items (cache, firebase, logger, mail, minio, xendit) clearly as integration modules that enable external communication.
- It might help to add brief notes on each interaction (e.g., “JWT Guard validates token”, “TypeORM migration applies schema changes”).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Nodes
    Client["External Client"]:::external

    APP["NestJS Application"]:::app

    %% Core Modules
    subgraph "Auth Module"
        A_CTRL["Auth Controller"]:::controller
        A_SVC["Auth Service"]:::service
    end

    subgraph "Payments Module"
        P_CTRL["Payments Controller"]:::controller
        P_SVC["Payments Service"]:::service
    end

    subgraph "Notifications Module"
        N_CTRL["Notifications Controller"]:::controller
        N_SVC["Notifications Service"]:::service
    end

    subgraph "Permissions Module"
        PERM_CTRL["Permissions Controller"]:::controller
        PERM_SVC["Permissions Service"]:::service
    end

    subgraph "Roles Module"
        R_CTRL["Roles Controller"]:::controller
        R_SVC["Roles Service"]:::service
    end

    subgraph "Users Module"
        U_CTRL["Users Controller"]:::controller
        U_SVC["Users Service"]:::service
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["TypeORM Database"]:::database
        MIG["Migrations & Seeds"]:::database
    end

    %% External Integrations
    subgraph "External Integrations"
        RDS["Redis Cache"]:::external
        MINIO["Minio File Storage"]:::external
        FIREBASE["Firebase Notifications"]:::external
        MAIL["Mail Service"]:::external
        XENDIT["Xendit Payment Gateway"]:::external
        LOGGER["Winston Logger"]:::external
    end

    %% Supporting Utilities & Config
    subgraph "Supporting Utilities & Config"
        CFG["Configuration"]:::utility
        UTILS["Utilities & Decorators/Filters/Interceptors/Pipes"]:::utility
    end

    %% Interactions: Client Requests to Controllers
    Client -->|"HTTP Request"| A_CTRL
    Client -->|"HTTP Request"| P_CTRL
    Client -->|"HTTP Request"| N_CTRL
    Client -->|"HTTP Request"| PERM_CTRL
    Client -->|"HTTP Request"| R_CTRL
    Client -->|"HTTP Request"| U_CTRL

    %% Controllers call respective Services
    A_CTRL -->|"calls"| A_SVC
    P_CTRL -->|"calls"| P_SVC
    N_CTRL -->|"calls"| N_SVC
    PERM_CTRL -->|"calls"| PERM_SVC
    R_CTRL -->|"calls"| R_SVC
    U_CTRL -->|"calls"| U_SVC

    %% Services interact with Database Layer
    A_SVC -->|"queries/persists"| DB
    P_SVC -->|"queries/persists"| DB
    N_SVC -->|"queries/persists"| DB
    PERM_SVC -->|"queries/persists"| DB
    R_SVC -->|"queries/persists"| DB
    U_SVC -->|"queries/persists"| DB

    %% Services can trigger Migrations/Seeds (setup/config)
    A_SVC -->|"uses"| MIG
    P_SVC -->|"uses"| MIG
    N_SVC -->|"uses"| MIG
    PERM_SVC -->|"uses"| MIG
    R_SVC -->|"uses"| MIG
    U_SVC -->|"uses"| MIG

    %% Services utilizing External Integrations
    A_SVC -->|"JWT Guard/Email"| MAIL
    P_SVC -->|"payment process"| XENDIT
    N_SVC -->|"push notification"| FIREBASE
    U_SVC -->|"user alerts"| MAIL
    U_SVC -->|"logs activity"| LOGGER

    %% Common dependencies from NestJS Application
    APP -->|"initializes"| A_CTRL
    APP -->|"initializes"| P_CTRL
    APP -->|"initializes"| N_CTRL
    APP -->|"initializes"| PERM_CTRL
    APP -->|"initializes"| R_CTRL
    APP -->|"initializes"| U_CTRL
    APP -->|"configures"| CFG
    APP -->|"injects"| UTILS
    APP -->|"integrates"| LOGGER

    %% External Integrations connections (shared across services)
    A_SVC -->|"caches data"| RDS
    P_SVC -->|"caches data"| RDS
    N_SVC -->|"caches data"| RDS
    PERM_SVC -->|"caches data"| RDS
    R_SVC -->|"caches data"| RDS
    U_SVC -->|"caches data"| RDS

    %% Class Definitions for Color Coding
    classDef app fill:#DDEBF7,stroke:#2F5496,stroke-width:2px;
    classDef controller fill:#FFF2CC,stroke:#BF9000,stroke-width:2px;
    classDef service fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
    classDef database fill:#F4CCCC,stroke:#CC0000,stroke-width:2px;
    classDef external fill:#EAD1DC,stroke:#B854A7,stroke-width:2px;
    classDef utility fill:#D9D2E9,stroke:#8E7CC3,stroke-width:2px;

    %% Click Events
    click APP "https://github.com/diaz-adrianz/nestjs-typeorm-ts/blob/main/src/app.module.ts"
    click A_CTRL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/core/auth"
    click P_CTRL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/core/payments"
    click N_CTRL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/core/notifications"
    click PERM_CTRL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/core/permissions"
    click R_CTRL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/core/roles"
    click U_CTRL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/core/users"
    click DB "https://github.com/diaz-adrianz/nestjs-typeorm-ts/blob/main/src/config/typeorm.config.ts"
    click MIG "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/database"
    click RDS "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/lib/cache"
    click MINIO "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/lib/minio"
    click FIREBASE "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/lib/firebase"
    click MAIL "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/lib/mail"
    click XENDIT "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/lib/xendit"
    click LOGGER "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/lib/logger"
    click CFG "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/config"
    click UTILS "https://github.com/diaz-adrianz/nestjs-typeorm-ts/tree/main/src/utils"
```
