# trungthanhdev/it_er_forum architecture

> Architecture diagram of the GitHub repository trungthanhdev/it_er_forum, 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/trungthanhdev/it_er_forum
- Repository: https://github.com/trungthanhdev/it_er_forum

## Overview

##### Main Components
- NestJS Application Core – Start with the application bootstrap (src/main.ts) that initializes the entire system.
- Modules – Each subdirectory under "src/modules" represents a key component. For instance, include modules for:
- Authentication (auth): Handles login, registration, and auth-related operations.
- Blacklist: Manages token refresh or security blacklisting.
- Comment: Manages operations related to comments.
- Notification: Deals with user notifications.
- Post: Manages posting logic.
- Report: Handles reporting of content.
- Tag and Tag_by: Manage tagging features.
- User: Handles all user-related functionalities.
- Global Components – Include elements defined in the "global" folder (e.g., enums) and "guard" for route/method protection (auth.guard, role.guard).
- Data Transfer Objects (DTOs) – Represented in the "dto" folder and inside module-specific dto directories, these ensure correct data formats for incoming and outgoing data.
- External Services/Infrastructure – Although not explicitly shown, include a generic Database component (as indicated by dbconfig.ts) where persistent storage will reside.

##### Relationships and Interactions
- Data Flow: Indicate how HTTP requests enter via controllers (e.g., auth.controller, post.controller) and then funneled through service layers.
- DTO Utilization: Show that the data flows between the client and server are validated by DTOs.

##### Architectural Patterns
- Modular Architecture: Emphasize the well-defined separation of concerns through distinct modules.
- Layered Architecture: Outline the typical request-handling flow from controller -> service -> entities/ORM -> database.
- Use of DTOs: Illustrate the pattern of data validation and transformation using DTOs.
- Dependency Injection: Optionally, note that NestJS relies on dependency injection, which wires controllers and services together, even if it is abstracted away in code.

