# hoanganhwhy/group7_arboris_rentalroommanagementsystem architecture

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

## Overview

1. **Overall shape**
   - HostelMate is a two-tier application: a **React + Vite + TypeScript single-page frontend** in `src/` and a **Node.js + Express backend** in `server/`.
   - The frontend talks to the backend over HTTP through a small API layer, and the backend persists data in **SQLite**.

2. **Frontend entry and composition**
   - The client bootstraps from `src/main.tsx`, renders `src/App.tsx`, and uses `index.html` as the Vite entry.
   - The UI is organized as page modules under `src/pages/` for the main business areas: **Dashboard, Rooms, Tenants, TenantAccounts, Invoices, MeterReadings, Repairs**.

3. **Shared UI boundary**
   - Reusable controls live in `src/components/ui/` such as `Button`, `Input`, `Modal`, `Sidebar`, and `FilterDropdown`.
   - This suggests a mostly page-driven admin console where pages assemble forms, tables, filters, and dialogs from shared primitives rather than using a heavyweight component framework.

4. **Client-to-server data flow**
   - `src/lib/api.ts` is the front-end boundary for backend calls; pages likely use it instead of calling `fetch` directly.
   - The architecture is: **page interaction → API helper → Express route → SQLite**. This keeps transport concerns separate from page logic.

5. **Backend service layer**
   - `server/server.js` is the Express application entry point and exposes the application’s REST APIs.
   - `server/db.js` centralizes database connection/setup, so route handlers can remain focused on domain rules instead of connection management.

6. **Persistence model**
   - The backend uses **SQLite files checked into the repo** (`server/csdl_hostelmate.sqlite`, `server/quan_ly_phong_tro.sqlite`), indicating a lightweight embedded database deployment.
   - The test suite also runs against **`:memory:` SQLite**, so tests are isolated from the production/dev database files.

7. **Domain subsystems**
   - The README identifies the main business modules as:
     - **Rooms**: room metadata, capacity, floor, area, rent, status, and deletion protection when occupied.
     - **Tenants**: tenant profiles and phone normalization to E.164.
     - **Room assignments / contracts**: check-in, representative tenant, renewal, and checkout with room status updates.
     - **Meter readings**: monthly electricity and water readings with monotonic validation.
     - **Invoices**: rent + utilities + other fees, with month/year selection and CSV/Excel export.
     - **Repairs**: issue reporting constrained to tenants actually occupying the room.

8. **Business-rule boundaries**
   - The core architecture is rule-heavy at the API layer: many actions are validated against current occupancy, tenant identity, and previous readings.
   - Important state transitions are centralized in the backend, especially when an action changes room state from **available → occupied → maintenance** or closes an assignment on checkout.

9. **Reporting and export**
   - Invoices are not just stored; they also support **structured export** for spreadsheet workflows, including UTF-8 BOM handling for Vietnamese text.
   - This makes the invoice subsystem a bridge between transactional data and operational reporting.

10. **Testing architecture**
   - Backend tests live in `server/tests/server.test.js` and run with **Jest + Supertest**.
   - The test setup is intentionally isolated from the real DB, which is important for reliable API-level verification of business rules.

11. **Tooling and quality gates**
   - The repo uses **ESLint** at both root and server level to enforce consistent code style.
   - GitHub Actions in `.github/workflows/ci.yml` automates CI on push/PR, combining linting and backend test execution.

12. **Repository-level deployment/runtime boundary**
   - The root `package.json` and the separate `server/package.json` imply independent frontend and backend dependency graphs, but a single developer workflow.
   - Local development runs both processes together; architecturally, the frontend is a consumer of the backend API, not a server-rendered app.

13. **What to draw in an architecture diagram**
   - Show four main boxes: **React UI**, **API client layer**, **Express API server**, and **SQLite database**.
   - Then subdivide the API server into the six domain modules above, and place **tests/CI** as a parallel quality pipeline rather than part of the runtime path.

