# nartc/nest-mean architecture

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

- Interactive diagram: https://gitdiagram.com/nartc/nest-mean
- Repository: https://github.com/nartc/nest-mean

## Overview

##### Main Components
- Frontend (Client): Located in the "client" directory, it is built using Angular 6 and uses AntDesign for UI components. Key files include Angular configuration files (angular.json, proxy.conf.json), the main application module under src/app, and Dockerfile/nginx.conf for production deployment via NGINX.
- Backend (Server): Inside the "server" directory, the backend is built with NestJS. It contains modules for user management, todo management, authentication (using JWT strategies), and shared utilities and services (e.g., mapper, exception filters).
- Database: Although the file tree does not include a database configuration per se, the README mentions running a MongoDB instance (using the mongod process). Therefore, include MongoDB as an essential external component.
- Docker & Deployment: Docker and Docker Compose are used for containerization. There are Dockerfiles in both the client and server directories, plus a docker-compose.yml at the root. Also, note the inclusion of NGINX for serving the Angular app and cAdvisor for container monitoring.
- API Generation (NSwag): On the server side, NSwag is used to auto-generate API client calls in the Angular frontend. Indicate this as an integration component bridging backend APIs with frontend consumption.

##### Relationships and Interactions
- The Angular client communicates with the NestJS backend through HTTP calls, which—when running locally—are proxied from port 4200 (client dev server) to port 3000 (backend).
- RESTful APIs exposed by NestJS (with dedicated modules such as user and todo) form the backend service layer.
- Authentication flows (login, register) are managed through API endpoints in the server, utilizing JWT strategies.
- The client uses the generated API calls (via NSwag) to abstract HTTP request complexity.
- Docker Compose orchestrates the entire system by running both containers (client behind NGINX and server) and monitoring with cAdvisor.

##### Architectural Patterns and Design Principles
- The backend likely follows a modular design (as evident by the dedicated folders for user, todo, and shared services in NestJS) similar to Domain-Driven Design.
- The client is structured following Angular’s modular and component-based architecture.
- Use of middleware elements such as guards, filters, and pipes in NestJS indicates robust error handling and security.
- The architecture promotes separation of concerns: the frontend focuses on presentation and user interactions, while the backend handles business logic and database operations.
- Docker encapsulation provides a clear separation of deployment environments and external services.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Top-level Deployment
    DC["Docker Compose"]:::infrastructure

    %% Frontend Layer
    subgraph "Frontend Layer"
        AC["Angular Client (Angular 6 + AntDesign)"]:::frontend
        ACfg["Angular Config (angular.json)"]:::frontend
        PCfg["Proxy Config (proxy.conf.json)"]:::frontend
        AMFE["App Module (client/src/app/app.module.ts)"]:::frontend
        NGINX["NGINX Config (nginx.conf)"]:::frontend
        Home["Home Page"]:::frontend
        Login["Login Page"]:::frontend
        Register["Register Page"]:::frontend
        Todo["Todo List Page"]:::frontend
        CDF["Client Dockerfile"]:::infrastructure
    end

    %% Backend Layer
    subgraph "Backend Layer"
        NS["NestJS Server (NestJS Application)"]:::backend
        AMBE["NestJS AppModule (server/src/app.module.ts)"]:::backend
        Auth["Auth (JWT) (server/src/shared/auth)"]:::backend
        User["User Module"]:::backend
        TodoMod["Todo Module"]:::backend
        Shared["Shared Services"]:::backend
        SDF["Server Dockerfile"]:::infrastructure
    end

    %% Integration Component
    subgraph "Integration"
        NSwag["NSwag API Generation"]:::integration
    end

    %% External Database
    DB["MongoDB (Database)"]:::database

    %% Arrows for Deployment
    DC -->|"orchestrates"| AC
    DC -->|"orchestrates"| NS

    %% Frontend internal connections
    AC --> ACfg
    ACfg --> PCfg
    PCfg --> AMFE
    AC --> NGINX
    AC --> Home
    Home --> Login
    Login --> Register
    Register --> Todo
    AC --> CDF

    %% Backend internal connections
    NS --> AMBE
    NS --> User
    NS --> TodoMod
    NS --> Auth
    NS --> Shared
    NS --> SDF

    %% Integration connections
    NS -->|"APIs"| NSwag
    NSwag -->|"GeneratedAPIs"| AC

    %% Direct client-server communication
    AC -->|"HTTPCalls"| NS

    %% Database connection
    NS -->|"DataPersistence"| DB

    %% Click Events
    click DC "https://github.com/nartc/nest-mean/blob/master/docker-compose.yml"
    click AC "https://github.com/nartc/nest-mean/tree/master/client/"
    click ACfg "https://github.com/nartc/nest-mean/blob/master/client/angular.json"
    click PCfg "https://github.com/nartc/nest-mean/blob/master/client/proxy.conf.json"
    click AMFE "https://github.com/nartc/nest-mean/blob/master/client/src/app/app.module.ts"
    click NGINX "https://github.com/nartc/nest-mean/blob/master/client/nginx.conf"
    click CDF "https://github.com/nartc/nest-mean/tree/master/client/Dockerfile"
    click NS "https://github.com/nartc/nest-mean/tree/master/server/"
    click AMBE "https://github.com/nartc/nest-mean/blob/master/server/src/app.module.ts"
    click Auth "https://github.com/nartc/nest-mean/tree/master/server/src/shared/auth"
    click NSwag "https://github.com/nartc/nest-mean/blob/master/server/NestMean.nswag"
    click SDF "https://github.com/nartc/nest-mean/tree/master/server/Dockerfile"

    %% Styles
    classDef frontend fill:#a8d0e6,stroke:#333,stroke-width:2px;
    classDef backend fill:#f76c6c,stroke:#333,stroke-width:2px;
    classDef database fill:#c5e1a5,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#ffeb3b,stroke:#333,stroke-width:2px;
    classDef integration fill:#9fa8da,stroke:#333,stroke-width:2px;
```
