# ulugbek-lab/safetruckai architecture

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

- Interactive diagram: https://gitdiagram.com/ulugbek-lab/safetruckai
- Repository: https://github.com/ulugbek-lab/safetruckai

## Overview

SafeTruck AI is a local computer-vision PPE incident detection and human-review product. Its principal workflow runs camera frames through person tracking, PPE detection and temporal confirmation, submits confirmed incidents to FastAPI for persistence, then presents them for dashboard analysis and review. The graph also includes the dashboard’s project guide and demo-data capability. Vision-stage links rely on README documentation because the detector source was not excerpted; other links cite the shown caller or documented HTTP/database relationships.

Main entry points: [`frontend/src/pages/DashboardPage.tsx`](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/pages/DashboardPage.tsx) (Dashboard page), [`backend/main.py`](https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/main.py) (Incident API), [`frontend/src/services/api.ts`](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/services/api.ts) (HTTP API client), [`frontend/src/types/incidents.ts`](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/types/incidents.ts) (Incident types)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Vision detection"]
  node_person_tracking["Person tracking<br/>[main.py]"]
  node_ppe_detection["PPE detection<br/>[main.py]"]
  node_ppe_association["Worker PPE association<br/>[main.py]"]
  node_alert_state["Evidence and cooldown<br/>[main.py]"]
end

subgraph group_backend["Incident backend"]
  node_api["Incident API<br/>[main.py]"]
  node_dashboard_routes["Dashboard endpoints<br/>[dashboard.py]"]
  node_incident_schema["Incident schemas<br/>[models.py]"]
  node_db_session["Database sessions<br/>[database.py]"]
end

subgraph group_dashboard["Review dashboard"]
  node_app_shell["App navigation<br/>[App.tsx]"]
  node_dashboard_page["Dashboard page<br/>[DashboardPage.tsx]"]
  node_dashboard_hook["Dashboard refresh<br/>[useDashboard.ts]"]
  node_api_client["HTTP API client<br/>[api.ts]"]
  node_demo_data["Demo data<br/>[demo.ts]"]
  node_stats_cards["Statistics cards"]
  node_analytics_charts["Analytics charts"]
  node_incident_table["Incident history<br/>[IncidentTable.tsx]"]
  node_incident_details["Incident review"]
  node_status_badge["Status badge<br/>[StatusBadge.tsx]"]
  node_incident_types["Incident types<br/>[incidents.ts]"]
  node_layout["Dashboard layout"]
end

subgraph group_guide["Project guide"]
  node_guide_page["Project walkthrough"]
end

node_operator(("Safety reviewer"))
node_camera["Local camera"]
node_postgres[("PostgreSQL")]

node_camera -->|"provides frames"| node_person_tracking
node_camera -->|"provides frames"| node_ppe_detection
node_person_tracking -->|"supplies tracks"| node_ppe_association
node_ppe_detection -->|"supplies detections"| node_ppe_association
node_ppe_association -->|"provides evidence"| node_alert_state
node_alert_state -->|"submits incidents"| node_api
node_api -->|"registers routes"| node_dashboard_routes
node_api -->|"validates incidents"| node_incident_schema
node_api -->|"creates tables"| node_db_session
node_api -->|"uses sessions"| node_db_session
node_dashboard_routes -->|"queries sessions"| node_db_session
node_dashboard_routes -->|"returns schemas"| node_incident_schema
node_db_session -->|"persists records"| node_postgres
node_operator -->|"reviews incidents"| node_dashboard_page
node_app_shell -->|"renders layout"| node_layout
node_app_shell -->|"selects overview"| node_dashboard_page
node_app_shell -->|"selects guide"| node_guide_page
node_dashboard_page -->|"loads dashboard"| node_dashboard_hook
node_dashboard_hook -->|"requests data"| node_api_client
node_api_client -->|"queries endpoints"| node_dashboard_routes
node_dashboard_page -->|"renders statistics"| node_stats_cards
node_dashboard_page -->|"renders analytics"| node_analytics_charts
node_dashboard_page -->|"renders history"| node_incident_table
node_dashboard_page -->|"opens incident"| node_incident_details
node_incident_table -->|"renders status"| node_status_badge
node_incident_details -->|"renders status"| node_status_badge
node_incident_details -->|"loads and reviews"| node_api_client
node_api_client -->|"uses demo mode"| node_demo_data
node_stats_cards -->|"uses data types"| node_incident_types
node_analytics_charts -->|"uses data types"| node_incident_types
node_incident_table -->|"uses data types"| node_incident_types
node_incident_details -->|"uses data types"| node_incident_types
node_api_client -->|"uses data types"| node_incident_types

