# farhandh/cdingin-back-end architecture

> Architecture diagram of the GitHub repository farhandh/cdingin-back-end, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/farhandh/cdingin-back-end
- Repository: https://github.com/farhandh/cdingin-back-end

## Overview

##### Main Components
- Application Entry Point: Represent the main file (main.ts) that starts the NestJS application.
- NestJS Framework: Indicate the overall structure built on NestJS.
- Core Business Modules: For each domain (ac-type, auth, building-type, etc.), show their controllers, services, entities, and seeds. These modules encapsulate the business logic and CRUD operations.
- Common Modules: Illustrate shared components such as:
- Database Module (src/common/database) with its data source configuration and migration files.
- Configuration and Utility Modules (src/common/config.ts, utils.ts).
- Logger and Middleware (src/common/logger) handling exceptions and response interception.
- External Interactions: An external client (or several types such as mobile or web frontends) sending API requests, and the database used to persist data.

##### Component Relationships & Interactions
- From External Clients (e.g., Postman, web/mobile clients) to API endpoints (Controllers) in your core modules.
- Controllers delegate work to Services in each module.
- Services interact with Entities (representing database models) via the Database Module.
- Shared services (like the Logger or Middleware) are applied across modules.
for instance, the Auth module might be used by several core modules to enforce authentication and authorization (guards in src/core/auth/guards).

##### Important Architectural Patterns
- Modular Architecture: Each domain is separated into its own feature module, which supports maintainability and scalability.
- MVC-like Separation: Although NestJS is not a strict MVC framework, the separation between controllers (handling HTTP routing), services (business logic), and entities/models (data representation) is clear.
- Database Migrations: The numerous migration files indicate a robust version control of the database schema.
- Middleware/Interceptor Usage: These add cross-cutting concerns such as logging and error handling.

##### Relevant Technologies
- NestJS and TypeScript: Mention the framework and language.
- Database Integration: Show the connection to the database as configured in common/database.
- Tools: Include build/formatting/configuration tools shown in the file tree (pnpm, ESLint, Prettier, SWC for compilation).

