# davidespinozaromero/deer-nestjs-base architecture

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

- Interactive diagram: https://gitdiagram.com/davidespinozaromero/deer-nestjs-base
- Repository: https://github.com/davidespinozaromero/deer-nestjs-base

## Overview

##### Project type and purpose
- This is a NestJS‐based backend REST API (no separate frontend directory).
- Its core features are user authentication (signup/login with JWT), role-based guards, and a “seed” endpoint to populate initial data into a Postgres DB.
- It uses Docker Compose to spin up Postgres, environment variables for configuration, and Jest for tests.

##### File structure
- Top-level configuration: `.env.template`, `docker-compose.yaml`, `nest-cli.json`, `tsconfig*.json`, `package.json`, ESLint/Prettier and Gitignore files.
- `src/main.ts` → boots the Nest application.
- `src/app.module.ts` → root module importing sub-modules.
- `src/modules/auth` → authentication module (controllers, services, DTOs, entities, guards, decorators, JWT strategy).
- `src/modules/seed` → seed module (controller + service to insert initial data).
- `src/modules/common` → shared logic (e.g., pagination DTO).
- Tests under `src/modules/*/*.spec.ts` and `test/app.e2e-spec.ts`.

##### README for additional insights
- Stack: NestJS + Postgres.
- Deployment: Docker Compose spins up the database.
- Environment variables configure DB connection, JWT secrets, and other Nest settings.

##### Elements
- From Client → Controllers
- Controllers → Services
- Services → Repositories → DB
- Services ↔ JWT Strategy / Guards

## Diagram (Mermaid)

```mermaid
graph TB
    %% Actors and External
    Client["Client (Web/Mobile/Postman)"]:::actor
    Env["Environment Variables (.env.template)"]:::infra
    DockerCompose["Docker Compose"]:::infra
    Postgres["Postgres DB"]:::infra

    %% NestJS Bootstrapping
    subgraph "NestJS API Server" 
        direction TB
        Main["main.ts\n(Nest Application Bootstrap)"]:::nest
        AppModule["app.module.ts\n(Root Module)"]:::nest

        subgraph "Auth Module" 
            direction TB
            AuthController["AuthController"]:::controller
            AuthService["AuthService"]:::service
            UserEntity["UserEntity"]:::entity
            DTOs["Auth DTOs"]:::dto
            JWTStrategy["JWT Strategy"]:::security
            Guards["Guards"]:::security
            Decorators["Decorators"]:::security
        end

        subgraph "Seed Module"
            direction TB
            SeedController["SeedController"]:::controller
            SeedService["SeedService"]:::service
            SeedData["Seed Data Directory"]:::module
        end

        subgraph "Common Module"
            direction TB
            PaginationDTO["Pagination DTO"]:::dto
        end
    end

    %% Relationships
    Client -->|"HTTP Requests"| AuthController
    Client -->|"HTTP Requests"| SeedController

    AuthController -->|"calls"| AuthService
    SeedController -->|"calls"| SeedService

    AuthService -->|"uses Repo"| UserEntity
    SeedService -->|"inserts into"| Postgres

    AuthService -->|"issues JWT"| JWTStrategy
    AuthController -->|"protected by"| Guards
    Guards -->|"reads"| JWTStrategy

    Main --> AppModule
    AppModule --> AuthModule
    AppModule --> SeedModule
    AppModule --> CommonModule

    Main -->|"reads"| Env
    DockerCompose --> Postgres
    DockerCompose --> Main

    Postgres ---|"persists Entities"| UserEntity

    %% Click Events
    click Main "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/main.ts"
    click AppModule "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/app.module.ts"
    click AuthModule "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/auth.module.ts"
    click AuthController "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/auth.controller.ts"
    click AuthService "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/auth.service.ts"
    click UserEntity "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/entities/user.entity.ts"
    click DTOs "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/dto/create-user.dto.ts"
    click DTOs "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/dto/login-user.dto.ts"
    click DTOs "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/dto/update-user.dto.ts"
    click JWTStrategy "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/strategies/jwt.strategy.ts"
    click Guards "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/guards/user-role.guard.ts"
    click Decorators "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/decorators/auth.decorator.ts"
    click Decorators "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/decorators/get-user.decorator.ts"
    click Decorators "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/auth/decorators/role-protected.decorator.ts"
    click SeedModule "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/seed/seed.module.ts"
    click SeedController "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/seed/seed.controller.ts"
    click SeedService "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/seed/seed.service.ts"
    click SeedData "https://github.com/davidespinozaromero/deer-nestjs-base/tree/master/src/modules/seed/data/"
    click PaginationDTO "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/src/modules/common/dto/pagination.dto.ts"
    click Env "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/.env.template"
    click DockerCompose "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/docker-compose.yaml"
    click Postgres "https://github.com/davidespinozaromero/deer-nestjs-base/blob/master/docker-compose.yaml"
    
    %% Styles
    classDef actor fill:#f9f,stroke:#333,stroke-width:1px
    classDef infra fill:#ccc,stroke:#333,stroke-width:1px
    classDef nest fill:#ccf,stroke:#333,stroke-width:1px
    classDef module fill:#cfc,stroke:#333,stroke-width:1px
    classDef controller fill:#9cf,stroke:#333,stroke-width:1px
    classDef service fill:#fc9,stroke:#333,stroke-width:1px
    classDef entity fill:#ffc,stroke:#333,stroke-width:1px
    classDef dto fill:#cff,stroke:#333,stroke-width:1px
    classDef security fill:#fcc,stroke:#333,stroke-width:1px
```
