# 8anissibrenda-stack/citypulse architecture

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

- Interactive diagram: https://gitdiagram.com/8anissibrenda-stack/citypulse
- Repository: https://github.com/8anissibrenda-stack/citypulse

## Overview

CityPulse combines two operational flows: camera-based near-collision prediction and ambulance signal priority. The vision pipeline accepts simulator or camera/video input, evaluates risk, renders video, stores events, and broadcasts updates; ambulance APIs ingest GPS or run route simulations against a signal state machine. FastAPI serves these capabilities to a dashboard, warning display, and mobile GPS page. Edges reflect README statements and shown source references; unsampled route and UI details are not inferred.

Main entry points: [`app/services/pipeline.py`](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/services/pipeline.py) (Vision Pipeline), [`app/main.py`](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/main.py) (FastAPI Application), [`app/routers/scenarios.py`](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/scenarios.py) (Scenario API), [`app/routers/ambulance.py`](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/ambulance.py) (Ambulance API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Road Safety"]
  node_pipeline["Vision Pipeline<br/>[pipeline.py]"]
  node_simulator["Junction Simulator<br/>[simulator.py]"]
  node_yolo["YOLO Detector<br/>[detector_yolo.py]"]
  node_types["Vision Data Types<br/>[types.py]"]
  node_risk["Risk Engine<br/>[engine.py]"]
  node_renderer["Frame Renderer<br/>[render.py]"]
end

subgraph group_ambulance["Ambulance Priority"]
  node_amb_router["Ambulance API<br/>[ambulance.py]"]
  node_amb_engine["Route Simulation<br/>[engine.py]"]
  node_signal_controller["Signal Controller<br/>[controller.py]"]
end

subgraph group_api["API and Services"]
  node_main["FastAPI Application<br/>[main.py]"]
  node_core_router["Core API<br/>[core.py]"]
  node_events_router["Events API<br/>[events.py]"]
  node_scenario_router["Scenario API<br/>[scenarios.py]"]
  node_metrics["Metrics Service<br/>[metrics.py]"]
end

subgraph group_state["Persistence and Signals"]
  node_database[("SQLite Data<br/>[db.py]")]
  node_websocket["WebSocket Manager<br/>[ws.py]"]
end

subgraph group_clients["User Interfaces"]
  node_dashboard["Dashboard<br/>[app.js]"]
  node_warning["Driver Warning Display<br/>[warning.html]"]
  node_phone["Mobile GPS Page<br/>[phone.html]"]
  node_video["Annotated Video Feed<br/>[index.html]"]
end

node_camera(("CCTV / Simulator"))
node_gps(("Ambulance GPS"))

node_camera -->|"supplies frames"| node_pipeline
node_pipeline -->|"uses simulator"| node_simulator
node_pipeline -->|"uses detector"| node_yolo
node_pipeline -->|"evaluates risk"| node_risk
node_pipeline -->|"renders frames"| node_renderer
node_pipeline -->|"stores events"| node_database
node_pipeline -->|"broadcasts alerts"| node_websocket
node_risk -->|"uses data types"| node_types
node_simulator -->|"outputs tracked objects"| node_types
node_yolo -->|"produces tracked objects"| node_types
node_renderer -->|"renders objects"| node_types
node_gps -->|"submits location"| node_amb_router
node_phone -->|"sends GPS"| node_amb_router
node_amb_router -->|"runs simulation"| node_amb_engine
node_amb_engine -->|"requests priority"| node_signal_controller
node_amb_router -->|"builds controller"| node_signal_controller
node_amb_router -->|"reads and writes"| node_database
node_main -->|"mounts routes"| node_core_router
node_main -->|"mounts routes"| node_amb_router
node_main -->|"mounts routes"| node_events_router
node_main -->|"mounts routes"| node_scenario_router
node_main -->|"starts pipeline"| node_pipeline
node_core_router -->|"controls pipeline"| node_pipeline
node_core_router -->|"queries configuration"| node_database
node_events_router -->|"uses metrics"| node_metrics
node_metrics -->|"queries events"| node_database
node_scenario_router -->|"loads scenario data"| node_database
node_scenario_router -->|"evaluates safety cases"| node_risk
node_scenario_router -->|"simulates ambulance cases"| node_amb_engine
node_scenario_router -->|"builds signal state"| node_signal_controller
node_dashboard -->|"controls pipeline"| node_core_router
node_dashboard -->|"views events"| node_events_router
node_dashboard -->|"runs scenarios"| node_scenario_router
node_dashboard -->|"receives updates"| node_websocket
node_warning -->|"receives warnings"| node_websocket
node_main -->|"serves endpoint"| node_websocket
node_main -->|"serves page"| node_video

click node_pipeline "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/services/pipeline.py"
click node_simulator "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/simulator.py"
click node_yolo "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/detector_yolo.py"
click node_types "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/types.py"
click node_risk "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/risk/engine.py"
click node_renderer "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/render.py"
click node_amb_router "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/ambulance.py"
click node_amb_engine "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/ambulance/engine.py"
click node_signal_controller "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/signals/controller.py"
click node_main "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/main.py"
click node_core_router "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/core.py"
click node_events_router "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/events.py"
click node_scenario_router "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/scenarios.py"
click node_metrics "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/services/metrics.py"
click node_database "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/db.py"
click node_websocket "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/ws.py"
click node_dashboard "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/app.js"
click node_warning "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/warning.html"
click node_phone "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/phone.html"
click node_video "https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/index.html"

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_pipeline,node_simulator,node_yolo,node_types,node_risk,node_renderer toneBlue
class node_amb_router,node_amb_engine,node_signal_controller toneAmber
class node_main,node_core_router,node_events_router,node_scenario_router,node_metrics toneMint
class node_database,node_websocket toneRose
class node_dashboard,node_warning,node_phone,node_video,node_camera,node_gps toneIndigo
```

## Components

### Road Safety

- [Vision Pipeline](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/services/pipeline.py): `app/services/pipeline.py`
- [Junction Simulator](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/simulator.py): `app/vision/simulator.py`
- [YOLO Detector](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/detector_yolo.py): `app/vision/detector_yolo.py`
- [Vision Data Types](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/types.py): `app/vision/types.py`
- [Risk Engine](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/risk/engine.py): `app/risk/engine.py`
- [Frame Renderer](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/vision/render.py): `app/vision/render.py`

### Ambulance Priority

- [Ambulance API](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/ambulance.py): `app/routers/ambulance.py`
- [Route Simulation](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/ambulance/engine.py): `app/ambulance/engine.py`
- [Signal Controller](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/signals/controller.py): `app/signals/controller.py`

### API and Services

- [FastAPI Application](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/main.py): `app/main.py`
- [Core API](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/core.py): `app/routers/core.py`
- [Events API](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/events.py): `app/routers/events.py`
- [Scenario API](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/routers/scenarios.py): `app/routers/scenarios.py`
- [Metrics Service](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/services/metrics.py): `app/services/metrics.py`

### Persistence and Signals

- [SQLite Data](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/db.py): `app/db.py`
- [WebSocket Manager](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/ws.py): `app/ws.py`

### User Interfaces

- [Dashboard](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/app.js): `app/static/app.js`
- [Driver Warning Display](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/warning.html): `app/static/warning.html`
- [Mobile GPS Page](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/phone.html): `app/static/phone.html`
- [Annotated Video Feed](https://github.com/8anissibrenda-stack/citypulse/blob/main/app/static/index.html): `app/static/index.html`

### Other components

- **CCTV / Simulator**
- **Ambulance GPS**

## Connections

- CCTV / Simulator → Vision Pipeline: supplies frames (evidence: `README.md`)
- Vision Pipeline → Junction Simulator: uses simulator (evidence: `app/services/pipeline.py`)
- Vision Pipeline → YOLO Detector: uses detector (evidence: `app/services/pipeline.py`)
- Vision Pipeline → Risk Engine: evaluates risk (evidence: `app/services/pipeline.py`)
- Vision Pipeline → Frame Renderer: renders frames (evidence: `app/services/pipeline.py`)
- Vision Pipeline → SQLite Data: stores events (evidence: `README.md`)
- Vision Pipeline → WebSocket Manager: broadcasts alerts (evidence: `README.md`)
- Risk Engine → Vision Data Types: uses data types (evidence: `app/risk/engine.py`)
- Junction Simulator → Vision Data Types: outputs tracked objects (evidence: `app/vision/simulator.py`)
- YOLO Detector → Vision Data Types: produces tracked objects (evidence: `app/vision/detector_yolo.py`)
- Frame Renderer → Vision Data Types: renders objects (evidence: `app/vision/render.py`)
- Ambulance GPS → Ambulance API: submits location (evidence: `README.md`)
- Mobile GPS Page → Ambulance API: sends GPS (evidence: `README.md`)
- Ambulance API → Route Simulation: runs simulation (evidence: `app/routers/ambulance.py`)
- Route Simulation → Signal Controller: requests priority (evidence: `app/ambulance/engine.py`)
- Ambulance API → Signal Controller: builds controller (evidence: `app/routers/ambulance.py`)
- Ambulance API → SQLite Data: reads and writes (evidence: `app/routers/ambulance.py`)
- FastAPI Application → Core API: mounts routes (evidence: `app/main.py`)
- FastAPI Application → Ambulance API: mounts routes (evidence: `app/main.py`)
- FastAPI Application → Events API: mounts routes (evidence: `app/main.py`)
- FastAPI Application → Scenario API: mounts routes (evidence: `app/main.py`)
- FastAPI Application → Vision Pipeline: starts pipeline (evidence: `app/main.py`)
- Core API → Vision Pipeline: controls pipeline (evidence: `app/routers/core.py`)
- Core API → SQLite Data: queries configuration (evidence: `app/routers/core.py`)
- Events API → Metrics Service: uses metrics (evidence: `app/routers/events.py`)
- Metrics Service → SQLite Data: queries events (evidence: `app/services/metrics.py`)
- Scenario API → SQLite Data: loads scenario data (evidence: `app/routers/scenarios.py`)
- Scenario API → Risk Engine: evaluates safety cases (evidence: `app/routers/scenarios.py`)
- Scenario API → Route Simulation: simulates ambulance cases (evidence: `app/routers/scenarios.py`)
- Scenario API → Signal Controller: builds signal state (evidence: `app/routers/scenarios.py`)
- Dashboard → Core API: controls pipeline (evidence: `README.md`)
- Dashboard → Events API: views events (evidence: `README.md`)
- Dashboard → Scenario API: runs scenarios (evidence: `README.md`)
- Dashboard → WebSocket Manager: receives updates (evidence: `README.md`)
- Driver Warning Display → WebSocket Manager: receives warnings (evidence: `README.md`)
- FastAPI Application → WebSocket Manager: serves endpoint (evidence: `app/main.py`)
- FastAPI Application → Annotated Video Feed: serves page (evidence: `app/main.py`)
