# huyhoang292/doantotnghiep architecture

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

- Interactive diagram: https://gitdiagram.com/huyhoang292/doantotnghiep
- Repository: https://github.com/huyhoang292/doantotnghiep

## Overview

This is a traffic-violation management platform: officers review camera/AI detections, verify or reject violations, and issue invoices; citizens use the web app to manage vehicles and view violations and invoices. The architecture combines a React frontend, Express API, AI plate-recognition service, and MySQL storage. The README documents the major workflow and service boundaries; source excerpts show selected routes, controller actions, and recognition logic, but not every frontend/API call or database configuration detail.

Main entry points: [`backend/src/controllers/officerController.js`](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/officerController.js) (Officer operations), [`backend/src/controllers/violationController.js`](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/violationController.js) (Violation processing), [`backend/src/db/database.config.js`](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/db/database.config.js) (MySQL data), [`backend/src/routes/officerRoutes.js`](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/routes/officerRoutes.js) (Officer routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_webapp["Web client<br/>[main.tsx]"]
  node_routegraph["Route tree<br/>[routeTree.gen.ts]"]
  node_officerui["Officer workspace<br/>[scan.tsx]"]
  node_citizenui["Citizen workspace<br/>[dashboard.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["Backend API"]
  node_backend["HTTP server<br/>[server.js]"]
  node_officer_routes["Officer routes<br/>[officerRoutes.js]"]
  node_citizen_routes["Citizen routes<br/>[citizenRoutes.js]"]
  node_auth["Authentication<br/>[authMiddleware.js]"]
  node_officer_ops["Officer operations"]
  node_violation_ops["Violation processing"]
  node_citizen_ops["Citizen operations"]
  node_mappers["Response mapping<br/>[mappers.js]"]
  node_recognizer["Recognition adapter"]
end

subgraph group_ai["Plate recognition"]
  node_ai_api["AI detection API<br/>[main.py]"]
  node_plate_text["Plate text assembly<br/>[plate_utils.py]"]
end

subgraph group_data["Operational data"]
  node_mysql[("MySQL data<br/>[database.config.js]")]
end

node_officer(("Traffic officer"))
node_citizen(("Citizen"))
node_camera(("Camera system"))

node_officer -->|"uses"| node_webapp
node_citizen -->|"uses"| node_webapp
node_camera -->|"submits frames"| node_ai_api
node_webapp -->|"loads routes"| node_routegraph
node_officerui -.->|"requests data"| node_api_client
node_citizenui -.->|"requests data"| node_api_client
node_api_client -->|"calls API"| node_backend
node_backend -->|"mounts"| node_officer_routes
node_backend -->|"mounts"| node_citizen_routes
node_officer_routes -->|"checks token"| node_auth
node_citizen_routes -->|"checks token"| node_auth
node_officer_routes -->|"dispatches"| node_officer_ops
node_officer_routes -->|"dispatches"| node_violation_ops
node_citizen_routes -->|"dispatches"| node_citizen_ops
node_officer_ops -.->|"reads and writes"| node_mysql
node_violation_ops -.->|"reads and writes"| node_mysql
node_citizen_ops -.->|"reads and writes"| node_mysql
node_officer_ops -->|"recognizes plates"| node_recognizer
node_officer_ops -->|"maps records"| node_mappers
node_violation_ops -->|"maps records"| node_mappers
node_citizen_ops -->|"maps records"| node_mappers
node_recognizer -.->|"calls service"| node_ai_api
node_ai_api -->|"assembles text"| node_plate_text
node_ai_api -.->|"stores detections"| node_mysql
node_officer_ops -.->|"promotes detections"| node_violation_ops
node_violation_ops -.->|"creates invoices"| node_mysql
node_citizenui -.->|"views violations"| node_officer_ops

click node_webapp "https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/main.tsx"
click node_routegraph "https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/routeTree.gen.ts"
click node_officerui "https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/routes/officer/scan.tsx"
click node_citizenui "https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/routes/citizen/dashboard.tsx"
click node_api_client "https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/lib/api.ts"
click node_backend "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/server.js"
click node_officer_routes "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/routes/officerRoutes.js"
click node_citizen_routes "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/routes/citizenRoutes.js"
click node_auth "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/middlewares/authMiddleware.js"
click node_officer_ops "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/officerController.js"
click node_violation_ops "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/violationController.js"
click node_citizen_ops "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/citizenController.js"
click node_mappers "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/utils/mappers.js"
click node_recognizer "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/services/plateRecognition.js"
click node_ai_api "https://github.com/huyhoang292/doantotnghiep/blob/main/ai-service/main.py"
click node_plate_text "https://github.com/huyhoang292/doantotnghiep/blob/main/ai-service/plate_utils.py"
click node_mysql "https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/db/database.config.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_routegraph,node_officerui,node_citizenui,node_api_client toneBlue
class node_backend,node_officer_routes,node_citizen_routes,node_auth,node_officer_ops,node_violation_ops,node_citizen_ops,node_mappers,node_recognizer toneAmber
class node_ai_api,node_plate_text toneMint
class node_mysql toneRose
class node_officer,node_citizen,node_camera toneIndigo
```

## Components

### Web application

- [Web client](https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/main.tsx): `frontend/src/main.tsx`
- [Route tree](https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/routeTree.gen.ts): `frontend/src/routeTree.gen.ts`
- [Officer workspace](https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/routes/officer/scan.tsx): `frontend/src/routes/officer/scan.tsx`
- [Citizen workspace](https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/routes/citizen/dashboard.tsx): `frontend/src/routes/citizen/dashboard.tsx`
- [API client](https://github.com/huyhoang292/doantotnghiep/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### Backend API

- [HTTP server](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/server.js): `backend/src/server.js`
- [Officer routes](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/routes/officerRoutes.js): `backend/src/routes/officerRoutes.js`
- [Citizen routes](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/routes/citizenRoutes.js): `backend/src/routes/citizenRoutes.js`
- [Authentication](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/middlewares/authMiddleware.js): `backend/src/middlewares/authMiddleware.js`
- [Officer operations](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/officerController.js): `backend/src/controllers/officerController.js`
- [Violation processing](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/violationController.js): `backend/src/controllers/violationController.js`
- [Citizen operations](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/controllers/citizenController.js): `backend/src/controllers/citizenController.js`
- [Response mapping](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/utils/mappers.js): `backend/src/utils/mappers.js`
- [Recognition adapter](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/services/plateRecognition.js): `backend/src/services/plateRecognition.js`

### Plate recognition

- [AI detection API](https://github.com/huyhoang292/doantotnghiep/blob/main/ai-service/main.py): `ai-service/main.py`
- [Plate text assembly](https://github.com/huyhoang292/doantotnghiep/blob/main/ai-service/plate_utils.py): `ai-service/plate_utils.py`

### Operational data

- [MySQL data](https://github.com/huyhoang292/doantotnghiep/blob/main/backend/src/db/database.config.js): `backend/src/db/database.config.js`

### Other components

- **Traffic officer**
- **Citizen**
- **Camera system**

## Connections

- Traffic officer → Web client: uses
- Citizen → Web client: uses
- Camera system → AI detection API: submits frames
- Web client → Route tree: loads routes (evidence: `frontend/src/main.tsx`)
- Officer workspace → API client: requests data
- Citizen workspace → API client: requests data
- API client → HTTP server: calls API
- HTTP server → Officer routes: mounts (evidence: `backend/src/server.js`)
- HTTP server → Citizen routes: mounts (evidence: `backend/src/server.js`)
- Officer routes → Authentication: checks token (evidence: `backend/src/routes/officerRoutes.js`)
- Citizen routes → Authentication: checks token (evidence: `backend/src/routes/citizenRoutes.js`)
- Officer routes → Officer operations: dispatches (evidence: `backend/src/routes/officerRoutes.js`)
- Officer routes → Violation processing: dispatches (evidence: `backend/src/routes/officerRoutes.js`)
- Citizen routes → Citizen operations: dispatches (evidence: `backend/src/routes/citizenRoutes.js`)
- Officer operations → MySQL data: reads and writes
- Violation processing → MySQL data: reads and writes
- Citizen operations → MySQL data: reads and writes
- Officer operations → Recognition adapter: recognizes plates (evidence: `backend/src/controllers/officerController.js`)
- Officer operations → Response mapping: maps records (evidence: `backend/src/controllers/officerController.js`)
- Violation processing → Response mapping: maps records (evidence: `backend/src/controllers/violationController.js`)
- Citizen operations → Response mapping: maps records (evidence: `backend/src/controllers/citizenController.js`)
- Recognition adapter → AI detection API: calls service
- AI detection API → Plate text assembly: assembles text (evidence: `ai-service/main.py`)
- AI detection API → MySQL data: stores detections
- Officer operations → Violation processing: promotes detections
- Violation processing → MySQL data: creates invoices
- Citizen workspace → Officer operations: views violations
