# lgabrielcor/apitransfer architecture

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

- Interactive diagram: https://gitdiagram.com/lgabrielcor/apitransfer
- Repository: https://github.com/lgabrielcor/apitransfer

## Overview

##### Main Components
- Application Core: At the center, the main entry point (src/main.ts) bootstraps the application using the NestJS framework. This is where the application’s lifecycle starts.
- Modules: The project is segregated into multiple modules:
- Auth Module: Handles user authentication using JWT, as evidenced by the presence of files like auth.controller, auth.service, various DTOs (for login, reset-password, etc.), and JWT strategies/guards.
- Items Module: Manages item-related functionalities, including creation and updates. It also has dedicated DTOs and an entity.
- Permissions Module: Handles permissions, complete with its own controllers, services, DTOs, and entity.
- Roles Module: Manages roles using similar structural patterns.
- Users Module: Deals with user management including creating and updating user records along with its DTOs and entity.
- Configuration: There’s a config folder (src/config) which, for instance, holds JWT configuration. This separates environment/configuration settings from business logic.
- Security Components: The security directory contains custom decorators which may be used to manage access control or authorization permissions.
- Test Suites: The tests directory and *.spec.ts files across modules indicate that unit and e2e tests are in place to validate functionality.

##### Relationships and Interactions
- All modules are integrated in the central application module (src/app.module.ts), so the high-level architecture shows a core “App Module” that imports and orchestrates the individual business modules.

##### Architectural Patterns and Design Principles Observed
- Modular Design: Each business area (users, roles, items, permissions, auth) is encapsulated in its own module, facilitating scalability and ease of testing.
- Layered Architecture: There’s a clear separation between controllers (presentation layer), services (business logic layer), and entities (data access layer).
- Dependency Injection: Utilized by NestJS to manage dependencies between controllers and services.
- Use of DTOs: Standardizing input and output data, ensuring robust data validation and transformation.