Main entry points: [`src/App.tsx`](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/App.tsx) (App Shell), [`server/server.js`](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/server.js) (Express API), [`src/lib/api.ts`](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/lib/api.ts) (API Client), [`server/db.js`](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/db.js) (DB Setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_index_html["Index HTML<br/>vite entry<br/>[index.html]"]
  node_main_tsx["Main<br/>react bootstrap<br/>[main.tsx]"]
  node_app_tsx["App Shell<br/>react shell<br/>[App.tsx]"]
  node_api_client["API Client<br/>http client<br/>[api.ts]"]
  node_dashboard_page["Dashboard<br/>page<br/>[Dashboard.tsx]"]
  node_rooms_page["Rooms<br/>page<br/>[Rooms.tsx]"]
  node_tenants_page["Tenants<br/>page<br/>[Tenants.tsx]"]
  node_tenant_accounts_page["Tenant Accounts<br/>page<br/>[TenantAccounts.tsx]"]
  node_invoices_page["Invoices<br/>page<br/>[Invoices.tsx]"]
  node_meter_page["Meter Readings<br/>page<br/>[MeterReadings.tsx]"]
  node_repairs_page["Repairs<br/>page<br/>[Repairs.tsx]"]
  node_shared_ui["UI Primitives<br/>components"]
end

subgraph group_backend["Backend"]
  node_express_api["Express API<br/>http server<br/>[server.js]"]
  node_db_setup["DB Setup<br/>db layer<br/>[db.js]"]
  node_sqlite_store[("SQLite Store<br/>embedded db")]
  node_rooms_service["Rooms Service<br/>domain module"]
  node_tenants_service["Tenants Service<br/>domain module"]
  node_assignments_service["Assignments<br/>domain module"]
  node_meter_service["Meter Service<br/>domain module"]
  node_invoices_service["Invoices Service<br/>domain module"]
  node_repairs_service["Repairs Service<br/>domain module"]
end

subgraph group_quality["Quality"]
  node_server_tests["API Tests<br/>jest+supertest<br/>[server.test.js]"]
  node_ci_workflow["CI Workflow<br/>github actions<br/>[ci.yml]"]
end

node_index_html -->|"loads"| node_main_tsx
node_main_tsx -->|"renders"| node_app_tsx
node_app_tsx -->|"navigates"| node_dashboard_page
node_app_tsx -->|"navigates"| node_rooms_page
node_app_tsx -->|"navigates"| node_tenants_page
node_app_tsx -->|"navigates"| node_tenant_accounts_page
node_app_tsx -->|"navigates"| node_invoices_page
node_app_tsx -->|"navigates"| node_meter_page
node_app_tsx -->|"navigates"| node_repairs_page
node_app_tsx -->|"uses"| node_shared_ui
node_dashboard_page -->|"requests"| node_api_client
node_rooms_page -->|"requests"| node_api_client
node_tenants_page -->|"requests"| node_api_client
node_tenant_accounts_page -->|"requests"| node_api_client
node_invoices_page -->|"requests"| node_api_client
node_meter_page -->|"requests"| node_api_client
node_repairs_page -->|"requests"| node_api_client
node_api_client -->|"calls"| node_express_api
node_express_api -->|"routes"| node_rooms_service
node_express_api -->|"routes"| node_tenants_service
node_express_api -->|"routes"| node_assignments_service
node_express_api -->|"routes"| node_meter_service
node_express_api -->|"routes"| node_invoices_service
node_express_api -->|"routes"| node_repairs_service
node_rooms_service -->|"reads/writes"| node_db_setup
node_tenants_service -->|"reads/writes"| node_db_setup
node_assignments_service -->|"reads/writes"| node_db_setup
node_meter_service -->|"reads/writes"| node_db_setup
node_invoices_service -->|"reads/writes"| node_db_setup
node_repairs_service -->|"reads/writes"| node_db_setup
node_db_setup -->|"connects"| node_sqlite_store
node_server_tests -->|"verifies"| node_express_api
node_server_tests -.->|"isolates"| node_sqlite_store
node_ci_workflow -->|"runs"| node_server_tests

click node_index_html "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/index.html"
click node_main_tsx "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/main.tsx"
click node_app_tsx "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/App.tsx"
click node_api_client "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/lib/api.ts"
click node_dashboard_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Dashboard.tsx"
click node_rooms_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Rooms.tsx"
click node_tenants_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Tenants.tsx"
click node_tenant_accounts_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/TenantAccounts.tsx"
click node_invoices_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Invoices.tsx"
click node_meter_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/MeterReadings.tsx"
click node_repairs_page "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Repairs.tsx"
click node_shared_ui "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/tree/main/src/components/ui"
click node_express_api "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/server.js"
click node_db_setup "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/db.js"
click node_sqlite_store "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/csdl_hostelmate.sqlite"
click node_server_tests "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/tests/server.test.js"
click node_ci_workflow "https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/.github/workflows/ci.yml"

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_index_html,node_main_tsx,node_app_tsx,node_api_client,node_dashboard_page,node_rooms_page,node_tenants_page,node_tenant_accounts_page,node_invoices_page,node_meter_page,node_repairs_page,node_shared_ui toneBlue
class node_express_api,node_db_setup,node_sqlite_store,node_rooms_service,node_tenants_service,node_assignments_service,node_meter_service,node_invoices_service,node_repairs_service toneAmber
class node_server_tests,node_ci_workflow toneMint
```

## Components

### Frontend

React + Vite single-page client

- [Index HTML](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/index.html): vite entry · Vite HTML entrypoint for the SPA · `index.html`
- [Main](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/main.tsx): react bootstrap · Bootstraps the React application · `src/main.tsx`
- [App Shell](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/App.tsx): react shell · Top-level application composition · `src/App.tsx`
- [API Client](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/lib/api.ts): http client · Front-end boundary for backend requests · `src/lib/api.ts`
- [Dashboard](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Dashboard.tsx): page · Overview and status page · `src/pages/Dashboard.tsx`
- [Rooms](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Rooms.tsx): page · Room management UI · `src/pages/Rooms.tsx`
- [Tenants](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Tenants.tsx): page · Tenant profile management UI · `src/pages/Tenants.tsx`
- [Tenant Accounts](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/TenantAccounts.tsx): page · Tenant account and billing view · `src/pages/TenantAccounts.tsx`
- [Invoices](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Invoices.tsx): page · Billing and export workflows · `src/pages/Invoices.tsx`
- [Meter Readings](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/MeterReadings.tsx): page · Utility reading entry and review · `src/pages/MeterReadings.tsx`
- [Repairs](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/src/pages/Repairs.tsx): page · Repair issue reporting UI · `src/pages/Repairs.tsx`
- [UI Primitives](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/tree/main/src/components/ui): components · Reusable buttons, inputs, modal, sidebar, and filters · `src/components/ui`

### Backend

Express API and SQLite persistence

- [Express API](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/server.js): http server · REST API entrypoint · `server/server.js`
- [DB Setup](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/db.js): db layer · Centralized SQLite connection and setup · `server/db.js`
- [SQLite Store](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/csdl_hostelmate.sqlite): embedded db · Repository-checked SQLite databases · `server/csdl_hostelmate.sqlite`
- **Rooms Service**: domain module · Room metadata, status, and occupancy rules
- **Tenants Service**: domain module · Tenant profiles and phone normalization
- **Assignments**: domain module · Check-in, renewal, representative tenant, checkout
- **Meter Service**: domain module · Monthly electricity and water readings
- **Invoices Service**: domain module · Rent, utilities, fees, and export output
- **Repairs Service**: domain module · Issue reporting constrained by occupancy

### Quality

Tests and CI checks

- [API Tests](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/server/tests/server.test.js): jest+supertest · Isolated backend tests against in-memory SQLite · `server/tests/server.test.js`
- [CI Workflow](https://github.com/hoanganhwhy/group7_arboris_rentalroommanagementsystem/blob/main/.github/workflows/ci.yml): github actions · Automated lint and backend test pipeline · `.github/workflows/ci.yml`

## Connections

- Index HTML → Main: loads · Vite HTML entry loads the client bootstrap
- Main → App Shell: renders · Mounts the top-level React app
- App Shell → Dashboard: navigates · Composes the main page modules
- App Shell → Rooms: navigates · Composes the main page modules
- App Shell → Tenants: navigates · Composes the main page modules
- App Shell → Tenant Accounts: navigates · Composes the main page modules
- App Shell → Invoices: navigates · Composes the main page modules
- App Shell → Meter Readings: navigates · Composes the main page modules
- App Shell → Repairs: navigates · Composes the main page modules
- App Shell → UI Primitives: uses · Pages build screens from shared controls
- Dashboard → API Client: requests · Uses the API helper for backend data
- Rooms → API Client: requests · Uses the API helper for backend data
- Tenants → API Client: requests · Uses the API helper for backend data
- Tenant Accounts → API Client: requests · Uses the API helper for backend data
- Invoices → API Client: requests · Uses the API helper for backend data
- Meter Readings → API Client: requests · Uses the API helper for backend data
- Repairs → API Client: requests · Uses the API helper for backend data
- API Client → Express API: calls · Client talks to the REST API over HTTP
- Express API → Rooms Service: routes · Delegates room operations to the domain boundary
- Express API → Tenants Service: routes · Delegates tenant operations to the domain boundary
- Express API → Assignments: routes · Delegates occupancy and checkout flows
- Express API → Meter Service: routes · Delegates utility reading flows
- Express API → Invoices Service: routes · Delegates billing and export flows
- Express API → Repairs Service: routes · Delegates repair workflows
- Rooms Service → DB Setup: reads/writes · Persists room state through the DB layer
- Tenants Service → DB Setup: reads/writes · Persists tenant records through the DB layer
- Assignments → DB Setup: reads/writes · Stores occupancy and contract state
- Meter Service → DB Setup: reads/writes · Stores monotonic meter readings
- Invoices Service → DB Setup: reads/writes · Builds and stores invoice data
- Repairs Service → DB Setup: reads/writes · Stores repair issues and status
- DB Setup → SQLite Store: connects · Centralized SQLite connection targets the repo database files
- API Tests → Express API: verifies · Exercises the API surface with Supertest
- API Tests → SQLite Store: isolates · Runs against in-memory SQLite during tests
- CI Workflow → API Tests: runs · CI executes the backend test suite
