# rodion-arr/nestjs-starter-kit architecture

> Architecture diagram of the GitHub repository rodion-arr/nestjs-starter-kit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rodion-arr/nestjs-starter-kit
- Repository: https://github.com/rodion-arr/nestjs-starter-kit

## Overview

##### Main Components

a. Client Layer:
- External API consumers
- Swagger UI (running on port 3000/api)

b. Application Layer:
- Nest.js API Server (port 3000)
- Main Modules:
- User Module (auth, JWT)
- Health Module
- Logger Module
- Cache Module
- Global Module
- DB Module

c. Infrastructure Layer:
- PostgreSQL Database
- Redis Cache
- MailHog SMTP Server (port 8025)

**┌─────────────┐**
- Clients   │
- ┘
- ↓
**┌─────────────┐**
- Application │
- ┘
- ↓
**┌─────────────┐**
- Infrastructure│
- ┘

##### Specific Implementation Details

- Main NestJS Application Container showing:
- Middleware (AsyncStorage for TraceID)
- Global Interceptors (Request Logger)
- Guards (JWT Auth)
- Core Modules

b. Service interactions:
- User Authentication Flow
- Cache Management
- Email Service
- Health Check endpoints

##### Important Relationships to Highlight

- JWT authentication flow
- Cache interactions with Redis
- Database migrations and TypeORM connections
- Email service flow to MailHog
- Health check connections to all services

##### Technical Details

Annotations for:
- Environment configuration flow
- TypeORM migrations
- Cache TTL configuration
- TraceID generation and propagation
- Graceful shutdown hooks

**[Client] → [Swagger UI]**
- ↓
**[NestJS API Server]**
- [Middleware Layer (AsyncStorage, Validation)]
- [Core Modules]
- [User Module (Auth, JWT)]
- [Health Module]
- [Cache Module]
- [Logger Module]
- [Services Layer]
- [Mail Service]
- [Config Service]
- [Cache Service]
- [Data Layer]
- [TypeORM]
- [Migrations]
- ↓
**[Infrastructure]**
- [PostgreSQL]
- [Redis]
- [MailHog]

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        API[API Consumers]
        SWAG[Swagger UI :3000/api]
    end

    subgraph NestJS["NestJS Application Server :3000"]
        MAIN["Main Application"]:::main
        click MAIN "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/main.ts"
        
        subgraph Middleware
            ASYNC["Async Storage Middleware"]:::middleware
            click ASYNC "https://github.com/rodion-arr/nestjs-starter-kit/tree/main/api/src/global/middleware/async-storage/"
        end

        subgraph Core["Core Modules"]
            USER["User Module"]:::module
            click USER "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/user/user.module.ts"
            
            HEALTH["Health Module"]:::module
            click HEALTH "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/health/health.module.ts"
            
            LOGGER["Logger Module"]:::module
            click LOGGER "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/logger/logger.module.ts"
            
            CACHE["Cache Module"]:::module
            click CACHE "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/app-cache/app-cache.module.ts"
            
            GLOBAL["Global Module"]:::module
            click GLOBAL "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/global/global.module.ts"
            
            DB["DB Module"]:::module
            click DB "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/db/db.module.ts"
        end

        subgraph Services
            AUTH["Auth Service"]:::service
            click AUTH "https://github.com/rodion-arr/nestjs-starter-kit/tree/main/api/src/user/services/auth/"
            
            JWT["JWT Service"]:::service
            click JWT "https://github.com/rodion-arr/nestjs-starter-kit/tree/main/api/src/user/services/jwt/"
            
            MAIL["Mail Service"]:::service
            click MAIL "https://github.com/rodion-arr/nestjs-starter-kit/blob/main/api/src/global/services/mail/mail.service.ts"
            
            CONFIG["Config Service"]:::service
            click CONFIG "https://github.com/rodion-arr/nestjs-starter-kit/tree/main/api/src/services/app-config/"
        end

        subgraph Guards
            JWTG["JWT Guard"]:::security
            click JWTG "https://github.com/rodion-arr/nestjs-starter-kit/tree/main/api/src/user/guards/jwt-auth/"
        end
    end

    subgraph Infrastructure
        POSTGRES[(PostgreSQL)]:::database
        REDIS[(Redis Cache)]:::cache
        click REDIS "https://github.com/rodion-arr/nestjs-starter-kit/tree/main/.docker-node-api/redis/"
        MAILHOG["MailHog SMTP :8025"]:::mail
    end

    %% Connections
    API --> SWAG
    API --> MAIN
    SWAG --> MAIN
    
    MAIN --> ASYNC
    ASYNC --> Core
    
    USER --> AUTH
    USER --> JWT
    USER --> JWTG
    
    CACHE --> REDIS
    DB --> POSTGRES
    MAIL --> MAILHOG
    
    %% Styles
    classDef main fill:#1E88E5,color:white
    classDef module fill:#42A5F5,color:white
    classDef service fill:#90CAF9,color:black
    classDef middleware fill:#FFB74D,color:black
    classDef security fill:#FDD835,color:black
    classDef database fill:#43A047,color:white
    classDef cache fill:#66BB6A,color:white
    classDef mail fill:#EC407A,color:white

    %% Legend
    subgraph Legend
        M1["Main Component"]:::main
        M2["Module"]:::module
        M3["Service"]:::service
        M4["Middleware"]:::middleware
        M5["Security"]:::security
        M6["Database"]:::database
        M7["Cache"]:::cache
        M8["Mail"]:::mail
    end
```
