# spiritussanctiswoyam/terra-pulse architecture

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

- Interactive diagram: https://gitdiagram.com/spiritussanctiswoyam/terra-pulse
- Repository: https://github.com/spiritussanctiswoyam/terra-pulse

## Overview

#### Purpose and entry points
Terra Pulse is a satellite-based disaster damage assessment system focused on flood inundation. Its two operational entry points are the Python batch pipeline at `pipeline/run_all.py` and the React/Vite dashboard at `src/main.jsx`; `pipeline/server.py` optionally exposes pipeline results locally. Production frontend deployment is configured by `vercel.json`.

#### Satellite ingestion boundary
`pipeline/fetch_data.py` retrieves pre- and post-event Sentinel-2 L2A imagery from the Microsoft Planetary Computer STAC API. It produces GeoTIFF inputs such as `data/before.tif` and `data/after.tif`. This is the principal external-data boundary: remote catalog/search and raster asset access are isolated from downstream analysis.

#### Raster change-detection stage
`pipeline/ndwi.py` calculates Normalized Difference Water Index values from Green and NIR raster bands for both time periods, then differences them to identify likely new water coverage. Generated intermediates include `output/ndwi_before.tif`, `output/ndwi_after.tif`, and `output/delta_ndwi.tif`. Rasterio/Numpy operate over pixel data; GeoTIFF files are the contract between ingestion and scoring.

#### Severity classification and spatial aggregation
`pipeline/severity.py` and `pipeline/severity_real.py` convert NDWI-change evidence into severity values and grid-level records. The resulting JSON artifacts, notably `output/severity_grid.json` and `output/severity_base.json`, form the structured assessment boundary consumed by prioritization and presentation. `schema/severity_schema.json` defines the intended severity-record shape.

#### Priority scoring
`pipeline/prioritize.py` combines modeled severity with population density and critical-infrastructure factors into response priority scores. This stage transforms physical change detection into dispatch-oriented rankings. `pipeline/run_all.py` orchestrates the end-to-end fetch → NDWI → severity → prioritization workflow and writes presentation-ready grid data such as `output/ndwi_grid.json` and `output/severity_grid.json`.

#### API and artifact serving
`pipeline/server.py` is a Flask-based optional local API layer, with Flask-CORS intended to allow the browser client to retrieve generated data across origins. The repository also carries static/demo data at `pipeline/static/demo_grid.json`, while frontend-bundled copies exist at `src/data/severity_grid.json` and `src/data/dummyZones.json`. These support dashboard operation when the live local pipeline/API is unavailable.

#### Dashboard application
The Vite React SPA starts from `src/main.jsx`, with application composition in `src/App.jsx`. Page-level navigation is organized in `src/pages/Home.jsx`, `src/pages/Dashboard.jsx`, and `src/pages/Details.jsx`. The dashboard is a decision interface rather than part of the ML pipeline: it renders and explains already-generated severity/priority records.

#### Geospatial decision UI
`src/components/MapView.jsx` is the core operational visualization boundary, using React Leaflet for map and spatial display. `src/components/Sidebar.jsx`, `src/components/RecommendationCard.jsx`, and `src/components/ActivationDetails.jsx` turn selected zones and scores into recommended response actions. Supporting alert/navigation elements include `src/components/AlertBanner.jsx` and `src/components/TopNav.jsx`. The frontend is deployed to Vercel, while live satellite processing remains a separately run Python workload.

