# zengroot147/groundwater-potential-zone-identification architecture

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

- Interactive diagram: https://gitdiagram.com/zengroot147/groundwater-potential-zone-identification
- Repository: https://github.com/zengroot147/groundwater-potential-zone-identification

## Overview

1. **What this repository is**
   - A groundwater potential prediction application with two main runtime layers: a **Python/Flask backend** and a **React/TypeScript frontend**.
   - The `webapp/` folder appears to be the primary integrated app; the top-level `frontend/` directory is a near-duplicate React client and likely a parallel/extracted copy.

2. **Primary runtime boundary**
   - **Browser users** interact with the React SPA.
   - The SPA sends API calls to the **Flask service** on port 5000.
   - The backend returns **predictions, statistics, map bounds, borewell estimates, reports, and overlay assets**.

3. **Backend architecture**
   - The core server is `webapp/app_hybrid.py`.
   - It exposes endpoints under `/api/` for:
     - groundwater prediction by coordinates
     - analytics/statistics
     - map boundary metadata
     - borewell depth prediction
     - PDF/report generation
   - It also serves the groundwater overlay image (`gwp_overlay.png`), and CORS is enabled so the frontend can call it cross-origin during development.

4. **Backend responsibilities**
   - The README indicates the backend does the domain-heavy work:
     - reads/uses the groundwater map overlay
     - computes environmental features such as NDVI, NDWI, and elevation from coordinates
     - integrates weather data
     - produces dashboard statistics
   - This is the main computation and data-access boundary in the system.

5. **Frontend architecture**
   - The frontend is a **single-page app** built with React 18, TypeScript, Vite, TailwindCSS, React Router, Leaflet/react-leaflet, Chart.js, Framer Motion, and Axios.
   - It is organized around pages such as:
     - `LandingPage`
     - `MapViewer`
     - `Dashboard`
     - `About`
     - `BatchAnalysis`
     - `ExplainableAI`
     - `LocationComparison`
     - `AdvancedFeatures`

6. **Frontend feature boundaries**
   - `InteractiveMap` is the map-centric component and is the main spatial interaction surface.
   - `Navbar`, `HeroVisual`, `StatsBar`, and `DataSourcesStrip` support the landing/dashboard experience.
   - The app is presentation-heavy, but all real prediction logic is delegated to the backend through HTTP calls.

7. **Core data flow**
   - User selects a point on the map or enters coordinates.
   - Frontend sends the coordinates to the Flask API.
   - Backend processes the location against geospatial/environmental inputs and returns a groundwater classification plus derived metrics.
   - The frontend renders the result in the map view and dashboard charts.

8. **Geospatial and scientific assets**
   - The repo includes multiple data files that likely feed preprocessing or offline analysis:
     - raster imagery: `.tif`, `.jp2`
     - vector GIS layers: `.shp`, `.shx`, `.dbf`, `.prj`
     - climate/model data: `.nc`
     - sample inputs: `sample_batch_locations.csv`
     - notebooks/scripts for analysis: `Groundwater.ipynb`, `debug_coordinates.py`, `get_coordinates.py`
   - These assets are central to the domain model even though the live app exposes them through the backend.

9. **Legacy / alternate UI paths**
   - `webapp/templates/` contains old Flask-rendered HTML pages, but the README says those routes were removed in favor of the React SPA.
   - Several backup versions exist for the map page (`MapViewer_backup.tsx`, `MapViewer_old.tsx`) and landing page.
   - This suggests an evolution from server-rendered pages to a client-rendered SPA with API-backed data.

10. **Build and deployment shape**
   - Frontend development uses Vite; built artifacts are checked in under `frontend/dist` and `webapp/frontend/dist`.
   - Python dependencies live in `webapp/requirements.txt`.
   - Windows startup scripts (`START_ALL_SERVERS.bat`, `start.bat`, `start.ps1`) indicate the app is intended for local desktop launch with separate backend/frontend terminals.

11. **What to draw in an architecture diagram**
   - Show three main boxes:
     - **Browser / React SPA**
     - **Flask API backend**
     - **Geospatial/data assets and analysis inputs**
   - Draw request/response arrows from SPA to Flask.
   - Draw backend-to-data arrows to the overlay image, raster/vector datasets, and any weather/API integration.
   - Treat report generation and analytics as backend subflows, not separate services.

12. **Important architectural takeaway**
   - This is not a generic web app: it is a **GIS/ML-style decision support system** where the frontend is mostly an interactive visualization layer, and the backend owns the actual groundwater inference and data processing.

