# phucduy2501/quanlydatdonxe architecture

> Architecture diagram of the GitHub repository phucduy2501/quanlydatdonxe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phucduy2501/quanlydatdonxe
- Repository: https://github.com/phucduy2501/quanlydatdonxe

## Overview

1. **Repository shape**
   - This is a two-tier application: a **React/Vite single-page frontend** in `src/` and a **Node backend** in `backend/`.
   - The domain looks like a business management / POS-style system covering orders, products, inventory, customers, sales, purchases, debts, expenses, staff, shifts, and profit.

2. **Frontend application shell**
   - The browser app is built with **React** and bundled by **Vite** (`vite.config.js`).
   - `src/main.jsx` boots the app, and `src/App.jsx` likely defines the top-level layout and routing.
   - Shared chrome lives in `src/components/`: `Header`, `Sidebar`, `NotificationBell`, and `ProductSearch` indicate a persistent navigation + utility bar around the feature pages.

3. **Page-driven feature boundaries**
   - `src/pages/` contains the major functional screens, each isolated as a page component.
   - Core business areas are separated into their own pages: `Dashboard`, `Sales`, `SalesMulti`, `Purchases`, `Inventory`, `Products`, `Customers`, `CustomerGroups`, `ProductGroups`, `Units`, `Channels`, `Cashbook`, `Expenses`, `Debts`, `Staff`, `Shifts`, `Membership`, `Profit`, `PriceList`, and `BaseCategory`.
   - This suggests a route-per-domain architecture rather than a single monolithic form workflow.

4. **Frontend data access layer**
   - `src/services/api.js` is the main frontend-to-backend API adapter.
   - `src/services/supabaseClient.js` indicates the frontend may also integrate with **Supabase** for auth or hosted data access, so the client layer likely abstracts more than one backend source.
   - The frontend architecture therefore has a clear boundary: UI components/pages do not talk directly to persistence; they go through service modules.

5. **Backend service boundary**
   - `backend/server.js` is the runtime entrypoint for the backend API.
   - `backend/db.js` suggests a database abstraction or query helper used by the server.
   - The backend is responsible for business data access and likely exposes REST endpoints consumed by `src/services/api.js`.

6. **Persistence and seed data**
   - `backend/data/db.json` points to a **JSON-file-backed store**, probably used for local development or lightweight persistence.
   - `backend/init.sql` indicates a **SQL schema/bootstrap path** as well, which means the system may support a relational database setup alongside or instead of the JSON file.
   - For an architecture diagram, it is worth showing persistence as an implementation-dependent data store behind the backend, with both JSON and SQL artifacts present.

7. **Authentication and session entry point**
   - The presence of a `Login` page plus `supabaseClient.js` suggests sign-in is handled separately from the main business pages.
   - Login likely gates access to the rest of the SPA, while authenticated state is then used by the dashboard and operational modules.

8. **UI composition and cross-cutting concerns**
   - Page-level CSS files such as `dashboard.css`, `purchase.css`, `sales.css`, and `customers.css` show styling is still localized by feature area.
   - Shared utility components like search and notifications imply cross-cutting interactions are centralized in reusable UI widgets instead of duplicated per page.

9. **Operational flows**
   - Typical flow is: user interacts with a page component → page calls `src/services/api.js` or Supabase client → backend/API or external service returns data → UI updates.
   - Business flows likely center on sales/purchases/inventory mutations feeding dashboard summaries, profit calculations, debts, and cashbook views.

10. **Deployment / runtime**
   - `backend/Dockerfile` plus `docker-compose.yml` show the backend is containerized and intended to be run as part of a composed environment.
   - The frontend is a standard Vite app, so it is likely run separately in development and built into static assets for production.

11. **Tooling boundary**
   - `eslint.config.js`, `package.json`, and lockfiles indicate a standard JavaScript toolchain with linting and deterministic dependency installs.
   - No evidence of TypeScript or a heavy state-management framework appears in the tree; the architecture looks intentionally lightweight and modular.

12. **What to draw in an architecture diagram**
   - Show three main zones: **React SPA frontend**, **backend API/service layer**, and **data stores/external services**.
   - Inside the frontend, group shared shell components separately from domain pages.
   - Inside the backend, show the server entrypoint and database helper as the bridge to storage.
   - Include both **local JSON/SQL persistence artifacts** and the **Supabase integration point** as possible data backends.

