# reneilwekeoagile061/landsat-water-analysis-ai architecture

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

- Interactive diagram: https://gitdiagram.com/reneilwekeoagile061/landsat-water-analysis-ai
- Repository: https://github.com/reneilwekeoagile061/landsat-water-analysis-ai

## Overview

#### Purpose and Entry Points
This is an offline geospatial ML pipeline plus static Vite/Leaflet dashboard for screening surface-water and groundwater-investigation potential in Botswana. The pipeline’s main interactive entry is `CET313_Artificial_Intelligence_Prototype (1).ipynb`; scriptable preparation begins in `scripts/export_frontend_data.py`. The browser application starts at `index.html` and `src/main.js`.

#### 1. Scene Acquisition and Source Boundaries
Landsat 8/9 and optional Sentinel-1 metadata are queried from Microsoft Planetary Computer STAC by `scripts/fetch_stac_catalog.py`, producing cached catalogs such as `data/landsat_stac.json` and `data/sentinel1_stac.json`. This external-service boundary supplies metadata/assets, not browser-live data. Soil clay enrichment is separately requested from ISRIC SoilGrids by `scripts/fetch_soilgrids.py`.

#### 2. Geospatial Feature Preparation
Notebook and reusable Python modules transform satellite and terrain inputs into water-relevant features: spectral indices in `scripts/indices.py` and elevation/slope in `scripts/dem_features.py`. The primary flow is scene/pixel data → NDWI/MNDWI and related features → prediction-ready tabular rows. AOIs and coordinates define the spatial partitioning rather than a server-side spatial database.

#### 3. Labeling, Training, and Scientific Guardrails
`scripts/labeling.py` creates composite/K-Means-derived water-potential labels; `scripts/train_water_potential.py` trains and spatially validates classifiers, including holdout-region handling. `scripts/validate_labels.py` evaluates agreement with independent rules. Model classes are Low/Medium/High, but the repository explicitly frames results as screening because checked-in hydrogeology may be synthetic demonstration data.

#### 4. Subsurface Screening and Evidence Model
`scripts/subsurface_metrics.py` derives depth-to-water categories, phreatophyte indicators, shallow-clay infiltration proxies, feasibility signals, and evidence/validation fields. `scripts/fetch_soilgrids.py` can replace some synthetic inputs with externally modeled clay observations. The key boundary is evidence provenance: exported properties distinguish measured, modeled, screening, and synthetic demonstration values; the UI should support investigation prioritization, not drilling guarantees.

#### 5. Export Contract and Static Data Delivery
`scripts/export_frontend_data.py` converts notebook prediction CSVs into the frontend contract: `data/exports/water_points.geojson`, `data/exports/aois.geojson`, `data/exports/scenes.json`, and `data/exports/metrics.json`. Deployable copies reside under `public/data/exports/`. This is the central handoff between Python processing and the browser; no backend API or runtime job system exists.

#### 6. Browser Data, State, and Validation
`src/api/loadData.js` fetches the four static resources and `src/api/schema.js` validates their shapes with Zod before rendering. `src/state/filters.js` applies AOI, season, tier, cloud, and confidence filtering as client-side pure state logic. `src/main.js` coordinates loading, filter application, UI refresh, and map updates.

#### 7. Mapping and Decision-Support UI
`src/map/mapController.js` owns Leaflet map lifecycle, AOI overlays, heatmaps, classified points, subsurface layers, popups, drawing, and property-level aggregation. `src/ui/dashboard.js` renders dashboard content, while `src/ui/tabs.js` controls panel visibility. Control flow is static export fetch → schema validation → filter state → map/dashboard rendering; interactions can recalculate local property and water-capture planning summaries without persisting data.

#### Runtime and Deployment
Python 3.10+ supports Jupyter, geospatial processing, scikit-learn/XGBoost, STAC, and SoilGrids clients. Node.js 18+, Vite, vanilla JavaScript, Leaflet/Leaflet.heat, and Zod build and serve the static frontend via `vite.config.js`. `vercel.json` supports static deployment; `.github/workflows/ci.yml` provides CI. Production deployment must include the public export files and does not require application-server infrastructure.

