# goatt69/meo_stationery architecture

> Architecture diagram of the GitHub repository goatt69/meo_stationery, 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/goatt69/meo_stationery
- Repository: https://github.com/goatt69/meo_stationery

## Overview

##### Main Components

- Frontend (Client Side):
- Pages & Layouts: The application’s public pages (e.g., homepage, product details, category listings, cart, checkout pages) reside under src/app. Notice separate directories like (main), admin, product, category, checkout, and cart.
- UI Components: Located in src/components (including specialized UI components in src/components/ui) and hooks under src/hooks. These together represent the presentation layer.
- Styling & Theming: Global styles (src/app/globals.css and src/styles/globals.css), Tailwind configuration (tailwind.config.ts), and theme provider components indicate the use of a consistent styling mechanism.

- Backend (Server/API Side):
- API Endpoints: In src/app/api you have endpoints for categories, customers, orders, products, search, and VNPay integration – these represent RESTful or serverless functions tied to the Next.js API routes.
- Server Logic & Middleware: The src/lib folder includes middleware, Prisma client initialization (prisma.ts), and utilities that support backend functionality.

- Database:
- Prisma: The prisma directory with schema.prisma shows that Prisma is being used as an ORM to interact with a relational database. This is a key component where persistent data (products, customers, orders, etc.) is managed.

- External Services:
- Payment Integration: The VNPay integration under src/app/api/vnpay and matching client-side checkout pages (src/app/checkout/payment/vnpay) indicates that the system interacts with external payment gateways.

##### Relationships and Interactions

- Data Flow:
- User Interaction: The client’s pages built with React (via Next.js) trigger events (such as adding an item to the cart or checking out) in the browser.
- API Communication: These events send data (HTTP requests) to API endpoints defined in src/app/api. The endpoints then perform operations such as CRUD on products, customers, etc.
- Database Interactions: API endpoints use Prisma (from src/lib/prisma.ts and schema definitions in prisma/schema.prisma) to query and update the database. Any business logic or middleware transforms these requests/responses as needed.
- Third-Party Integrations: When processing payments (via VNPay), the front end communicates with a dedicated VNPay route in the API, which then interacts with the external payment service and returns necessary data to the client.

- Administrative vs. Public Areas:
- Admin Section: The admin routes (under src/app/admin) provide dashboards and management views for orders, customers, products. There might be additional authentication and authorization logic (e.g., via the AdminRouteDetector component in src/components) to restrict access.
- Public Facing: All the public-facing pages (e.g., product listings, about, contact, etc.) make up the main user interface for customers.

##### Architectural Patterns and Technologies

- Next.js App Router: Utilizing file-based routing to dynamically manage pages and API endpoints.
- Server-Side Rendering & API Routes: Routes in src/app/(main) for static pages, plus server functions in src/app/api to interact with the backend.
- ORM via Prisma: Direct integration with a database providing type safety and migrations.
- Payment Gateway Integration: A dedicated API and frontend sub-module for payment processing with VNPay.
- Component-Based UI: Extensive use of modular and reusable UI components separated from business logic.
- Tailwind CSS & Custom Theming: For consistent styling across the application.

##### Specific Elements

- Clear Labels: Mark each component – Frontend (with page clusters like “Public Pages,” “Admin Pages”), API Endpoints (with subdomains like “Products API”, “Checkout API”), Database, and External Payment Gateway.

a. Frontend:

b. API/Backend:
- Create another cluster labeled “Server/API” with nodes for each API grouping (Products, Orders, Customers, Categories, Search, VNPay) and a separate node for Middleware/Utils.

c. Frontend to the API:

d. Database Layer:

e. External Integrations:

f. Final Touches:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        PublicPages["Public Pages"]:::frontend
        ProductPages["Product Pages"]:::frontend
        CategoryPages["Category Pages"]:::frontend
        Cart["Cart"]:::frontend
        Checkout["Checkout"]:::frontend
        AdminDashboard["Admin Dashboard"]:::frontend
        UIComponents["UI Components"]:::frontend
        Hooks["Hooks"]:::frontend
    end

    %% Server/API Layer
    subgraph "Server/API Layer"
        CategoriesAPI["Categories API"]:::backend
        CustomersAPI["Customers API"]:::backend
        OrdersAPI["Orders API"]:::backend
        ProductsAPI["Products API"]:::backend
        SearchAPI["Search API"]:::backend
        VNPayAPI["VNPay API"]:::backend
    end

    %% Server Utilities
    subgraph "Server Utilities"
        PrismaClient["Prisma Client"]:::utility
        Utils["Utils"]:::utility
        Middleware["Middleware"]:::utility
    end

    %% Database Layer
    subgraph "Database"
        PrismaSchema["Prisma Schema"]:::database
    end

    %% External Services
    subgraph "External Services"
        VNPayGateway["VNPay Payment Gateway"]:::external
    end

    %% Frontend to API Connections
    PublicPages -->|"HTTP_Request"| ProductsAPI
    ProductPages -->|"HTTP_Request"| ProductsAPI
    CategoryPages -->|"HTTP_Request"| ProductsAPI
    Cart -->|"Add_Item"| OrdersAPI
    Checkout -->|"PaymentRequest"| VNPayAPI
    AdminDashboard -->|"AdminRequest"| ProductsAPI
    AdminDashboard -->|"AdminRequest"| OrdersAPI
    AdminDashboard -->|"AdminRequest"| CustomersAPI

    %% API to Server Utilities (All APIs use Prisma for CRUD operations)
    CategoriesAPI -->|"CRUD_Query"| PrismaClient
    CustomersAPI -->|"CRUD_Query"| PrismaClient
    OrdersAPI -->|"CRUD_Query"| PrismaClient
    ProductsAPI -->|"CRUD_Query"| PrismaClient
    SearchAPI -->|"CRUD_Query"| PrismaClient
    VNPayAPI -->|"CRUD_Query"| PrismaClient

    %% Server Utilities to Database
    PrismaClient -->|"DB_Query"| PrismaSchema

    %% VNPay API to External Payment Gateway
    VNPayAPI <-->|"Payment"| VNPayGateway

    %% Click Events for Frontend Components
    click PublicPages "https://github.com/goatt69/meo_stationery/tree/master/src/app/(main)"
    click ProductPages "https://github.com/goatt69/meo_stationery/tree/master/src/app/product/[id]"
    click CategoryPages "https://github.com/goatt69/meo_stationery/tree/master/src/app/category/[category]"
    click Cart "https://github.com/goatt69/meo_stationery/tree/master/src/app/cart"
    click Checkout "https://github.com/goatt69/meo_stationery/tree/master/src/app/checkout"
    click AdminDashboard "https://github.com/goatt69/meo_stationery/tree/master/src/app/admin"
    click UIComponents "https://github.com/goatt69/meo_stationery/tree/master/src/components"
    click Hooks "https://github.com/goatt69/meo_stationery/tree/master/src/hooks"

    %% Click Events for API Endpoints
    click CategoriesAPI "https://github.com/goatt69/meo_stationery/tree/master/src/app/api/categories"
    click CustomersAPI "https://github.com/goatt69/meo_stationery/tree/master/src/app/api/customers"
    click OrdersAPI "https://github.com/goatt69/meo_stationery/tree/master/src/app/api/orders"
    click ProductsAPI "https://github.com/goatt69/meo_stationery/tree/master/src/app/api/products"
    click SearchAPI "https://github.com/goatt69/meo_stationery/tree/master/src/app/api/search"
    click VNPayAPI "https://github.com/goatt69/meo_stationery/blob/master/src/app/api/vnpay/generate-payment-url/route.ts"

    %% Click Events for Server Utilities
    click PrismaClient "https://github.com/goatt69/meo_stationery/blob/master/src/lib/prisma.ts"
    click Utils "https://github.com/goatt69/meo_stationery/blob/master/src/lib/utils.ts"
    click Middleware "https://github.com/goatt69/meo_stationery/blob/master/src/lib/middleware.ts"

    %% Click Event for Database Schema
    click PrismaSchema "https://github.com/goatt69/meo_stationery/blob/master/prisma/schema.prisma"

    %% Click Event for External Payment Gateway
    click VNPayGateway "https://github.com/goatt69/meo_stationery/blob/master/src/app/checkout/payment/vnpay/page.tsx"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1565C0,stroke-width:2px;
    classDef backend fill:#F1F8E9,stroke:#33691E,stroke-width:2px;
    classDef utility fill:#FFF3E0,stroke:#E65100,stroke-width:2px;
    classDef database fill:#E8F5E9,stroke:#1B5E20,stroke-width:2px;
    classDef external fill:#FCE4EC,stroke:#880E4F,stroke-width:2px;
```