Main entry points: [`src/App.jsx`](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/App.jsx) (Shell), [`src/services/api.js`](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/services/api.js) (API client), [`backend/db.js`](https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/db.js) (DB helper), [`src/pages/Sales.jsx`](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Sales.jsx) (Sales)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_src_main["App boot<br/>entrypoint<br/>[main.jsx]"]
  node_src_app["Shell<br/>layout/router<br/>[App.jsx]"]
  node_ui_header["Header<br/>ui-shell<br/>[Header.jsx]"]
  node_ui_sidebar["Sidebar<br/>ui-shell<br/>[Sidebar.jsx]"]
  node_ui_bell["Alerts<br/>ui-widget"]
  node_ui_search["Search<br/>ui-widget<br/>[ProductSearch.jsx]"]
  node_page_login["Login<br/>auth page<br/>[Login.jsx]"]
  node_page_dashboard["Dashboard<br/>ops page<br/>[Dashboard.jsx]"]
  node_page_sales["Sales<br/>[Sales.jsx]"]
  node_page_sales_multi["Multi sale<br/>sales page<br/>[SalesMulti.jsx]"]
  node_page_purchases["Purchases<br/>procurement page<br/>[Purchases.jsx]"]
  node_page_inventory["Inventory<br/>stock page<br/>[Inventory.jsx]"]
  node_page_products["Products<br/>catalog page<br/>[Products.jsx]"]
  node_page_customers["Customers<br/>crm page<br/>[Customers.jsx]"]
  node_page_cashbook["Cashbook<br/>finance page<br/>[Cashbook.jsx]"]
  node_page_expenses["Expenses<br/>finance page<br/>[Expenses.jsx]"]
  node_page_debts["Debts<br/>finance page<br/>[Debts.jsx]"]
  node_page_staff["Staff<br/>admin page<br/>[Staff.jsx]"]
  node_page_shifts["Shifts<br/>workforce page<br/>[Shifts.jsx]"]
  node_page_profit["Profit<br/>analytics page<br/>[Profit.jsx]"]
  node_page_orders["Orders<br/>ops page<br/>[Orders.jsx]"]
  node_svc_api["API client<br/>service adapter<br/>[api.js]"]
  node_svc_supabase["Supabase<br/>auth/data client<br/>[supabaseClient.js]"]
end

subgraph group_backend["Backend API"]
  node_be_server["Server<br/>node api<br/>[server.js]"]
  node_be_db["DB helper<br/>data access<br/>[db.js]"]
end

subgraph group_data["Data backends"]
  node_store_json[("JSON store<br/>local persistence<br/>[db.json]")]
  node_store_sql["SQL schema<br/>bootstrap sql<br/>[init.sql]"]
  node_store_supabase[("Supabase backend<br/>external service")]
end

node_src_main -->|"mounts"| node_src_app
node_src_app -->|"renders"| node_ui_header
node_src_app -->|"renders"| node_ui_sidebar
node_src_app -->|"includes"| node_ui_bell
node_src_app -->|"includes"| node_ui_search
node_src_app -->|"routes"| node_page_login
node_src_app -->|"routes"| node_page_dashboard
node_src_app -->|"routes"| node_page_sales
node_src_app -->|"routes"| node_page_sales_multi
node_src_app -->|"routes"| node_page_purchases
node_src_app -->|"routes"| node_page_inventory
node_src_app -->|"routes"| node_page_products
node_src_app -->|"routes"| node_page_customers
node_src_app -->|"routes"| node_page_cashbook
node_src_app -->|"routes"| node_page_expenses
node_src_app -->|"routes"| node_page_debts
node_src_app -->|"routes"| node_page_staff
node_src_app -->|"routes"| node_page_shifts
node_src_app -->|"routes"| node_page_profit
node_src_app -->|"routes"| node_page_orders
node_page_sales -->|"reads/writes"| node_svc_api
node_page_sales_multi -->|"reads/writes"| node_svc_api
node_page_purchases -->|"reads/writes"| node_svc_api
node_page_inventory -->|"reads"| node_svc_api
node_page_products -->|"reads/writes"| node_svc_api
node_page_customers -->|"reads/writes"| node_svc_api
node_page_cashbook -->|"reads"| node_svc_api
node_page_expenses -->|"reads/writes"| node_svc_api
node_page_debts -->|"reads/writes"| node_svc_api
node_page_staff -->|"reads/writes"| node_svc_api
node_page_shifts -->|"reads/writes"| node_svc_api
node_page_profit -->|"reads"| node_svc_api
node_svc_api -->|"http"| node_be_server
node_svc_supabase -->|"sdk"| node_store_supabase
node_be_server -->|"uses"| node_be_db
node_be_db -->|"file store"| node_store_json
node_be_db -->|"bootstrap"| node_store_sql

