# nguyenmanhha-ptit/ks_csdl architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenmanhha-ptit/ks_csdl
- Repository: https://github.com/nguyenmanhha-ptit/ks_csdl

## Overview

1. This is a fullstack hotel management system with a very clear 3-tier shape: a React frontend, a Node.js/Express backend, and a MySQL database. The main runtime flow is browser UI → API calls → server logic → SQL database.

2. The frontend lives in the root `src/` folder and is built with Vite. `src/main.jsx` boots the app, `src/App.jsx` likely wires routing and global providers, and `src/index.css` plus `tailwind.config.js` / `postcss.config.js` indicate Tailwind-based styling.

3. The UI is organized by user role rather than by generic feature. The pages folder contains separate entry pages for `AdminPages.jsx`, `ManagerPages.jsx`, `ReceptionistPages.jsx`, `CustomerPages.jsx`, plus `LoginPage.jsx` and `RegisterPage.jsx`. This strongly suggests role-based navigation and role-specific dashboards.

4. Shared UI structure is concentrated in `src/components/`, especially `components/layout/DashboardLayout.jsx` and `components/common/`. That points to a reusable shell around the different role pages, with common navigation/chrome separated from page-specific business views.

5. Client-side state for authentication is centralized in `src/store/AuthContext.jsx`. Architecturally, this is the main boundary for login state, current user identity, and likely role checks used to gate access to the different page groups.

6. API access is isolated in `src/services/api.js`. That means the frontend does not call the backend directly from components; instead, it routes network communication through a single service layer, which is important for diagramming the data flow and the separation between presentation and transport concerns.

7. The backend is a separate Node.js app under `backend/`, with `server.js` as the entry point and `db.js` as the database connection module. This is the server-side boundary where HTTP requests are received, business rules are applied, and MySQL queries are executed.

8. The database is MySQL, and the schema is intentionally shipped as SQL scripts at the repository root (`mysql_schema.sql` and `SQLQuerytaocosodulieu.sql`). The README says the schema creates the `HotelManagementDB` database and its tables, so the data layer is not abstracted by an ORM in the repository structure.

9. Authentication appears to be token-based, most likely JWT-based, because the README requires a `JWT_SECRET` in `backend/.env`. That implies the backend is responsible for issuing and validating auth tokens, while the frontend stores auth state in context and uses it to control page access.

10. The built frontend is committed in `dist/`, including hashed assets and `index.html`. For architecture purposes, this means the React app is designed as a static SPA build artifact that can be served independently from the Node backend or by another static host.

11. The main external boundary is the MySQL server configured through environment variables (`DB_HOST`, `DB_USER`, `DB_PASSWORD`, `DB_NAME`). The app depends on local or hosted MySQL infrastructure, but no other external services are evident from the repository layout.

12. In diagram terms, the most important subsystems are: role-based SPA frontend, auth/context and API service layer, Express backend, MySQL persistence layer, and SQL schema provisioning scripts. The primary data flow is user interaction in the browser, authenticated API requests to the backend, and database reads/writes for hotel management data.

Main entry points: [`src/App.jsx`](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/App.jsx) (Route Shell), [`src/services/api.js`](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/services/api.js) (API Client), [`src/main.jsx`](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/main.jsx) (App Shell), [`src/store/AuthContext.jsx`](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/store/AuthContext.jsx) (Auth Context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("Browser UI<br/>user-facing client"))
  node_app["App Shell<br/>React entry<br/>[main.jsx]"]
  node_routes["Route Shell<br/>React root<br/>[App.jsx]"]
  node_auth["Auth Context<br/>state<br/>[AuthContext.jsx]"]
  node_api["API Client<br/>[api.js]"]
  node_layout["Dashboard Layout<br/>shared layout"]
  node_common["Common UI<br/>shared components<br/>[index.jsx]"]
  node_admin["Admin Pages<br/>role pages<br/>[AdminPages.jsx]"]
  node_manager["Manager Pages<br/>role pages<br/>[ManagerPages.jsx]"]
  node_reception["Receptionist Pages<br/>role pages"]
  node_customer["Customer Pages<br/>role pages<br/>[CustomerPages.jsx]"]
  node_login["Login Page<br/>auth page<br/>[LoginPage.jsx]"]
  node_register["Register Page<br/>auth page<br/>[RegisterPage.jsx]"]
