# minhtoan-nmt/web-programming-project architecture

> Architecture diagram of the GitHub repository minhtoan-nmt/web-programming-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/minhtoan-nmt/web-programming-project
- Repository: https://github.com/minhtoan-nmt/web-programming-project

## Overview

##### Project type and purpose
- This is a full-stack e-commerce web application built on Next.js 13 (App Router).
- It contains three “zones” or domains:
– Client-facing storefront ((client))
– Authentication flows ((auth))
– Admin panel for managing products, posts, users, invoices ((admin))
- It exposes REST-style API endpoints via Next.js route handlers under src/app/api.

##### File structure
- Top-level config & scripts:
– Dockerfile, .env, next.config.mjs, postcss.config.mjs, jsconfig.json
- Public assets: public/image/**
- Source code (src/app):
– (client), (auth), (admin) sub-folders each with nested route folders and page.js files
– _component and _comhome shared React components (Navbar, Footer, Banner, etc.)
– API folder (src/app/api) with sub-folders per resource (products, post, cart, user, comment, invoice status) each implementing a route.js handler
- Global styles: globals.css
- Package & lock files: package.json, package-lock.json

##### README
- Confirms this is a Next.js “create-next-app” boilerplate with integrated font optimization.

##### Main components & their interactions
a. Browser clients (desktop/mobile)
– Render React components delivered by Next.js
– Call internal API endpoints (fetch) for data
b. Next.js server (Node.js)
– Serves Server Components (SSR) from app/**/*.js
– Serves Client Components for browser interactivity
– Hosts RESTful route handlers under src/app/api/** (serverless functions)
– Reads environment variables from .env (e.g., DB URL, JWT secret)
c. Data store
– A relational (MySQL/Postgres) or NoSQL (MongoDB) database (connection code resides inside API route handlers)
d. Static assets
– Hosted from public/image
e. External services (optional)
– Email service for contact form
– Payment gateway (Stripe/PayPal) invoked in checkout flow
– Authentication provider (custom JWT or third-party OTP)

Interactions:
- Client UI → Next.js Server Components → API → Database
- Admin UI ↔ API ↔ Database
- Auth UI ↔ API ↔ Database / JWT issuance
- External payment gateway ↔ API ↔ Database

##### Architectural patterns & design principles
- Monolithic Next.js App Router combining front- and back-end in one codebase
- Domain-driven folder structure ((client), (auth), (admin))
- Separation of concerns:
– Server Components for data-fetching and SSR
– Client Components for interactive bits (modals, confirm dialogs)
– API route handlers encapsulate CRUD operations
- Shared UI components under _component and _comhome
- CSS Modules and global CSS for styling
- Containerization via Dockerfile

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser (Client)" 
        Browser["User Browser"]:::ui
    end

    subgraph "Next.js Monolithic App"
        subgraph "Frontend - UI"
            subgraph "Zones"
                ClientZone["Client Storefront"]:::ui
                AuthZone["Authentication Flows"]:::ui
                AdminZone["Admin Panel"]:::ui
            end
            SharedGen["Generic Components"]:::ui
            SharedHome["Homepage Components"]:::ui
            Layout["App Layout"]:::ui
            RootPage["Root Page"]:::ui
            GlobalCSS["Global Styles"]:::ui
        end
        subgraph "API Layer"
            ProdAPI{"Products API"}:::api
            PostAPI{"Posts API"}:::api
            CartAPI{"Cart APIs"}:::api
            UserAPI{"User API"}:::api
            CommAPI{"Comment API"}:::api
            InvoiceAPI{"Invoice Status API"}:::api
        end
    end

    DB["Database"]:::data
    StaticAssets["Static Assets (public/image)"]:::data

    subgraph "External Services"
        Payment["Payment Gateway"]:::external
        Email["Email Service"]:::external
        AuthProv["Auth Provider"]:::external
    end

    Browser -->|"SSR & Client fetch"| ClientZone
    ClientZone -->|"uses Shared UI"| SharedGen
    ClientZone --> SharedHome
    ClientZone --> Layout
    ClientZone --> RootPage
    ClientZone -->|"fetch /api/products"| ProdAPI
    ClientZone -->|"fetch /api/post"| PostAPI
    AuthZone -->|"fetch /api/user"| UserAPI
    AdminZone -->|"fetch /api/products"| ProdAPI
    AdminZone -->|"fetch /api/user"| UserAPI

    ProdAPI -->|"CRUD /products"| DB
    PostAPI -->|"CRUD /post"| DB
    CartAPI -->|"GET/POST cart"| DB
    UserAPI -->|"CRUD /user"| DB
    CommAPI -->|"CRUD /comment"| DB
    InvoiceAPI -->|"SET status"| DB

    InvoiceAPI -->|"charge"| Payment
    PostAPI -->|"send email"| Email
    UserAPI -->|"authenticate"| AuthProv

    Browser -->|"GET images"| StaticAssets

    click ClientZone "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/(client)"
    click AuthZone "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/(auth)"
    click AdminZone "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/(admin)"
    click ProdAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/products"
    click PostAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/post"
    click CartAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/get_cart"
    click CartAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/update_cart"
    click CartAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/add_item_to_cart"
    click CartAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/remove_item_from_cart"
    click UserAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/user"
    click CommAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/comment"
    click InvoiceAPI "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/api/set_status_invoice"
    click SharedGen "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/_component"
    click SharedHome "https://github.com/minhtoan-nmt/web-programming-project/tree/main/src/app/_comhome"
    click Layout "https://github.com/minhtoan-nmt/web-programming-project/blob/main/src/app/layout.js"
    click RootPage "https://github.com/minhtoan-nmt/web-programming-project/blob/main/src/app/page.js"
    click GlobalCSS "https://github.com/minhtoan-nmt/web-programming-project/blob/main/src/app/globals.css"
    click StaticAssets "https://github.com/minhtoan-nmt/web-programming-project/tree/main/public/image"
    click Dockerfile "https://github.com/minhtoan-nmt/web-programming-project/tree/main/Dockerfile"
    click EnvFile "https://github.com/minhtoan-nmt/web-programming-project/blob/main/.env"
    click NextConfig "https://github.com/minhtoan-nmt/web-programming-project/blob/main/next.config.mjs"
    click PostCSS "https://github.com/minhtoan-nmt/web-programming-project/blob/main/postcss.config.mjs"
    click JSConfig "https://github.com/minhtoan-nmt/web-programming-project/blob/main/jsconfig.json"
    click Package "https://github.com/minhtoan-nmt/web-programming-project/blob/main/package.json"
    click PackageLock "https://github.com/minhtoan-nmt/web-programming-project/blob/main/package-lock.json"

    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef api fill:#FFE6BA,stroke:#d9822b,color:#d9822b
    classDef data fill:#D3F9D8,stroke:#2a9d8f,color:#2a9d8f
    classDef external fill:#E2E2E2,stroke:#666666,color:#343434
```
