# welpmemates/gsra architecture

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

- Interactive diagram: https://gitdiagram.com/welpmemates/gsra
- Repository: https://github.com/welpmemates/gsra

## Overview

GSRA is a site-readiness decision system for Ahmedabad. A user explores the map, selects a location, and receives a 0–100 score with factor breakdowns; the dashboard also exposes spatial layers, heatmaps, clusters, hotspots, and travel-time areas. Comparison, reporting, configurable use-case weights, and weight optimization are additional product workflows. The backend combines PostGIS metrics with explainable scoring, while ETL prepares spatial datasets and H3 grids. Connections for unsampled features are included only where the README documents them; source excerpts provide stronger evidence for the main scoring and map interactions.

Main entry points: [`backend/app/main.py`](https://github.com/welpmemates/gsra/blob/main/backend/app/main.py) (HTTP API), [`frontend/src/App.jsx`](https://github.com/welpmemates/gsra/blob/main/frontend/src/App.jsx) (Page router), [`frontend/src/api/api.js`](https://github.com/welpmemates/gsra/blob/main/frontend/src/api/api.js) (API client), [`frontend/src/components/map/IndiaMap.jsx`](https://github.com/welpmemates/gsra/blob/main/frontend/src/components/map/IndiaMap.jsx) (Interactive map)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_app["Page router<br/>[App.jsx]"]
  node_dashboard["Map dashboard<br/>[Dashboard.jsx]"]
  node_map["Interactive map<br/>[IndiaMap.jsx]"]
  node_state["UI state<br/>[useStore.js]"]
  node_api["API client<br/>[api.js]"]
  node_compare["Site comparison<br/>[Compare.jsx]"]
  node_report["Reports and export<br/>[Report.jsx]"]
  node_settings["Scoring settings<br/>[Settings.jsx]"]
end

subgraph group_service["Scoring service"]
  node_backend["HTTP API<br/>[main.py]"]
  node_query["Metric extraction<br/>[spatial_queries.py]"]
  node_engine["Score engine<br/>[engine.py]"]
  node_weights["Weight profiles<br/>[weights.py]"]
  node_optimizer["Weight optimizer<br/>[optimizer.py]"]
end

subgraph group_analysis["Spatial analysis"]
  node_layers["Spatial layers<br/>[main.py]"]
  node_clusters["DBSCAN clusters<br/>[dbscan_clusters.py]"]
  node_hotspots["Gi* hotspots<br/>[gi_star.py]"]
  node_isochrone["Isochrone service<br/>[isochrone.py]"]
  node_grid_score["Grid scoring<br/>[score_h3_grid.py]"]
end

subgraph group_data["Spatial data"]
  node_postgis[("PostGIS database")]
end

subgraph group_prep["Data preparation"]
  node_etl["Spatial ETL"]
  node_load["PostGIS loader<br/>[04_load_postgis.py]"]
  node_h3["H3 grid generation"]
end

node_user(("Analyst"))
node_osrm["OSRM routing"]

node_user -->|"uses"| node_app
node_app -->|"selects page"| node_dashboard
node_app -->|"selects page"| node_compare
node_app -->|"selects page"| node_report
node_app -->|"selects page"| node_settings
node_dashboard -->|"renders"| node_map
node_map -->|"requests scores"| node_api
node_map -->|"updates selection"| node_state
node_compare -->|"requests comparison"| node_api
node_report -->|"requests export"| node_api
node_settings -->|"sets weights"| node_state
node_api -->|"HTTP requests"| node_backend
node_backend -->|"fetches metrics"| node_query
node_backend -->|"computes score"| node_engine
node_engine -->|"uses profiles"| node_weights
node_query -->|"queries metrics"| node_postgis
node_backend -->|"optimizes weights"| node_optimizer
node_optimizer -->|"evaluates scores"| node_engine
node_optimizer -->|"loads metrics"| node_query
node_backend -->|"serves GeoJSON"| node_layers
node_backend -->|"dispatches cluster query"| node_clusters
node_backend -->|"dispatches hotspot query"| node_hotspots
node_backend -->|"routes request"| node_isochrone
node_isochrone -->|"requests routes"| node_osrm
node_etl -->|"prepares data"| node_load
node_load -->|"loads datasets"| node_postgis
node_h3 -->|"stores grid"| node_postgis
node_grid_score -.->|"scores grid"| node_h3
node_backend -.->|"serves heatmap"| node_grid_score

click node_app "https://github.com/welpmemates/gsra/blob/main/frontend/src/App.jsx"
click node_dashboard "https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Dashboard.jsx"
click node_map "https://github.com/welpmemates/gsra/blob/main/frontend/src/components/map/IndiaMap.jsx"
click node_state "https://github.com/welpmemates/gsra/blob/main/frontend/src/store/useStore.js"
click node_api "https://github.com/welpmemates/gsra/blob/main/frontend/src/api/api.js"
click node_compare "https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Compare.jsx"
click node_report "https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Report.jsx"
click node_settings "https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Settings.jsx"
click node_backend "https://github.com/welpmemates/gsra/blob/main/backend/app/main.py"
click node_query "https://github.com/welpmemates/gsra/blob/main/backend/app/db/spatial_queries.py"
click node_engine "https://github.com/welpmemates/gsra/blob/main/backend/app/scoring/engine.py"
click node_weights "https://github.com/welpmemates/gsra/blob/main/backend/app/scoring/weights.py"
click node_optimizer "https://github.com/welpmemates/gsra/blob/main/backend/app/optimizer.py"
click node_layers "https://github.com/welpmemates/gsra/blob/main/backend/app/main.py"
click node_clusters "https://github.com/welpmemates/gsra/blob/main/backend/app/clustering/dbscan_clusters.py"
click node_hotspots "https://github.com/welpmemates/gsra/blob/main/backend/app/clustering/gi_star.py"
click node_isochrone "https://github.com/welpmemates/gsra/blob/main/backend/app/routing/isochrone.py"
click node_etl "https://github.com/welpmemates/gsra/blob/main/backend/etl/02_reproject_and_clean.py"
click node_load "https://github.com/welpmemates/gsra/blob/main/backend/etl/04_load_postgis.py"
click node_h3 "https://github.com/welpmemates/gsra/blob/main/backend/etl/05_generate_h3_grid.py"
click node_grid_score "https://github.com/welpmemates/gsra/blob/main/backend/app/scripts/score_h3_grid.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_app,node_dashboard,node_map,node_state,node_api,node_compare,node_report,node_settings toneBlue
class node_backend,node_query,node_engine,node_weights,node_optimizer toneAmber
class node_layers,node_clusters,node_hotspots,node_isochrone,node_grid_score toneMint
class node_postgis toneRose
class node_etl,node_load,node_h3,node_user,node_osrm toneIndigo
```

## Components

### Web application

- [Page router](https://github.com/welpmemates/gsra/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Map dashboard](https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Interactive map](https://github.com/welpmemates/gsra/blob/main/frontend/src/components/map/IndiaMap.jsx): `frontend/src/components/map/IndiaMap.jsx`
- [UI state](https://github.com/welpmemates/gsra/blob/main/frontend/src/store/useStore.js): `frontend/src/store/useStore.js`
- [API client](https://github.com/welpmemates/gsra/blob/main/frontend/src/api/api.js): `frontend/src/api/api.js`
- [Site comparison](https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Compare.jsx): `frontend/src/pages/Compare.jsx`
- [Reports and export](https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Report.jsx): `frontend/src/pages/Report.jsx`
- [Scoring settings](https://github.com/welpmemates/gsra/blob/main/frontend/src/pages/Settings.jsx): `frontend/src/pages/Settings.jsx`

### Scoring service

- [HTTP API](https://github.com/welpmemates/gsra/blob/main/backend/app/main.py): `backend/app/main.py`
- [Metric extraction](https://github.com/welpmemates/gsra/blob/main/backend/app/db/spatial_queries.py): `backend/app/db/spatial_queries.py`
- [Score engine](https://github.com/welpmemates/gsra/blob/main/backend/app/scoring/engine.py): `backend/app/scoring/engine.py`
- [Weight profiles](https://github.com/welpmemates/gsra/blob/main/backend/app/scoring/weights.py): `backend/app/scoring/weights.py`
- [Weight optimizer](https://github.com/welpmemates/gsra/blob/main/backend/app/optimizer.py): `backend/app/optimizer.py`

### Spatial analysis

- [Spatial layers](https://github.com/welpmemates/gsra/blob/main/backend/app/main.py): `backend/app/main.py`
- [DBSCAN clusters](https://github.com/welpmemates/gsra/blob/main/backend/app/clustering/dbscan_clusters.py): `backend/app/clustering/dbscan_clusters.py`
- [Gi* hotspots](https://github.com/welpmemates/gsra/blob/main/backend/app/clustering/gi_star.py): `backend/app/clustering/gi_star.py`
- [Isochrone service](https://github.com/welpmemates/gsra/blob/main/backend/app/routing/isochrone.py): `backend/app/routing/isochrone.py`
- [Grid scoring](https://github.com/welpmemates/gsra/blob/main/backend/app/scripts/score_h3_grid.py): `backend/app/scripts/score_h3_grid.py`

### Spatial data

- **PostGIS database**

### Data preparation

- [Spatial ETL](https://github.com/welpmemates/gsra/blob/main/backend/etl/02_reproject_and_clean.py): `backend/etl/02_reproject_and_clean.py`
- [PostGIS loader](https://github.com/welpmemates/gsra/blob/main/backend/etl/04_load_postgis.py): `backend/etl/04_load_postgis.py`
- [H3 grid generation](https://github.com/welpmemates/gsra/blob/main/backend/etl/05_generate_h3_grid.py): `backend/etl/05_generate_h3_grid.py`

### Other components

- **Analyst**
- **OSRM routing**

## Connections

- Analyst → Page router: uses
- Page router → Map dashboard: selects page (evidence: `frontend/src/App.jsx`)
- Page router → Site comparison: selects page (evidence: `frontend/src/App.jsx`)
- Page router → Reports and export: selects page (evidence: `frontend/src/App.jsx`)
- Page router → Scoring settings: selects page (evidence: `frontend/src/App.jsx`)
- Map dashboard → Interactive map: renders (evidence: `frontend/src/pages/Dashboard.jsx`)
- Interactive map → API client: requests scores (evidence: `frontend/src/components/map/IndiaMap.jsx`)
- Interactive map → UI state: updates selection (evidence: `frontend/src/components/map/IndiaMap.jsx`)
- Site comparison → API client: requests comparison (evidence: `frontend/src/pages/Compare.jsx`)
- Reports and export → API client: requests export (evidence: `frontend/src/pages/Report.jsx`)
- Scoring settings → UI state: sets weights (evidence: `frontend/src/pages/Settings.jsx`)
- API client → HTTP API: HTTP requests (evidence: `frontend/src/api/api.js`)
- HTTP API → Metric extraction: fetches metrics (evidence: `backend/app/main.py`)
- HTTP API → Score engine: computes score (evidence: `backend/app/main.py`)
- Score engine → Weight profiles: uses profiles (evidence: `backend/app/scoring/engine.py`)
- Metric extraction → PostGIS database: queries metrics (evidence: `backend/app/db/spatial_queries.py`)
- HTTP API → Weight optimizer: optimizes weights (evidence: `backend/app/main.py`)
- Weight optimizer → Score engine: evaluates scores (evidence: `backend/app/optimizer.py`)
- Weight optimizer → Metric extraction: loads metrics (evidence: `backend/app/optimizer.py`)
- HTTP API → Spatial layers: serves GeoJSON (evidence: `README.md`)
- HTTP API → DBSCAN clusters: dispatches cluster query (evidence: `backend/app/main.py`)
- HTTP API → Gi* hotspots: dispatches hotspot query (evidence: `backend/app/main.py`)
- HTTP API → Isochrone service: routes request (evidence: `backend/app/main.py`)
- Isochrone service → OSRM routing: requests routes (evidence: `README.md`)
- Spatial ETL → PostGIS loader: prepares data (evidence: `README.md`)
- PostGIS loader → PostGIS database: loads datasets (evidence: `README.md`)
- H3 grid generation → PostGIS database: stores grid (evidence: `README.md`)
- Grid scoring → H3 grid generation: scores grid
- HTTP API → Grid scoring: serves heatmap
