# ahmadalhamadani2001/mg-service-approval architecture

> Architecture diagram of the GitHub repository ahmadalhamadani2001/mg-service-approval, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmadalhamadani2001/mg-service-approval
- Repository: https://github.com/ahmadalhamadani2001/mg-service-approval

## Overview

MG Service Approval is a role-based after-sales request workflow with a browser UI, API, server-enforced approvals, service catalog, vehicle/warranty tools, and persistent state. Sales-originated requests and Aftersales walk-in estimates enter review; the Sales Manager may approve, return, or reject, and some requests proceed to Finance before Aftersales estimates or executes them. The README documents workflow branches; source excerpts and the SOURCE INDEX support server routing and core dependencies, but the frontend implementation and several route details were not sampled.

Main entry points: [`server/index.js`](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/index.js) (HTTP server), [`server/db.js`](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/db.js) (Application state), [`server/routes/requests.js`](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/requests.js) (Service requests), [`server/routes/services.js`](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/services.js) (Service catalog)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser experience"]
  node_browser["Approval UI<br/>[app.js]"]
  node_localization["Bilingual UI<br/>[i18n.js]"]
end

subgraph group_workflow["Approval workflow"]
  node_auth_api["Login API<br/>[auth.js]"]
  node_requests["Service requests<br/>[requests.js]"]
  node_state["Workflow rules<br/>[stateMachine.js]"]
end

subgraph group_operations["Administration and records"]
  node_services["Service catalog<br/>[services.js]"]
  node_audit["Audit log<br/>[audit.js]"]
  node_branches["Branch management<br/>[branches.js]"]
  node_users["Account management<br/>[users.js]"]
  node_vehicles["Vehicle management<br/>[vehicles.js]"]
  node_warranty["Warranty checks<br/>[warranty.js]"]
end

subgraph group_platform["Server and persistence"]
  node_server["HTTP server<br/>[index.js]"]
  node_auth["Session and roles<br/>[auth.js]"]
  node_vehicle_store[("Vehicle store<br/>[vehiclesStore.js]")]
  node_app_state[("Application state<br/>[db.js]")]
  node_json_file[("Local JSON storage")]
end

node_staff(("Staff roles"))
node_postgres[("Postgres storage")]

node_staff -->|"uses"| node_browser
node_browser -->|"calls API"| node_server
node_localization -.->|"localizes"| node_browser
node_server -->|"routes"| node_auth_api
node_server -->|"routes"| node_requests
node_server -->|"routes"| node_services
node_server -->|"routes"| node_audit
node_server -->|"routes"| node_branches
node_server -->|"routes"| node_users
node_server -->|"routes"| node_vehicles
node_server -->|"serves UI"| node_browser
node_auth_api -->|"signs sessions"| node_auth
node_auth_api -->|"reads users"| node_app_state
node_requests -->|"transitions requests"| node_state
node_requests -->|"reads and writes"| node_app_state
node_services -->|"reads and writes"| node_app_state
node_branches -->|"reads and writes"| node_app_state
node_users -->|"reads and writes"| node_app_state
node_audit -->|"reads audit"| node_app_state
node_vehicles -->|"manages vehicles"| node_vehicle_store
node_vehicles -->|"checks coverage"| node_warranty
node_server -->|"initializes"| node_app_state
node_server -->|"initializes"| node_vehicle_store
node_app_state -->|"persists locally"| node_json_file
node_app_state -.->|"persists optionally"| node_postgres
node_staff -->|"submits and reviews"| node_requests
node_requests -->|"enforces stages"| node_state
node_services -.->|"sets approval levels"| node_requests
node_staff -->|"maintains catalog"| node_services
node_staff -->|"manages and checks"| node_vehicles
node_staff -->|"manages accounts"| node_users

