# dohuyit/frontend-qnhg architecture

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

- Interactive diagram: https://gitdiagram.com/dohuyit/frontend-qnhg
- Repository: https://github.com/dohuyit/frontend-qnhg

## Overview

##### Project Type and Purpose
- This is a front-end SPA built with React + Vite.
- It provides two UIs:
- Admin panel (user/role management, orders, kitchen, etc.)
- Client/site interface (menu browsing, cart, booking).
- It uses a JSON file (db.json) or mock/fake-backend helpers for local development and communicates with real back-end services (via Axios).
- State management for Admin is handled via Redux & Redux-Saga; Client uses React Context for the cart and hooks/custom hooks.

##### File Structure
- src/components, src/pages, src/layouts, src/routes—split per “admin” and “client” plus “common.”
- src/services—API layer (admin/ and client/).
- src/store/admin—Redux store: actions, reducers, sagas.
- src/hooks, src/helpers, src/utils—custom logic and utilities.
- src/assets—static files (images, fonts, CSS/SCSS) scoped for admin and client.
- i18n and locales—for internationalization.
- Configuration: .env, config.jsx, vite.config.js.

##### Extract Insights from README
- README confirms directory roles: assets, components, constants, hooks, layouts, pages, routes, services, utils, store.
- Highlights separation of concerns: UI components vs. API services vs. state management vs. layout vs. routing vs. assets.

##### Main Components
a. User’s Web Browser (Client)
b. SPA Entry Point (main.jsx → App.jsx)
c. Routing Layer (React Router)
– AdminRoutes & ClientRoutes
d. Layouts
– AdminLayout (sidebar, header)
– ClientLayout (header, footer)
e. UI Components
– Admin Components (dashboard, orders, categories, etc.)
– Client Components (menu, cart, booking, blog, etc.)
– Common Components (shared header/footer, UI widgets)
f. State Management
– Redux Store (Admin): actions → sagas → API calls → reducers → state
– React Context (Client Cart)
g. Services / API Layer
– Axios-based modules under src/services/admin & src/services/client
– Mock/fake-backend helpers for local development
h. External Services
– Real back-end REST API (authentication, CRUD, payment)
– Firebase (face recognition, if used)
– JSON–server (db.json) for mocks
i. Utilities / Helpers
– src/hooks, src/utils, src/helpers (formatting, auth tokens, URL helpers)
j. Asset Server / CDN
– Static assets (images, fonts, CSS) served from public/ or CDN

##### Relationships and Data Flows
- User clicks a route → React Router selects AdminLayout or ClientLayout.
- Layout loads relevant page → page composes UI components.
- Components dispatch an action (Admin) or call a hook/context (Client) → reaches Service layer.
- Service layer (Axios) → sends HTTP request to back-end API or JSON-server → returns JSON.
- For Admin: data flows back into Redux-Saga → reducer → updates store → components re-render.
- For Client: custom hooks update Context state → components re-render.
- i18n middleware intercepts text.
- Assets (images/CSS) loaded from public/ or CDN.

