# sayho93/nest-boilerplate architecture

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

- Interactive diagram: https://gitdiagram.com/sayho93/nest-boilerplate
- Repository: https://github.com/sayho93/nest-boilerplate

## Overview

##### Main Application Components

a) Core Application Layer:
- Auth Module
- Users Module
- Credits Module
- Projects Module
- Request Module
- Mail Module

b) Infrastructure Layer:
- Database (MariaDB) - indicated by the presence of TypeORM config and migrations
- Redis Cache - shown in the cache module and configuration
- Queue System - evidenced by the queue module
- Mail Service - shown by the mail module

##### External Services Integration
- Google OAuth (visible in auth strategies)
- JWT Authentication Service

##### Cross-Cutting Concerns
As horizontal layers:
- AOP (Aspect-Oriented Programming) Module
- Logger Module
- Cache Layer
- Transaction Management
- Event System

##### Specific Design Elements

Use the following representation guidelines:

a) Database Entities (show as connected tables):
- User Entity
- Auth Entity
- Credit Entity
- Project Entity
- Request Entity

- Local Auth Strategy
- JWT Strategy
- Google Strategy
- Refresh Token Flow

c) Request Processing Pipeline (show as a flow):
- Request ID Interceptor
- Request Log Interceptor
- Global Exception Filter
- AsyncLocalStorage Middleware

##### Important Relationships to Highlight

Key interactions:
- User ←→ Auth relationships
- Credit ←→ User relationships
- Project ←→ User relationships
- Queue processing flows
- Cache interaction patterns
- Transaction boundaries

##### Additional Elements

Supporting components:
- Configuration Management
- Migration System
- Seeding System
- Docker Container Boundary
- Nginx Reverse Proxy

##### Technical Details

Annotations for:
- TypeORM as the ORM layer
- Redis for caching and queue
- MariaDB as the primary database
- JWT for token management
- Bull for queue processing

For the actual drawing:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Main["NestJS Application"]
        subgraph CoreModules["Core Application Modules"]
            Auth["Auth Module"]:::core
            Users["Users Module"]:::core
            Credits["Credits Module"]:::core
            Projects["Projects Module"]:::core
            Request["Request Module"]:::core
            Mail["Mail Module"]:::core
        end

        subgraph Infrastructure["Infrastructure Layer"]
            DB[(MariaDB)]:::infra
            Redis[(Redis Cache)]:::infra
            Queue["Queue System"]:::infra
            MailService["Mail Service"]:::infra
        end

        subgraph CrossCutting["Cross-Cutting Concerns"]
            AOP["AOP Module"]:::cross
            Logger["Logger Module"]:::cross
            Cache["Cache Layer"]:::cross
            Transaction["Transaction Management"]:::cross
            Events["Event System"]:::cross
        end

        subgraph Auth_Components["Authentication Components"]
            LocalAuth["Local Strategy"]:::auth
            JWTAuth["JWT Strategy"]:::auth
            GoogleAuth["Google Strategy"]:::auth
            RefreshToken["JWT Refresh"]:::auth
        end

        subgraph Pipeline["Request Pipeline"]
            ReqID["Request ID Interceptor"]:::pipe
            ReqLog["Request Log Interceptor"]:::pipe
            ExceptionFilter["Global Exception Filter"]:::pipe
            AsyncStorage["AsyncLocalStorage Middleware"]:::pipe
        end
    end

    subgraph External["External Services"]
        GoogleOAuth["Google OAuth"]:::external
        JWTService["JWT Service"]:::external
    end

    %% Core Module Relationships
    Auth --> Users
    Credits --> Users
    Projects --> Users
    Request --> Users
    Mail --> Users

    %% Infrastructure Connections
    Auth --> DB
    Users --> DB
    Credits --> DB
    Projects --> DB
    Request --> DB
    Queue --> Redis
    Cache --> Redis
    MailService --> Mail

    %% Auth Flow
    Auth --> LocalAuth
    Auth --> JWTAuth
    Auth --> GoogleAuth
    Auth --> RefreshToken
    GoogleAuth --> GoogleOAuth
    JWTAuth --> JWTService

    %% Request Pipeline Flow
    Pipeline --> CoreModules

    %% Cross-Cutting Concerns
    CrossCutting --> CoreModules
    CrossCutting --> Infrastructure

    %% Click Events
    click Auth "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/auth"
    click Users "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/users"
    click Credits "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/credits"
    click Projects "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/projects"
    click Request "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/request"
    click Mail "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/mail"
    click Queue "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/queue"
    click MailService "https://github.com/sayho93/nest-boilerplate/blob/main/src/modules/mail/mail.service.ts"
    click AOP "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/aop"
    click Logger "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/logger"
    click Cache "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/cache"
    click Transaction "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/transaction"
    click Events "https://github.com/sayho93/nest-boilerplate/tree/main/src/modules/events"
    click LocalAuth "https://github.com/sayho93/nest-boilerplate/blob/main/src/modules/auth/strategies/local.strategy.ts"
    click JWTAuth "https://github.com/sayho93/nest-boilerplate/blob/main/src/modules/auth/strategies/jwt.strategy.ts"
    click GoogleAuth "https://github.com/sayho93/nest-boilerplate/blob/main/src/modules/auth/strategies/google.strategy.ts"
    click RefreshToken "https://github.com/sayho93/nest-boilerplate/blob/main/src/modules/auth/strategies/jwt-refresh.strategy.ts"
    click ReqID "https://github.com/sayho93/nest-boilerplate/blob/main/src/interceptors/request-id.interceptor.ts"
    click ReqLog "https://github.com/sayho93/nest-boilerplate/blob/main/src/interceptors/request-log.interceptor.ts"
    click ExceptionFilter "https://github.com/sayho93/nest-boilerplate/blob/main/src/filters/global-exceptions.filter.ts"
    click AsyncStorage "https://github.com/sayho93/nest-boilerplate/blob/main/src/middlewares/async-local-storage.middleware.ts"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef infra fill:#FFC107,stroke:#FFA000,color:black
    classDef cross fill:#9E9E9E,stroke:#616161,color:white
    classDef auth fill:#F44336,stroke:#D32F2F,color:white
    classDef external fill:#4CAF50,stroke:#388E3C,color:white
    classDef pipe fill:#FF9800,stroke:#F57C00,color:white

    %% Legend
    subgraph Legend
        CoreLegend["Core Module"]:::core
        InfraLegend["Infrastructure"]:::infra
        CrossLegend["Cross-Cutting"]:::cross
        AuthLegend["Authentication"]:::auth
        ExtLegend["External Service"]:::external
        PipeLegend["Pipeline Component"]:::pipe
    end
```