Main entry points: [`pipeline/run_all.py`](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/run_all.py) (Batch workflow), [`pipeline/severity.py`](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/severity.py) (Severity aggregation), [`output/delta_ndwi.tif`](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/delta_ndwi.tif) (NDWI GeoTIFFs), [`src/pages/Dashboard.jsx`](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/pages/Dashboard.jsx) (Dashboard pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Assessment Pipeline"]
  node_stac[("Planetary Computer STAC<br/>external imagery catalog")]
  node_fetch["Satellite ingestion<br/>Python fetcher<br/>[fetch_data.py]"]
  node_ndwi["NDWI change detection<br/>Python raster analysis<br/>[ndwi.py]"]
  node_severity["Severity aggregation<br/>Python classifier<br/>[severity.py]"]
  node_severity_real["Real severity variant<br/>Python classifier<br/>[severity_real.py]"]
  node_prioritize["Response prioritization<br/>Python scorer<br/>[prioritize.py]"]
  node_orchestrator{{"Batch workflow<br/>Python entry point<br/>[run_all.py]"}}
end

subgraph group_artifacts["Data Contracts"]
  node_source_rasters["Before / after GeoTIFFs<br/>raster inputs<br/>[before.tif]"]
  node_ndwi_rasters["NDWI GeoTIFFs<br/>raster intermediates<br/>[delta_ndwi.tif]"]
  node_severity_schema["Severity record schema<br/>JSON schema"]
  node_severity_data["Severity JSON<br/>assessment records<br/>[severity_grid.json]"]
  node_presentation_data["Presentation grid JSON<br/>dashboard data<br/>[ndwi_grid.json]"]
end

subgraph group_api["Local Serving"]
  node_local_api["Local results API<br/>Flask server<br/>[server.py]"]
  node_demo_data["Demo grid data<br/>static fallback<br/>[demo_grid.json]"]
end

subgraph group_frontend["Decision Dashboard"]
  node_react_entry{{"React/Vite entry<br/>SPA entry point<br/>[main.jsx]"}}
  node_app["Dashboard application<br/>React composition<br/>[App.jsx]"]
  node_pages["Dashboard pages<br/>React pages<br/>[Dashboard.jsx]"]
  node_map["Geospatial decision UI<br/>React Leaflet map<br/>[MapView.jsx]"]
  node_recommendations["Response recommendations<br/>React components"]
  node_bundled_data["Bundled fallback data<br/>frontend static data<br/>[severity_grid.json]"]
  node_vercel["Vercel deployment<br/>frontend deployment<br/>[vercel.json]"]
end

node_stac -->|"catalog search and assets"| node_fetch
node_fetch -->|"writes imagery"| node_source_rasters
node_source_rasters -->|"reads bands"| node_ndwi
node_ndwi -->|"writes NDWI change"| node_ndwi_rasters
node_ndwi_rasters -->|"classifies evidence"| node_severity
node_ndwi_rasters -.->|"alternate classification"| node_severity_real
node_severity_schema -.->|"record contract"| node_severity
node_severity -->|"writes grid records"| node_severity_data
node_severity_real -.->|"writes alternate records"| node_severity_data
node_severity_data -->|"severity input"| node_prioritize
node_prioritize -->|"writes ranked grids"| node_presentation_data
node_orchestrator -->|"orchestrates"| node_fetch
node_orchestrator -->|"orchestrates"| node_ndwi
node_orchestrator -->|"orchestrates"| node_severity
node_orchestrator -->|"orchestrates"| node_prioritize
node_presentation_data -->|"served results"| node_local_api
node_demo_data -.->|"demo fallback"| node_local_api
node_react_entry -->|"boots"| node_app
node_app -->|"navigates"| node_pages
node_pages -->|"renders dashboard map"| node_map
node_pages -->|"renders actions"| node_recommendations
node_local_api -.->|"live assessment data"| node_map
node_bundled_data -.->|"offline fallback"| node_map
node_react_entry -->|"deployed as SPA"| node_vercel

click node_fetch "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/fetch_data.py"
click node_source_rasters "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/data/before.tif"
click node_ndwi "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/ndwi.py"
click node_ndwi_rasters "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/delta_ndwi.tif"
click node_severity "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/severity.py"
click node_severity_real "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/severity_real.py"
click node_severity_schema "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/schema/severity_schema.json"
click node_severity_data "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/severity_grid.json"
click node_prioritize "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/prioritize.py"
click node_presentation_data "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/ndwi_grid.json"
click node_orchestrator "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/run_all.py"
click node_local_api "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/server.py"
click node_demo_data "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/static/demo_grid.json"
click node_react_entry "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/main.jsx"
click node_app "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/App.jsx"
click node_pages "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/pages/Dashboard.jsx"
click node_map "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/components/MapView.jsx"
click node_recommendations "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/components/RecommendationCard.jsx"
click node_bundled_data "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/data/severity_grid.json"
click node_vercel "https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/vercel.json"

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_stac,node_fetch,node_ndwi,node_severity,node_severity_real,node_prioritize,node_orchestrator toneBlue
class node_source_rasters,node_ndwi_rasters,node_severity_schema,node_severity_data,node_presentation_data toneAmber
class node_local_api,node_demo_data toneMint
class node_react_entry,node_app,node_pages,node_map,node_recommendations,node_bundled_data,node_vercel toneRose
```

## Components

### Assessment Pipeline

Python batch workflow that produces flood assessment artifacts.

- **Planetary Computer STAC**: external imagery catalog · Sentinel-2 L2A catalog and raster asset boundary.
- [Satellite ingestion](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/fetch_data.py): Python fetcher · Retrieves pre- and post-event Sentinel-2 imagery. · `pipeline/fetch_data.py`
- [NDWI change detection](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/ndwi.py): Python raster analysis · Computes water-index change from Green and NIR bands. · `pipeline/ndwi.py`
- [Severity aggregation](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/severity.py): Python classifier · Converts NDWI evidence into grid-level severity records. · `pipeline/severity.py`
- [Real severity variant](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/severity_real.py): Python classifier · Alternate severity-record generation path. · `pipeline/severity_real.py`
- [Response prioritization](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/prioritize.py): Python scorer · Combines severity, population, and infrastructure factors. · `pipeline/prioritize.py`
- [Batch workflow](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/run_all.py): Python entry point · Runs fetch through prioritization end to end. · `pipeline/run_all.py`

### Data Contracts

Raster and JSON artifacts passed between processing stages.

- [Before / after GeoTIFFs](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/data/before.tif): raster inputs · Examples include data/before.tif and data/after.tif. · `data/before.tif`
- [NDWI GeoTIFFs](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/delta_ndwi.tif): raster intermediates · Before, after, and delta NDWI rasters. · `output/delta_ndwi.tif`
- [Severity record schema](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/schema/severity_schema.json): JSON schema · Defines the intended severity-record shape. · `schema/severity_schema.json`
- [Severity JSON](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/severity_grid.json): assessment records · Includes severity_base.json and severity_grid.json. · `output/severity_grid.json`
- [Presentation grid JSON](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/output/ndwi_grid.json): dashboard data · Includes NDWI and severity grid outputs. · `output/ndwi_grid.json`

### Local Serving

Optional local access to generated results.

- [Local results API](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/server.py): Flask server · Optionally serves generated artifacts with CORS. · `pipeline/server.py`
- [Demo grid data](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/pipeline/static/demo_grid.json): static fallback · Pipeline-side static dashboard fallback. · `pipeline/static/demo_grid.json`

### Decision Dashboard

React application for reviewing response priorities.

- [React/Vite entry](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/main.jsx): SPA entry point · Bootstraps the dashboard application. · `src/main.jsx`
- [Dashboard application](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/App.jsx): React composition · Composes home, dashboard, and details navigation. · `src/App.jsx`
- [Dashboard pages](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/pages/Dashboard.jsx): React pages · Home, Dashboard, and Details decision views. · `src/pages/Dashboard.jsx`
- [Geospatial decision UI](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/components/MapView.jsx): React Leaflet map · Displays zones and spatial assessment data. · `src/components/MapView.jsx`
- [Response recommendations](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/components/RecommendationCard.jsx): React components · Turns selected zones and scores into recommended actions. · `src/components/RecommendationCard.jsx`
- [Bundled fallback data](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/src/data/severity_grid.json): frontend static data · Used when the live local pipeline/API is unavailable. · `src/data/severity_grid.json`
- [Vercel deployment](https://github.com/spiritussanctiswoyam/terra-pulse/blob/main/vercel.json): frontend deployment · Deploys the Vite React dashboard. · `vercel.json`

## Connections

- Planetary Computer STAC → Satellite ingestion: catalog search and assets
- Satellite ingestion → Before / after GeoTIFFs: writes imagery
- Before / after GeoTIFFs → NDWI change detection: reads bands
- NDWI change detection → NDWI GeoTIFFs: writes NDWI change
- NDWI GeoTIFFs → Severity aggregation: classifies evidence
- NDWI GeoTIFFs → Real severity variant: alternate classification
- Severity record schema → Severity aggregation: record contract
- Severity aggregation → Severity JSON: writes grid records
- Real severity variant → Severity JSON: writes alternate records
- Severity JSON → Response prioritization: severity input
- Response prioritization → Presentation grid JSON: writes ranked grids
- Batch workflow → Satellite ingestion: orchestrates
- Batch workflow → NDWI change detection: orchestrates
- Batch workflow → Severity aggregation: orchestrates
- Batch workflow → Response prioritization: orchestrates
- Presentation grid JSON → Local results API: served results
- Demo grid data → Local results API: demo fallback
- React/Vite entry → Dashboard application: boots
- Dashboard application → Dashboard pages: navigates
- Dashboard pages → Geospatial decision UI: renders dashboard map
- Dashboard pages → Response recommendations: renders actions
- Local results API → Geospatial decision UI: live assessment data
- Bundled fallback data → Geospatial decision UI: offline fallback
- React/Vite entry → Vercel deployment: deployed as SPA
