# ferreirase/xbri-test architecture

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

- Interactive diagram: https://gitdiagram.com/ferreirase/xbri-test
- Repository: https://github.com/ferreirase/xbri-test

## Overview

##### Main Components
- NestJS Application Core: The central setup (starting in src/main.ts and src/app.module.ts) that bootstraps the application.
- Modules & Controllers: The “auth” folder in src contains the auth controller (auth.controller.ts) that defines the REST API endpoints and the associated auth service (auth.service.ts) for business logic.
- Providers and Strategies: Notice the providers folder with auth.provider.ts and user-typeorm-repository.provider.ts, as well as the authentication guards and strategies (jwt, local) in the auth/guards and auth/strategies directories.
- Domain Layer for Authentication: Under src/libs/auth there is a well-organized domain that includes entities (user.ts), value-objects (email, password), and domain-specific interfaces.
- Application Layer for Authentication: In the same libs/auth directory, the application segment organizes use cases (e.g., signup-usecase.ts) and repository interfaces. This is where business use cases are defined separately from the infrastructure.
- Infrastructure Layer: The “infra” directory within libs/auth details the implementations for interacting with the database, including TypeORM setups, entity definitions (user.entity.ts), and schema definitions.
- External Dependencies and Configurations: Files like the docker-compose.yaml, .env.example, and configuration files for Nest CLI, Prettier, and ESLint set up the environmental and coding standards.

##### Understand the Relationships and Interactions
- The API Layer (controllers) handles incoming HTTP requests and delegates the logic to services.
- The Services call use case logic defined in the application layer, which in turn uses repository interfaces.
- The repository interfaces are implemented by TypeORM-based repositories in the infrastructure layer for data persistence.
- Guards and strategies ensure that authentication flows (such as JWT and local strategy mechanisms) are enforced before reaching the business logic.
- Providers are used for dependency injection, wiring up various parts of the system (e.g., linking the user repository instance to the service).

##### Architectural Patterns and Design Principles
- Domain-Driven Design (DDD): Notice how the auth functionality is split between domain (entities, value-objects), application (use cases, repository interfaces), and infrastructure (database, TypeORM implementations).
- Modular Design: Each major piece (auth module, providers, and the general app module) is self-contained and can be extended or maintained individually.
- Layered Architecture: Clear separation with controllers on top, then services (application logic), followed by repository abstractions and infrastructure.

##### Relevant Technologies
- Framework: NestJS (and its module system, dependency injection, controllers, providers)
- ORM: TypeORM (for database interactions)
- Security: JWT for authentication, with corresponding strategies and guards.
- Development Tools: Docker for container orchestration via docker-compose, ESLint, Prettier configurations ensure code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% NestJS Core
    A["NestJS Core\n(main.ts & app.module.ts)"]:::core

    %% API Layer
    subgraph "API Layer"
        B1["Auth Controller\n(Handles HTTP requests)"]:::api
        B2["Auth Service\n(Business logic)"]:::api
    end

    %% Security Layer (Guards & Strategies)
    subgraph "Security Layer"
        D1["JWT Guard"]:::security
        D2["Local Guard"]:::security
        E1["JWT Strategy"]:::security
        E2["Local Strategy"]:::security
    end

    %% Providers Layer
    subgraph "Providers"
        C1["Auth Provider"]:::providers
        C2["User Repository Provider"]:::providers
    end

    %% Application Layer
    subgraph "Application Layer"
        F1["Signup Use Case"]:::app
        F2["User Auth Repository Interface"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        G1["User Entity"]:::domain
        G2["Email Value Object"]:::domain
        G3["Password Value Object"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        H1["User TypeORM Repository"]:::infra
        H2["User DB Entity"]:::infra
        H3["User Schema"]:::infra
    end

    %% Database
    I["Database"]:::db

    %% Connections
    A -->|"bootstraps"| B1
    A -->|"bootstraps"| B2

    B1 -->|"delegates"| B2
    B1 ---|"protectedBy"| D1
    B1 ---|"protectedBy"| D2
    B1 ---|"uses"| E1
    B1 ---|"uses"| E2

    B2 -->|"injects"| C1
    B2 -->|"injects"| C2
    B2 -->|"calls"| F1

    F1 -->|"invokes domain"| G1
    F1 -->|"invokes domain"| G2
    F1 -->|"invokes domain"| G3

    F1 -->|"uses interface"| F2
    F2 -->|"implementedBy"| H1

    H1 -->|"maps to"| H2
    H1 -->|"maps to"| H3
    H1 -->|"persists data to"| I

    %% Click Events
    click A "https://github.com/ferreirase/xbri-test/blob/master/src/main.ts"
    click A "https://github.com/ferreirase/xbri-test/blob/master/src/app.module.ts"
    click B1 "https://github.com/ferreirase/xbri-test/blob/master/src/auth/auth.controller.ts"
    click B2 "https://github.com/ferreirase/xbri-test/blob/master/src/auth/auth.service.ts"
    click D1 "https://github.com/ferreirase/xbri-test/blob/master/src/auth/guards/jwt.guard.ts"
    click D2 "https://github.com/ferreirase/xbri-test/blob/master/src/auth/guards/local.guard.ts"
    click E1 "https://github.com/ferreirase/xbri-test/blob/master/src/auth/strategies/jwt.strategy.ts"
    click E2 "https://github.com/ferreirase/xbri-test/blob/master/src/auth/strategies/local.strategy.ts"
    click G1 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/domain/entities/user.ts"
    click G2 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/domain/value-objects/email.ts"
    click G3 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/domain/value-objects/password.ts"
    click F1 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/application/usecases/signup-usecase.ts"
    click F2 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/application/repositories/user-auth.repository.ts"
    click H1 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/infra/repositories/typeorm/user-typeorm.repository.ts"
    click H2 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/infra/db/entities/user.entity.ts"
    click H3 "https://github.com/ferreirase/xbri-test/blob/master/src/libs/auth/infra/db/typeorm/schemas/user.schema.ts"
    click C1 "https://github.com/ferreirase/xbri-test/blob/master/src/providers/auth.provider.ts"
    click C2 "https://github.com/ferreirase/xbri-test/blob/master/src/providers/user-typeorm-repository.provider.ts"

    %% Styles
    classDef core fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef api fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef providers fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef security fill:#f9e79f,stroke:#af601a,stroke-width:2px;
    classDef app fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef domain fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
    classDef infra fill:#fad7a0,stroke:#ca6f1e,stroke-width:2px;
    classDef db fill:#d5f5e3,stroke:#117864,stroke-width:2px;
```
