# hvora2005/industrial-defect-detection architecture

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

- Interactive diagram: https://gitdiagram.com/hvora2005/industrial-defect-detection
- Repository: https://github.com/hvora2005/industrial-defect-detection

## Overview

The product is a local-network industrial defect inspection system: a phone browser captures or uploads images, the laptop backend decodes and evaluates them, and results return to the phone while also reaching a live monitor and persistent history. Dashboard statistics and CSV/PDF exports form a reporting branch; model preparation and training form an offline model lifecycle branch. The main request, detector, database, reports, and browser interactions are excerpted. Dashboard and training connections follow explicit README descriptions or shown client requests; other unsampled details are omitted.

Main entry points: [`backend/main.py`](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py) (FastAPI Routes), [`backend/database.py`](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/database.py) (History & Stats), [`backend/detector.py`](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/detector.py) (YOLO Detection), [`frontend/app.js`](https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/app.js) (Capture & Upload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Phone Inspection"]
  node_capture_ui["Capture &amp; Upload<br/>[app.js]"]
end

subgraph group_service["Inspection Backend"]
  node_api["FastAPI Routes<br/>[main.py]"]
  node_image_decode["Image Decode<br/>[main.py]"]
  node_detector["YOLO Detection<br/>[detector.py]"]
  node_config["Inference Config<br/>[config.py]"]
end

subgraph group_records["History &amp; Reporting"]
  node_db_api["History &amp; Stats<br/>[database.py]"]
  node_sqlite[("Inspection History<br/>[database.py]")]
  node_exports["CSV/PDF Reports<br/>[reports.py]"]
end

subgraph group_views["Laptop Views"]
  node_monitor_clients["Monitor Connections<br/>[main.py]"]
  node_monitor_page["Live Monitor<br/>[monitor.js]"]
  node_dashboard["Statistics Dashboard<br/>[dashboard.js]"]
end

subgraph group_modeling["Model Lifecycle"]
  node_voc_convert["Dataset Conversion"]
  node_training["YOLO Training<br/>[train.py]"]
  node_weights["Trained Weights"]
end

node_phone(("Phone Browser"))
node_local_network{{"Local Wi-Fi"}}
node_operator(("Operator"))

node_operator -->|"uses"| node_phone
node_phone -->|"sends images"| node_local_network
node_local_network -->|"HTTPS requests"| node_api
node_capture_ui -->|"posts /detect, /upload"| node_api
node_api -->|"decodes upload"| node_image_decode
node_api -->|"calls predict"| node_detector
node_detector -->|"reads settings"| node_config
node_training -->|"copies best weights"| node_weights
node_detector -.->|"loads model"| node_weights
node_api -->|"returns result"| node_capture_ui
node_api -->|"saves inspection"| node_db_api
node_db_api -->|"reads and writes"| node_sqlite
node_api -->|"broadcasts results"| node_monitor_clients
node_monitor_page -->|"opens WebSocket"| node_api
node_monitor_clients -->|"pushes detections"| node_monitor_page
node_dashboard -->|"requests stats, history, trend"| node_api
node_api -->|"queries history and stats"| node_db_api
node_api -->|"builds exports"| node_exports
node_exports -->|"reads stored data"| node_db_api
node_voc_convert -->|"prepares dataset"| node_training

click node_capture_ui "https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/app.js"
click node_api "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py"
click node_image_decode "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py"
click node_detector "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/detector.py"
click node_config "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/config.py"
click node_monitor_clients "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py"
click node_monitor_page "https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/monitor.js"
click node_dashboard "https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/dashboard.js"
click node_db_api "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/database.py"
click node_sqlite "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/database.py"
click node_exports "https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/reports.py"
click node_voc_convert "https://github.com/hvora2005/industrial-defect-detection/blob/master/training/convert_voc_to_yolo.py"
click node_training "https://github.com/hvora2005/industrial-defect-detection/blob/master/training/train.py"
click node_weights "https://github.com/hvora2005/industrial-defect-detection/tree/master/model"

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_capture_ui,node_phone toneBlue
class node_api,node_image_decode,node_detector,node_config toneAmber
class node_db_api,node_sqlite,node_exports toneMint
class node_monitor_clients,node_monitor_page,node_dashboard toneRose
class node_voc_convert,node_training,node_weights,node_local_network,node_operator toneIndigo
```

## Components

### Phone Inspection

- [Capture & Upload](https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/app.js): `frontend/app.js`

### Inspection Backend

- [FastAPI Routes](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py): `backend/main.py`
- [Image Decode](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py): `backend/main.py`
- [YOLO Detection](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/detector.py): `backend/detector.py`
- [Inference Config](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/config.py): `backend/config.py`

### History & Reporting

- [History & Stats](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/database.py): `backend/database.py`
- [Inspection History](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/database.py): `backend/database.py`
- [CSV/PDF Reports](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/reports.py): `backend/reports.py`

### Laptop Views

- [Monitor Connections](https://github.com/hvora2005/industrial-defect-detection/blob/master/backend/main.py): `backend/main.py`
- [Live Monitor](https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/monitor.js): `frontend/monitor.js`
- [Statistics Dashboard](https://github.com/hvora2005/industrial-defect-detection/blob/master/frontend/dashboard.js): `frontend/dashboard.js`

### Model Lifecycle

- [Dataset Conversion](https://github.com/hvora2005/industrial-defect-detection/blob/master/training/convert_voc_to_yolo.py): `training/convert_voc_to_yolo.py`
- [YOLO Training](https://github.com/hvora2005/industrial-defect-detection/blob/master/training/train.py): `training/train.py`
- [Trained Weights](https://github.com/hvora2005/industrial-defect-detection/tree/master/model): `model`

### Other components

- **Phone Browser**
- **Local Wi-Fi**
- **Operator**

## Connections

- Operator → Phone Browser: uses (evidence: `README.md`)
- Phone Browser → Local Wi-Fi: sends images (evidence: `README.md`)
- Local Wi-Fi → FastAPI Routes: HTTPS requests (evidence: `README.md`)
- Capture & Upload → FastAPI Routes: posts /detect, /upload (evidence: `frontend/app.js`)
- FastAPI Routes → Image Decode: decodes upload (evidence: `backend/main.py`)
- FastAPI Routes → YOLO Detection: calls predict (evidence: `backend/main.py`)
- YOLO Detection → Inference Config: reads settings (evidence: `backend/detector.py`)
- YOLO Training → Trained Weights: copies best weights (evidence: `training/train.py`)
- YOLO Detection → Trained Weights: loads model
- FastAPI Routes → Capture & Upload: returns result (evidence: `README.md`)
- FastAPI Routes → History & Stats: saves inspection (evidence: `backend/main.py`)
- History & Stats → Inspection History: reads and writes (evidence: `backend/database.py`)
- FastAPI Routes → Monitor Connections: broadcasts results (evidence: `backend/main.py`)
- Live Monitor → FastAPI Routes: opens WebSocket (evidence: `README.md`)
- Monitor Connections → Live Monitor: pushes detections (evidence: `backend/main.py`)
- Statistics Dashboard → FastAPI Routes: requests stats, history, trend (evidence: `frontend/dashboard.js`)
- FastAPI Routes → History & Stats: queries history and stats (evidence: `backend/main.py`)
- FastAPI Routes → CSV/PDF Reports: builds exports (evidence: `backend/main.py`)
- CSV/PDF Reports → History & Stats: reads stored data (evidence: `backend/reports.py`)
- Dataset Conversion → YOLO Training: prepares dataset (evidence: `README.md`)
