# harashwar006/traffic_ml- architecture

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

- Interactive diagram: https://gitdiagram.com/harashwar006/traffic_ml-
- Repository: https://github.com/harashwar006/traffic_ml-

## Overview

Traffic ML & Video Analytics Engine processes camera video into vehicle detections, persistent tracks, road/movement assignments, ROI counts, speed and traffic-state analytics, then serves live telemetry and annotated output to a React dashboard. Users monitor camera summaries, launch single- or multi-camera analysis, inspect live results and history, and use the simulator. The map includes data/configuration, inference and analytics stages plus the API and dashboard. Some backend and UI subsystems are represented from README claims and the source index; unsampled implementation details and uncertain links are omitted.

Main entry points: [`src/inference/pipeline.py`](https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/pipeline.py) (Single-Camera Pipeline), [`src/inference/multi_pipeline.py`](https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/multi_pipeline.py) (Multi-Camera Pipeline), [`web/src/App.tsx`](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/App.tsx) (Dashboard Router), [`api/server.py`](https://github.com/harashwar006/traffic_ml-/blob/main/api/server.py) (FastAPI Backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Video and Configuration"]
  node_video["Camera Video<br/>[video_loader.py]"]
  node_annotations["Camera Annotations"]
  node_roadconfig["Road Configuration<br/>[road_config.py]"]
end

subgraph group_engine["Inference and Tracking"]
  node_detector["Vehicle Detection<br/>[detector.py]"]
  node_tracker["ByteTrack Tracker<br/>[tracker.py]"]
  node_roadassign["Road Assignment<br/>[road_assigner.py]"]
  node_movementstate["Movement State<br/>[movement_state.py]"]
  node_movement["Movement Assignment"]
  node_pipeline["Single-Camera Pipeline<br/>[pipeline.py]"]
  node_multipipeline["Multi-Camera Pipeline<br/>[multi_pipeline.py]"]
end

subgraph group_analytics["Traffic Analytics"]
  node_counter["ROI Counting<br/>[roi_counter.py]"]
  node_trafficstate["Traffic State<br/>[traffic_state.py]"]
  node_evaluation["Counting Evaluation<br/>[counting_eval.py]"]
  node_visualizer["Video Visualizer<br/>[visualizer.py]"]
end

subgraph group_service["API Service"]
  node_api["FastAPI Backend<br/>[server.py]"]
  node_models["API Models<br/>[models.py]"]
end

subgraph group_dashboard["Web Dashboard"]
  node_app["Dashboard Router<br/>[App.tsx]"]
  node_live["Live Analysis<br/>[LiveAnalysis.tsx]"]
  node_overview["Traffic Overview<br/>[Overview.tsx]"]
  node_simulator["Strategy Simulator<br/>[Simulator.tsx]"]
  node_history["Analysis History<br/>[History.tsx]"]
  node_webapi["API Client<br/>[api.ts]"]
end

node_operator(("Traffic Operator"))
node_browser(("Dashboard User"))

node_operator -.->|"provides video"| node_video
node_video -->|"supplies frames"| node_pipeline
node_annotations -->|"loads annotations"| node_pipeline
node_roadconfig -->|"loads road regions"| node_pipeline
node_pipeline -->|"tracks vehicles"| node_tracker
node_pipeline -->|"assigns roads"| node_roadassign
node_pipeline -->|"updates movement state"| node_movementstate
node_pipeline -->|"assigns movements"| node_movement
node_pipeline -->|"counts ROI events"| node_counter
node_pipeline -->|"estimates traffic"| node_trafficstate
node_pipeline -->|"renders frames"| node_visualizer
node_pipeline -->|"evaluates counts"| node_evaluation
node_multipipeline -->|"loads camera video"| node_video
node_multipipeline -->|"loads annotations"| node_annotations
node_multipipeline -->|"tracks vehicles"| node_tracker
node_multipipeline -->|"assigns movements"| node_movement
node_multipipeline -->|"counts ROI events"| node_counter
node_multipipeline -->|"estimates traffic"| node_trafficstate
node_multipipeline -->|"renders frames"| node_visualizer
node_api -->|"runs analysis"| node_pipeline
node_api -->|"runs camera jobs"| node_multipipeline
node_api -->|"uses schemas"| node_models
node_browser -->|"opens dashboard"| node_app
node_app -->|"routes to"| node_live
node_app -->|"routes to"| node_overview
node_app -->|"routes to"| node_simulator
node_app -->|"routes to"| node_history
node_app -->|"fetches dashboard state"| node_webapi
node_live -->|"requests live telemetry"| node_webapi
node_simulator -->|"requests simulation"| node_webapi
node_webapi -->|"calls HTTP and streaming endpoints"| node_api

click node_video "https://github.com/harashwar006/traffic_ml-/blob/main/src/data/video_loader.py"
click node_annotations "https://github.com/harashwar006/traffic_ml-/blob/main/src/data/annotation_loader.py"
click node_roadconfig "https://github.com/harashwar006/traffic_ml-/blob/main/src/data/road_config.py"
click node_detector "https://github.com/harashwar006/traffic_ml-/blob/main/src/detection/detector.py"
click node_tracker "https://github.com/harashwar006/traffic_ml-/blob/main/src/tracking/tracker.py"
click node_roadassign "https://github.com/harashwar006/traffic_ml-/blob/main/src/tracking/road_assigner.py"
click node_movementstate "https://github.com/harashwar006/traffic_ml-/blob/main/src/tracking/movement_state.py"
click node_movement "https://github.com/harashwar006/traffic_ml-/blob/main/src/movement/movement_assigner.py"
click node_counter "https://github.com/harashwar006/traffic_ml-/blob/main/src/counting/roi_counter.py"
click node_trafficstate "https://github.com/harashwar006/traffic_ml-/blob/main/src/analytics/traffic_state.py"
click node_evaluation "https://github.com/harashwar006/traffic_ml-/blob/main/src/evaluation/counting_eval.py"
click node_pipeline "https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/pipeline.py"
click node_multipipeline "https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/multi_pipeline.py"
click node_visualizer "https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/visualizer.py"
click node_api "https://github.com/harashwar006/traffic_ml-/blob/main/api/server.py"
click node_models "https://github.com/harashwar006/traffic_ml-/blob/main/api/models.py"
click node_app "https://github.com/harashwar006/traffic_ml-/blob/main/web/src/App.tsx"
click node_live "https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/LiveAnalysis.tsx"
click node_overview "https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/Overview.tsx"
click node_simulator "https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/Simulator.tsx"
click node_history "https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/History.tsx"
click node_webapi "https://github.com/harashwar006/traffic_ml-/blob/main/web/src/services/api.ts"

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_video,node_annotations,node_roadconfig,node_browser toneBlue
class node_detector,node_tracker,node_roadassign,node_movementstate,node_movement,node_pipeline,node_multipipeline toneAmber
class node_counter,node_trafficstate,node_evaluation,node_visualizer toneMint
class node_api,node_models toneRose
class node_app,node_live,node_overview,node_simulator,node_history,node_webapi,node_operator toneIndigo
```

## Components

### Video and Configuration

- [Camera Video](https://github.com/harashwar006/traffic_ml-/blob/main/src/data/video_loader.py): `src/data/video_loader.py`
- [Camera Annotations](https://github.com/harashwar006/traffic_ml-/blob/main/src/data/annotation_loader.py): `src/data/annotation_loader.py`
- [Road Configuration](https://github.com/harashwar006/traffic_ml-/blob/main/src/data/road_config.py): `src/data/road_config.py`

### Inference and Tracking

- [Vehicle Detection](https://github.com/harashwar006/traffic_ml-/blob/main/src/detection/detector.py): `src/detection/detector.py`
- [ByteTrack Tracker](https://github.com/harashwar006/traffic_ml-/blob/main/src/tracking/tracker.py): `src/tracking/tracker.py`
- [Road Assignment](https://github.com/harashwar006/traffic_ml-/blob/main/src/tracking/road_assigner.py): `src/tracking/road_assigner.py`
- [Movement State](https://github.com/harashwar006/traffic_ml-/blob/main/src/tracking/movement_state.py): `src/tracking/movement_state.py`
- [Movement Assignment](https://github.com/harashwar006/traffic_ml-/blob/main/src/movement/movement_assigner.py): `src/movement/movement_assigner.py`
- [Single-Camera Pipeline](https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/pipeline.py): `src/inference/pipeline.py`
- [Multi-Camera Pipeline](https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/multi_pipeline.py): `src/inference/multi_pipeline.py`

### Traffic Analytics

- [ROI Counting](https://github.com/harashwar006/traffic_ml-/blob/main/src/counting/roi_counter.py): `src/counting/roi_counter.py`
- [Traffic State](https://github.com/harashwar006/traffic_ml-/blob/main/src/analytics/traffic_state.py): `src/analytics/traffic_state.py`
- [Counting Evaluation](https://github.com/harashwar006/traffic_ml-/blob/main/src/evaluation/counting_eval.py): `src/evaluation/counting_eval.py`
- [Video Visualizer](https://github.com/harashwar006/traffic_ml-/blob/main/src/inference/visualizer.py): `src/inference/visualizer.py`

### API Service

- [FastAPI Backend](https://github.com/harashwar006/traffic_ml-/blob/main/api/server.py): `api/server.py`
- [API Models](https://github.com/harashwar006/traffic_ml-/blob/main/api/models.py): `api/models.py`

### Web Dashboard

- [Dashboard Router](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [Live Analysis](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/LiveAnalysis.tsx): `web/src/pages/LiveAnalysis.tsx`
- [Traffic Overview](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/Overview.tsx): `web/src/pages/Overview.tsx`
- [Strategy Simulator](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/Simulator.tsx): `web/src/pages/Simulator.tsx`
- [Analysis History](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/pages/History.tsx): `web/src/pages/History.tsx`
- [API Client](https://github.com/harashwar006/traffic_ml-/blob/main/web/src/services/api.ts): `web/src/services/api.ts`

### Other components

- **Traffic Operator**
- **Dashboard User**

## Connections

- Traffic Operator → Camera Video: provides video
- Camera Video → Single-Camera Pipeline: supplies frames (evidence: `src/inference/pipeline.py`)
- Camera Annotations → Single-Camera Pipeline: loads annotations (evidence: `src/inference/pipeline.py`)
- Road Configuration → Single-Camera Pipeline: loads road regions (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → ByteTrack Tracker: tracks vehicles (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → Road Assignment: assigns roads (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → Movement State: updates movement state (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → Movement Assignment: assigns movements (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → ROI Counting: counts ROI events (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → Traffic State: estimates traffic (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → Video Visualizer: renders frames (evidence: `src/inference/pipeline.py`)
- Single-Camera Pipeline → Counting Evaluation: evaluates counts (evidence: `src/inference/pipeline.py`)
- Multi-Camera Pipeline → Camera Video: loads camera video (evidence: `src/inference/multi_pipeline.py`)
- Multi-Camera Pipeline → Camera Annotations: loads annotations (evidence: `src/inference/multi_pipeline.py`)
- Multi-Camera Pipeline → ByteTrack Tracker: tracks vehicles (evidence: `src/inference/multi_pipeline.py`)
- Multi-Camera Pipeline → Movement Assignment: assigns movements (evidence: `src/inference/multi_pipeline.py`)
- Multi-Camera Pipeline → ROI Counting: counts ROI events (evidence: `src/inference/multi_pipeline.py`)
- Multi-Camera Pipeline → Traffic State: estimates traffic (evidence: `src/inference/multi_pipeline.py`)
- Multi-Camera Pipeline → Video Visualizer: renders frames (evidence: `src/inference/multi_pipeline.py`)
- FastAPI Backend → Single-Camera Pipeline: runs analysis (evidence: `api/server.py`)
- FastAPI Backend → Multi-Camera Pipeline: runs camera jobs (evidence: `api/server.py`)
- FastAPI Backend → API Models: uses schemas (evidence: `api/server.py`)
- Dashboard User → Dashboard Router: opens dashboard (evidence: `README.md`)
- Dashboard Router → Live Analysis: routes to (evidence: `web/src/App.tsx`)
- Dashboard Router → Traffic Overview: routes to (evidence: `web/src/App.tsx`)
- Dashboard Router → Strategy Simulator: routes to (evidence: `web/src/App.tsx`)
- Dashboard Router → Analysis History: routes to (evidence: `web/src/App.tsx`)
- Dashboard Router → API Client: fetches dashboard state (evidence: `web/src/App.tsx`)
- Live Analysis → API Client: requests live telemetry (evidence: `web/src/pages/LiveAnalysis.tsx`)
- Strategy Simulator → API Client: requests simulation (evidence: `web/src/pages/Simulator.tsx`)
- API Client → FastAPI Backend: calls HTTP and streaming endpoints (evidence: `README.md`)
