# vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p architecture

> Architecture diagram of the GitHub repository vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p
- Repository: https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p

## Overview

Cosmetics CRM is a role-based web application for store administration, customer relationship management, and customer engagement. Users sign in and enter role-specific screens; browser modules call the Express API, which applies business rules and accesses SQL Server through a query adapter. The documented and visible capabilities include account and product/supplier administration, customer analytics, surveys, feedback, and database backup/restore. The source excerpts show only selected API handlers, so links for unsampled feature routes are limited to explicit browser API calls or documented capabilities.

Main entry points: [`database/db.js`](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/db.js) (SQL query adapter), [`public/js/app.js`](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/app.js) (Auth and router), [`server.js`](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js) (Express API), [`public/js/admin.js`](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/admin.js) (Admin console)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web client"]
  node_admin["Admin console<br/>[admin.js]"]
  node_manager["Manager CRM<br/>[manager.js]"]
  node_customer["Customer portal<br/>[customer.js]"]
  node_client_core["Auth and router<br/>[app.js]"]
end

subgraph group_api["Application API"]
  node_server["Express API<br/>[server.js]"]
  node_auth["Authentication<br/>[server.js]"]
  node_catalog["Products and suppliers<br/>[server.js]"]
  node_customer_mgmt["Customer management<br/>[server.js]"]
  node_surveys["Survey campaigns<br/>[server.js]"]
  node_feedback["Feedback handling<br/>[server.js]"]
  node_analytics["CRM analytics<br/>[server.js]"]
  node_vercel_entry["Vercel entry<br/>[index.js]"]
end

subgraph group_data["Data layer"]
  node_adapter["SQL query adapter<br/>[db.js]"]
  node_schema["SQL Server schema"]
  node_sqlserver[("SQL Server")]
end

subgraph group_ops["Database operations"]
  node_backup_ui["Backup console<br/>[admin.js]"]
  node_backup_api["Backup and restore API<br/>[server.js]"]
  node_backup_sql["Backup procedures<br/>[backup_restore.sql]"]
end

node_browser_user(("CRM user"))

node_browser_user -->|"uses"| node_client_core
node_client_core -->|"submits login"| node_auth
node_client_core -->|"routes admin"| node_admin
node_client_core -->|"routes manager"| node_manager
node_client_core -->|"routes customer"| node_customer
node_admin -->|"calls admin API"| node_server
node_manager -->|"calls manager API"| node_server
node_customer -->|"calls customer API"| node_server
node_server -->|"queries through"| node_adapter
node_adapter -->|"executes SQL"| node_sqlserver
node_auth -->|"reads accounts"| node_adapter
node_catalog -->|"reads and writes"| node_adapter
node_customer_mgmt -->|"reads and writes"| node_adapter
node_surveys -->|"queries results"| node_adapter
node_feedback -->|"queries records"| node_adapter
node_analytics -->|"aggregates data"| node_adapter
node_backup_ui -->|"requests backups"| node_backup_api
node_backup_api -.->|"backs up database"| node_sqlserver
node_backup_sql -.->|"defines procedures"| node_sqlserver
node_vercel_entry -->|"exports app"| node_server
node_schema -.->|"defines schema"| node_sqlserver

click node_admin "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/admin.js"
click node_manager "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/manager.js"
click node_customer "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/customer.js"
click node_client_core "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/app.js"
click node_server "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_auth "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_catalog "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_customer_mgmt "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_surveys "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_feedback "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_analytics "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_adapter "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/db.js"
click node_schema "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/schema_sqlserver.sql"
click node_backup_ui "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/admin.js"
click node_backup_api "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js"
click node_backup_sql "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/backup_restore.sql"
click node_vercel_entry "https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/api/index.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_admin,node_manager,node_customer,node_client_core,node_browser_user toneBlue
class node_server,node_auth,node_catalog,node_customer_mgmt,node_surveys,node_feedback,node_analytics,node_vercel_entry toneAmber
class node_adapter,node_schema,node_sqlserver toneMint
class node_backup_ui,node_backup_api,node_backup_sql toneRose
```

## Components

### Web client

- [Admin console](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/admin.js): `public/js/admin.js`
- [Manager CRM](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/manager.js): `public/js/manager.js`
- [Customer portal](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/customer.js): `public/js/customer.js`
- [Auth and router](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/app.js): `public/js/app.js`

### Application API

- [Express API](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Authentication](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Products and suppliers](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Customer management](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Survey campaigns](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Feedback handling](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [CRM analytics](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Vercel entry](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/api/index.js): `api/index.js`

### Data layer

- [SQL query adapter](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/db.js): `database/db.js`
- [SQL Server schema](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/schema_sqlserver.sql): `database/schema_sqlserver.sql`
- **SQL Server**

### Database operations

- [Backup console](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/public/js/admin.js): `public/js/admin.js`
- [Backup and restore API](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/server.js): `server.js`
- [Backup procedures](https://github.com/vphatnguyen/h--th-ng-th-ng-tin-doanh-nghi-p/blob/main/database/backup_restore.sql): `database/backup_restore.sql`

### Other components

- **CRM user**

## Connections

- CRM user → Auth and router: uses (evidence: `public/js/app.js`)
- Auth and router → Authentication: submits login (evidence: `public/js/app.js`)
- Auth and router → Admin console: routes admin (evidence: `public/js/app.js`)
- Auth and router → Manager CRM: routes manager (evidence: `public/js/app.js`)
- Auth and router → Customer portal: routes customer (evidence: `public/js/app.js`)
- Admin console → Express API: calls admin API (evidence: `public/js/admin.js`)
- Manager CRM → Express API: calls manager API (evidence: `public/js/manager.js`)
- Customer portal → Express API: calls customer API (evidence: `public/js/customer.js`)
- Express API → SQL query adapter: queries through (evidence: `server.js`)
- SQL query adapter → SQL Server: executes SQL (evidence: `database/db.js`)
- Authentication → SQL query adapter: reads accounts (evidence: `server.js`)
- Products and suppliers → SQL query adapter: reads and writes (evidence: `server.js`)
- Customer management → SQL query adapter: reads and writes (evidence: `server.js`)
- Survey campaigns → SQL query adapter: queries results (evidence: `server.js`)
- Feedback handling → SQL query adapter: queries records (evidence: `server.js`)
- CRM analytics → SQL query adapter: aggregates data (evidence: `server.js`)
- Backup console → Backup and restore API: requests backups (evidence: `public/js/admin.js`)
- Backup and restore API → SQL Server: backs up database
- Backup procedures → SQL Server: defines procedures
- Vercel entry → Express API: exports app (evidence: `api/index.js`)
- SQL Server schema → SQL Server: defines schema
