# tientruongminh/nextjsdemo architecture

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

- Interactive diagram: https://gitdiagram.com/tientruongminh/nextjsdemo
- Repository: https://github.com/tientruongminh/nextjsdemo

## Overview

##### Project type and purpose
- This is a full‑stack e‑commerce “Shop bán hàng đơn giản” demo:
- Frontend: Next.js 14 (React‑based, server‑rendered)
- Backend: Fastify (Node.js web server)
- Database: Prisma (SQLite in dev, can be swapped)
- Key features: user registration/login, CRUD products, basic SEO.

##### File structure
- Top‑level:
- /client – Next.js app with app‑directory, API routes, components, styling, schema validations
- /server – Fastify app with controllers, routes, plugins, schema validations, Prisma in /prisma
- Root package.json – workspace management, scripts
- Frontend patterns:
- App router (layout, pages under /app)
- Reusable UI in /components/ui, shared logic in /lib and /schemaValidations
- API calls centralized in /apiRequests
- Backend patterns:
- Routes → Controllers → Hooks → Plugins
- Schema validation via fastify validatorCompiler.plugins
- Prisma client in database/index.ts
- JWT auth utilities, error‑handler plugin.

##### Insights from README
- Confirms tech stack and functional scope: authentication, product management, SEO focus.

##### Elements
- Clear labels: e.g., “Next.js App”, “Fastify Server”, “Prisma (DB)”
- Page load flow: Browser → Next.js Server → Browser
- Data flow: Browser → Frontend fetch → Backend REST → DB

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Browser (User)"]:::ui
    subgraph "Frontend (Next.js 14)"
        AppRouter["Next.js App Router"]:::frontend
        NextApi["Next.js API Routes"]:::api
        DataLayer["Frontend Data Fetch Layer"]:::logic
        UIComp["Frontend UI Components"]:::ui
        SharedComp["Shared Components & Layouts"]:::ui
        SchemaValFE["Frontend Schema Validations"]:::validation
        UtilsFE["Frontend Utility Functions & Config"]:::logic
    end

    %% Server
    subgraph "Backend (Fastify Server)"
        ServerEntry["Fastify Server Entry Point"]:::backend
        Routes["Fastify Route Definitions"]:::backend
        Controllers["Fastify Controllers"]:::backend
        Plugins["Fastify Plugins (Auth, Error Handler, Validator)"]:::middleware
        Hooks["Fastify Hooks"]:::middleware
        SchemaValBE["Backend Schema Validations"]:::validation
        PrismaInit["Prisma Client Initialization"]:::database
        JWTUtils["JWT Utilities"]:::backend
        UtilsBE["General Backend Utilities & Error Handling"]:::backend
        ConfigBE["Environment & Configuration"]:::backend
    end

    %% Database
    subgraph "Database (Prisma)"
        PrismaSchema["Prisma Schema & Dev DB"]:::database
    end

    %% Data Flows
    Browser -->|"HTTP Request / SSR/CSR"| AppRouter
    AppRouter --> UIComp
    UIComp --> DataLayer
    DataLayer --> NextApi
    NextApi -->|"REST API Calls"| Routes
    Routes --> SchemaValBE
    SchemaValBE --> Controllers
    Routes --> Controllers
    Controllers --> Plugins
    Controllers --> Hooks
    Plugins --> Controllers
    Hooks --> Controllers
    Controllers --> JWTUtils
    Controllers --> UtilsBE
    Controllers --> PrismaInit
    PrismaInit --> PrismaSchema
    Controllers --> ConfigBE

    %% Click Events - Frontend
    click AppRouter "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/app"
    click NextApi "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/app/api"
    click DataLayer "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/apiRequests"
    click UIComp "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/components/ui"
    click SharedComp "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/components"
    click SchemaValFE "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/schemaValidations"
    click UtilsFE "https://github.com/tientruongminh/nextjsdemo/tree/main/client/src/lib"
    click UtilsFE "https://github.com/tientruongminh/nextjsdemo/blob/main/client/src/config.ts"

    %% Click Events - Backend
    click ServerEntry "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/index.ts"
    click Routes "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/routes/*.route.ts"
    click Controllers "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/controllers/*.controller.ts"
    click Plugins "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/plugins/auth.plugins.ts"
    click Plugins "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/plugins/errorHandler.plugins.ts"
    click Plugins "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/plugins/validatorCompiler.plugins.ts"
    click Hooks "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/hooks/auth.hooks.ts"
    click SchemaValBE "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/schemaValidations/*.schema.ts"
    click PrismaInit "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/database/index.ts"
    click JWTUtils "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/utils/jwt.ts"
    click UtilsBE "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/utils/errors.ts"
    click UtilsBE "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/utils/helpers.ts"
    click ConfigBE "https://github.com/tientruongminh/nextjsdemo/blob/main/server/src/config.ts"
    click PrismaSchema "https://github.com/tientruongminh/nextjsdemo/blob/main/server/prisma/schema.prisma"
    click PrismaSchema "https://github.com/tientruongminh/nextjsdemo/blob/main/server/prisma/dev.db"

    %% Styles
    classDef ui fill:#f9f,stroke:#333,stroke-width:1px
    classDef frontend fill:#bbf,stroke:#333,stroke-width:1px
    classDef api fill:#ccf,stroke:#333,stroke-width:1px
    classDef logic fill:#bfb,stroke:#333,stroke-width:1px
    classDef validation fill:#fcc,stroke:#333,stroke-width:1px
    classDef backend fill:#fbb,stroke:#333,stroke-width:1px
    classDef middleware fill:#fcf,stroke:#333,stroke-width:1px
    classDef database fill:#fed,stroke:#333,stroke-width:1px
```
