# nhducit/multi-tenants architecture

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

- Interactive diagram: https://gitdiagram.com/nhducit/multi-tenants
- Repository: https://github.com/nhducit/multi-tenants

## Overview

##### Main Components
- Next.js Application: This is the core framework. Emphasize that the project is structured using Next.js 13’s appDir, which includes both server and client components.
- Routing & Dynamic Pages: The “src/app” directory is organized with dynamic segments ([domain] and [language]) to handle multi-tenancy and multi-language support. Notice the “gift-card” subdirectory under these dynamic routes.
- API Layer: There is an “src/apis” folder which likely contains API utilities used by the Next.js pages.
- Middleware: The “src/middleware.ts” file indicates that there is some middleware logic (for tasks like authentication, routing, or header manipulation) applied globally.
- Static Assets & Styles: The “public” folder for static files and “src/globals.css” for global CSS styling, along with Tailwind styling configurations (tailwind.config.ts) are essential parts.
- Build & Configuration Files: Environment configuration, ESLint rules, Next.js configuration, and TypeScript configuration files indicate a well-configured application environment.

##### Relationships and Interactions
- Dynamic Routing: Show that requests are routed based on the domain and language segments, leading into specific areas of the app (for example, the “gift-card” pages).
- API Calls: Illustrate connections between pages (or middleware) and the API layer from “src/apis” to denote data fetching or manipulation.
- Middleware: Represent middleware as a layer between the incoming request and the page rendering logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Incoming HTTP Requests"]:::incoming
    B["Middleware"]:::middleware
    A -->|"processes"| B
    B --> C["Next.js Application"]:::app

    subgraph "Core Routing"
        direction TB
        C --> D["Dynamic Routing (Domain & Language)"]:::dynamic
        D --> E["Gift-Card Listing"]:::gift
        E --> F["Gift-Card Detail"]:::gift
    end

    C --> G["API Layer"]:::api
    C --> H["ISR Process"]:::isr

    subgraph "Side Infrastructure"
        direction TB
        I["Global Styles"]:::assets
        J["Static Assets"]:::assets
        K["Internationalization Configuration"]:::i18n
        subgraph "Configuration"
            direction TB
            L1[".env.local.example"]:::config
            L2["next.config.js"]:::config
            L3["tailwind.config.ts"]:::config
            L4[".eslintrc.json"]:::config
            L5["tsconfig.json"]:::config
            L6["package.json"]:::config
            L7["pnpm-lock.yaml"]:::config
        end
        M["Configuration Summary"]:::config
    end

    I --> C
    J --> C
    M --> C
    K --- D

    %% Styles
    classDef incoming fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef middleware fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
    classDef app fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef dynamic fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef gift fill:#e6ccff,stroke:#9933ff,stroke-width:2px;
    classDef api fill:#ffebcc,stroke:#ff9900,stroke-width:2px;
    classDef isr fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef assets fill:#e6e6e6,stroke:#999999,stroke-width:2px;
    classDef config fill:#f2f2f2,stroke:#666666,stroke-width:2px;
    classDef i18n fill:#d0f0fd,stroke:#005f8f,stroke-width:2px;

    %% Click Events
    click C "https://github.com/nhducit/multi-tenants/tree/main/src/app"
    click D "https://github.com/nhducit/multi-tenants/tree/main/src/app/[domain]/[language]"
    click E "https://github.com/nhducit/multi-tenants/tree/main/src/app/[domain]/[language]/gift-card"
    click F "https://github.com/nhducit/multi-tenants/tree/main/src/app/[domain]/[language]/gift-card/[id]"
    click G "https://github.com/nhducit/multi-tenants/blob/main/src/apis/apis.ts"
    click B "https://github.com/nhducit/multi-tenants/blob/main/src/middleware.ts"
    click I "https://github.com/nhducit/multi-tenants/blob/main/src/app/globals.css"
    click J "https://github.com/nhducit/multi-tenants/tree/main/public"
    click L1 "https://github.com/nhducit/multi-tenants/blob/main/.env.local.example"
    click L2 "https://github.com/nhducit/multi-tenants/blob/main/next.config.js"
    click L3 "https://github.com/nhducit/multi-tenants/blob/main/tailwind.config.ts"
    click L4 "https://github.com/nhducit/multi-tenants/blob/main/.eslintrc.json"
    click L5 "https://github.com/nhducit/multi-tenants/blob/main/tsconfig.json"
    click L6 "https://github.com/nhducit/multi-tenants/blob/main/package.json"
    click L7 "https://github.com/nhducit/multi-tenants/blob/main/pnpm-lock.yaml"
    click K "https://github.com/nhducit/multi-tenants/blob/main/src/i18n-config.ts"
```