click node_person_tracking "https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py"
click node_ppe_detection "https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py"
click node_ppe_association "https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py"
click node_alert_state "https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py"
click node_api "https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/main.py"
click node_dashboard_routes "https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/dashboard.py"
click node_incident_schema "https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/models.py"
click node_db_session "https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/database.py"
click node_app_shell "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/App.tsx"
click node_dashboard_page "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/pages/DashboardPage.tsx"
click node_dashboard_hook "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/hooks/useDashboard.ts"
click node_api_client "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/services/api.ts"
click node_demo_data "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/services/demo.ts"
click node_stats_cards "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/StatisticsCards.tsx"
click node_analytics_charts "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/AnalyticsCharts.tsx"
click node_incident_table "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/IncidentTable.tsx"
click node_incident_details "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/IncidentDetails.tsx"
click node_status_badge "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/StatusBadge.tsx"
click node_incident_types "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/types/incidents.ts"
click node_layout "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/layouts/DashboardLayout.tsx"
click node_guide_page "https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/pages/ProjectGuidePage.tsx"

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_person_tracking,node_ppe_detection,node_ppe_association,node_alert_state,node_operator toneBlue
class node_api,node_dashboard_routes,node_incident_schema,node_db_session,node_postgres toneAmber
class node_app_shell,node_dashboard_page,node_dashboard_hook,node_api_client,node_demo_data,node_stats_cards,node_analytics_charts,node_incident_table,node_incident_details,node_status_badge,node_incident_types,node_layout toneMint
class node_guide_page toneRose
class node_camera toneIndigo
```

## Components

### Vision detection

- [Person tracking](https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py): `main.py`
- [PPE detection](https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py): `main.py`
- [Worker PPE association](https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py): `main.py`
- [Evidence and cooldown](https://github.com/ulugbek-lab/safetruckai/blob/develop/main.py): `main.py`

### Incident backend

- [Incident API](https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/main.py): `backend/main.py`
- [Dashboard endpoints](https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/dashboard.py): `backend/dashboard.py`
- [Incident schemas](https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/models.py): `backend/models.py`
- [Database sessions](https://github.com/ulugbek-lab/safetruckai/blob/develop/backend/database.py): `backend/database.py`

### Review dashboard

- [App navigation](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Dashboard page](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [Dashboard refresh](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/hooks/useDashboard.ts): `frontend/src/hooks/useDashboard.ts`
- [HTTP API client](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Demo data](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/services/demo.ts): `frontend/src/services/demo.ts`
- [Statistics cards](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/StatisticsCards.tsx): `frontend/src/components/StatisticsCards.tsx`
- [Analytics charts](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/AnalyticsCharts.tsx): `frontend/src/components/AnalyticsCharts.tsx`
- [Incident history](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/IncidentTable.tsx): `frontend/src/components/IncidentTable.tsx`
- [Incident review](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/IncidentDetails.tsx): `frontend/src/components/IncidentDetails.tsx`
- [Status badge](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/components/StatusBadge.tsx): `frontend/src/components/StatusBadge.tsx`
- [Incident types](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/types/incidents.ts): `frontend/src/types/incidents.ts`
- [Dashboard layout](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/layouts/DashboardLayout.tsx): `frontend/src/layouts/DashboardLayout.tsx`

### Project guide

- [Project walkthrough](https://github.com/ulugbek-lab/safetruckai/blob/develop/frontend/src/pages/ProjectGuidePage.tsx): `frontend/src/pages/ProjectGuidePage.tsx`

### Other components

- **Safety reviewer**
- **Local camera**
- **PostgreSQL**

## Connections

- Local camera → Person tracking: provides frames (evidence: `README.md`)
- Local camera → PPE detection: provides frames (evidence: `README.md`)
- Person tracking → Worker PPE association: supplies tracks (evidence: `README.md`)
- PPE detection → Worker PPE association: supplies detections (evidence: `README.md`)
- Worker PPE association → Evidence and cooldown: provides evidence (evidence: `README.md`)
- Evidence and cooldown → Incident API: submits incidents (evidence: `README.md`)
- Incident API → Dashboard endpoints: registers routes (evidence: `backend/main.py`)
- Incident API → Incident schemas: validates incidents (evidence: `backend/main.py`)
- Incident API → Database sessions: creates tables (evidence: `backend/main.py`)
- Incident API → Database sessions: uses sessions (evidence: `backend/main.py`)
- Dashboard endpoints → Database sessions: queries sessions (evidence: `backend/dashboard.py`)
- Dashboard endpoints → Incident schemas: returns schemas (evidence: `backend/dashboard.py`)
- Database sessions → PostgreSQL: persists records (evidence: `README.md`)
- Safety reviewer → Dashboard page: reviews incidents (evidence: `README.md`)
- App navigation → Dashboard layout: renders layout (evidence: `frontend/src/App.tsx`)
- App navigation → Dashboard page: selects overview (evidence: `frontend/src/App.tsx`)
- App navigation → Project walkthrough: selects guide (evidence: `frontend/src/App.tsx`)
- Dashboard page → Dashboard refresh: loads dashboard (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Dashboard refresh → HTTP API client: requests data (evidence: `frontend/src/hooks/useDashboard.ts`)
- HTTP API client → Dashboard endpoints: queries endpoints (evidence: `frontend/src/services/api.ts`)
- Dashboard page → Statistics cards: renders statistics (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Dashboard page → Analytics charts: renders analytics (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Dashboard page → Incident history: renders history (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Dashboard page → Incident review: opens incident (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Incident history → Status badge: renders status (evidence: `frontend/src/components/IncidentTable.tsx`)
- Incident review → Status badge: renders status (evidence: `frontend/src/components/IncidentDetails.tsx`)
- Incident review → HTTP API client: loads and reviews (evidence: `frontend/src/components/IncidentDetails.tsx`)
- HTTP API client → Demo data: uses demo mode (evidence: `frontend/src/services/api.ts`)
- Statistics cards → Incident types: uses data types (evidence: `frontend/src/components/StatisticsCards.tsx`)
- Analytics charts → Incident types: uses data types (evidence: `frontend/src/components/AnalyticsCharts.tsx`)
- Incident history → Incident types: uses data types (evidence: `frontend/src/components/IncidentTable.tsx`)
- Incident review → Incident types: uses data types (evidence: `frontend/src/components/IncidentDetails.tsx`)
- HTTP API client → Incident types: uses data types (evidence: `frontend/src/services/api.ts`)
