# xoldskool/color-dashboard-v3 architecture

> Architecture diagram of the GitHub repository xoldskool/color-dashboard-v3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xoldskool/color-dashboard-v3
- Repository: https://github.com/xoldskool/color-dashboard-v3

## Overview

##### Project type and purpose
- The README confirms it was bootstrapped with Create-Next-App and uses the new App Router (src/app) plus API Route handlers.

##### File structure
- src/app: Next.js App Router folders (page.tsx, layout.tsx) plus serverless API routes under src/app/api (magazzinoPantoni, materiali, pantoni).
- src/components: React UI components (buttons, tables, modals, sidebar).
- src/lib: Server-side logic and DB access (connectToMongoDb.ts, per-domain db.ts and logic.ts).
- src/schemas: Type validation for MongoDB documents.
- src/store & src/hooks: Client-side state (Zustand stores) and custom hooks.
- src/constants, src/types, src/utils: Shared constants, TypeScript types, utility functions.
- Next.js config files: next.config.ts, tsconfig.json, ESLint/Prettier.

##### README for additional insights
- Assumes deployment on Vercel, serverless execution of API Routes.

##### Elements
- Clear labels: “Browser / React UI,” “Next.js App Router,” “API Routes,” “Business Logic,” “Data Access,” “MongoDB.”
- UI → API Routes (fetch)
- API Routes → Business Logic → DB Layer → MongoDB
- DB → returns data up the stack → UI
- Green for Backend services