click node_src_main "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/main.jsx"
click node_src_app "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/App.jsx"
click node_ui_header "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/Header.jsx"
click node_ui_sidebar "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/Sidebar.jsx"
click node_ui_bell "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/NotificationBell.jsx"
click node_ui_search "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/ProductSearch.jsx"
click node_page_login "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Login.jsx"
click node_page_dashboard "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Dashboard.jsx"
click node_page_sales "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Sales.jsx"
click node_page_sales_multi "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/SalesMulti.jsx"
click node_page_purchases "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Purchases.jsx"
click node_page_inventory "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Inventory.jsx"
click node_page_products "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Products.jsx"
click node_page_customers "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Customers.jsx"
click node_page_cashbook "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Cashbook.jsx"
click node_page_expenses "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Expenses.jsx"
click node_page_debts "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Debts.jsx"
click node_page_staff "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Staff.jsx"
click node_page_shifts "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Shifts.jsx"
click node_page_profit "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Profit.jsx"
click node_page_orders "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Orders.jsx"
click node_svc_api "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/services/api.js"
click node_svc_supabase "https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/services/supabaseClient.js"
click node_be_server "https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/server.js"
click node_be_db "https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/db.js"
click node_store_json "https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/data/db.json"
click node_store_sql "https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/init.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_main,node_src_app,node_ui_header,node_ui_sidebar,node_ui_bell,node_ui_search,node_page_login,node_page_dashboard,node_page_sales,node_page_sales_multi,node_page_purchases,node_page_inventory,node_page_products,node_page_customers,node_page_cashbook,node_page_expenses,node_page_debts,node_page_staff,node_page_shifts,node_page_profit,node_page_orders,node_svc_api,node_svc_supabase toneBlue
class node_be_server,node_be_db toneAmber
class node_store_json,node_store_sql,node_store_supabase toneMint
```

## Components

### React SPA

Browser application built with React and Vite.

- [App boot](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/main.jsx): entrypoint · Bootstraps the React application. · `src/main.jsx`
- [Shell](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/App.jsx): layout/router · Top-level SPA layout and routing. · `src/App.jsx`
- [Header](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/Header.jsx): ui-shell · Persistent top-level chrome. · `src/components/Header.jsx`
- [Sidebar](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/Sidebar.jsx): ui-shell · Primary navigation shell. · `src/components/Sidebar.jsx`
- [Alerts](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/NotificationBell.jsx): ui-widget · Notification indicator and actions. · `src/components/NotificationBell.jsx`
- [Search](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/components/ProductSearch.jsx): ui-widget · Shared product search utility. · `src/components/ProductSearch.jsx`
- [Login](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Login.jsx): auth page · Authentication entry screen. · `src/pages/Login.jsx`
- [Dashboard](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Dashboard.jsx): ops page · Overview and business summaries. · `src/pages/Dashboard.jsx`
- [Sales](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Sales.jsx): sales page · Single-sale operational workflow. · `src/pages/Sales.jsx`
- [Multi sale](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/SalesMulti.jsx): sales page · Multi-item or bulk sales workflow. · `src/pages/SalesMulti.jsx`
- [Purchases](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Purchases.jsx): procurement page · Purchase entry and supplier flow. · `src/pages/Purchases.jsx`
- [Inventory](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Inventory.jsx): stock page · Stock visibility and adjustments. · `src/pages/Inventory.jsx`
- [Products](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Products.jsx): catalog page · Product management screen. · `src/pages/Products.jsx`
- [Customers](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Customers.jsx): crm page · Customer records and activity. · `src/pages/Customers.jsx`
- [Cashbook](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Cashbook.jsx): finance page · Cash movements and ledger view. · `src/pages/Cashbook.jsx`
- [Expenses](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Expenses.jsx): finance page · Expense tracking screen. · `src/pages/Expenses.jsx`
- [Debts](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Debts.jsx): finance page · Outstanding debt management. · `src/pages/Debts.jsx`
- [Staff](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Staff.jsx): admin page · Employee management screen. · `src/pages/Staff.jsx`
- [Shifts](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Shifts.jsx): workforce page · Shift scheduling and tracking. · `src/pages/Shifts.jsx`
- [Profit](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Profit.jsx): analytics page · Profit and margin reporting. · `src/pages/Profit.jsx`
- [Orders](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/pages/Orders.jsx): ops page · Order-centric workflow screen. · `src/pages/Orders.jsx`
- [API client](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/services/api.js): service adapter · Frontend adapter to backend endpoints. · `src/services/api.js`
- [Supabase](https://github.com/phucduy2501/quanlydatdonxe/blob/main/src/services/supabaseClient.js): auth/data client · External client for auth or hosted data. · `src/services/supabaseClient.js`

### Backend API

Node service handling business data and persistence access.

- [Server](https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/server.js): node api · Backend runtime entrypoint. · `backend/server.js`
- [DB helper](https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/db.js): data access · Backend database abstraction and queries. · `backend/db.js`

### Data backends

Local and external storage/integration points used by the system.

- [JSON store](https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/data/db.json): local persistence · File-backed data store for local use. · `backend/data/db.json`
- [SQL schema](https://github.com/phucduy2501/quanlydatdonxe/blob/main/backend/init.sql): bootstrap sql · Database initialization and schema script. · `backend/init.sql`
- **Supabase backend**: external service · Hosted backend used through the Supabase client.

## Connections

- App boot → Shell: mounts · React entry mounts the app shell.
- Shell → Header: renders · Top-level shell includes shared header.
- Shell → Sidebar: renders · Top-level shell includes navigation.
- Shell → Alerts: includes · Shell exposes notification actions.
- Shell → Search: includes · Shell exposes shared search utility.
- Shell → Login: routes · Authentication entry screen is part of the app flow.
- Shell → Dashboard: routes · Dashboard is a primary route.
- Shell → Sales: routes · Sales is a primary route.
- Shell → Multi sale: routes · Multi-sale workflow is a route.
- Shell → Purchases: routes · Purchases is a primary route.
- Shell → Inventory: routes · Inventory is a primary route.
- Shell → Products: routes · Products is a primary route.
- Shell → Customers: routes · Customers is a primary route.
- Shell → Cashbook: routes · Cashbook is a primary route.
- Shell → Expenses: routes · Expenses is a primary route.
- Shell → Debts: routes · Debts is a primary route.
- Shell → Staff: routes · Staff is a primary route.
- Shell → Shifts: routes · Shifts is a primary route.
- Shell → Profit: routes · Profit is a primary route.
- Shell → Orders: routes · Orders is a primary route.
- Sales → API client: reads/writes · Sales page uses the API adapter for business operations.
- Multi sale → API client: reads/writes · Multi-sale workflow uses the API adapter.
- Purchases → API client: reads/writes · Purchasing workflow uses backend services.
- Inventory → API client: reads · Inventory screen loads stock data.
- Products → API client: reads/writes · Product catalog is managed through the API layer.
- Customers → API client: reads/writes · Customer records are handled through the API layer.
- Cashbook → API client: reads · Cashbook consumes transaction data.
- Expenses → API client: reads/writes · Expense tracking uses the API layer.
- Debts → API client: reads/writes · Debt management uses the API layer.
- Staff → API client: reads/writes · Staff management uses the API layer.
- Shifts → API client: reads/writes · Shift tracking uses the API layer.
- Profit → API client: reads · Profit reporting aggregates backend data.
- API client → Server: http · Frontend API client talks to the Node backend.
- Supabase → Supabase backend: sdk · Supabase client connects to hosted services.
- Server → DB helper: uses · Server delegates persistence access to DB helper.
- DB helper → JSON store: file store · Local JSON-backed persistence path.
- DB helper → SQL schema: bootstrap · SQL schema/bootstrap supports relational setup.
