# buqiyuan/nest-admin architecture

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

- Interactive diagram: https://gitdiagram.com/buqiyuan/nest-admin
- Repository: https://github.com/buqiyuan/nest-admin

## Overview

##### Main Components
- Backend Server: At the center, show the NestJS backend as the core. Represent it as a container that includes the layered structure typical of NestJS – controllers, services, modules, pipes, guards, interceptors, etc.
- Feature Modules: Within the backend, list major modules such as:
- Auth Module (handles JWT, login, token management, etc.)
- System Module (managing departments, dictionary types/items, logs, menus, roles, etc.)
- User Module (managing user accounts and profiles)
- Netdisk Module (file handling and management)
- Additional modules like Health, SSE (Server-Sent Events), Tasks, Tools (email, storage, upload) and Todo.
- Shared and Common Components:
- Shared modules (helper, logger, redis, mailer, database)
- Global configuration and decorators, interceptors, pipes that are used across modules.
- Socket module for WebSocket communication.
- External Services: Outside the backend component, include:
- MySQL database (configured via TypeORM and initialized using SQL scripts from the deploy folder)
- Redis (used for caching and pub/sub mechanisms)
- Deployment & DevOps: Represent Docker configurations (Dockerfile, docker-compose files, ecosystem.config.js) and deployment scripts that manage container orchestration.
- API Documentation: Include the Swagger documentation endpoint (accessible via /api-docs/) to indicate the API layer interface.

##### Out Relationships and Data Flow
- Within the NestJS backend, show how controllers interact with services, and how services might use helper modules, configuration, or shared modules.
- Flow from the NestJS application to external databases (MySQL) and cache (Redis) services.
- Communication paths for WebSocket events via the Socket module.
- If desired, indicate how the scheduled tasks (from modules like Tasks) and cron/queue operations interact with the overall system.

##### Architectural Patterns and Design Principles
- Modular Architecture: Each feature is encapsulated in its own module (e.g., auth, system, netdisk, tasks, etc.) following NestJS’s Angular-inspired modular structure.
- Separation of Concerns: Clearly separate controllers (API layer), services (business logic), and providers (helpers, interceptors, etc.).
- Use of Decorators and Interceptors: Emphasize that custom decorators, pipes, and interceptors are being used for cross-cutting concerns like validation, transformation, logging, and error handling.

##### Relevant Technologies
- NestJS, TypeScript, TypeORM, and Redis as part of the backend tech stack.
- Mention the database (MySQL) and container orchestration (Docker).
- Additional libraries such as Swagger (for API documentation), Socket.io or Fastify (for adapters in the adapters folder), and custom helper functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Frontend["Frontend Client (Vue3)"]:::external

    %% Core Backend Application
    BackendCore["Core Application (NestJS)"]:::backend

    %% Feature Modules Subgraph
    subgraph "Feature Modules"
        AuthModule["Auth Module"]:::module
        SystemModule["System Module"]:::module
        UserModule["User Module"]:::module
        NetdiskModule["Netdisk Module"]:::module
        HealthModule["Health Module"]:::module
        SSEModule["SSE Module"]:::module
        TasksModule["Tasks Module"]:::module
        ToolsModule["Tools Module"]:::module
        TodoModule["Todo Module"]:::module
    end

    %% Shared & Common Subgraph
    subgraph "Shared & Common"
        CommonU["Common Utilities"]:::shared
        SharedM["Shared Modules"]:::shared
    end

    %% Socket Module for WebSocket Communication
    SocketModule["Socket Module"]:::socket

    %% API Documentation
    Swagger["Swagger API Docs"]:::documentation

    %% External Services Subgraph
    subgraph "External Services"
        MySQL["MySQL Database"]:::database
        Redis["Redis"]:::database
    end

    %% Deployment & DevOps Subgraph
    subgraph "Deployment & DevOps"
        Docker["Docker Configurations"]:::deployment
        ProcessManager["Process Manager"]:::deployment
        DeployScripts["Deployment Scripts"]:::deployment
    end

    %% Data Flow Connections
    Frontend -->|"APICall"| BackendCore

    %% Core Application uses feature modules
    BackendCore --> AuthModule
    BackendCore --> SystemModule
    BackendCore --> UserModule
    BackendCore --> NetdiskModule
    BackendCore --> HealthModule
    BackendCore --> SSEModule
    BackendCore --> TasksModule
    BackendCore --> ToolsModule
    BackendCore --> TodoModule

    %% Core Application uses shared & common components
    BackendCore --> CommonU
    BackendCore --> SharedM

    %% Core Application integrates WebSocket communication
    BackendCore --> SocketModule

    %% API Documentation exposure
    BackendCore --> Swagger

    %% Core Application interacts with External Databases/Caches
    BackendCore -->|"Uses"| MySQL
    BackendCore -->|"Caches"| Redis

    %% Deployment & DevOps orchestrates Backend and External Services
    Docker --> BackendCore
    ProcessManager --> BackendCore
    DeployScripts --> BackendCore
    Docker --> MySQL
    Docker --> Redis

    %% Styles
    classDef external fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef module fill:#e6e6ff,stroke:#6666ff,stroke-width:2px;
    classDef shared fill:#d5f5e3,stroke:#2e8b57,stroke-width:2px;
    classDef socket fill:#f9e6ff,stroke:#a64d79,stroke-width:2px;
    classDef documentation fill:#fff2cc,stroke:#b38f00,stroke-width:2px;
    classDef database fill:#eeeeee,stroke:#999999,stroke-width:2px,stroke-dasharray: 5 5;
    classDef deployment fill:#f2f2f2,stroke:#666666,stroke-width:2px,stroke-dasharray: 3 3;

    %% Click Events
    click BackendCore "https://github.com/buqiyuan/nest-admin/blob/main/src/main.ts"
    click AuthModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/auth/"
    click SystemModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/system/"
    click UserModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/user/"
    click NetdiskModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/netdisk/"
    click HealthModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/health/"
    click SSEModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/sse/"
    click TasksModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/tasks/"
    click ToolsModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/tools/"
    click TodoModule "https://github.com/buqiyuan/nest-admin/tree/main/src/modules/todo/"
    click CommonU "https://github.com/buqiyuan/nest-admin/tree/main/src/common/"
    click SharedM "https://github.com/buqiyuan/nest-admin/tree/main/src/shared/"
    click SocketModule "https://github.com/buqiyuan/nest-admin/tree/main/src/socket/"
    click MySQL "https://github.com/buqiyuan/nest-admin/blob/main/deploy/sql/nest_admin.sql"
    click Redis "https://github.com/buqiyuan/nest-admin/blob/main/src/config/redis.config.ts"
    click Docker "https://github.com/buqiyuan/nest-admin/tree/main/Dockerfile"
    click ProcessManager "https://github.com/buqiyuan/nest-admin/blob/main/ecosystem.config.js"
    click DeployScripts "https://github.com/buqiyuan/nest-admin/tree/main/deploy/"
    click Swagger "https://github.com/buqiyuan/nest-admin/blob/main/src/setup-swagger.ts"
```