##### Additional Detail
- Don’t hesitate to break down components further if needed (i.e., show that within each “core” module, there are controllers, services, and entity definitions).
- Representing utility functions (common/utils.ts) and config files as supplementary components that support multiple areas of the architecture.
- Integration points, such as how authentication (using guards like jwt.guard.ts) influences controller behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client and Application Startup
    ExternalClient["External Client (Web/Mobile/Postman)"]:::client

    subgraph "Application Startup"
        AppEntry["Application Entry Point"]:::entry
        NestModule["NestJS App Module"]:::framework
        NestController["NestJS App Controller"]:::framework
    end

    ExternalClient -->|"APIRequest"| AppEntry
    AppEntry --> NestModule
    NestModule --> NestController

    %% Core Business Modules
    subgraph "Core Business Modules"
        %% AC Type Module
        subgraph "AC Type Module"
            ACController["AC Type Controller"]:::controller
            ACService["AC Type Service"]:::service
            ACEntity["AC Type Entity"]:::entity
            ACController -->|"calls"| ACService
            ACService -->|"accesses"| ACEntity
        end

        %% Auth Module
        subgraph "Auth Module"
            AuthController["Auth Controller"]:::controller
            AuthService["Auth Service"]:::service
            AuthGuards["Auth Guards"]:::guard
            AuthController -->|"calls"| AuthService
            AuthService -->|"uses"| AuthGuards
        end

        %% Building Type Module
        subgraph "Building Type Module"
            BuildingController["Building Type Controller"]:::controller
            BuildingService["Building Type Service"]:::service
            BuildingEntity["Building Type Entity"]:::entity
            BuildingController -->|"calls"| BuildingService
            BuildingService -->|"accesses"| BuildingEntity
        end

        %% Contact Module
        subgraph "Contact Module"
            ContactController["Contact Controller"]:::controller
            ContactService["Contact Service"]:::service
            ContactEntity["Contact Entity"]:::entity
            ContactController -->|"calls"| ContactService
            ContactService -->|"accesses"| ContactEntity
        end

        %% Customer Module
        subgraph "Customer Module"
            CustomerController["Customer Controller"]:::controller
            CustomerService["Customer Service"]:::service
            CustomerEntity["Customer Entity"]:::entity
            CustomerController -->|"calls"| CustomerService
            CustomerService -->|"accesses"| CustomerEntity
        end

        %% Notification Module
        subgraph "Notification Module"
            NotificationController["Notification Controller"]:::controller
            NotificationService["Notification Service"]:::service
            NotificationEntity["Notification Entity"]:::entity
            NotificationController -->|"calls"| NotificationService
            NotificationService -->|"accesses"| NotificationEntity
        end

        %% Order Module
        subgraph "Order Module"
            OrderController["Order Controller"]:::controller
            OrderService["Order Service"]:::service
            OrderEntity["Order Entity"]:::entity
            OrderController -->|"calls"| OrderService
            OrderService -->|"accesses"| OrderEntity
        end

        %% Problem Type Module
        subgraph "Problem Type Module"
            ProblemController["Problem Type Controller"]:::controller
            ProblemService["Problem Type Service"]:::service
            ProblemEntity["Problem Type Entity"]:::entity
            ProblemController -->|"calls"| ProblemService
            ProblemService -->|"accesses"| ProblemEntity
        end

        %% Technicians Module
        subgraph "Technicians Module"
            TechniciansController["Technicians Controller"]:::controller
            TechniciansService["Technicians Service"]:::service
            TechniciansEntity["Technicians Entity"]:::entity
            TechniciansController -->|"calls"| TechniciansService
            TechniciansService -->|"accesses"| TechniciansEntity
        end

        %% Connect NestJS App Controller to each Core Module Controller
        NestController --> ACController
        NestController --> AuthController
        NestController --> BuildingController
        NestController --> ContactController
        NestController --> CustomerController
        NestController --> NotificationController
        NestController --> OrderController
        NestController --> ProblemController
        NestController --> TechniciansController
    end

    %% Common Services & Data Layer
    subgraph "Common Services & Data"
        DatabaseModule["Database Module"]:::database
        Config["Configuration"]:::config
        Utilities["Utilities"]:::utility
        LoggerMiddleware["Logger & Middleware"]:::middleware
        ResponseInterceptor["Response Interceptor"]:::interceptor
    end

    %% Link Entities to the Database Module
    ACEntity -->|"persists"| DatabaseModule
    BuildingEntity -->|"persists"| DatabaseModule
    ContactEntity -->|"persists"| DatabaseModule
    CustomerEntity -->|"persists"| DatabaseModule
    NotificationEntity -->|"persists"| DatabaseModule
    OrderEntity -->|"persists"| DatabaseModule
    ProblemEntity -->|"persists"| DatabaseModule
    TechniciansEntity -->|"persists"| DatabaseModule

    %% Connect NestJS Bootstrapping to Common Services
    NestModule -->|"configures"| Config
    NestModule -->|"configures"| Utilities
    NestModule -->|"integrates"| LoggerMiddleware
    NestModule -->|"integrates"| ResponseInterceptor

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef entry fill:#ff9,stroke:#333,stroke-width:2px;
    classDef framework fill:#9f9,stroke:#333,stroke-width:2px;
    classDef controller fill:#ccf,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef entity fill:#fc9,stroke:#333,stroke-width:2px;
    classDef guard fill:#f99,stroke:#333,stroke-width:2px;
    classDef database fill:#cff,stroke:#333,stroke-width:2px,stroke-dasharray:5,5;
    classDef config fill:#dfd,stroke:#333,stroke-width:2px,stroke-dasharray:2,2;
    classDef utility fill:#dfd,stroke:#333,stroke-width:2px,stroke-dasharray:2,2;
    classDef middleware fill:#fdd,stroke:#333,stroke-width:2px,stroke-dasharray:2,2;
    classDef interceptor fill:#fda,stroke:#333,stroke-width:2px,stroke-dasharray:2,2;

    %% Click Events
    click AppEntry "https://github.com/farhandh/cdingin-back-end/blob/main/src/main.ts"
    click NestModule "https://github.com/farhandh/cdingin-back-end/blob/main/src/app.module.ts"
    click NestController "https://github.com/farhandh/cdingin-back-end/blob/main/src/app.controller.ts"
    click ACController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/ac-type"
    click AuthController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/auth"
    click BuildingController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/building-type"
    click ContactController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/contact"
    click CustomerController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/customer"
    click NotificationController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/notification"
    click OrderController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/order"
    click ProblemController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/problem-type"
    click TechniciansController "https://github.com/farhandh/cdingin-back-end/tree/main/src/core/technicians"
    click DatabaseModule "https://github.com/farhandh/cdingin-back-end/tree/main/src/common/database"
    click Config "https://github.com/farhandh/cdingin-back-end/blob/main/src/common/config.ts"
    click Utilities "https://github.com/farhandh/cdingin-back-end/blob/main/src/common/utils.ts"
    click LoggerMiddleware "https://github.com/farhandh/cdingin-back-end/tree/main/src/common/logger"
    click ResponseInterceptor "https://github.com/farhandh/cdingin-back-end/blob/main/src/common/response.interceptor.ts"
```
