# mikemajesty/nestjs-monorepo architecture

> Architecture diagram of the GitHub repository mikemajesty/nestjs-monorepo, 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/mikemajesty/nestjs-monorepo
- Repository: https://github.com/mikemajesty/nestjs-monorepo

## Overview

##### Main Components Identification

The system is a microservices-based architecture with the following key components:

a. Applications (Microservices):
- Auth API Service (Authentication/Authorization)
- Cats API Service (Example Business Service)

b. Shared Libraries:
- Core Library (Business Rules)
- Modules Library (NestJS Modules)
- Utils Library (Shared Utilities)

c. Infrastructure Services:
- MongoDB (Multiple databases)
- Redis (Caching)
- Elastic/Kibana (Logging)
- Jaeger (Tracing)

##### Component Relationships

- HTTP Communication (REST APIs)
- Database Connections
- Cache Interactions
- Logging/Tracing Flow

##### Special Architectural Elements

Following patterns:
- Dependency Inversion (Show interfaces and implementations)
- Anti-Corruption Layer (Between services and external systems)
- Interface Adapters (Show adapter pattern implementation)
- Generic Repository Pattern (Database interactions)

##### Additional Details

- Authentication Flow
- Error Handling Flow
- Observability Pipeline
- Module Dependencies

##### Technical Specifications

Annotations for:
- Node.js Version Requirements
- Docker Container Boundaries
- Network Zones
- Security Boundaries

##### Implementation Notes

- Modular structure of the monorepo
- Clear separation of concerns
- Shared resource usage
- Security boundaries
- Scalability points

##### Deployment View

A small section showing:
- Docker container organization
- Service discovery
- Load balancing
- Network isolation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        API[API Consumers]
        SWAGGER[Swagger UI]
    end

    subgraph APIGateway
        AUTH_FLOW[Authentication Flow]
        REQ_FLOW[Request/Response Flow]
    end

    subgraph Microservices
        AUTH_API[Auth API Service]:::service
        click AUTH_API "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/auth-api"
        
        subgraph AuthModules
            LOGIN[Login Module]:::module
            click LOGIN "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/auth-api/src/modules/login"
            USER[User Module]:::module
            click USER "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/auth-api/src/modules/user"
            HEALTH_AUTH[Health Module]:::module
            click HEALTH_AUTH "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/auth-api/src/modules/health"
        end

        CATS_API[Cats API Service]:::service
        click CATS_API "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/cats-api"
        
        subgraph CatsModules
            CATS[Cats Module]:::module
            click CATS "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/cats-api/src/modules/cats"
            HEALTH_CATS[Health Module]:::module
            click HEALTH_CATS "https://github.com/mikemajesty/nestjs-monorepo/tree/main/apps/cats-api/src/modules/health"
        end
    end

    subgraph SharedLibraries
        CORE[Core Library]:::library
        click CORE "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/core"
        
        subgraph Modules
            AUTH_MOD[Auth Module]:::module
            click AUTH_MOD "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/auth"
            CACHE_MOD[Cache Module]:::module
            click CACHE_MOD "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/cache"
            DB_MOD[Database Module]:::module
            click DB_MOD "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/database"
            GLOBAL_MOD[Global Module]:::module
            click GLOBAL_MOD "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/global"
            HTTP_MOD[HTTP Module]:::module
            click HTTP_MOD "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/http"
        end

        subgraph Utils
            DOC[Documentation]:::util
            click DOC "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/utils/documentation"
            FILTERS[Filters]:::util
            click FILTERS "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/utils/filters"
            INTERCEPTORS[Interceptors]:::util
            click INTERCEPTORS "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/utils/interceptors"
            MIDDLEWARE[Middleware]:::util
            click MIDDLEWARE "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/utils/middleware"
        end
    end

    subgraph Infrastructure
        MONGO[(MongoDB)]:::infra
        REDIS[(Redis)]:::infra
        ELK[Elastic/Kibana]:::infra
        JAEGER[Jaeger]:::infra
    end

    subgraph Components
        TOKEN[Token Service]:::component
        click TOKEN "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/auth/token"
        AUTH_MID[Auth Middleware]:::component
        click AUTH_MID "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/utils/middleware/auth"
        LOGGER[Logger Module]:::component
        click LOGGER "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/global/logger"
        LOGGER_INT[Logger Interceptor]:::component
        click LOGGER_INT "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/utils/interceptors/logger"
        EXC_FILTER[Exception Filter]:::component
        click EXC_FILTER "https://github.com/mikemajesty/nestjs-monorepo/blob/main/libs/utils/filters/http-exception.filter.ts"
        EXC_INT[Exception Interceptor]:::component
        click EXC_INT "https://github.com/mikemajesty/nestjs-monorepo/blob/main/libs/utils/interceptors/exception/http-exception.interceptor.ts"
        SECRETS[Secrets Management]:::component
        click SECRETS "https://github.com/mikemajesty/nestjs-monorepo/tree/main/libs/modules/global/secrets"
    end

    %% Connections
    Client --> APIGateway
    APIGateway --> Microservices
    Microservices --> SharedLibraries
    SharedLibraries --> Infrastructure

    %% Specific Component Connections
    AUTH_API --> MONGO
    CATS_API --> MONGO
    Microservices --> REDIS
    Microservices --> ELK
    Microservices --> JAEGER

    %% Styling
    classDef service fill:#2196F3,stroke:#1565C0,color:white
    classDef module fill:#4CAF50,stroke:#388E3C,color:white
    classDef library fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef util fill:#FF9800,stroke:#F57C00,color:white
    classDef infra fill:#795548,stroke:#5D4037,color:white
    classDef component fill:#607D8B,stroke:#455A64,color:white

    %% Legend
    subgraph Legend
        SVC[Service]:::service
        MOD[Module]:::module
        LIB[Library]:::library
        UTL[Utility]:::util
        INF[Infrastructure]:::infra
        CMP[Component]:::component
    end
```
