# unloosedfiend/ai-traffic-management architecture

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

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

## Overview

This repository is an edge-traffic-management demo: camera imagery is analyzed for vehicles and emergency vehicles, traffic logic selects a lane and green duration, and commands can be sent to a Raspberry Pi signal controller. The graph includes the desktop controller, standalone inference entry points, dashboard, and Pi-side inference/control. The README provides only a title, and several modules are unsampled; edges are limited to relationships visible in excerpts or the source index.

Main entry points: [`src/app.py`](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/app.py) (Traffic controller), [`src/comms/pi_client.py`](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/comms/pi_client.py) (Signal client), [`src/web/dashboard.py`](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/web/dashboard.py) (Dashboard service), [`src/logic/traffic_logic.py`](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/logic/traffic_logic.py) (Lane selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop control"]
  node_desktop_app["Traffic controller<br/>[app.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
  node_camera_manager["Camera capture<br/>[camera_manager.py]"]
  node_yolo["YOLO detection<br/>[yolo_detector.py]"]
  node_traffic_logic["Lane selection<br/>[traffic_logic.py]"]
  node_pi_client["Signal client<br/>[pi_client.py]"]
end

subgraph group_inference["Inference entry points"]
  node_multi_inference["Multi-camera inference"]
  node_realtime_inference["Single-camera inference"]
  node_web_launcher["Web launcher<br/>[web_launcher.py]"]
end

subgraph group_dashboard["Monitoring dashboard"]
  node_dashboard_app["Dashboard service<br/>[dashboard.py]"]
end

subgraph group_pi["Raspberry Pi"]
  node_pi_app["Signal and camera API<br/>[app.py]"]
  node_tflite["TFLite detection<br/>[detect_tflite.py]"]
  node_signal_server["Signal server variant"]
end

node_operator(("Operator"))
node_browser(("Dashboard user"))

node_operator -->|"starts"| node_desktop_app
node_desktop_app -->|"reads settings"| node_settings
node_desktop_app -->|"starts cameras"| node_camera_manager
node_desktop_app -->|"runs detection"| node_yolo
node_desktop_app -->|"selects lane"| node_traffic_logic
node_desktop_app -->|"sends command"| node_pi_client
node_multi_inference -->|"sends commands"| node_pi_client
node_realtime_inference -->|"sends commands"| node_pi_client
node_web_launcher -->|"uses decisions"| node_traffic_logic
node_web_launcher -->|"sends commands"| node_pi_client
node_operator -->|"views status"| node_dashboard_app
node_dashboard_app -->|"starts cameras"| node_camera_manager
node_dashboard_app -->|"runs detection"| node_yolo
node_dashboard_app -->|"uses decisions"| node_traffic_logic
node_dashboard_app -->|"sends commands"| node_pi_client
node_pi_client -->|"posts signal request"| node_pi_app
node_pi_app -->|"uses detector"| node_tflite

click node_desktop_app "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/app.py"
click node_settings "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/config.py"
click node_camera_manager "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/cameras/camera_manager.py"
click node_yolo "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/vision/yolo_detector.py"
click node_traffic_logic "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/logic/traffic_logic.py"
click node_pi_client "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/comms/pi_client.py"
click node_multi_inference "https://github.com/unloosedfiend/ai-traffic-management/blob/main/scripts/run_multi_camera_inference.py"
click node_realtime_inference "https://github.com/unloosedfiend/ai-traffic-management/blob/main/scripts/run_realtime_inference.py"
click node_web_launcher "https://github.com/unloosedfiend/ai-traffic-management/blob/main/scripts/web_launcher.py"
click node_dashboard_app "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/web/dashboard.py"
click node_pi_app "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/pi/app.py"
click node_tflite "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/pi/detect_tflite.py"
click node_signal_server "https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/pi/signal_server_v2.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_desktop_app,node_settings,node_camera_manager,node_yolo,node_traffic_logic,node_pi_client,node_browser toneBlue
class node_multi_inference,node_realtime_inference,node_web_launcher toneAmber
class node_dashboard_app toneMint
class node_pi_app,node_tflite,node_signal_server toneRose
class node_operator toneIndigo
```

## Components

### Desktop control

- [Traffic controller](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/app.py): `src/app.py`
- [Runtime settings](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/config.py): `src/config.py`
- [Camera capture](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/cameras/camera_manager.py): `src/cameras/camera_manager.py`
- [YOLO detection](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/vision/yolo_detector.py): `src/vision/yolo_detector.py`
- [Lane selection](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/logic/traffic_logic.py): `src/logic/traffic_logic.py`
- [Signal client](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/comms/pi_client.py): `src/comms/pi_client.py`

### Inference entry points

- [Multi-camera inference](https://github.com/unloosedfiend/ai-traffic-management/blob/main/scripts/run_multi_camera_inference.py): `scripts/run_multi_camera_inference.py`
- [Single-camera inference](https://github.com/unloosedfiend/ai-traffic-management/blob/main/scripts/run_realtime_inference.py): `scripts/run_realtime_inference.py`
- [Web launcher](https://github.com/unloosedfiend/ai-traffic-management/blob/main/scripts/web_launcher.py): `scripts/web_launcher.py`

### Monitoring dashboard

- [Dashboard service](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/web/dashboard.py): `src/web/dashboard.py`

### Raspberry Pi

- [Signal and camera API](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/pi/app.py): `src/pi/app.py`
- [TFLite detection](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/pi/detect_tflite.py): `src/pi/detect_tflite.py`
- [Signal server variant](https://github.com/unloosedfiend/ai-traffic-management/blob/main/src/pi/signal_server_v2.py): `src/pi/signal_server_v2.py`

### Other components

- **Operator**
- **Dashboard user**

## Connections

- Operator → Traffic controller: starts (evidence: `src/app.py`)
- Traffic controller → Runtime settings: reads settings (evidence: `src/app.py`)
- Traffic controller → Camera capture: starts cameras (evidence: `src/app.py`)
- Traffic controller → YOLO detection: runs detection (evidence: `src/app.py`)
- Traffic controller → Lane selection: selects lane (evidence: `src/app.py`)
- Traffic controller → Signal client: sends command (evidence: `src/app.py`)
- Multi-camera inference → Signal client: sends commands (evidence: `scripts/run_multi_camera_inference.py`)
- Single-camera inference → Signal client: sends commands (evidence: `scripts/run_realtime_inference.py`)
- Web launcher → Lane selection: uses decisions (evidence: `scripts/web_launcher.py`)
- Web launcher → Signal client: sends commands (evidence: `scripts/web_launcher.py`)
- Operator → Dashboard service: views status (evidence: `src/web/dashboard.py`)
- Dashboard service → Camera capture: starts cameras (evidence: `src/web/dashboard.py`)
- Dashboard service → YOLO detection: runs detection (evidence: `src/web/dashboard.py`)
- Dashboard service → Lane selection: uses decisions (evidence: `src/web/dashboard.py`)
- Dashboard service → Signal client: sends commands (evidence: `src/web/dashboard.py`)
- Signal client → Signal and camera API: posts signal request (evidence: `src/comms/pi_client.py`)
- Signal and camera API → TFLite detection: uses detector (evidence: `src/pi/app.py`)
