# domu1206/traffic-monitoring-ai architecture

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

- Interactive diagram: https://gitdiagram.com/domu1206/traffic-monitoring-ai
- Repository: https://github.com/domu1206/traffic-monitoring-ai

## Overview

This is a traffic-video analysis application with a Flask interface and a separate video-processing loop. A user uploads a video; the web app saves it and starts the processing program, which tracks vehicles, estimates speed, and records overspeed violations with plate text and snapshot evidence. The loop also updates and displays a traffic heatmap. The web dashboard exposes stored violations. Helmet-model configuration and a helmet helper exist, but the sampled processing loop does not use them, so no helmet-detection workflow is shown. Source excerpts establish the main processing calls; template behavior is not sampled.

Main entry points: [`main.py`](https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py) (Processing loop), [`app.py`](https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py) (Flask routes), [`utils/storage.py`](https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/storage.py) (Evidence storage), [`videos`](https://github.com/domu1206/traffic-monitoring-ai/tree/main/videos) (Input video)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_webapp["Flask routes<br/>[app.py]"]
  node_upload["Video upload<br/>[app.py]"]
  node_dashboard["Dashboard view<br/>[index.html]"]
  node_select["Mode selection<br/>[select.html]"]
  node_violations_api["Violations API<br/>[app.py]"]
end

subgraph group_analysis["Video analysis"]
  node_video["Input video"]
  node_processor["Processing loop<br/>[main.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
  node_tracker["Vehicle tracking<br/>[tracker.py]"]
  node_speed["Speed estimation<br/>[speed.py]"]
  node_heatmap["Traffic heatmap<br/>[heatmap.py]"]
end

subgraph group_violation["Violation processing"]
  node_overspeed["Overspeed handling<br/>[main.py]"]
  node_plate_detection["Plate detection<br/>[main.py]"]
  node_anpr["Plate recognition<br/>[anpr.py]"]
end

subgraph group_persistence["Persistence"]
  node_storage["Evidence storage<br/>[storage.py]"]
  node_evidence["Evidence files"]
  node_mongo[("Violations database")]
end

node_user(("User"))

node_user -->|"uses"| node_webapp
node_webapp -->|"renders"| node_select
node_user -->|"uploads"| node_upload
node_upload -->|"saves"| node_video
node_upload -->|"starts"| node_processor
node_webapp -->|"renders"| node_dashboard
node_webapp -->|"serves"| node_violations_api
node_violations_api -->|"reads"| node_mongo
node_processor -->|"reads"| node_settings
node_processor -->|"opens"| node_video
node_processor -->|"calls"| node_tracker
node_processor -->|"calls"| node_speed
node_processor -->|"updates"| node_heatmap
node_processor -->|"checks"| node_overspeed
node_overspeed -->|"runs"| node_plate_detection
node_plate_detection -->|"recognizes"| node_anpr
node_overspeed -->|"saves violation"| node_storage
node_storage -->|"writes snapshots"| node_evidence
node_storage -->|"inserts"| node_mongo

click node_webapp "https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py"
click node_upload "https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py"
click node_dashboard "https://github.com/domu1206/traffic-monitoring-ai/blob/main/templates/index.html"
click node_select "https://github.com/domu1206/traffic-monitoring-ai/blob/main/templates/select.html"
click node_violations_api "https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py"
click node_video "https://github.com/domu1206/traffic-monitoring-ai/tree/main/videos"
click node_processor "https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py"
click node_settings "https://github.com/domu1206/traffic-monitoring-ai/blob/main/config.py"
click node_tracker "https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/tracker.py"
click node_speed "https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/speed.py"
click node_heatmap "https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/heatmap.py"
click node_overspeed "https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py"
click node_plate_detection "https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py"
click node_anpr "https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/anpr.py"
click node_storage "https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/storage.py"
click node_evidence "https://github.com/domu1206/traffic-monitoring-ai/tree/main/evidence"

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_upload,node_dashboard,node_select,node_violations_api,node_user toneBlue
class node_video,node_processor,node_settings,node_tracker,node_speed,node_heatmap toneAmber
class node_overspeed,node_plate_detection,node_anpr toneMint
class node_storage,node_evidence,node_mongo toneRose
```

## Components

### Web interface

- [Flask routes](https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py): `app.py`
- [Video upload](https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py): `app.py`
- [Dashboard view](https://github.com/domu1206/traffic-monitoring-ai/blob/main/templates/index.html): `templates/index.html`
- [Mode selection](https://github.com/domu1206/traffic-monitoring-ai/blob/main/templates/select.html): `templates/select.html`
- [Violations API](https://github.com/domu1206/traffic-monitoring-ai/blob/main/app.py): `app.py`

### Video analysis

- [Input video](https://github.com/domu1206/traffic-monitoring-ai/tree/main/videos): `videos`
- [Processing loop](https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py): `main.py`
- [Runtime settings](https://github.com/domu1206/traffic-monitoring-ai/blob/main/config.py): `config.py`
- [Vehicle tracking](https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/tracker.py): `utils/tracker.py`
- [Speed estimation](https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/speed.py): `utils/speed.py`
- [Traffic heatmap](https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/heatmap.py): `utils/heatmap.py`

### Violation processing

- [Overspeed handling](https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py): `main.py`
- [Plate detection](https://github.com/domu1206/traffic-monitoring-ai/blob/main/main.py): `main.py`
- [Plate recognition](https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/anpr.py): `utils/anpr.py`

### Persistence

- [Evidence storage](https://github.com/domu1206/traffic-monitoring-ai/blob/main/utils/storage.py): `utils/storage.py`
- [Evidence files](https://github.com/domu1206/traffic-monitoring-ai/tree/main/evidence): `evidence`
- **Violations database**

### Other components

- **User**

## Connections

- User → Flask routes: uses (evidence: `app.py`)
- Flask routes → Mode selection: renders (evidence: `app.py`)
- User → Video upload: uploads (evidence: `app.py`)
- Video upload → Input video: saves (evidence: `app.py`)
- Video upload → Processing loop: starts (evidence: `app.py`)
- Flask routes → Dashboard view: renders (evidence: `app.py`)
- Flask routes → Violations API: serves (evidence: `app.py`)
- Violations API → Violations database: reads (evidence: `app.py`)
- Processing loop → Runtime settings: reads (evidence: `main.py`)
- Processing loop → Input video: opens (evidence: `main.py`)
- Processing loop → Vehicle tracking: calls (evidence: `main.py`)
- Processing loop → Speed estimation: calls (evidence: `main.py`)
- Processing loop → Traffic heatmap: updates (evidence: `main.py`)
- Processing loop → Overspeed handling: checks (evidence: `main.py`)
- Overspeed handling → Plate detection: runs (evidence: `main.py`)
- Plate detection → Plate recognition: recognizes (evidence: `main.py`)
- Overspeed handling → Evidence storage: saves violation (evidence: `main.py`)
- Evidence storage → Evidence files: writes snapshots (evidence: `utils/storage.py`)
- Evidence storage → Violations database: inserts (evidence: `utils/storage.py`)