##### Architectural Patterns / Principles
- Feature-based structure: grouping by admin vs. client vs. common.
- Layered architecture: Presentation (components/pages/layouts), State (store/Context), Domain (services), Infrastructure (external APIs).
- Clear separation of concerns:
- Routing layer isolates navigation
- Layout layer handles chrome (header/sidebar/footer)
- Page layer for business views
- Component layer for reusable UI
- Service layer for API abstraction
- State layer for global data
- Use of design patterns:
- Container/Presentational
- Observer (Redux store)
- Facade (services behind simple methods)
- Saga (for side-effects)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser
    Browser["User Web Browser"]:::external

    %% SPA Entry Point
    subgraph "SPA Entry Point"
        direction TB
        Main["main.jsx"]:::ui
        App["App.jsx"]:::ui
        AppCSS["App.css"]:::ui
    end

    %% Routing Layer
    subgraph "Routing Layer"
        direction TB
        AdminRoutes["src/routes/admin/index.jsx"]:::ui
        AdminRoute["src/routes/admin/route.jsx"]:::ui
        ClientRoutes["src/routes/client/index.jsx"]:::ui
        ClientRoute["src/routes/client/route.jsx"]:::ui
    end

    %% Layouts
    subgraph "Layouts"
        direction TB
        AdminLayout["AdminLayout"]:::ui
        ClientLayout["ClientLayout"]:::ui
    end

    %% UI Components
    subgraph "UI Components"
        direction TB
        subgraph "Admin UI Components"
            direction TB
            AdminUI["src/components/admin/ui/"]:::ui
            AdminInclude["src/components/admin/Include/"]:::ui
            AdminFeatures["Orders, Dishes, Combos, ..."]:::ui
        end
        subgraph "Client UI Components"
            direction TB
            ClientCart["src/components/client/cart/"]:::ui
            ClientMenu["src/components/client/menu/"]:::ui
            ClientBranch["src/components/client/branchDetail/"]:::ui
            ClientOrder["src/components/client/order/"]:::ui
            ClientIncludeHeader["src/components/client/include/header/"]:::ui
            ClientIncludeFooter["src/components/client/include/footer/"]:::ui
            ClientOther["src/components/client/home/, detail-blog/, ..."]:::ui
        end
        subgraph "Common Components"
            direction TB
            CommonUI["src/components/common/"]:::ui
        end
    end

    %% State Management
    subgraph "State Management"
        direction TB
        subgraph "Admin (Redux/Saga)"
            direction TB
            AdminStore["src/store/admin/index.js"]:::state
            AdminReducers["src/store/admin/reducers.js"]:::state
            AdminSagas["src/store/admin/sagas.js"]:::state
            AdminActions["src/store/admin/actions.js"]:::state
        end
        subgraph "Client (Context)"
            direction TB
            CartContext["src/components/client/cart/cartContext.jsx"]:::state
            ClientHooks["src/hooks/client/"]:::state
        end
    end

    %% Services / API Layer
    subgraph "Services/API Layer"
        direction TB
        subgraph "Admin Services"
            direction TB
            AdminAPI["src/services/admin/api.js"]:::api
            AdminAuthService["authService.js"]:::api
            AdminOtherServices["other admin services"]:::api
        end
        subgraph "Client Services"
            direction TB
            ClientCategoryService["src/services/client/CategoryService.js"]:::api
            ClientMenuService["src/services/client/menuService.js"]:::api
            ClientAuthServices["src/services/client/auth/"]:::api
        end
    end

    %% Mock & External Backends
    subgraph "Backends"
        direction TB
        MockServer["db.json"]:::external
        FakeBackend["src/helpers/admin/fakebackend_helper.jsx"]:::external
        RealAPI["External REST API"]:::external
        Firebase["Firebase (face recognition)"]:::external
    end

    %% Helpers & Utils
    subgraph "Helpers & Utilities"
        direction TB
        FormatPrice["src/helpers/formatPriceToVND.js"]:::helper
        AdminHelpers["src/helpers/admin/"]:::helper
        Utils["src/utils/"]:::helper
    end

    %% Internationalization
    subgraph "Internationalization"
        direction TB
        I18nBootstrap["src/i18n.jsx"]:::helper
        Locales["src/locales/"]:::helper
    end

    %% Assets
    subgraph "Static Assets"
        direction TB
        AdminAssets["src/assets/admin/"]:::asset
        ClientAssets["src/assets/client/"]:::asset
        PublicAssets["public/"]:::asset
    end

    %% Flows
    Browser -->|"loads"| Main
    Main --> App
    App -->|"initializes"| AdminRoutes
    App -->|"initializes"| ClientRoutes
    AdminRoutes --> AdminLayout
    ClientRoutes --> ClientLayout
    AdminLayout --> AdminUI
    AdminLayout --> AdminInclude
    AdminLayout --> AdminFeatures
    ClientLayout --> ClientCart
    ClientLayout --> ClientMenu
    ClientLayout --> ClientIncludeHeader
    ClientLayout --> ClientIncludeFooter
    ClientLayout --> ClientOther

    AdminFeatures -->|"dispatch actions"| AdminStore
    AdminUI -->|"dispatch actions"| AdminStore
    AdminStore -->|"runs sagas"| AdminSagas
    AdminSagas -->|"calls"| AdminAPI
    ClientCart -->|"uses context"| CartContext
    ClientMenu -->|"uses hooks"| ClientHooks
    CartContext -->|"calls"| ClientCategoryService
    ClientHooks -->|"calls"| ClientMenuService

    AdminAPI -->|dashed| RealAPI
    AdminAPI -->|dashed| MockServer
    ClientCategoryService -->|dashed| RealAPI
    ClientMenuService -->|dashed| RealAPI
    FakeBackend -->|dashed| AdminAPI

    App --> I18nBootstrap
    I18nBootstrap --> Locales
    AppCSS --> PublicAssets

    AdminUI --> FormatPrice
    AdminUI --> AdminHelpers
    ClientOther --> Utils

    AdminAssets -.-> AdminLayout
    ClientAssets -.-> ClientLayout

    %% Click Events
    click Main "https://github.com/dohuyit/frontend-qnhg/blob/master/src/main.jsx"
    click App "https://github.com/dohuyit/frontend-qnhg/blob/master/src/App.jsx"
    click AppCSS "https://github.com/dohuyit/frontend-qnhg/blob/master/src/App.css"
    click AdminRoutes "https://github.com/dohuyit/frontend-qnhg/blob/master/src/routes/admin/index.jsx"
    click AdminRoute "https://github.com/dohuyit/frontend-qnhg/blob/master/src/routes/admin/route.jsx"
    click ClientRoutes "https://github.com/dohuyit/frontend-qnhg/blob/master/src/routes/client/index.jsx"
    click ClientRoute "https://github.com/dohuyit/frontend-qnhg/blob/master/src/routes/client/route.jsx"
    click AdminLayout "https://github.com/dohuyit/frontend-qnhg/blob/master/src/layouts/AdminLayout.jsx"
    click ClientLayout "https://github.com/dohuyit/frontend-qnhg/blob/master/src/components/client/include/ClientLayout.jsx"
    click AdminUI "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/admin/ui/"
    click AdminInclude "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/admin/Include/"
    click AdminFeatures "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/admin/Orders/"
    click ClientCart "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/cart/"
    click ClientMenu "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/menu/"
    click ClientBranch "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/branchDetail/"
    click ClientOrder "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/order/"
    click ClientIncludeHeader "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/include/header/"
    click ClientIncludeFooter "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/include/footer/"
    click ClientOther "https://github.com/dohuyit/frontend-qnhg/tree/master/src/components/client/home/"
    click AdminStore "https://github.com/dohuyit/frontend-qnhg/blob/master/src/store/admin/index.js"
    click AdminReducers "https://github.com/dohuyit/frontend-qnhg/blob/master/src/store/admin/reducers.js"
    click AdminSagas "https://github.com/dohuyit/frontend-qnhg/blob/master/src/store/admin/sagas.js"
    click AdminActions "https://github.com/dohuyit/frontend-qnhg/blob/master/src/store/admin/actions.js"
    click CartContext "https://github.com/dohuyit/frontend-qnhg/blob/master/src/components/client/cart/cartContext.jsx"
    click ClientHooks "https://github.com/dohuyit/frontend-qnhg/tree/master/src/hooks/client/"
    click AdminAPI "https://github.com/dohuyit/frontend-qnhg/blob/master/src/services/admin/api.js"
    click AdminAuthService "https://github.com/dohuyit/frontend-qnhg/blob/master/src/services/admin/authService.js"
    click ClientCategoryService "https://github.com/dohuyit/frontend-qnhg/blob/master/src/services/client/CategoryService.js"
    click ClientMenuService "https://github.com/dohuyit/frontend-qnhg/blob/master/src/services/client/menuService.js"
    click ClientAuthServices "https://github.com/dohuyit/frontend-qnhg/tree/master/src/services/client/auth/"
    click MockServer "https://github.com/dohuyit/frontend-qnhg/blob/master/db.json"
    click FakeBackend "https://github.com/dohuyit/frontend-qnhg/blob/master/src/helpers/admin/fakebackend_helper.jsx"
    click FormatPrice "https://github.com/dohuyit/frontend-qnhg/blob/master/src/helpers/formatPriceToVND.js"
    click AdminHelpers "https://github.com/dohuyit/frontend-qnhg/tree/master/src/helpers/admin/"
    click I18nBootstrap "https://github.com/dohuyit/frontend-qnhg/blob/master/src/i18n.jsx"
    click Locales "https://github.com/dohuyit/frontend-qnhg/tree/master/src/locales/"
    click AdminAssets "https://github.com/dohuyit/frontend-qnhg/tree/master/src/assets/admin/"
    click ClientAssets "https://github.com/dohuyit/frontend-qnhg/tree/master/src/assets/client/"
    click PublicAssets "https://github.com/dohuyit/frontend-qnhg/tree/master/public/"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef state fill:#d4edda,stroke:#333,stroke-width:1px
    classDef api fill:#ffeeba,stroke:#333,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef helper fill:#f8d7da,stroke:#333,stroke-width:1px
    classDef asset fill:#d6d8db,stroke:#333,stroke-width:1px
```