Main entry points: [`webapp/app_hybrid.py`](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py) (Flask API), [`webapp/frontend/src/main.tsx`](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/main.tsx) (Routing), [`webapp/frontend/src/App.tsx`](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/App.tsx) (React SPA), [`webapp/frontend/src/components/InteractiveMap.tsx`](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/components/InteractiveMap.tsx) (Map view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Client app"]
  node_n1(("Browser<br/>user/client"))
  node_n2["React SPA<br/>frontend app<br/>[App.tsx]"]
  node_n3["Routing<br/>navigation<br/>[main.tsx]"]
  node_n4["Map view<br/>spatial UI<br/>[InteractiveMap.tsx]"]
  node_n5["Dashboard<br/>analytics UI<br/>[Dashboard.tsx]"]
  node_n6["Landing UI<br/>presentation<br/>[LandingPage.tsx]"]
  node_n7["Feature pages<br/>views<br/>[BatchAnalysis.tsx]"]
  node_n8["HTTP client<br/>api client"]
end

subgraph group_g2["API backend"]
  node_n9["Flask API<br/>backend app<br/>[app_hybrid.py]"]
  node_n10["Prediction API<br/>endpoint set<br/>[app_hybrid.py]"]
  node_n11["Analytics API<br/>endpoint set<br/>[app_hybrid.py]"]
  node_n12["Report API<br/>endpoint set<br/>[app_hybrid.py]"]
  node_n13[("Overlay asset<br/>map layer")]
  node_n14["CORS / static<br/>middleware<br/>[app_hybrid.py]"]
  node_n20["Legacy templates<br/>server-rendered UI<br/>[index.html]"]
end

subgraph group_g3["Data and analysis"]
  node_n15[("Geospatial rasters<br/>dataset<br/>[out.tif]")]
  node_n16[("GIS vectors<br/>dataset<br/>[District.shp]")]
  node_n17[("Climate model<br/>dataset<br/>[rf_1deg_dec_clm.nc]")]
  node_n18["Sample inputs<br/>analysis data"]
  node_n19["Notebook analysis<br/>offline analysis<br/>[Groundwater.ipynb]"]
end

node_n1 -->|"uses"| node_n2
node_n2 -->|"routes"| node_n3
node_n3 -->|"opens"| node_n4
node_n3 -->|"opens"| node_n5
node_n3 -->|"opens"| node_n6
node_n3 -->|"opens"| node_n7
node_n4 -->|"requests"| node_n8
node_n5 -->|"requests"| node_n8
node_n7 -->|"requests"| node_n8
node_n8 -->|"calls"| node_n9
node_n9 -->|"exposes"| node_n10
node_n9 -->|"exposes"| node_n11
node_n9 -->|"exposes"| node_n12
node_n9 -->|"serves"| node_n13
node_n9 -->|"enables"| node_n14
node_n10 -->|"uses"| node_n15
node_n10 -->|"uses"| node_n16
node_n10 -->|"uses"| node_n17
node_n11 -->|"summarizes"| node_n13
node_n12 -->|"uses"| node_n18
node_n18 -->|"feeds"| node_n19
node_n20 -.->|"legacy path"| node_n9

click node_n2 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/App.tsx"
click node_n3 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/main.tsx"
click node_n4 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/components/InteractiveMap.tsx"
click node_n5 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/pages/Dashboard.tsx"
click node_n6 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/pages/LandingPage.tsx"
click node_n7 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/pages/BatchAnalysis.tsx"
click node_n9 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py"
click node_n10 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py"
click node_n11 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py"
click node_n12 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py"
click node_n14 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py"
click node_n15 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/out.tif"
click node_n16 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/District.shp"
click node_n17 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/rf_1deg_dec_clm.nc"
click node_n18 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/sample_batch_locations.csv"
click node_n19 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/Groundwater.ipynb"
click node_n20 "https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/templates/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_n1,node_n2,node_n3,node_n4,node_n5,node_n6,node_n7,node_n8 toneBlue
class node_n9,node_n10,node_n11,node_n12,node_n13,node_n14,node_n20 toneAmber
class node_n15,node_n16,node_n17,node_n18,node_n19 toneMint
```

## Components

### Client app

React single-page application used by browser users

- **Browser**: user/client · End users interact with the SPA in the browser
- [React SPA](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/App.tsx): frontend app · Primary TypeScript single-page application · `webapp/frontend/src/App.tsx`
- [Routing](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/main.tsx): navigation · Routes between landing, map, dashboard, and feature pages · `webapp/frontend/src/main.tsx`
- [Map view](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/components/InteractiveMap.tsx): spatial UI · Interactive mapping and coordinate selection surface · `webapp/frontend/src/components/InteractiveMap.tsx`
- [Dashboard](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/pages/Dashboard.tsx): analytics UI · Charts and summary panels for predictions and statistics · `webapp/frontend/src/pages/Dashboard.tsx`
- [Landing UI](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/pages/LandingPage.tsx): presentation · Entry experience with hero, nav, and summary components · `webapp/frontend/src/pages/LandingPage.tsx`
- [Feature pages](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/frontend/src/pages/BatchAnalysis.tsx): views · Batch analysis, explainable AI, comparison, and advanced features pages · `webapp/frontend/src/pages/BatchAnalysis.tsx`
- **HTTP client**: api client · Browser-side calls to the Flask API

### API backend

Flask service that computes groundwater results and serves assets

- [Flask API](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py): backend app · Core server that exposes groundwater prediction and metadata endpoints · `webapp/app_hybrid.py`
- [Prediction API](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py): endpoint set · Coordinate-based groundwater classification and derived metrics · `webapp/app_hybrid.py`
- [Analytics API](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py): endpoint set · Statistics, dashboard summaries, and map boundary metadata · `webapp/app_hybrid.py`
- [Report API](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py): endpoint set · Borewell estimates and PDF/report generation endpoints · `webapp/app_hybrid.py`
- **Overlay asset**: map layer · Groundwater overlay imagery served by the backend
- [CORS / static](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/app_hybrid.py): middleware · Cross-origin access and static asset serving for the SPA · `webapp/app_hybrid.py`
- [Legacy templates](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/webapp/templates/index.html): server-rendered UI · Old Flask HTML pages retained as legacy paths · `webapp/templates/index.html`

### Data and analysis

Geospatial layers, models, and offline analysis inputs

- [Geospatial rasters](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/out.tif): dataset · Raster inputs used for terrain, climate, and environmental context · `out.tif`
- [GIS vectors](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/District.shp): dataset · District and boundary shapefiles used for spatial context · `District.shp`
- [Climate model](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/rf_1deg_dec_clm.nc): dataset · NetCDF climate or model input used by the backend · `rf_1deg_dec_clm.nc`
- [Sample inputs](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/sample_batch_locations.csv): analysis data · CSV sample locations and batch-analysis inputs · `sample_batch_locations.csv`
- [Notebook analysis](https://github.com/zengroot147/groundwater-potential-zone-identification/blob/main/Groundwater.ipynb): offline analysis · Exploratory groundwater analysis and feature experimentation · `Groundwater.ipynb`

## Connections

- Browser → React SPA: uses · Users interact with the application through the React SPA
- React SPA → Routing: routes · SPA routes to pages and feature views
- Routing → Map view: opens · One major route centers on interactive map workflows
- Routing → Dashboard: opens · One major route shows prediction summaries and charts
- Routing → Landing UI: opens · Landing pages provide entry and overview content
- Routing → Feature pages: opens · Additional pages expose advanced workflows
- Map view → HTTP client: requests · Map interactions trigger backend lookup and prediction calls
- Dashboard → HTTP client: requests · Dashboard fetches analytics and statistics from the API
- Feature pages → HTTP client: requests · Advanced workflows rely on API-backed inference and reports
- HTTP client → Flask API: calls · Frontend communicates with the Flask service
- Flask API → Prediction API: exposes · Prediction endpoints implement the main groundwater inference flow
- Flask API → Analytics API: exposes · Analytics endpoints provide summaries and map metadata
- Flask API → Report API: exposes · Report and borewell endpoints support decision workflows
- Flask API → Overlay asset: serves · Backend serves overlay imagery used by the map UI
- Flask API → CORS / static: enables · CORS and static serving make SPA-backend integration work
- Prediction API → Geospatial rasters: uses · Predictions incorporate raster-derived environmental features
- Prediction API → GIS vectors: uses · Predictions use district and boundary layers for spatial context
- Prediction API → Climate model: uses · Predictions may incorporate climate/model inputs
- Analytics API → Overlay asset: summarizes · Analytics and map metadata are tied to overlay context
- Report API → Sample inputs: uses · Batch and report workflows consume sample location data
- Sample inputs → Notebook analysis: feeds · Offline notebooks and scripts support analysis and experimentation
- Legacy templates → Flask API: legacy path · Old server-rendered pages were replaced by the SPA