end

subgraph group_backend["Backend"]
  node_server["Express Server<br/>Node API<br/>[server.js]"]
  node_dbconn["DB Connector<br/>database module<br/>[db.js]"]
end

subgraph group_data["Data"]
  node_mysql[("MySQL DB<br/>relational database")]
  node_schema["Schema SQL<br/>provisioning scripts<br/>[mysql_schema.sql]"]
  node_alt_schema["Legacy SQL<br/>provisioning script"]
end

subgraph group_build["Build"]
  node_dist["SPA Build<br/>bundled frontend<br/>[index.html]"]
end

node_browser -->|"opens app"| node_app
node_app -->|"boots"| node_routes
node_routes -->|"reads auth"| node_auth
node_routes -->|"uses shell"| node_layout
node_layout -->|"composes"| node_common
node_routes -->|"navigates to"| node_admin
node_routes -->|"navigates to"| node_manager
node_routes -->|"navigates to"| node_reception
node_routes -->|"navigates to"| node_customer
node_routes -->|"navigates to"| node_login
node_routes -->|"navigates to"| node_register
node_auth -->|"auth headers"| node_api
node_admin -->|"requests"| node_api
node_manager -->|"requests"| node_api
node_reception -->|"requests"| node_api
node_customer -->|"requests"| node_api
node_login -->|"signs in"| node_api
node_register -->|"registers"| node_api
node_api -->|"HTTP API"| node_server
node_server -->|"queries"| node_dbconn
node_dbconn -->|"reads/writes"| node_mysql
node_schema -->|"creates"| node_mysql
node_alt_schema -->|"initializes"| node_mysql
node_dist -->|"served as SPA"| node_browser