click node_browser "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/public/app.js"
click node_localization "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/public/i18n.js"
click node_server "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/index.js"
click node_auth_api "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/auth.js"
click node_auth "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/auth.js"
click node_requests "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/requests.js"
click node_state "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/stateMachine.js"
click node_services "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/services.js"
click node_audit "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/audit.js"
click node_branches "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/branches.js"
click node_users "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/users.js"
click node_vehicles "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/vehicles.js"
click node_warranty "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/warranty.js"
click node_vehicle_store "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/vehiclesStore.js"
click node_app_state "https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/db.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_browser,node_localization toneBlue
class node_auth_api,node_requests,node_state,node_postgres toneAmber
class node_services,node_audit,node_branches,node_users,node_vehicles,node_warranty toneMint
class node_server,node_auth,node_vehicle_store,node_app_state,node_json_file toneRose
class node_staff toneIndigo
```

## Components

### Browser experience

- [Approval UI](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/public/app.js): `public/app.js`
- [Bilingual UI](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/public/i18n.js): `public/i18n.js`

### Approval workflow

- [Login API](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/auth.js): `server/routes/auth.js`
- [Service requests](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/requests.js): `server/routes/requests.js`
- [Workflow rules](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/stateMachine.js): `server/stateMachine.js`

### Administration and records

- [Service catalog](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/services.js): `server/routes/services.js`
- [Audit log](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/audit.js): `server/routes/audit.js`
- [Branch management](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/branches.js): `server/routes/branches.js`
- [Account management](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/users.js): `server/routes/users.js`
- [Vehicle management](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/routes/vehicles.js): `server/routes/vehicles.js`
- [Warranty checks](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/warranty.js): `server/warranty.js`

### Server and persistence

- [HTTP server](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/index.js): `server/index.js`
- [Session and roles](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/auth.js): `server/auth.js`
- [Vehicle store](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/vehiclesStore.js): `server/vehiclesStore.js`
- [Application state](https://github.com/ahmadalhamadani2001/mg-service-approval/blob/main/server/db.js): `server/db.js`
- **Local JSON storage**

### Other components

- **Staff roles**
- **Postgres storage**

## Connections

- Staff roles → Approval UI: uses (evidence: `README.md`)
- Approval UI → HTTP server: calls API (evidence: `README.md`)
- Bilingual UI → Approval UI: localizes
- HTTP server → Login API: routes (evidence: `server/index.js`)
- HTTP server → Service requests: routes (evidence: `server/index.js`)
- HTTP server → Service catalog: routes (evidence: `server/index.js`)
- HTTP server → Audit log: routes (evidence: `server/index.js`)
- HTTP server → Branch management: routes (evidence: `server/index.js`)
- HTTP server → Account management: routes (evidence: `server/index.js`)
- HTTP server → Vehicle management: routes (evidence: `server/index.js`)
- HTTP server → Approval UI: serves UI (evidence: `server/index.js`)
- Login API → Session and roles: signs sessions (evidence: `server/routes/auth.js`)
- Login API → Application state: reads users (evidence: `server/routes/auth.js`)
- Service requests → Workflow rules: transitions requests (evidence: `server/routes/requests.js`)
- Service requests → Application state: reads and writes (evidence: `server/routes/requests.js`)
- Service catalog → Application state: reads and writes (evidence: `server/routes/services.js`)
- Branch management → Application state: reads and writes (evidence: `server/routes/branches.js`)
- Account management → Application state: reads and writes (evidence: `server/routes/users.js`)
- Audit log → Application state: reads audit (evidence: `server/routes/audit.js`)
- Vehicle management → Vehicle store: manages vehicles (evidence: `server/routes/vehicles.js`)
- Vehicle management → Warranty checks: checks coverage (evidence: `server/routes/vehicles.js`)
- HTTP server → Application state: initializes (evidence: `server/index.js`)
- HTTP server → Vehicle store: initializes (evidence: `server/index.js`)
- Application state → Local JSON storage: persists locally (evidence: `README.md`)
- Application state → Postgres storage: persists optionally (evidence: `server/db.js`)
- Staff roles → Service requests: submits and reviews (evidence: `README.md`)
- Service requests → Workflow rules: enforces stages (evidence: `server/routes/requests.js`)
- Service catalog → Service requests: sets approval levels (evidence: `README.md`)
- Staff roles → Service catalog: maintains catalog (evidence: `README.md`)
- Staff roles → Vehicle management: manages and checks (evidence: `README.md`)
- Staff roles → Account management: manages accounts (evidence: `README.md`)