##### Technologies and Frameworks
- NestJS: The application framework driving the backend.
- TypeScript: The language used throughout the project.
- Testing Frameworks: Jest is being used for unit and e2e tests based on the .spec.ts files.
- (Potentially) ORM: The presence of entity files implies that an ORM (like TypeORM) may be in use to interact with a database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Core
    subgraph "Application Core"
        A1["Bootstrap (main.ts)"]:::core
        A2["App Module (app.module.ts)"]:::core
    end
    A1 -->|"Bootstraps"| A2

    %% Client Request Entry
    CR["Client Request"]:::external
    CR -->|"Request"| A2

    %% Modules Container
    subgraph "Modules"
        %% Auth Module
        subgraph "Auth Module"
            AC["Controller"]:::controller
            AS["Service"]:::service
            AD["DTOs"]:::dto
            AG["JWT Guard"]:::security
            AJ["JWT Strategy"]:::security
        end

        %% Items Module
        subgraph "Items Module"
            IC["Controller"]:::controller
            IS["Service"]:::service
            ID["DTOs"]:::dto
            IE["Entity (Item)"]:::entity
        end

        %% Permissions Module
        subgraph "Permissions Module"
            PC["Controller"]:::controller
            PS["Service"]:::service
            PD["DTOs"]:::dto
            PE["Entity (Permission)"]:::entity
        end

        %% Roles Module
        subgraph "Roles Module"
            RC["Controller"]:::controller
            RS["Service"]:::service
            RD["DTOs"]:::dto
            RE["Entity (Role)"]:::entity
        end

        %% Users Module
        subgraph "Users Module"
            UC["Controller"]:::controller
            US["Service"]:::service
            UD["DTOs"]:::dto
            UE["Entity (User)"]:::entity
        end
    end

    %% App Module loads modules
    A2 -->|"loads"| AC
    A2 -->|"loads"| IC
    A2 -->|"loads"| PC
    A2 -->|"loads"| RC
    A2 -->|"loads"| UC

    %% Client Request flows into each module's controller
    CR -->|"Request"| AC
    CR -->|"Request"| IC
    CR -->|"Request"| PC
    CR -->|"Request"| RC
    CR -->|"Request"| UC

    %% Internal Module Interactions
    %% Auth Module Flow
    AC -->|"calls"| AS
    AC -->|"validates"| AD
    AS -->|"utilizes"| AD
    AS -->|"invokes"| AG
    AS -->|"invokes"| AJ
    %% Items Module Flow
    IC -->|"calls"| IS
    IC -->|"validates"| ID
    IS -->|"operates on"| IE
    %% Permissions Module Flow
    PC -->|"calls"| PS
    PC -->|"validates"| PD
    PS -->|"operates on"| PE
    %% Roles Module Flow
    RC -->|"calls"| RS
    RC -->|"validates"| RD
    RS -->|"operates on"| RE
    %% Users Module Flow
    UC -->|"calls"| US
    UC -->|"validates"| UD
    US -->|"operates on"| UE

    %% Configuration and Security Integration
    Conf["Configuration (JWT)"]:::config
    Security["Security Components"]:::security2

    AS -->|"uses"| Conf
    AG -->|"decorated by"| Security

    %% Test Suites
    Tests["Test Suites"]:::test
    AS -->|"testedBy"| Tests
    IS -->|"testedBy"| Tests
    PS -->|"testedBy"| Tests
    RS -->|"testedBy"| Tests
    US -->|"testedBy"| Tests

    %% Click Events
    click A1 "https://github.com/lgabrielcor/apitransfer/blob/main/src/main.ts"
    click A2 "https://github.com/lgabrielcor/apitransfer/blob/main/src/app.module.ts"

    click AC "https://github.com/lgabrielcor/apitransfer/blob/main/src/auth/auth.controller.ts"
    click AS "https://github.com/lgabrielcor/apitransfer/blob/main/src/auth/auth.service.ts"
    click AD "https://github.com/lgabrielcor/apitransfer/tree/main/src/auth/dto"
    click AG "https://github.com/lgabrielcor/apitransfer/blob/main/src/auth/jwt-auth.guard.ts"
    click AJ "https://github.com/lgabrielcor/apitransfer/blob/main/src/auth/jwt.strategy.ts"

    click IC "https://github.com/lgabrielcor/apitransfer/blob/main/src/items/items.controller.ts"
    click IS "https://github.com/lgabrielcor/apitransfer/blob/main/src/items/items.service.ts"
    click ID "https://github.com/lgabrielcor/apitransfer/tree/main/src/items/dto"
    click IE "https://github.com/lgabrielcor/apitransfer/blob/main/src/items/entities/item.entity.ts"

    click PC "https://github.com/lgabrielcor/apitransfer/blob/main/src/permissions/permissions.controller.ts"
    click PS "https://github.com/lgabrielcor/apitransfer/blob/main/src/permissions/permissions.service.ts"
    click PD "https://github.com/lgabrielcor/apitransfer/tree/main/src/permissions/dto"
    click PE "https://github.com/lgabrielcor/apitransfer/blob/main/src/permissions/entities/permission.entity.ts"

    click RC "https://github.com/lgabrielcor/apitransfer/blob/main/src/roles/roles.controller.ts"
    click RS "https://github.com/lgabrielcor/apitransfer/blob/main/src/roles/roles.service.ts"
    click RD "https://github.com/lgabrielcor/apitransfer/tree/main/src/roles/dto"
    click RE "https://github.com/lgabrielcor/apitransfer/blob/main/src/roles/entities/role.entity.ts"

    click UC "https://github.com/lgabrielcor/apitransfer/blob/main/src/users/users.controller.ts"
    click US "https://github.com/lgabrielcor/apitransfer/blob/main/src/users/users.service.ts"
    click UD "https://github.com/lgabrielcor/apitransfer/tree/main/src/users/dto"
    click UE "https://github.com/lgabrielcor/apitransfer/blob/main/src/users/entities/user.entity.ts"

    click Conf "https://github.com/lgabrielcor/apitransfer/blob/main/src/config/jwt.config.ts"
    click Security "https://github.com/lgabrielcor/apitransfer/blob/main/src/security/custom-decorator.ts"
    click Tests "https://github.com/lgabrielcor/apitransfer/tree/main/test"

    %% Styles
    classDef core fill:#f9c,stroke:#333,stroke-width:2px;
    classDef controller fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#bfb,stroke:#333,stroke-width:2px;
    classDef dto fill:#dfd,stroke:#333,stroke-width:2px;
    classDef entity fill:#fdd,stroke:#333,stroke-width:2px;
    classDef security fill:#fbb,stroke:#333,stroke-width:2px;
    classDef config fill:#ff9,stroke:#333,stroke-width:2px;
    classDef test fill:#ccc,stroke:#333,stroke-width:2px;
    classDef external fill:#9cf,stroke:#333,stroke-width:2px;
    classDef security2 fill:#fbb,stroke:#333,stroke-width:2px;
```
