# tetris973/mono-next-nest-template architecture

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

- Interactive diagram: https://gitdiagram.com/tetris973/mono-next-nest-template
- Repository: https://github.com/tetris973/mono-next-nest-template

## Overview

##### Main Components
- Frontend: Represent the Next.js application housed in the apps/web directory. Include details such as:
- Next.js (React) with server/client components.
- UI libraries like Mantine, testing tools such as Playwright, Vitest, and Storybook integration.
- Backend: Represent the NestJS server found in apps/server. Key aspects include:
- REST API controllers and modules (e.g., auth, user, role, and common utility folders).
- Authentication (Passport with JWT and local strategies).
- Authorization via CASL.
- ORM and database integration using Prisma (extended with Kysely) connecting to a Postgres database.
- Logging using Pino and Swagger for API documentation.
- Shared Package(s): Include the backend API SDK found in packages/backend-api-sdk which the frontend likely uses to interact with backend APIs using OpenAPI-generated code.
- Database and Infrastructure: Indicate that a Postgres database is set up (managed via Prisma migrations) and Docker containers are provided for both local development and production deployment. This component is backed by the docker/ directories (development and production setups).
- CI/CD and DevOps: You might add a component showing integration with GitLab CI/CD ('.gitlab-ci.yml') and other dev tooling (Husky, ESLint, Prettier, linters).

##### Relationships and Dependencies
- Frontend (Next.js) making API calls to the backend (NestJS).
- The backend interacting with the database (Postgres) and using Prisma/Kysely for ORM functionality.
- The shared backend API SDK serving as an integration layer, ensuring type-safe API calls between frontend and backend.
- Authentication flow where the frontend sends login credentials, the backend processes them via Passport strategies, and returns a JWT token.
- Integration points such as Swagger endpoints for API documentation and CASL for authorization.
- Docker should be represented either as an envelope around these components for deployment consistency or as an infrastructure container that houses the backend, database, and possibly a reverse proxy.

##### Architectural Patterns/Design Principles
- Monorepo Structure: Emphasize that the overall project is set up as a monorepo with separate apps for the frontend and backend plus shared packages. This suggests high cohesion across components and common build tooling (pnpm workspaces).
- Domain Driven/Modular Design: Identify modules for authentication, authorization, user management, and roles.
- Test Strategy Components: Show the inclusion of unit tests, integration/E2E tests (both in apps/server/test and apps/web/test), indicating a strong culture of automated testing.
- Dockerization: Point out that Docker (with separate development and production configurations) is used for environment consistency and deployment.

##### Relevant Technologies and Frameworks
- Backend: NestJS, Prisma, CASL, Passport.js, pino, Swagger, Vitest.
- Frontend: Next.js, React 18, Mantine, Playwright, Vitest, Storybook.
- Developer Tooling: pnpm, Husky, ESLint, Prettier, GitLab CI/CD, and Docker.
- Shared API SDK: OpenAPI integration to generate backend API clients.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F1["Next.js Frontend (React, Mantine, Playwright, Vitest, Storybook)"]:::frontend
    end

    %% Shared Package
    subgraph "Shared Package"
        SP["Shared API SDK (OpenAPI)"]:::shared
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1["NestJS Backend (Controllers, Modules, Services)"]:::backend
        B2["Authentication & Authorization<br/>(Passport, JWT, CASL)"]:::backend
        B3["ORM Integration<br/>(Prisma, Kysely)"]:::backend
        B4["API Documentation<br/>(Swagger)"]:::backend
        DB["Postgres Database"]:::database
    end

    %% Infrastructure & DevOps
    subgraph "Infrastructure & DevOps"
        D["Docker Infrastructure<br/>(Development & Production)"]:::docker
        C["CI/CD & DevOps<br/>(GitLab CI/CD, Husky, ESLint, Prettier)"]:::cicd
    end

    %% Connections
    F1 -->|"uses"| SP
    SP -->|"calls"| B1
    B1 -->|"handles"| B2
    B1 -->|"integrates"| B3
    B1 -->|"auto-generates"| B4
    B3 -->|"operates on"| DB

    %% Deployment and Containerization
    C -->|"deploys to"| F1
    C -->|"deploys to"| B1
    C -->|"deploys to"| DB
    D -->|"containers"| F1
    D -->|"containers"| B1
    D -->|"containers"| DB

    %% Styles
    classDef frontend fill:#d1e8ff,stroke:#1f77b4,stroke-width:2px;
    classDef backend fill:#ffe4b5,stroke:#ff8c00,stroke-width:2px;
    classDef shared fill:#d5f5e3,stroke:#2ecc71,stroke-width:2px;
    classDef database fill:#f9e79f,stroke:#f39c12,stroke-width:2px,stroke-dasharray: 5 5;
    classDef docker fill:#f5cba7,stroke:#d35400,stroke-width:2px;
    classDef cicd fill:#e8daef,stroke:#8e44ad,stroke-width:2px;

    %% Click Events
    click F1 "https://github.com/tetris973/mono-next-nest-template/tree/main/apps/web"
    click B1 "https://github.com/tetris973/mono-next-nest-template/tree/main/apps/server"
    click SP "https://github.com/tetris973/mono-next-nest-template/tree/main/packages/backend-api-sdk"
    click B3 "https://github.com/tetris973/mono-next-nest-template/tree/main/apps/server/src/prisma"
    click D "https://github.com/tetris973/mono-next-nest-template/tree/main/docker"
    click C "https://github.com/tetris973/mono-next-nest-template/blob/main/.gitlab-ci.yml"
```