##### Final advice
- Be exhaustive: represent each layer (UI, state, API, logic, DB).
- Use nested groupings: e.g., “src/lib” contains Logic and DB subcomponents.
- Call out dynamic routing in App Router (e.g., [id] pages).
- How shared modules (schemas, utils, constants) feed into both logic and UI.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Browser / React UI" 
        direction TB
        UI["React UI Components"]:::frontend
        Stores["Zustand Stores"]:::frontend
        Hooks["Custom React Hooks"]:::frontend
    end

    UI -->|"updates state"| Stores
    UI -->|"uses hooks"| Hooks

    %% Shared Modules
    subgraph "Shared Modules"
        direction TB
        Constants["Constants"]:::shared
        Types["Types"]:::shared
        Utils["Utilities"]:::shared
        Schemas["Schema Validation"]:::schema
    end

    Constants <-->|"imported by"| UI
    Types <-->|"imported by"| UI
    Utils <-->|"imported by"| UI
    Schemas <-->|"imported by"| BackendLogic

    %% Client → Server
    UI -->|"fetch API"| API

    %% Backend Layer
    subgraph "Backend (Vercel Functions)" 
        direction TB
        subgraph "Next.js App Router" 
            direction TB
            Layout["layout.tsx"]:::backend
            HomePage["page.tsx"]:::backend
            MaterialiList["materiali/page.tsx"]:::backend
            MaterialeDetail["materiali/[id]/page.tsx"]:::backend
            PantoneDetail["pantone/[id]/page.tsx"]:::backend
        end

        subgraph "API Routes" 
            direction TB
            API["API Routes"]:::backend
            PantoniRoute["/api/pantoni"]:::backend
            UndoProduceRoute["/api/pantoni/undo-produce"]:::backend
            MaterialiRoute["/api/materiali"]:::backend
            CaricoScarico["/api/materiali/carico-scarico-pantone"]:::backend
            MagazzinoRoute["/api/magazzinoPantoni"]:::backend
            ConsegnaRoute["/api/magazzinoPantoni/consegna"]:::backend
        end

        API -->|"/pantoni"| PantoniRoute
        API -->|"/pantoni/undo-produce"| UndoProduceRoute
        API -->|"/materiali"| MaterialiRoute
        API -->|"/materiali/carico-scarico-pantone"| CaricoScarico
        API -->|"/magazzinoPantoni"| MagazzinoRoute
        API -->|"/magazzinoPantoni/consegna"| ConsegnaRoute
    end

    %% Business Logic
    subgraph "Business Logic Layer" 
        direction TB
        BackendLogic["Business Logic"]:::logic
        PantoniLogic["pantoni/logic.ts"]:::logic
        MaterialiLogic["materiali/logic.ts"]:::logic
        MagazzinoLogic["magazzinoPantoni/logic.ts"]:::logic
    end

    PantoniRoute -->|calls| PantoniLogic
    UndoProduceRoute -->|calls| PantoniLogic
    MaterialiRoute -->|calls| MaterialiLogic
    CaricoScarico -->|calls| MaterialiLogic
    MagazzinoRoute -->|calls| MagazzinoLogic
    ConsegnaRoute -->|calls| MagazzinoLogic

    BackendLogic --> PantoniLogic
    BackendLogic --> MaterialiLogic
    BackendLogic --> MagazzinoLogic

    %% Data Access Layer
    subgraph "Data Access Layer" 
        direction TB
        DBLayer["DB Modules"]:::db
        PantoniDB["pantoni/db.ts"]:::db
        MaterialiDB["materiali/db.ts"]:::db
        MagazzinoDB["magazzinoPantoni/db.ts"]:::db
        ConnectDB["connectToMongoDb.ts"]:::db
        Adapter["adapter.ts"]:::db
    end

    PantoniLogic --> PantoniDB
    MaterialiLogic --> MaterialiDB
    MagazzinoLogic --> MagazzinoDB
    DBLayer --> ConnectDB
    DBLayer --> Adapter

    PantoniDB --> ConnectDB
    MaterialiDB --> ConnectDB
    MagazzinoDB --> ConnectDB
    ConnectDB --> Adapter

    %% Database
    subgraph "MongoDB Database" 
        direction TB
        Mongo["MongoDB"]:::db
    end

    Adapter -->|queries| Mongo

    Mongo -->|returns data| PantoniDB
    Mongo -->|returns data| MaterialiDB
    Mongo -->|returns data| MagazzinoDB

    %% Click Events
    click UI "https://github.com/xoldskool/color-dashboard-v3/tree/main/src/components"
    click Stores "https://github.com/xoldskool/color-dashboard-v3/tree/main/src/store"
    click Hooks "https://github.com/xoldskool/color-dashboard-v3/tree/main/src/hooks"
    click Layout "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/layout.tsx"
    click HomePage "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/page.tsx"
    click MaterialiList "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/materiali/page.tsx"
    click MaterialeDetail "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/materiali/[id]/page.tsx"
    click PantoneDetail "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/pantone/[id]/page.tsx"
    click PantoniRoute "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/api/pantoni/route.ts"
    click UndoProduceRoute "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/api/pantoni/undo-produce/route.ts"
    click MaterialiRoute "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/api/materiali/route.ts"
    click CaricoScarico "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/api/materiali/carico-scarico-pantone/route.ts"
    click MagazzinoRoute "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/api/magazzinoPantoni/route.ts"
    click ConsegnaRoute "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/app/api/magazzinoPantoni/consegna/route.ts"
    click PantoniLogic "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/pantoni/logic.ts"
    click MaterialiLogic "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/materiali/logic.ts"
    click MagazzinoLogic "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/magazzinoPantoni/logic.ts"
    click PantoniDB "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/pantoni/db.ts"
    click MaterialiDB "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/materiali/db.ts"
    click MagazzinoDB "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/magazzinoPantoni/db.ts"
    click ConnectDB "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/connectToMongoDb.ts"
    click Adapter "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/lib/adapter.ts"
    click Schemas "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/schemas/PantoneSchema.ts"
    click Schemas "https://github.com/xoldskool/color-dashboard-v3/blob/main/src/schemas/MaterialeSchema.ts"
    click Constants "https://github.com/xoldskool/color-dashboard-v3/tree/main/src/constants"
    click Types "https://github.com/xoldskool/color-dashboard-v3/tree/main/src/types"
    click Utils "https://github.com/xoldskool/color-dashboard-v3/tree/main/src/utils"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000;
    classDef backend fill:#90EE90,stroke:#000;
    classDef logic fill:#98FB98,stroke:#000;
    classDef db fill:#FFA500,stroke:#000;
    classDef schema fill:#FFD700,stroke:#000;
    classDef shared fill:#D3D3D3,stroke:#000;
```
