# kaul1415/traffic-ai architecture

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

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

## Overview

Smart Traffic System is a Flask dashboard for adaptive four-lane signals. Its main runtime flow reads lane videos, detects and confirms vehicles and ambulances, feeds lane counts to the signal controller, then presents live status and analytics in the dashboard. Uploads can replace lane clips; a separate report summarizes saved ambulance detections. The excerpts show the controller adapter and video-processing logic, but not the full route or template implementation, so dashboard wiring is based on README documentation.

Main entry points: [`app.py`](https://github.com/kaul1415/traffic-ai/blob/main/app.py) (Flask runtime), [`templates/index.html`](https://github.com/kaul1415/traffic-ai/blob/main/templates/index.html) (Live dashboard), [`run_video.py`](https://github.com/kaul1415/traffic-ai/blob/main/run_video.py) (Single-video runner), [`traffic_logic.py`](https://github.com/kaul1415/traffic-ai/blob/main/traffic_logic.py) (Signal controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Traffic runtime"]
  node_app["Flask runtime<br/>[app.py]"]
  node_controller["Signal controller<br/>[traffic_logic.py]"]
  node_baseline_detector["Baseline detector<br/>[detector.py]"]
  node_single_video_runner["Single-video runner<br/>[run_video.py]"]
end

subgraph group_dashboard["Dashboard and reporting"]
  node_dashboard_ui["Live dashboard<br/>[index.html]"]
  node_dashboard_style["Dashboard styling<br/>[style.css]"]
  node_dashboard_charts["Dashboard charts<br/>[chart.umd.js]"]
  node_ambulance_log["Ambulance log"]
  node_ambulance_report["Ambulance report<br/>[amb_report.py]"]
end

subgraph group_video["Video inputs"]
  node_video_prep["Video preparation<br/>[prepare_videos.py]"]
  node_lane_videos["Lane video clips"]
end

node_operator(("Traffic operator"))

node_operator -->|"uses dashboard"| node_app
node_lane_videos -->|"feeds lanes"| node_app
node_app -->|"updates and ticks"| node_controller
node_app -->|"converts uploads"| node_video_prep
node_app -->|"serves dashboard"| node_dashboard_ui
node_dashboard_ui -.->|"uses styles"| node_dashboard_style
node_dashboard_ui -.->|"renders charts"| node_dashboard_charts
node_app -->|"saves detections"| node_ambulance_log
node_ambulance_log -->|"provides records"| node_ambulance_report
node_single_video_runner -->|"calls detector"| node_baseline_detector

click node_app "https://github.com/kaul1415/traffic-ai/blob/main/app.py"
click node_controller "https://github.com/kaul1415/traffic-ai/blob/main/traffic_logic.py"
click node_video_prep "https://github.com/kaul1415/traffic-ai/blob/main/prepare_videos.py"
click node_dashboard_ui "https://github.com/kaul1415/traffic-ai/blob/main/templates/index.html"
click node_dashboard_style "https://github.com/kaul1415/traffic-ai/blob/main/static/style.css"
click node_dashboard_charts "https://github.com/kaul1415/traffic-ai/blob/main/static/chart.umd.js"
click node_ambulance_report "https://github.com/kaul1415/traffic-ai/blob/main/amb_report.py"
click node_baseline_detector "https://github.com/kaul1415/traffic-ai/blob/main/detector.py"
click node_single_video_runner "https://github.com/kaul1415/traffic-ai/blob/main/run_video.py"

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_app,node_controller,node_baseline_detector,node_single_video_runner toneBlue
class node_dashboard_ui,node_dashboard_style,node_dashboard_charts,node_ambulance_log,node_ambulance_report toneAmber
class node_video_prep,node_lane_videos toneMint
class node_operator toneIndigo
```

## Components

### Traffic runtime

- [Flask runtime](https://github.com/kaul1415/traffic-ai/blob/main/app.py): `app.py`
- [Signal controller](https://github.com/kaul1415/traffic-ai/blob/main/traffic_logic.py): `traffic_logic.py`
- [Baseline detector](https://github.com/kaul1415/traffic-ai/blob/main/detector.py): `detector.py`
- [Single-video runner](https://github.com/kaul1415/traffic-ai/blob/main/run_video.py): `run_video.py`

### Dashboard and reporting

- [Live dashboard](https://github.com/kaul1415/traffic-ai/blob/main/templates/index.html): `templates/index.html`
- [Dashboard styling](https://github.com/kaul1415/traffic-ai/blob/main/static/style.css): `static/style.css`
- [Dashboard charts](https://github.com/kaul1415/traffic-ai/blob/main/static/chart.umd.js): `static/chart.umd.js`
- **Ambulance log**
- [Ambulance report](https://github.com/kaul1415/traffic-ai/blob/main/amb_report.py): `amb_report.py`

### Video inputs

- [Video preparation](https://github.com/kaul1415/traffic-ai/blob/main/prepare_videos.py): `prepare_videos.py`
- **Lane video clips**

### Other components

- **Traffic operator**

## Connections

- Traffic operator → Flask runtime: uses dashboard (evidence: `readme.md`)
- Lane video clips → Flask runtime: feeds lanes (evidence: `readme.md`)
- Flask runtime → Signal controller: updates and ticks (evidence: `app.py`)
- Flask runtime → Video preparation: converts uploads (evidence: `readme.md`)
- Flask runtime → Live dashboard: serves dashboard (evidence: `readme.md`)
- Live dashboard → Dashboard styling: uses styles
- Live dashboard → Dashboard charts: renders charts
- Flask runtime → Ambulance log: saves detections (evidence: `readme.md`)
- Ambulance log → Ambulance report: provides records (evidence: `amb_report.py`)
- Single-video runner → Baseline detector: calls detector (evidence: `run_video.py`)
