# flukelaster/siahra architecture

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

- Interactive diagram: https://gitdiagram.com/flukelaster/siahra
- Repository: https://github.com/flukelaster/siahra

## Overview

SIAHRA is a Thailand-focused 3D hazard-intelligence platform. Users choose a province and time, explore terrain and hazard layers, and inspect live observations, alerts, flood scenes, and local-authority impacts. The browser app combines API-fed data with preprocessed geospatial assets; the edge API serves observations and derived results, while ETL and the GFM tools prepare base geography and satellite-flood products. The graph preserves the documented capability branches; several internal API and ingestion links are omitted because their wiring was not shown in the excerpts.

Main entry points: [`apps/web/src/hooks`](https://github.com/flukelaster/SIAHRA/tree/main/apps/web/src/hooks) (Data hooks), [`apps/api/src/routes`](https://github.com/flukelaster/SIAHRA/tree/main/apps/api/src/routes) (API endpoints), [`apps/api/src/durable-objects/observation-cache.ts`](https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/durable-objects/observation-cache.ts) (Observation cache), [`apps/etl/src`](https://github.com/flukelaster/SIAHRA/tree/main/apps/etl/src) (Geospatial ETL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Interactive map"]
  node_app["App state<br/>[App.tsx]"]
  node_hooks["Data hooks"]
  node_viewport["3D viewport<br/>[Map3DCanvas.tsx]"]
  node_hazardui["Hazard panels"]
  node_stations["Station surfaces"]
end

subgraph group_api["Edge API"]
  node_router["Request router<br/>[router.ts]"]
  node_routes["API endpoints"]
  node_ingestion["Source ingestion"]
  node_cache[("Observation cache")]
  node_alerts[("Alert engine<br/>[alert-engine.ts]")]
  node_impact["Authority impact"]
end

subgraph group_prep["Geospatial preparation"]
  node_etl["Geospatial ETL"]
  node_boundary["Authority boundaries"]
  node_exposuredata["Exposure baseline"]
  node_gfm["GFM processing<br/>[cli.py]"]
end

subgraph group_shared["Shared contracts"]
  node_sharedtypes["Domain types"]
end

node_user(("Map user"))
node_webapi{{"Browser API"}}
node_sources{{"Agency sources"}}

node_user -->|"selects area"| node_app
node_app -->|"loads data"| node_hooks
node_hooks -->|"fetches data"| node_webapi
node_webapi -->|"requests"| node_router
node_router -.->|"dispatches"| node_routes
node_routes -->|"reads flood data"| node_cache
node_routes -->|"computes impact"| node_impact
node_alerts -->|"fetches observations"| node_cache
node_sources -->|"supplies feeds"| node_ingestion
node_ingestion -.->|"updates observations"| node_cache
node_hooks -->|"feeds panels"| node_hazardui
node_hooks -->|"feeds overlays"| node_viewport
node_viewport -.->|"delegates filling"| node_stations
node_etl -->|"builds boundaries"| node_boundary
node_etl -->|"builds exposure"| node_exposuredata
node_boundary -.->|"serves polygons"| node_routes
node_exposuredata -.->|"serves baseline"| node_routes
node_gfm -->|"provides flood scenes"| node_hooks
node_sharedtypes -.->|"defines contracts"| node_routes
node_sharedtypes -.->|"defines contracts"| node_hooks

click node_app "https://github.com/flukelaster/SIAHRA/blob/main/apps/web/src/App.tsx"
click node_hooks "https://github.com/flukelaster/SIAHRA/tree/main/apps/web/src/hooks"
click node_viewport "https://github.com/flukelaster/SIAHRA/blob/main/apps/web/src/components/layout/Map3DCanvas.tsx"
click node_hazardui "https://github.com/flukelaster/SIAHRA/tree/main/apps/web/src/components/hazard"
click node_stations "https://github.com/flukelaster/SIAHRA/blob/main/apps/web/src/workers/stationSheet.worker.ts"
click node_router "https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/router.ts"
click node_routes "https://github.com/flukelaster/SIAHRA/tree/main/apps/api/src/routes"
click node_ingestion "https://github.com/flukelaster/SIAHRA/tree/main/apps/api/src/ingestion"
click node_cache "https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/durable-objects/observation-cache.ts"
click node_alerts "https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/durable-objects/alert-engine.ts"
click node_impact "https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/geo/floodIntersection.ts"
click node_etl "https://github.com/flukelaster/SIAHRA/tree/main/apps/etl/src"
click node_boundary "https://github.com/flukelaster/SIAHRA/blob/main/apps/etl/src/buildLocalAuthorityBoundaries.ts"
click node_exposuredata "https://github.com/flukelaster/SIAHRA/blob/main/apps/etl/src/buildLocalAuthorityExposure.ts"
click node_gfm "https://github.com/flukelaster/SIAHRA/blob/main/apps/etl/gfm/gfm/cli.py"
click node_sharedtypes "https://github.com/flukelaster/SIAHRA/tree/main/packages/shared-types/src"

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_app,node_hooks,node_viewport,node_hazardui,node_stations,node_user,node_webapi toneBlue
class node_router,node_routes,node_ingestion,node_cache,node_alerts,node_impact toneAmber
class node_etl,node_boundary,node_exposuredata,node_gfm toneMint
class node_sharedtypes toneRose
class node_sources toneIndigo
```

## Components

### Interactive map

- [App state](https://github.com/flukelaster/SIAHRA/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [Data hooks](https://github.com/flukelaster/SIAHRA/tree/main/apps/web/src/hooks): `apps/web/src/hooks`
- [3D viewport](https://github.com/flukelaster/SIAHRA/blob/main/apps/web/src/components/layout/Map3DCanvas.tsx): `apps/web/src/components/layout/Map3DCanvas.tsx`
- [Hazard panels](https://github.com/flukelaster/SIAHRA/tree/main/apps/web/src/components/hazard): `apps/web/src/components/hazard`
- [Station surfaces](https://github.com/flukelaster/SIAHRA/blob/main/apps/web/src/workers/stationSheet.worker.ts): `apps/web/src/workers/stationSheet.worker.ts`

### Edge API

- [Request router](https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/router.ts): `apps/api/src/router.ts`
- [API endpoints](https://github.com/flukelaster/SIAHRA/tree/main/apps/api/src/routes): `apps/api/src/routes`
- [Source ingestion](https://github.com/flukelaster/SIAHRA/tree/main/apps/api/src/ingestion): `apps/api/src/ingestion`
- [Observation cache](https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/durable-objects/observation-cache.ts): `apps/api/src/durable-objects/observation-cache.ts`
- [Alert engine](https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/durable-objects/alert-engine.ts): `apps/api/src/durable-objects/alert-engine.ts`
- [Authority impact](https://github.com/flukelaster/SIAHRA/blob/main/apps/api/src/geo/floodIntersection.ts): `apps/api/src/geo/floodIntersection.ts`

### Geospatial preparation

- [Geospatial ETL](https://github.com/flukelaster/SIAHRA/tree/main/apps/etl/src): `apps/etl/src`
- [Authority boundaries](https://github.com/flukelaster/SIAHRA/blob/main/apps/etl/src/buildLocalAuthorityBoundaries.ts): `apps/etl/src/buildLocalAuthorityBoundaries.ts`
- [Exposure baseline](https://github.com/flukelaster/SIAHRA/blob/main/apps/etl/src/buildLocalAuthorityExposure.ts): `apps/etl/src/buildLocalAuthorityExposure.ts`
- [GFM processing](https://github.com/flukelaster/SIAHRA/blob/main/apps/etl/gfm/gfm/cli.py): `apps/etl/gfm/gfm/cli.py`

### Shared contracts

- [Domain types](https://github.com/flukelaster/SIAHRA/tree/main/packages/shared-types/src): `packages/shared-types/src`

### Other components

- **Map user**
- **Browser API**
- **Agency sources**

## Connections

- Map user → App state: selects area (evidence: `README.md`)
- App state → Data hooks: loads data (evidence: `apps/web/src/App.tsx`)
- Data hooks → Browser API: fetches data (evidence: `apps/web/src/hooks/useAffectedAuthorities.ts`)
- Browser API → Request router: requests (evidence: `README.md`)
- Request router → API endpoints: dispatches (evidence: `apps/api/src/routes/localAuthorities.ts`)
- API endpoints → Observation cache: reads flood data (evidence: `apps/api/src/routes/localAuthorities.ts`)
- API endpoints → Authority impact: computes impact (evidence: `apps/api/src/routes/localAuthorities.ts`)
- Alert engine → Observation cache: fetches observations (evidence: `apps/api/src/durable-objects/alert-engine.ts`)
- Agency sources → Source ingestion: supplies feeds (evidence: `README.md`)
- Source ingestion → Observation cache: updates observations
- Data hooks → Hazard panels: feeds panels (evidence: `README.md`)
- Data hooks → 3D viewport: feeds overlays (evidence: `apps/web/src/hooks/useLayerDescriptors.ts`)
- 3D viewport → Station surfaces: delegates filling
- Geospatial ETL → Authority boundaries: builds boundaries (evidence: `apps/etl/src/buildLocalAuthorityBoundaries.ts`)
- Geospatial ETL → Exposure baseline: builds exposure (evidence: `apps/etl/src/buildLocalAuthorityExposure.ts`)
- Authority boundaries → API endpoints: serves polygons
- Exposure baseline → API endpoints: serves baseline
- GFM processing → Data hooks: provides flood scenes (evidence: `README.md`)
- Domain types → API endpoints: defines contracts
- Domain types → Data hooks: defines contracts