##### Relevant Technologies and Frameworks
- NestJS – The overall Node.js framework powering the application.
- TypeScript – The language used for type safety across modules.
- Database (ORM) – While the specific ORM (like TypeORM) isn’t explicitly mentioned, the presence of entity files and a dbconfig.ts suggests one is used.
- Testing Frameworks – Represent "jest" usage by noting the test folder for unit and integration/e2e tests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("HTTP Client"):::external
    Bootstrap("NestJS Bootstrap"):::bootstrap
    Client -->|"HTTPRequest"| Bootstrap

    subgraph "Authentication Module"
        A1("Auth Module"):::module
        A2("Auth Controller"):::controller
        A3("Auth Service"):::service
        A1 --> A2
        A2 -->|"Executes"| A3
    end

    subgraph "Blacklist Module"
        B1("Blacklist Module"):::module
        B2("Blacklist Controller"):::controller
        B3("Blacklist Service"):::service
        B4("Blacklist Entities"):::entity
        B1 --> B2
        B2 -->|"Executes"| B3
        B3 -->|"StoresData"| B4
    end

    subgraph "Comment Module"
        C1("Comment Module"):::module
        C2("Comment Controller"):::controller
        C3("Comment Service"):::service
        C4("Comment Entities"):::entity
        C1 --> C2
        C2 -->|"Executes"| C3
        C3 -->|"StoresData"| C4
    end

    subgraph "Notification Module"
        N1("Notification Module"):::module
        N2("Notification Controller"):::controller
        N3("Notification Service"):::service
        N4("Notification Entities"):::entity
        N1 --> N2
        N2 -->|"Executes"| N3
        N3 -->|"StoresData"| N4
    end

    subgraph "Post Module"
        P1("Post Module"):::module
        P2("Post Controller"):::controller
        P3("Post Service"):::service
        P4("Post DTOs"):::dto
        P5("Post Entities"):::entity
        P1 --> P2
        P2 -->|"Validates"| P4
        P2 -->|"Executes"| P3
        P3 -->|"StoresData"| P5
    end

    subgraph "Report Module"
        R1("Report Module"):::module
        R2("Report Controller"):::controller
        R3("Report Service"):::service
        R4("Report Entities"):::entity
        R1 --> R2
        R2 -->|"Executes"| R3
        R3 -->|"StoresData"| R4
    end

    subgraph "Tag Module"
        T1("Tag Module"):::module
        T2("Tag Controller"):::controller
        T3("Tag Service"):::service
        T4("Tag Entities"):::entity
        T1 --> T2
        T2 -->|"Executes"| T3
        T3 -->|"StoresData"| T4
    end

    subgraph "Tag_by Module"
        TB1("Tag_by Module"):::module
        TB2("Tag_by Controller"):::controller
        TB3("Tag_by Service"):::service
        TB4("Tag_by Entities"):::entity
        TB1 --> TB2
        TB2 -->|"Executes"| TB3
        TB3 -->|"StoresData"| TB4
    end

    subgraph "User Module"
        U1("User Module"):::module
        U2("User Controller"):::controller
        U3("User Service"):::service
        U4("User DTOs"):::dto
        U5("User Entities"):::entity
        U1 --> U2
        U2 -->|"Validates"| U4
        U2 -->|"Executes"| U3
        U3 -->|"StoresData"| U5
    end

    subgraph "Global Components"
        G1("Global Enums"):::globalComp
        G2("Auth Guard"):::globalComp
        G3("Role Guard"):::globalComp
        G4("Shared DTOs"):::dto
    end

    DB("Database"):::database

    %% Connect Bootstrap to Modules
    Bootstrap --> A1
    Bootstrap --> B1
    Bootstrap --> C1
    Bootstrap --> N1
    Bootstrap --> P1
    Bootstrap --> R1
    Bootstrap --> T1
    Bootstrap --> TB1
    Bootstrap --> U1

    %% Controllers call services which use Database
    A3 -->|"UsesORM"| DB
    B3 -->|"UsesORM"| DB
    C3 -->|"UsesORM"| DB
    N3 -->|"UsesORM"| DB
    P3 -->|"UsesORM"| DB
    R3 -->|"UsesORM"| DB
    T3 -->|"UsesORM"| DB
    TB3 -->|"UsesORM"| DB
    U3 -->|"UsesORM"| DB

    %% Global Guards and Enums influence Controllers (dotted lines)
    A2 --- G1
    A2 --- G2
    A2 --- G3
    B2 --- G1
    B2 --- G2
    B2 --- G3
    C2 --- G1
    C2 --- G2
    C2 --- G3
    N2 --- G1
    N2 --- G2
    N2 --- G3
    P2 --- G1
    P2 --- G2
    P2 --- G3
    R2 --- G1
    R2 --- G2
    R2 --- G3
    T2 --- G1
    T2 --- G2
    T2 --- G3
    TB2 --- G1
    TB2 --- G2
    TB2 --- G3
    U2 --- G1
    U2 --- G2
    U2 --- G3

    %% Shared DTOs linked with Controllers
    A2 --- G4
    B2 --- G4
    C2 --- G4
    N2 --- G4
    P2 --- G4
    R2 --- G4
    T2 --- G4
    TB2 --- G4
    U2 --- G4

    %% Illustrate module interdependencies
    U3 -->|"CallsAuth"| A3
    P3 -->|"TriggersNotification"| N3

    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
    classDef bootstrap fill:#ffd700,stroke:#333,stroke-width:2px;
    classDef module fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef controller fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef service fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef dto fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef entity fill:#ffa500,stroke:#333,stroke-width:2px;
    classDef database fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef globalComp fill:#e6e6fa,stroke:#333,stroke-width:2px;

    click Bootstrap "https://github.com/trungthanhdev/it_er_forum/blob/master/src/main.ts"
    click A1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/auth"
    click B1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/blacklist"
    click C1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/comment"
    click N1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/notification"
    click P1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/post"
    click R1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/report"
    click T1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/tag"
    click TB1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/tag_by"
    click U1 "https://github.com/trungthanhdev/it_er_forum/tree/master/src/modules/user"
    click G1 "https://github.com/trungthanhdev/it_er_forum/blob/master/global/enum.global.ts"
    click G2 "https://github.com/trungthanhdev/it_er_forum/blob/master/guard/auth.guard.ts"
    click G3 "https://github.com/trungthanhdev/it_er_forum/blob/master/guard/role.guard.ts"
    click G4 "https://github.com/trungthanhdev/it_er_forum/tree/master/dto"
    click DB "https://github.com/trungthanhdev/it_er_forum/blob/master/dbconfig.ts"
```
