# shegga9x/phungfrontend architecture

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

## Overview

##### Main Layers and Components
- Frontend User Interface: Split into two main sections – the public “landing” pages (user authentication, book browsing, cart, profile, etc.) and the “admin” pages (admin dashboard, user and notification management).
- API Routes: Located in the /app/api directory. These endpoints handle key business logic such as book details, purchasing, ratings, cart management, GHN for shipping, order processing, and VNP (likely payment).
- Authentication Module: Clearly integrated via NextAuth.js (as mentioned in the README) along with supporting code under the lib/auth folder.
- Integration with PhungBackend: Although not part of this repo, the frontend’s API integration and authentication allude to a backend service (PhungBackend) providing data and CRUD operations.
- External Deployment Environment: The application is deployed on Vercel; include this as the hosting and delivery layer.

##### Architectural Patterns & Technologies
- SSR/Static Generation advantage of Next.js.
- Use of file-based routing (especially under /app and /app/api) indicating a separation of concerns.
- A dedicated section or annotation for the authentication flow:
- User credentials pass through NextAuth.js.
- Protected routes/components (e.g., admin pages, permission/role guards in components such as role-guard.tsx and permission-guard.tsx) enforce access control.
- Modularity of the system by listing reusable UI components (from the components and components/v2 directories) and utility modules (e.g., lib/utils, models).

## Diagram (Mermaid)

```mermaid
graph TD
    A["Client Browser"]:::client

    subgraph "Next.js Web Application"
        B["Landing Pages"]:::frontend
        C["Admin Pages"]:::frontend
        D["UI Components"]:::frontend
        E["UI Components V2"]:::frontend
        F["Authentication Module"]:::frontend
        G["Recoil Provider"]:::frontend
        H["Atoms"]:::frontend
    end

    I["Next.js API Routes"]:::api

    subgraph "Backend Integration"
        J["PhungBackend"]:::external
        K["GHN Service"]:::external
        L["VNP Payment Service"]:::external
    end

    M["Vercel Deployment"]:::deployment

    %% Connections from Client to Next.js Application
    A -->|"loads"| B
    A -->|"loads"| C

    %% Internal Next.js Application flows
    B -->|"renders"| D
    B -->|"authVia"| F
    C -->|"renders"| E
    C -->|"authVia"| F
    D -->|"stateManagedBy"| G
    D -->|"dataFrom"| H
    F -->|"secureCall"| I

    %% API communication from Next.js Application
    B -->|"APIcall"| I
    C -->|"APIcall"| I

    %% API Routes interaction with external services
    I -->|"CRUD"| J
    I -->|"shipping"| K
    I -->|"payment"| L

    %% Deployment indication
    B ---|"hostedOn"| M
    I ---|"hostedOn"| M

    %% Click Events
    click B "https://github.com/shegga9x/phungfrontend/tree/main/app/(landing)"
    click C "https://github.com/shegga9x/phungfrontend/tree/main/app/(admin)"
    click I "https://github.com/shegga9x/phungfrontend/tree/main/app/api"
    click F "https://github.com/shegga9x/phungfrontend/tree/main/lib/auth"
    click D "https://github.com/shegga9x/phungfrontend/tree/main/components"
    click E "https://github.com/shegga9x/phungfrontend/tree/main/components/v2"
    click G "https://github.com/shegga9x/phungfrontend/blob/main/app/recoilContextProvider.tsx"
    click H "https://github.com/shegga9x/phungfrontend/blob/main/atoms/index.ts"
    click M "https://github.com/shegga9x/phungfrontend/blob/main/vercel.json"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef frontend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef api fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef external fill:#CCD1D1,stroke:#566573,stroke-dasharray: 5 5,stroke-width:2px;
    classDef deployment fill:#BB8FCE,stroke:#6C3483,stroke-width:2px;
```
