# saluki/nestjs-template architecture

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

- Interactive diagram: https://gitdiagram.com/saluki/nestjs-template
- Repository: https://github.com/saluki/nestjs-template

## Overview

##### Main Components Identification

The system is a NestJS-based REST API with the following key components:
- API Layer (NestJS + Fastify)
- Database Layer (PostgreSQL with Prisma ORM)
- Authentication/Security Layer
- Module Structure
- External Interfaces (REST endpoints)

##### Common Module
- Health Controller
- Configuration Provider
- Logger Service
- Security Guards (Guest, Health, Restricted)
- Joi Validation Pipe

##### Passenger Module
- Controller
- Service
- Data Models (Input/Output)
- Custom Pipes

##### Infrastructure Services
- Prisma Provider
- JWT Authentication
- Configuration Service

D. Database Layer (Bottom)
- PostgreSQL Database
- Prisma ORM Layer
- Migrations

##### Specific Implementation Details

a. Modular Architecture:
- Clear separation between Common and Passenger modules
- Hierarchical structure (app.module as parent)

b. Request Flow:
- Incoming HTTP request
- Middleware/Guard processing
- Controller routing
- Service processing
- Database interaction
- Response flow

c. Security Layer:
- JWT authentication flow
- Guard implementation points
- Health check token validation

##### Technical Stack Callouts

Technologies:
- NestJS 10
- Fastify
- Prisma ORM
- PostgreSQL
- Joi Validation
- Winston Logger
- JWT Authentication

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        REST[REST API Clients]
        SWAGGER["/docs - Swagger UI"]
    end

    subgraph Gateway
        FASTIFY[Fastify HTTP Server]:::server
        click FASTIFY "https://github.com/Saluki/nestjs-template/blob/master/src/server.ts"
        APIROUTE["/api/v1"]:::api
        APP[App Module]:::module
        click APP "https://github.com/Saluki/nestjs-template/blob/master/src/modules/app.module.ts"
    end

    subgraph Core
        subgraph Common
            COMMON[Common Module]:::module
            click COMMON "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/common.module.ts"
            CONFIG[Configuration Provider]:::service
            click CONFIG "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/provider/config.provider.ts"
            LOGGER[Logger Service]:::service
            click LOGGER "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/provider/logger.service.ts"
            PRISMAP[Prisma Provider]:::service
            click PRISMAP "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/provider/prisma.provider.ts"
            
            subgraph Security
                GGUARD[Guest Guard]:::security
                click GGUARD "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/security/guest.guard.ts"
                HGUARD[Health Guard]:::security
                click HGUARD "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/security/health.guard.ts"
                RGUARD[Restricted Guard]:::security
                click RGUARD "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/security/restricted.guard.ts"
                SUTIL[Security Utils]:::security
                click SUTIL "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/security/security-utils.ts"
            end

            subgraph Flow
                JOIVAL[Joi Validation Pipe]:::pipe
                click JOIVAL "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/flow/joi-validation.pipe.ts"
                LOGINT[Log Interceptor]:::interceptor
                click LOGINT "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/flow/log.interceptor.ts"
            end

            HEALTH[Health Controller]:::controller
            click HEALTH "https://github.com/Saluki/nestjs-template/blob/master/src/modules/common/controller/health.controller.ts"
        end

        subgraph Passenger
            PMOD[Passenger Module]:::module
            click PMOD "https://github.com/Saluki/nestjs-template/blob/master/src/modules/passenger/passenger.module.ts"
            PCTRL[Passenger Controller]:::controller
            click PCTRL "https://github.com/Saluki/nestjs-template/blob/master/src/modules/passenger/controller/passenger.controller.ts"
            PSVC[Passenger Service]:::service
            click PSVC "https://github.com/Saluki/nestjs-template/blob/master/src/modules/passenger/service/passenger.service.ts"
            PDATA[Passenger Data Model]:::model
            click PDATA "https://github.com/Saluki/nestjs-template/blob/master/src/modules/passenger/model/passenger.data.ts"
            PINPUT[Passenger Input Model]:::model
            click PINPUT "https://github.com/Saluki/nestjs-template/blob/master/src/modules/passenger/model/passenger.input.ts"
            PPIPE[Passenger Pipe]:::pipe
            click PPIPE "https://github.com/Saluki/nestjs-template/blob/master/src/modules/passenger/flow/passenger.pipe.ts"
        end
    end

    subgraph Database
        PRISMA[Prisma ORM]:::database
        click PRISMA "https://github.com/Saluki/nestjs-template/blob/master/prisma/schema.prisma"
        POSTGRES[(PostgreSQL)]:::database
        MIGRATION[Migrations]:::database
        click MIGRATION "https://github.com/Saluki/nestjs-template/blob/master/prisma/migrations/20240113113057_passengers_table/migration.sql"
    end

    %% Connections
    REST --> FASTIFY
    REST --> SWAGGER
    FASTIFY --> APIROUTE
    APIROUTE --> APP
    APP --> COMMON
    APP --> PMOD
    COMMON --> HEALTH
    COMMON --> CONFIG
    COMMON --> LOGGER
    COMMON --> PRISMAP
    PMOD --> PCTRL
    PCTRL --> PSVC
    PSVC --> PDATA
    PSVC --> PINPUT
    PSVC --> PPIPE
    PRISMAP --> PRISMA
    PRISMA --> POSTGRES
    PRISMA --> MIGRATION

    %% Styles
    classDef module fill:#a4c2f4
    classDef controller fill:#b6d7a8
    classDef service fill:#d5a6bd
    classDef security fill:#f9cb9c
    classDef pipe fill:#ffe599
    classDef interceptor fill:#ea9999
    classDef database fill:#f9cb9c
    classDef api fill:#a4c2f4
    classDef server fill:#b6d7a8
    classDef model fill:#d5a6bd

    %% Legend
    subgraph Legend
        L1[Module]:::module
        L2[Controller]:::controller
        L3[Service]:::service
        L4[Security]:::security
        L5[Pipe/Interceptor]:::pipe
        L6[Database]:::database
    end
```
