# pratyushwinorlearn/delhi-traffic-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/pratyushwinorlearn/delhi-traffic-tracker
- Repository: https://github.com/pratyushwinorlearn/delhi-traffic-tracker

## Overview

Delhi Rain Choke Points collects rainfall and traffic observations at configured Delhi locations, stores samples, and compares rainy and dry congestion by matched hour/day buckets to rank hotspots. The repository also includes a Streamlit multiplier dashboard and a separate Next.js live map with location history. The README describes SQLite, while the sampled storage.py implements PostgreSQL and analyze.py refers to a DB_FILE not present in that excerpt; those storage paths may reflect a repository inconsistency. The map/API and analytics features are shown separately where their wiring is evidenced.

Main entry points: [`delhi-traffic-map/app/page.tsx`](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/page.tsx) (Live map UI), [`collector.py`](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/collector.py) (Collector pass), [`traffic.py`](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/traffic.py) (Traffic fetcher), [`analyze.py`](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/analyze.py) (Multiplier analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Sample collection"]
  node_collector["Collector pass<br/>[collector.py]"]
  node_locations["Hotspot locations<br/>[locations.json]"]
  node_traffic["Traffic fetcher<br/>[traffic.py]"]
end

subgraph group_analysis["Multiplier analysis"]
  node_analyze["Multiplier analysis<br/>[analyze.py]"]
end

subgraph group_web["Web views"]
  node_dashboard["Streamlit dashboard<br/>[dashboard.py]"]
  node_home["Live map UI<br/>[page.tsx]"]
  node_trafficapi["Latest traffic API<br/>[route.js]"]
  node_historyapi["Location history API<br/>[route.js]"]
end

subgraph group_persistence["Data storage"]
  node_storage["Sample storage<br/>[storage.py]"]
  node_database[("PostgreSQL samples")]
end

node_scheduler(("Scheduled runner"))
node_weatherapi["Open-Meteo"]
node_tomtom["TomTom Flow API"]
node_webuser(("Web visitor"))
node_leaflet["Leaflet assets"]
node_tomtomtiles["TomTom map tiles"]
node_charts["Chart rendering"]

node_scheduler -->|"runs"| node_collector
node_collector -->|"loads"| node_locations
node_collector -->|"requests weather"| node_weatherapi
node_collector -->|"calls"| node_traffic
node_traffic -->|"requests flow"| node_tomtom
node_collector -->|"inserts samples"| node_storage
node_storage -->|"writes"| node_database
node_dashboard -->|"loads and computes"| node_analyze
node_analyze -.->|"reads samples"| node_database
node_webuser -->|"opens"| node_home
node_home -->|"fetches latest"| node_trafficapi
node_home -->|"fetches history"| node_historyapi
node_trafficapi -->|"queries latest"| node_database
node_historyapi -->|"queries history"| node_database
node_home -.->|"loads assets"| node_leaflet
node_home -.->|"requests tiles"| node_tomtomtiles
node_home -->|"renders history"| node_charts

click node_collector "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/collector.py"
click node_locations "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/config/locations.json"
click node_traffic "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/traffic.py"
click node_storage "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/storage.py"
click node_analyze "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/analyze.py"
click node_dashboard "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/dashboard.py"
click node_home "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/page.tsx"
click node_trafficapi "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/api/traffic/route.js"
click node_historyapi "https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/api/history/route.js"

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_collector,node_locations,node_traffic toneBlue
class node_analyze toneAmber
class node_dashboard,node_home,node_trafficapi,node_historyapi,node_tomtom toneMint
class node_storage,node_database toneRose
class node_scheduler,node_weatherapi,node_webuser,node_leaflet,node_tomtomtiles,node_charts toneIndigo
```

## Components

### Sample collection

- [Collector pass](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/collector.py): `collector.py`
- [Hotspot locations](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/config/locations.json): `config/locations.json`
- [Traffic fetcher](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/traffic.py): `traffic.py`

### Multiplier analysis

- [Multiplier analysis](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/analyze.py): `analyze.py`

### Web views

- [Streamlit dashboard](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/dashboard.py): `dashboard.py`
- [Live map UI](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/page.tsx): `delhi-traffic-map/app/page.tsx`
- [Latest traffic API](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/api/traffic/route.js): `delhi-traffic-map/app/api/traffic/route.js`
- [Location history API](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/delhi-traffic-map/app/api/history/route.js): `delhi-traffic-map/app/api/history/route.js`

### Data storage

- [Sample storage](https://github.com/pratyushwinorlearn/delhi-traffic-tracker/blob/main/storage.py): `storage.py`
- **PostgreSQL samples**

### Other components

- **Scheduled runner**
- **Open-Meteo**
- **TomTom Flow API**
- **Web visitor**
- **Leaflet assets**
- **TomTom map tiles**
- **Chart rendering**

## Connections

- Scheduled runner → Collector pass: runs
- Collector pass → Hotspot locations: loads
- Collector pass → Open-Meteo: requests weather
- Collector pass → Traffic fetcher: calls
- Traffic fetcher → TomTom Flow API: requests flow
- Collector pass → Sample storage: inserts samples
- Sample storage → PostgreSQL samples: writes
- Streamlit dashboard → Multiplier analysis: loads and computes
- Multiplier analysis → PostgreSQL samples: reads samples
- Web visitor → Live map UI: opens
- Live map UI → Latest traffic API: fetches latest
- Live map UI → Location history API: fetches history
- Latest traffic API → PostgreSQL samples: queries latest
- Location history API → PostgreSQL samples: queries history
- Live map UI → Leaflet assets: loads assets
- Live map UI → TomTom map tiles: requests tiles
- Live map UI → Chart rendering: renders history
