# druv08/safevision-ai architecture

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

- Interactive diagram: https://gitdiagram.com/druv08/safevision-ai
- Repository: https://github.com/druv08/safevision-ai

## Overview

SafeVision AI monitors workplace PPE: an operator submits an image or video, the backend runs YOLO detection, records violation evidence, and exposes results for dashboard review. The graph also preserves the documented model-training and dataset-preparation branch. The README describes webcam monitoring and database storage, but the shown runtime endpoints accept image/video uploads and the sampled persistence code writes CSV and screenshots; no webcam API or database integration is evidenced here.

Main entry points: [`frontend/src/App.jsx`](https://github.com/druv08/safevision-ai/blob/main/frontend/src/App.jsx) (SafeVision UI), [`backend/services/video_detection_service.py`](https://github.com/druv08/safevision-ai/blob/main/backend/services/video_detection_service.py) (Video detection), [`frontend/src/services/api.js`](https://github.com/druv08/safevision-ai/blob/main/frontend/src/services/api.js) (API client), [`backend/routes/detection.py`](https://github.com/druv08/safevision-ai/blob/main/backend/routes/detection.py) (Detection routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Operator interface"]
  node_webapp["SafeVision UI<br/>[App.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_imagepage["Image review<br/>[ImageDetection.jsx]"]
  node_videopage["Video review<br/>[VideoDetection.jsx]"]
  node_violationpage["Violation review<br/>[Violations.jsx]"]
  node_api["API client<br/>[api.js]"]
end

subgraph group_backend["Detection backend"]
  node_backendapp["FastAPI app<br/>[main.py]"]
  node_routes["Detection routes<br/>[detection.py]"]
  node_image["Image detection"]
  node_video["Video detection"]
  node_models["YOLO model loader<br/>[model_service.py]"]
end

subgraph group_evidence["Violation evidence"]
  node_violations["Violation reader"]
  node_screenshots["Screenshot files"]
  node_csv["Violation log"]
end

subgraph group_ml["Model development"]
  node_autolabel["Pose auto-labeling"]
  node_datasets["Dataset preparation"]
  node_training["YOLO training"]
  node_modelweights["Trained weights"]
end

node_officer(("Safety officer"))

node_officer -->|"uses"| node_webapp
node_webapp -->|"routes to"| node_dashboard
node_webapp -->|"routes to"| node_imagepage
node_webapp -->|"routes to"| node_videopage
node_webapp -->|"routes to"| node_violationpage
node_dashboard -->|"requests data"| node_api
node_imagepage -->|"submits image"| node_api
node_videopage -->|"submits video"| node_api
node_violationpage -->|"requests records"| node_api
node_api -.->|"calls API"| node_backendapp
node_backendapp -->|"registers routes"| node_routes
node_routes -->|"invokes"| node_image
node_routes -->|"invokes"| node_video
node_routes -->|"reads records"| node_violations
node_image -->|"loads models"| node_models
node_video -->|"loads models"| node_models
node_image -->|"saves evidence"| node_video
node_video -->|"writes images"| node_screenshots
node_video -->|"appends records"| node_csv
node_violations -->|"reads log"| node_csv
node_backendapp -->|"serves files"| node_screenshots
node_autolabel -->|"builds samples"| node_datasets
node_datasets -.->|"prepares data for"| node_training
node_training -.->|"produces weights"| node_modelweights
node_models -->|"loads weights"| node_modelweights

click node_webapp "https://github.com/druv08/safevision-ai/blob/main/frontend/src/App.jsx"
click node_dashboard "https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/Dashboard.jsx"
click node_imagepage "https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/ImageDetection.jsx"
click node_videopage "https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/VideoDetection.jsx"
click node_violationpage "https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/Violations.jsx"
click node_api "https://github.com/druv08/safevision-ai/blob/main/frontend/src/services/api.js"
click node_backendapp "https://github.com/druv08/safevision-ai/blob/main/backend/main.py"
click node_routes "https://github.com/druv08/safevision-ai/blob/main/backend/routes/detection.py"
click node_image "https://github.com/druv08/safevision-ai/blob/main/backend/services/detection_service.py"
click node_video "https://github.com/druv08/safevision-ai/blob/main/backend/services/video_detection_service.py"
click node_models "https://github.com/druv08/safevision-ai/blob/main/backend/services/model_service.py"
click node_violations "https://github.com/druv08/safevision-ai/blob/main/backend/services/violations_service.py"
click node_autolabel "https://github.com/druv08/safevision-ai/blob/main/ai-model/training/autolabel_webcam_pose.py"
click node_datasets "https://github.com/druv08/safevision-ai/tree/main/ai-model/training"
click node_training "https://github.com/druv08/safevision-ai/tree/main/ai-model/training"

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_dashboard,node_imagepage,node_videopage,node_violationpage,node_api toneBlue
class node_backendapp,node_routes,node_image,node_video,node_models toneAmber
class node_violations,node_screenshots,node_csv toneMint
class node_autolabel,node_datasets,node_training,node_modelweights toneRose
class node_officer toneIndigo
```

## Components

### Operator interface

- [SafeVision UI](https://github.com/druv08/safevision-ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Dashboard](https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Image review](https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/ImageDetection.jsx): `frontend/src/pages/ImageDetection.jsx`
- [Video review](https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/VideoDetection.jsx): `frontend/src/pages/VideoDetection.jsx`
- [Violation review](https://github.com/druv08/safevision-ai/blob/main/frontend/src/pages/Violations.jsx): `frontend/src/pages/Violations.jsx`
- [API client](https://github.com/druv08/safevision-ai/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Detection backend

- [FastAPI app](https://github.com/druv08/safevision-ai/blob/main/backend/main.py): `backend/main.py`
- [Detection routes](https://github.com/druv08/safevision-ai/blob/main/backend/routes/detection.py): `backend/routes/detection.py`
- [Image detection](https://github.com/druv08/safevision-ai/blob/main/backend/services/detection_service.py): `backend/services/detection_service.py`
- [Video detection](https://github.com/druv08/safevision-ai/blob/main/backend/services/video_detection_service.py): `backend/services/video_detection_service.py`
- [YOLO model loader](https://github.com/druv08/safevision-ai/blob/main/backend/services/model_service.py): `backend/services/model_service.py`

### Violation evidence

- [Violation reader](https://github.com/druv08/safevision-ai/blob/main/backend/services/violations_service.py): `backend/services/violations_service.py`
- **Screenshot files**
- **Violation log**

### Model development

- [Pose auto-labeling](https://github.com/druv08/safevision-ai/blob/main/ai-model/training/autolabel_webcam_pose.py): `ai-model/training/autolabel_webcam_pose.py`
- [Dataset preparation](https://github.com/druv08/safevision-ai/tree/main/ai-model/training): `ai-model/training`
- [YOLO training](https://github.com/druv08/safevision-ai/tree/main/ai-model/training): `ai-model/training`
- **Trained weights**

### Other components

- **Safety officer**

## Connections

- Safety officer → SafeVision UI: uses (evidence: `README.md`)
- SafeVision UI → Dashboard: routes to (evidence: `frontend/src/App.jsx`)
- SafeVision UI → Image review: routes to (evidence: `frontend/src/App.jsx`)
- SafeVision UI → Video review: routes to (evidence: `frontend/src/App.jsx`)
- SafeVision UI → Violation review: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard → API client: requests data (evidence: `frontend/src/pages/Dashboard.jsx`)
- Image review → API client: submits image (evidence: `frontend/src/pages/ImageDetection.jsx`)
- Video review → API client: submits video (evidence: `frontend/src/pages/VideoDetection.jsx`)
- Violation review → API client: requests records (evidence: `frontend/src/pages/Violations.jsx`)
- API client → FastAPI app: calls API
- FastAPI app → Detection routes: registers routes (evidence: `backend/main.py`)
- Detection routes → Image detection: invokes (evidence: `backend/routes/detection.py`)
- Detection routes → Video detection: invokes (evidence: `backend/routes/detection.py`)
- Detection routes → Violation reader: reads records (evidence: `backend/routes/detection.py`)
- Image detection → YOLO model loader: loads models (evidence: `backend/services/detection_service.py`)
- Video detection → YOLO model loader: loads models (evidence: `backend/services/video_detection_service.py`)
- Image detection → Video detection: saves evidence (evidence: `backend/services/detection_service.py`)
- Video detection → Screenshot files: writes images (evidence: `backend/services/video_detection_service.py`)
- Video detection → Violation log: appends records (evidence: `backend/services/video_detection_service.py`)
- Violation reader → Violation log: reads log (evidence: `backend/services/violations_service.py`)
- FastAPI app → Screenshot files: serves files (evidence: `backend/main.py`)
- Pose auto-labeling → Dataset preparation: builds samples (evidence: `ai-model/training/autolabel_webcam_pose.py`)
- Dataset preparation → YOLO training: prepares data for
- YOLO training → Trained weights: produces weights
- YOLO model loader → Trained weights: loads weights (evidence: `backend/services/model_service.py`)
