# ja-in/weather-aware-truck-routing architecture

> Architecture diagram of the GitHub repository ja-in/weather-aware-truck-routing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ja-in/weather-aware-truck-routing
- Repository: https://github.com/ja-in/weather-aware-truck-routing

## Overview

Weather-Aware Truck Routing accepts a freight trip request, compares route alternatives using checkpoint weather and load-sensitive risk, ranks routes and departure times, then presents the result in a map and synchronized checkpoint views. The hosted path is Next.js API routes plus Drizzle/PostgreSQL; the README documents Django as an interchangeable backend. The graph includes both implementations and the major visualization and fallback capabilities. Some service internals were only partially excerpted, so uncertain call details are omitted.

Main entry points: [`src/lib/weather-routing.ts`](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/weather-routing.ts) (Route analysis), [`backend/routing_api/services.py`](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/services.py) (Route analysis), [`src/components/route-planner.tsx`](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/route-planner.tsx) (Route planner), [`backend/routing_api/views.py`](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/views.py) (Django API views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_planner["Planner and visualization"]
  node_planner_page["Planner page<br/>[page.tsx]"]
  node_planner_ui["Route planner<br/>[route-planner.tsx]"]
  node_map["Corridor map<br/>[corridor-map.tsx]"]
  node_timeline["Checkpoint views"]
  node_corridor_logic["Layer snapshots<br/>[corridor.ts]"]
  node_domain_types["Route data types<br/>[domain.ts]"]
end

subgraph group_next_backend["Next.js analysis backend"]
  node_next_api["Analysis API<br/>[route.ts]"]
  node_analysis_engine["Route analysis<br/>[weather-routing.ts]"]
  node_geo_logic["Geospatial sampling<br/>[geo.ts]"]
  node_risk_logic["Risk rules<br/>[risk.ts]"]
  node_offline_fallback["Offline fallback"]
  node_browser_geocoder["Browser geocoder<br/>[geocode-browser.ts]"]
  node_db_connector["Database connector<br/>[index.ts]"]
  node_db_schema["Analysis schema<br/>[schema.ts]"]
end

subgraph group_django_backend["Django alternative backend"]
  node_django_views["Django API views<br/>[views.py]"]
  node_django_serializers["Request validation<br/>[serializers.py]"]
  node_django_services["Route analysis<br/>[services.py]"]
  node_django_geo["Geospatial sampling<br/>[geo.py]"]
  node_django_risk["Risk rules<br/>[risk.py]"]
  node_django_models["Analysis models<br/>[models.py]"]
end

subgraph group_providers["Routing and weather providers"]
  node_nominatim["Nominatim"]
  node_osrm["OSRM"]
  node_open_meteo["Open-Meteo"]
end

node_dispatcher(("Dispatcher"))
node_postgres[("PostgreSQL")]

node_dispatcher -->|"opens planner"| node_planner_page
node_planner_page -->|"renders"| node_planner_ui
node_planner_ui -->|"submits request"| node_next_api
node_planner_ui -.->|"can submit instead"| node_django_views
node_planner_ui -->|"retries geocoding"| node_browser_geocoder
node_browser_geocoder -->|"resolves places"| node_nominatim
node_next_api -->|"runs analysis"| node_analysis_engine
node_analysis_engine -->|"uses sampling"| node_geo_logic
node_analysis_engine -->|"classifies risk"| node_risk_logic
node_analysis_engine -->|"uses fallback"| node_offline_fallback
node_analysis_engine -->|"queries database"| node_db_connector
node_analysis_engine -->|"uses tables"| node_db_schema
node_db_connector -->|"connects"| node_postgres
node_analysis_engine -->|"geocodes places"| node_nominatim
node_analysis_engine -->|"requests routes"| node_osrm
node_analysis_engine -->|"fetches forecasts"| node_open_meteo
node_planner_ui -->|"renders results"| node_map
node_planner_ui -->|"renders checkpoints"| node_timeline
node_map -->|"gets snapshots"| node_corridor_logic
node_timeline -->|"gets snapshots"| node_corridor_logic
node_django_views -->|"validates requests"| node_django_serializers
node_django_views -->|"dispatches analysis"| node_django_services
node_django_services -->|"uses sampling"| node_django_geo
node_django_services -->|"classifies risk"| node_django_risk
node_django_services -->|"persists analyses"| node_django_models
node_django_services -->|"geocodes places"| node_nominatim
node_django_services -->|"requests routes"| node_osrm
node_django_services -->|"fetches forecasts"| node_open_meteo

click node_planner_page "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/app/planner/page.tsx"
click node_planner_ui "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/route-planner.tsx"
click node_map "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/corridor-map.tsx"
click node_timeline "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/checkpoint-timeline.tsx"
click node_corridor_logic "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/corridor.ts"
click node_domain_types "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/domain.ts"
click node_next_api "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/app/api/route-analysis/route.ts"
click node_analysis_engine "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/weather-routing.ts"
click node_geo_logic "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/geo.ts"
click node_risk_logic "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/risk.ts"
click node_offline_fallback "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/offline-fallback.ts"
click node_browser_geocoder "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/geocode-browser.ts"
click node_db_connector "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/db/index.ts"
click node_db_schema "https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/db/schema.ts"
click node_django_views "https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/views.py"
click node_django_serializers "https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/serializers.py"
click node_django_services "https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/services.py"
click node_django_geo "https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/geo.py"
click node_django_risk "https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/risk.py"
click node_django_models "https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/models.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_planner_page,node_planner_ui,node_map,node_timeline,node_corridor_logic,node_domain_types toneBlue
class node_next_api,node_analysis_engine,node_geo_logic,node_risk_logic,node_offline_fallback,node_browser_geocoder,node_db_connector,node_db_schema,node_postgres toneAmber
class node_django_views,node_django_serializers,node_django_services,node_django_geo,node_django_risk,node_django_models toneMint
class node_nominatim,node_osrm,node_open_meteo toneRose
class node_dispatcher toneIndigo
```

## Components

### Planner and visualization

- [Planner page](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/app/planner/page.tsx): `src/app/planner/page.tsx`
- [Route planner](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/route-planner.tsx): `src/components/route-planner.tsx`
- [Corridor map](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/corridor-map.tsx): `src/components/corridor-map.tsx`
- [Checkpoint views](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/components/checkpoint-timeline.tsx): `src/components/checkpoint-timeline.tsx`
- [Layer snapshots](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/corridor.ts): `src/lib/corridor.ts`
- [Route data types](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/domain.ts): `src/lib/domain.ts`

### Next.js analysis backend

- [Analysis API](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/app/api/route-analysis/route.ts): `src/app/api/route-analysis/route.ts`
- [Route analysis](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/weather-routing.ts): `src/lib/weather-routing.ts`
- [Geospatial sampling](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/geo.ts): `src/lib/geo.ts`
- [Risk rules](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/risk.ts): `src/lib/risk.ts`
- [Offline fallback](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/offline-fallback.ts): `src/lib/offline-fallback.ts`
- [Browser geocoder](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/lib/geocode-browser.ts): `src/lib/geocode-browser.ts`
- [Database connector](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/db/index.ts): `src/db/index.ts`
- [Analysis schema](https://github.com/ja-in/weather-aware-truck-routing/blob/main/src/db/schema.ts): `src/db/schema.ts`

### Django alternative backend

- [Django API views](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/views.py): `backend/routing_api/views.py`
- [Request validation](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/serializers.py): `backend/routing_api/serializers.py`
- [Route analysis](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/services.py): `backend/routing_api/services.py`
- [Geospatial sampling](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/geo.py): `backend/routing_api/geo.py`
- [Risk rules](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/risk.py): `backend/routing_api/risk.py`
- [Analysis models](https://github.com/ja-in/weather-aware-truck-routing/blob/main/backend/routing_api/models.py): `backend/routing_api/models.py`

### Routing and weather providers

- **Nominatim**
- **OSRM**
- **Open-Meteo**

### Other components

- **Dispatcher**
- **PostgreSQL**

## Connections

- Dispatcher → Planner page: opens planner (evidence: `README.md`)
- Planner page → Route planner: renders (evidence: `src/app/planner/page.tsx`)
- Route planner → Analysis API: submits request (evidence: `src/components/route-planner.tsx`)
- Route planner → Django API views: can submit instead (evidence: `README.md`)
- Route planner → Browser geocoder: retries geocoding (evidence: `src/components/route-planner.tsx`)
- Browser geocoder → Nominatim: resolves places (evidence: `README.md`)
- Analysis API → Route analysis: runs analysis (evidence: `src/app/api/route-analysis/route.ts`)
- Route analysis → Geospatial sampling: uses sampling (evidence: `src/lib/weather-routing.ts`)
- Route analysis → Risk rules: classifies risk (evidence: `src/lib/weather-routing.ts`)
- Route analysis → Offline fallback: uses fallback (evidence: `src/lib/weather-routing.ts`)
- Route analysis → Database connector: queries database (evidence: `src/lib/weather-routing.ts`)
- Route analysis → Analysis schema: uses tables (evidence: `src/lib/weather-routing.ts`)
- Database connector → PostgreSQL: connects (evidence: `src/db/index.ts`)
- Route analysis → Nominatim: geocodes places (evidence: `README.md`)
- Route analysis → OSRM: requests routes (evidence: `README.md`)
- Route analysis → Open-Meteo: fetches forecasts (evidence: `README.md`)
- Route planner → Corridor map: renders results (evidence: `src/components/route-planner.tsx`)
- Route planner → Checkpoint views: renders checkpoints (evidence: `src/components/route-planner.tsx`)
- Corridor map → Layer snapshots: gets snapshots (evidence: `src/components/corridor-map.tsx`)
- Checkpoint views → Layer snapshots: gets snapshots (evidence: `src/components/checkpoint-timeline.tsx`)
- Django API views → Request validation: validates requests (evidence: `backend/routing_api/views.py`)
- Django API views → Route analysis: dispatches analysis (evidence: `backend/routing_api/views.py`)
- Route analysis → Geospatial sampling: uses sampling (evidence: `backend/routing_api/services.py`)
- Route analysis → Risk rules: classifies risk (evidence: `backend/routing_api/services.py`)
- Route analysis → Analysis models: persists analyses (evidence: `backend/routing_api/services.py`)
- Route analysis → Nominatim: geocodes places (evidence: `README.md`)
- Route analysis → OSRM: requests routes (evidence: `README.md`)
- Route analysis → Open-Meteo: fetches forecasts (evidence: `README.md`)