Main entry points: [`scripts/train_water_potential.py`](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/train_water_potential.py) (Spatial model training), [`src/main.js`](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/main.js) (Application coordinator), [`scripts/export_frontend_data.py`](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/export_frontend_data.py) (Frontend export builder), [`scripts/subsurface_metrics.py`](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/subsurface_metrics.py) (Subsurface evidence metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sources["External Sources"]
  node_planetary_computer{{"Planetary Computer STAC<br/>external catalog"}}
  node_soilgrids{{"ISRIC SoilGrids<br/>external soil service"}}
end

subgraph group_pipeline["Python Screening Pipeline"]
  node_stac_fetch["STAC catalog fetch<br/>Python acquisition"]
  node_soil_fetch["SoilGrids fetch<br/>Python acquisition<br/>[fetch_soilgrids.py]"]
  node_cached_catalogs["Cached scene catalogs<br/>JSON cache<br/>[landsat_stac.json]"]
  node_feature_prep["Water feature preparation<br/>geospatial features<br/>[indices.py]"]
  node_dem_features["Terrain features<br/>geospatial features<br/>[dem_features.py]"]
  node_labeling["Potential labeling<br/>ML labels<br/>[labeling.py]"]
  node_training["Spatial model training<br/>ML training"]
  node_label_validation["Independent label checks<br/>scientific validation<br/>[validate_labels.py]"]
  node_subsurface["Subsurface evidence metrics<br/>screening enrichment"]
  node_notebook["Interactive analysis<br/>Jupyter notebook"]
end

subgraph group_exports["Static Export Contract"]
  node_exporter["Frontend export builder<br/>Python export"]
  node_export_artifacts["GeoJSON and metrics exports<br/>static data contract"]
  node_public_exports["Deployable public exports<br/>static assets"]
end

subgraph group_frontend["Vite / Leaflet Dashboard"]
  node_data_api["Static data loader and schemas<br/>browser data boundary<br/>[loadData.js]"]
  node_filter_state["Client filter state<br/>browser state<br/>[filters.js]"]
  node_app_entry["Application coordinator<br/>Vite entry<br/>[main.js]"]
  node_map["Leaflet map controller<br/>map rendering<br/>[mapController.js]"]
  node_dashboard["Dashboard panels<br/>UI rendering<br/>[dashboard.js]"]
  node_tabs["Panel tabs<br/>UI state<br/>[tabs.js]"]
  node_static_site["Static Vite site<br/>deployment artifact<br/>[index.html]"]
end

node_planetary_computer -->|"catalog query"| node_stac_fetch
node_stac_fetch -->|"cache metadata"| node_cached_catalogs
node_cached_catalogs -->|"scene inputs"| node_feature_prep
node_soilgrids -->|"clay request"| node_soil_fetch
node_feature_prep -->|"prediction rows"| node_labeling
node_dem_features -->|"terrain inputs"| node_training
node_labeling -->|"training labels"| node_training
node_training -->|"predictions"| node_label_validation
node_training -->|"screening points"| node_subsurface
node_soil_fetch -->|"modeled clay"| node_subsurface
node_subsurface -->|"evidence and provenance"| node_exporter
node_training -->|"classified predictions"| node_exporter
node_notebook -->|"prediction CSVs"| node_exporter
node_exporter -->|"generate"| node_export_artifacts
node_export_artifacts -->|"deploy copies"| node_public_exports
node_public_exports -->|"static fetch"| node_data_api
node_data_api -->|"validated data"| node_app_entry
node_filter_state -->|"filter results"| node_app_entry
node_app_entry -->|"map updates"| node_map
node_app_entry -->|"dashboard refresh"| node_dashboard
node_tabs -->|"panel visibility"| node_dashboard
node_static_site -->|"browser startup"| node_app_entry

click node_stac_fetch "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/fetch_stac_catalog.py"
click node_soil_fetch "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/fetch_soilgrids.py"
click node_cached_catalogs "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/data/landsat_stac.json"
click node_feature_prep "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/indices.py"
click node_dem_features "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/dem_features.py"
click node_labeling "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/labeling.py"
click node_training "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/train_water_potential.py"
click node_label_validation "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/validate_labels.py"
click node_subsurface "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/subsurface_metrics.py"
click node_notebook "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/CET313_Artificial_Intelligence_Prototype%20(1).ipynb"
click node_exporter "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/export_frontend_data.py"
click node_export_artifacts "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/data/exports/water_points.geojson"
click node_data_api "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/api/loadData.js"
click node_filter_state "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/state/filters.js"
click node_app_entry "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/main.js"
click node_map "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/map/mapController.js"
click node_dashboard "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/ui/dashboard.js"
click node_tabs "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/ui/tabs.js"
click node_static_site "https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/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_planetary_computer,node_soilgrids toneBlue
class node_stac_fetch,node_soil_fetch,node_cached_catalogs,node_feature_prep,node_dem_features,node_labeling,node_training,node_label_validation,node_subsurface,node_notebook toneAmber
class node_exporter,node_export_artifacts,node_public_exports toneMint
class node_data_api,node_filter_state,node_app_entry,node_map,node_dashboard,node_tabs,node_static_site toneRose
```

## Components

### External Sources

- **Planetary Computer STAC**: external catalog · Landsat and optional Sentinel-1 metadata and assets.
- **ISRIC SoilGrids**: external soil service · Modeled clay observations.

### Python Screening Pipeline

- [STAC catalog fetch](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/fetch_stac_catalog.py): Python acquisition · `scripts/fetch_stac_catalog.py`
- [SoilGrids fetch](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/fetch_soilgrids.py): Python acquisition · `scripts/fetch_soilgrids.py`
- [Cached scene catalogs](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/data/landsat_stac.json): JSON cache · `data/landsat_stac.json`
- [Water feature preparation](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/indices.py): geospatial features · Produces spectral and terrain features for prediction rows. · `scripts/indices.py`
- [Terrain features](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/dem_features.py): geospatial features · Elevation and slope enrichment. · `scripts/dem_features.py`
- [Potential labeling](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/labeling.py): ML labels · Composite and K-Means-derived water-potential labels. · `scripts/labeling.py`
- [Spatial model training](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/train_water_potential.py): ML training · Spatial holdout validation produces Low, Medium, and High screening predictions. · `scripts/train_water_potential.py`
- [Independent label checks](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/validate_labels.py): scientific validation · `scripts/validate_labels.py`
- [Subsurface evidence metrics](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/subsurface_metrics.py): screening enrichment · Adds depth, clay, feasibility, and provenance fields. · `scripts/subsurface_metrics.py`
- [Interactive analysis](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/CET313_Artificial_Intelligence_Prototype%20(1).ipynb): Jupyter notebook · Interactive pipeline entry point. · `CET313_Artificial_Intelligence_Prototype (1).ipynb`

### Static Export Contract

- [Frontend export builder](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/scripts/export_frontend_data.py): Python export · Central Python-to-browser handoff. · `scripts/export_frontend_data.py`
- [GeoJSON and metrics exports](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/data/exports/water_points.geojson): static data contract · Water points, AOIs, scenes, and metrics. · `data/exports/water_points.geojson`
- **Deployable public exports**: static assets · Copies served with the dashboard.

### Vite / Leaflet Dashboard

- [Static data loader and schemas](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/api/loadData.js): browser data boundary · Fetches and Zod-validates the four export resources. · `src/api/loadData.js`
- [Client filter state](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/state/filters.js): browser state · AOI, season, tier, cloud, and confidence filtering. · `src/state/filters.js`
- [Application coordinator](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/main.js): Vite entry · Coordinates loading, filtering, and rendering. · `src/main.js`
- [Leaflet map controller](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/map/mapController.js): map rendering · Renders AOIs, points, heatmaps, subsurface layers, and local summaries. · `src/map/mapController.js`
- [Dashboard panels](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/ui/dashboard.js): UI rendering · `src/ui/dashboard.js`
- [Panel tabs](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/src/ui/tabs.js): UI state · `src/ui/tabs.js`
- [Static Vite site](https://github.com/reneilwekeoagile061/landsat-water-analysis-ai/blob/main/index.html): deployment artifact · No application server or runtime jobs. · `index.html`

## Connections

- Planetary Computer STAC → STAC catalog fetch: catalog query
- STAC catalog fetch → Cached scene catalogs: cache metadata
- Cached scene catalogs → Water feature preparation: scene inputs
- ISRIC SoilGrids → SoilGrids fetch: clay request
- Water feature preparation → Potential labeling: prediction rows
- Terrain features → Spatial model training: terrain inputs
- Potential labeling → Spatial model training: training labels
- Spatial model training → Independent label checks: predictions
- Spatial model training → Subsurface evidence metrics: screening points
- SoilGrids fetch → Subsurface evidence metrics: modeled clay
- Subsurface evidence metrics → Frontend export builder: evidence and provenance
- Spatial model training → Frontend export builder: classified predictions
- Interactive analysis → Frontend export builder: prediction CSVs
- Frontend export builder → GeoJSON and metrics exports: generate
- GeoJSON and metrics exports → Deployable public exports: deploy copies
- Deployable public exports → Static data loader and schemas: static fetch
- Static data loader and schemas → Application coordinator: validated data
- Client filter state → Application coordinator: filter results
- Application coordinator → Leaflet map controller: map updates
- Application coordinator → Dashboard panels: dashboard refresh
- Panel tabs → Dashboard panels: panel visibility
- Static Vite site → Application coordinator: browser startup
