How dohuyit/frontend-qnhg works
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)