# denispham1107/quanlycuahang architecture

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

- Interactive diagram: https://gitdiagram.com/denispham1107/quanlycuahang
- Repository: https://github.com/denispham1107/quanlycuahang

## Overview

Quản lý cửa hàng is a static, shared-data store-management web app with Firebase-backed accounts and a PWA shell. Users sign in, select a store, and manage cashbook income/expenses, purchasing, inventory, sales, and related histories and reports; admins also manage employee accounts and permissions. The browser app is concentrated in `app.js`, while `functions/index.js` provides employee operations and AI-backed reporting/action endpoints. The README documents the wider business capabilities; sampled excerpts do not expose all UI-to-data wiring, so uncertain links are omitted.

Main entry points: [`app.js`](https://github.com/denispham1107/quanlycuahang/blob/main/app.js) (Management web app), [`functions/index.js`](https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js) (AI reports and queries), [`firestore.rules`](https://github.com/denispham1107/quanlycuahang/blob/main/firestore.rules) (Firestore access rules), [`service-worker.js`](https://github.com/denispham1107/quanlycuahang/blob/main/service-worker.js) (Offline app shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_business["Store operations"]
  node_webapp["Management web app<br/>[app.js]"]
  node_cashbook["Income and expenses<br/>[app.js]"]
  node_overview["Store overview<br/>[app.js]"]
  node_activity["Activity history<br/>[app.js]"]
end

subgraph group_commerce["Inventory and sales"]
  node_purchasing["Purchasing<br/>[app.js]"]
  node_inventory["Inventory<br/>[app.js]"]
  node_sales["Sales and bills<br/>[app.js]"]
  node_customers["Customer records<br/>[app.js]"]
end

subgraph group_identity["Access management"]
  node_login["Authentication and profiles<br/>[app.js]"]
  node_employee_admin["Employee management<br/>[app.js]"]
  node_employee_api["Employee functions<br/>[index.js]"]
end

subgraph group_assistant["AI assistance"]
  node_ai_reports["AI reports and queries<br/>[index.js]"]
  node_ai_actions["AI action confirmation<br/>[index.js]"]
end

subgraph group_platform["Firebase and PWA"]
  node_firestore[("Firestore")]
  node_auth_service["Firebase Authentication"]
  node_rules["Firestore access rules<br/>[firestore.rules]"]
  node_pwa["Offline app shell<br/>[service-worker.js]"]
  node_openai["OpenAI service"]
end

node_staff(("Store staff"))

node_staff -->|"uses"| node_webapp
node_webapp -->|"signs in"| node_login
node_webapp -->|"manages"| node_cashbook
node_webapp -->|"views"| node_overview
node_webapp -->|"reviews"| node_activity
node_webapp -->|"manages"| node_purchasing
node_webapp -->|"manages"| node_inventory
node_webapp -->|"creates and reviews"| node_sales
node_webapp -->|"maintains"| node_customers
node_webapp -->|"administers"| node_employee_admin
node_login -->|"authenticates"| node_auth_service
node_login -->|"reads profile"| node_firestore
node_webapp -->|"loads and saves state"| node_firestore
node_rules -->|"governs access"| node_firestore
node_employee_admin -->|"calls"| node_employee_api
node_webapp -->|"requests employee state"| node_employee_api
node_employee_api -->|"reads and mutates"| node_firestore
node_webapp -.->|"sends AI queries"| node_ai_reports
node_webapp -.->|"confirms AI actions"| node_ai_actions
node_ai_reports -->|"reads shared state"| node_firestore
node_ai_reports -.->|"requests AI"| node_openai
node_ai_actions -.->|"uses AI service"| node_openai
node_webapp -->|"registers"| node_pwa

click node_webapp "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_cashbook "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_overview "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_activity "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_purchasing "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_inventory "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_sales "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_customers "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_login "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_employee_admin "https://github.com/denispham1107/quanlycuahang/blob/main/app.js"
click node_employee_api "https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js"
click node_ai_reports "https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js"
click node_ai_actions "https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js"
click node_rules "https://github.com/denispham1107/quanlycuahang/blob/main/firestore.rules"
click node_pwa "https://github.com/denispham1107/quanlycuahang/blob/main/service-worker.js"

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_webapp,node_cashbook,node_overview,node_activity toneBlue
class node_purchasing,node_inventory,node_sales,node_customers toneAmber
class node_login,node_employee_admin,node_employee_api toneMint
class node_ai_reports,node_ai_actions toneRose
class node_firestore,node_auth_service,node_rules,node_pwa,node_openai,node_staff toneIndigo
```

## Components

### Store operations

- [Management web app](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Income and expenses](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Store overview](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Activity history](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`

### Inventory and sales

- [Purchasing](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Inventory](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Sales and bills](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Customer records](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`

### Access management

- [Authentication and profiles](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Employee management](https://github.com/denispham1107/quanlycuahang/blob/main/app.js): `app.js`
- [Employee functions](https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js): `functions/index.js`

### AI assistance

- [AI reports and queries](https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js): `functions/index.js`
- [AI action confirmation](https://github.com/denispham1107/quanlycuahang/blob/main/functions/index.js): `functions/index.js`

### Firebase and PWA

- **Firestore**
- **Firebase Authentication**
- [Firestore access rules](https://github.com/denispham1107/quanlycuahang/blob/main/firestore.rules): `firestore.rules`
- [Offline app shell](https://github.com/denispham1107/quanlycuahang/blob/main/service-worker.js): `service-worker.js`
- **OpenAI service**

### Other components

- **Store staff**

## Connections

- Store staff → Management web app: uses
- Management web app → Authentication and profiles: signs in
- Management web app → Income and expenses: manages
- Management web app → Store overview: views
- Management web app → Activity history: reviews
- Management web app → Purchasing: manages
- Management web app → Inventory: manages
- Management web app → Sales and bills: creates and reviews
- Management web app → Customer records: maintains
- Management web app → Employee management: administers
- Authentication and profiles → Firebase Authentication: authenticates
- Authentication and profiles → Firestore: reads profile
- Management web app → Firestore: loads and saves state
- Firestore access rules → Firestore: governs access
- Employee management → Employee functions: calls
- Management web app → Employee functions: requests employee state
- Employee functions → Firestore: reads and mutates
- Management web app → AI reports and queries: sends AI queries
- Management web app → AI action confirmation: confirms AI actions
- AI reports and queries → Firestore: reads shared state
- AI reports and queries → OpenAI service: requests AI
- AI action confirmation → OpenAI service: uses AI service
- Management web app → Offline app shell: registers