click node_app "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/main.jsx"
click node_routes "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/App.jsx"
click node_auth "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/store/AuthContext.jsx"
click node_api "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/services/api.js"
click node_layout "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/components/layout/DashboardLayout.jsx"
click node_common "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/components/common/index.jsx"
click node_admin "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/AdminPages.jsx"
click node_manager "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/ManagerPages.jsx"
click node_reception "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/ReceptionistPages.jsx"
click node_customer "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/CustomerPages.jsx"
click node_login "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/LoginPage.jsx"
click node_register "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/RegisterPage.jsx"
click node_server "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/backend/server.js"
click node_dbconn "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/backend/db.js"
click node_schema "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/mysql_schema.sql"
click node_alt_schema "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/SQLQuerytaocosodulieu.sql"
click node_dist "https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/dist/index.html"

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_browser,node_app,node_routes,node_auth,node_api,node_layout,node_common,node_admin,node_manager,node_reception,node_customer,node_login,node_register toneBlue
class node_server,node_dbconn toneAmber
class node_mysql,node_schema,node_alt_schema toneMint
class node_dist toneRose
```

## Components

### Frontend

React SPA, role-based pages, shared layout, auth state, and API client

- **Browser UI**: user-facing client · End-user interaction surface for the hotel management system
- [App Shell](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/main.jsx): React entry · Bootstraps the SPA and global routing/provider composition · `src/main.jsx`
- [Route Shell](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/App.jsx): React root · Top-level app wiring for navigation and page composition · `src/App.jsx`
- [Auth Context](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/store/AuthContext.jsx): state · Centralized login state, identity, and role gating · `src/store/AuthContext.jsx`
- [API Client](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/services/api.js): service · Single network boundary for backend requests · `src/services/api.js`
- [Dashboard Layout](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/components/layout/DashboardLayout.jsx): shared layout · Reusable authenticated shell for role dashboards · `src/components/layout/DashboardLayout.jsx`
- [Common UI](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/components/common/index.jsx): shared components · Reusable UI primitives used across pages · `src/components/common/index.jsx`
- [Admin Pages](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/AdminPages.jsx): role pages · Admin-facing management views and workflows · `src/pages/AdminPages.jsx`
- [Manager Pages](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/ManagerPages.jsx): role pages · Manager-facing management views and workflows · `src/pages/ManagerPages.jsx`
- [Receptionist Pages](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/ReceptionistPages.jsx): role pages · Receptionist-facing operational views and workflows · `src/pages/ReceptionistPages.jsx`
- [Customer Pages](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/CustomerPages.jsx): role pages · Customer-facing booking and account views · `src/pages/CustomerPages.jsx`
- [Login Page](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/LoginPage.jsx): auth page · User sign-in entry point · `src/pages/LoginPage.jsx`
- [Register Page](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/src/pages/RegisterPage.jsx): auth page · User account creation entry point · `src/pages/RegisterPage.jsx`

### Backend

Node.js/Express server and database connection

- [Express Server](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/backend/server.js): Node API · HTTP API entry point and server-side request handling · `backend/server.js`
- [DB Connector](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/backend/db.js): database module · MySQL connection and query plumbing · `backend/db.js`

### Data

MySQL schema and persistence layer

- **MySQL DB**: relational database · Persistent storage for hotel management data
- [Schema SQL](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/mysql_schema.sql): provisioning scripts · Database creation and table definition scripts · `mysql_schema.sql`
- [Legacy SQL](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/SQLQuerytaocosodulieu.sql): provisioning script · Additional SQL script for schema or data setup · `SQLQuerytaocosodulieu.sql`

### Build

Bundled frontend artifacts and root-level build config

- [SPA Build](https://github.com/nguyenmanhha-ptit/ks_csdl/blob/main/dist/index.html): bundled frontend · Committed production build of the React app · `dist/index.html`

## Connections

- Browser UI → App Shell: opens app · The browser loads the SPA entry
- App Shell → Route Shell: boots · Main entry composes the app shell and top-level UI
- Route Shell → Auth Context: reads auth · Route decisions and guards depend on authenticated user state
- Route Shell → Dashboard Layout: uses shell · Protected views are wrapped in the dashboard layout
- Dashboard Layout → Common UI: composes · The shared shell reuses common UI primitives
- Route Shell → Admin Pages: navigates to · Role-based navigation exposes admin views
- Route Shell → Manager Pages: navigates to · Role-based navigation exposes manager views
- Route Shell → Receptionist Pages: navigates to · Role-based navigation exposes receptionist views
- Route Shell → Customer Pages: navigates to · Role-based navigation exposes customer views
- Route Shell → Login Page: navigates to · Unauthenticated users enter through login
- Route Shell → Register Page: navigates to · Account creation is exposed as a public page
- Auth Context → API Client: auth headers · Auth state feeds authenticated API requests
- Admin Pages → API Client: requests · Role pages call backend endpoints through the service layer
- Manager Pages → API Client: requests · Role pages call backend endpoints through the service layer
- Receptionist Pages → API Client: requests · Role pages call backend endpoints through the service layer
- Customer Pages → API Client: requests · Role pages call backend endpoints through the service layer
- Login Page → API Client: signs in · Login submits credentials through the shared client
- Register Page → API Client: registers · Registration submits new account data through the shared client
- API Client → Express Server: HTTP API · Frontend service layer communicates with the Express backend
- Express Server → DB Connector: queries · Server logic uses the database connector for persistence operations
- DB Connector → MySQL DB: reads/writes · MySQL stores operational and account data
- Schema SQL → MySQL DB: creates · Schema scripts provision the database and tables
- Legacy SQL → MySQL DB: initializes · Additional SQL script supports database setup or seeding
- SPA Build → Browser UI: served as SPA · Production build is the static frontend artifact delivered to users
