# omkar0816/hydrosnap-3d architecture

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

- Interactive diagram: https://gitdiagram.com/omkar0816/hydrosnap-3d
- Repository: https://github.com/omkar0816/hydrosnap-3d

## Overview

HydroSnap 3D is a browser-based watershed field-evidence and monitoring prototype for geo-coded photos, watershed boundaries, and satellite indicators; its demo records and analysis are illustrative, and no backend or database is connected. The main workflow begins when a field officer uses the browser app to prepare and save an observation: the app checks evidence and location in the client, stores the observation locally, and attempts to sync it when online. Other user workflows inspect watersheds and assets, view dashboard/map analytics, and generate exports or inspection PDFs.

#### Components

##### Browser app and user workflows
- **Browser entry point** — `src/main.tsx`: mounts the React application and imports its global styles.
- **Routes and shared app state** — `src/App.tsx`: defines route entry points for dashboard, map, upload, asset passport, and workspace views, plus shared watershed, layer, and notification state.
- **Upload and evidence capture** — `src/pages/ImageUploadPage.tsx`: provides the field-observation workflow, including image metadata/GPS handling and officer-confirmed location; the excerpt shows client trust assessment and save-oriented UI.
- **Dashboard and workspace screens** — `src/pages/DashboardPage.tsx`: implements the dashboard; `src/pages/WorkspacePage.tsx` groups workspace sections such as evidence, interventions, reports, and administration.
- **Asset passport and inspection report** — `src/pages/AssetPassportPage.tsx`: presents an asset’s inspection history and uses the report-PDF utility.
- **Map analysis screen** — `src/pages/MapAnalysisPage.tsx`: composes map analysis, timeline, watershed details, and export functionality.
- **Map rendering and interaction** — `src/components/maps/WatershedMap.tsx`: renders watershed and asset layers with MapLibre, optional PMTiles boundaries, basemaps, and measurement tools.
- **Shared map detail and timeline UI** — `src/components/maps/WatershedPanel.tsx`: shows selected-watershed details; `src/components/maps/MapTimeline.tsx` renders timeline controls.
- **App shell and sync UI** — `src/components/layout/AppLayout.tsx`: provides the shared shell; `src/components/sync/SyncIndicator.tsx` presents queue/sync status and controls.
- **Trust explanation UI** — `src/components/evidence/TrustPanel.tsx`: displays trust status and reasons.

##### Data access, persistence, and integration
- **Query and mutation hooks** — `src/hooks/useHydroSnap.ts`: exposes React Query reads and mutations for users, watersheds, assets, observations, analysis, interventions, and reports.
- **Domain data service** — `src/services/hydrosnapService.ts`: centralizes data I/O, selects mock or API behavior, and handles local-first observation saves.
- **Demo records** — `src/services/mock/mockData.ts`: holds the separately maintained demo data used by mock-mode reads.
- **HTTP client** — `src/services/apiClient.ts`: performs configured REST requests and converts non-success responses to `ApiError`.
- **Offline queue** — `src/services/offlineStore.ts`: persists queued observations in browser IndexedDB.
- **Sync orchestration** — `src/services/syncService.ts`: claims eligible queue records, uploads them, updates retry/sync state, and supports sync listeners.
- **Domain and GeoJSON types** — `src/types/domain.ts`: defines observations, assets, watersheds, trust assessments, sync state, and analysis types; `src/types/geojson.ts` defines the geometric structures they use.
- **Environment selection** — `src/config/env.ts`: reads API, mock-mode, and optional watershed-PMTiles settings.

##### Spatial analysis, evidence, and outputs
- **Spatial operations** — `src/utils/geo.ts`: implements coordinate validation, point-in-watershed resolution, geometry bounds, distances, and nearest-stream calculations.
- **Evidence trust rules** — `src/utils/trust.ts`: evaluates evidence consistency and produces a client-side trust assessment.
- **Asset matching and watershed summaries** — `src/utils/assetMatch.ts` matches nearby assets; `src/utils/watershedStats.ts` computes per-watershed counts.
- **Timeline calculations** — `src/utils/timeline.ts`: prepares timeline data used by map views.
- **Exports and inspection PDF** — `src/utils/exporters.ts` provides GeoJSON, CSV, and audit JSON exports; `src/utils/reportPdf.ts` generates a browser-side inspection PDF.

##### Data preparation
- **Watershed boundary preparation** — `scripts/prepare_watersheds/prepare_watersheds.py`: prepares real boundary data for PMTiles use, as documented in the README.
- **Satellite-index pipeline fixture** — `scripts/compute_indices/compute_indices.py`: computes NDVI/NDWI analysis for the documented pipeline fixture; the README cautions that this is not a real asset result.

#### Relationships

- **Field officer -> Browser app and user workflows**: initiates observation entry; evidence: `README.md`
- **Browser app entry point -> Routes and shared app state**: renders the application; evidence: `src/main.tsx`
- **Routes and shared app state -> Upload and evidence capture**: routes `/upload` to the upload page; evidence: `src/App.tsx`
- **Routes and shared app state -> Dashboard and workspace screens**: routes `/` and workspace paths to their screens; evidence: `src/App.tsx`
- **Routes and shared app state -> Asset passport and inspection report**: routes `/assets/:assetId`; evidence: `src/App.tsx`
- **Routes and shared app state -> Map analysis screen**: routes `/map`; evidence: `src/App.tsx`
- **Upload and evidence capture -> Query and mutation hooks**: uses the data hook; evidence: `src/pages/ImageUploadPage.tsx`
- **Map analysis screen -> Query and mutation hooks**: uses the data hook; evidence: `src/pages/MapAnalysisPage.tsx`
- **Asset passport and inspection report -> Query and mutation hooks**: uses the data hook; evidence: `src/pages/AssetPassportPage.tsx`
- **Query and mutation hooks -> Domain data service**: binds reads and mutations to service methods; evidence: `src/hooks/useHydroSnap.ts`
- **Domain data service -> Demo records**: uses demo collections in mock mode; evidence: `src/services/hydrosnapService.ts`
- **Domain data service -> Offline queue**: enqueues locally saved observations and reads queued records; evidence: `src/services/hydrosnapService.ts`
- **Domain data service -> Sync orchestration**: triggers sync after saving when online; evidence: `src/services/hydrosnapService.ts`
- **Domain data service -> HTTP client**: uses API requests when mock mode is disabled; evidence: `src/services/hydrosnapService.ts`
- **Sync orchestration -> Offline queue**: reads, claims, and updates queued records; evidence: `src/services/syncService.ts`
- **Sync orchestration -> HTTP client**: posts observations to the uploads endpoint outside mock mode; evidence: `src/services/syncService.ts`
- **Upload and evidence capture -> Evidence trust rules**: computes a trust preview for confirmed evidence; evidence: `src/pages/ImageUploadPage.tsx`
- **Upload and evidence capture -> Spatial operations**: uses location conversion and spatial helpers; evidence: `src/pages/ImageUploadPage.tsx`
- **Map rendering and interaction -> Spatial operations**: uses geometry bounds, distance, and center calculations; evidence: `src/components/maps/WatershedMap.tsx`
- **Asset passport and inspection report -> Exports and inspection PDF**: uses the PDF utility; evidence: `src/pages/AssetPassportPage.tsx`
- **Map analysis screen -> Timeline calculations**: uses timeline utilities; evidence: `src/pages/MapAnalysisPage.tsx`

#### Coverage limits

The repository and README describe a frontend-only prototype, not a deployed backend. The API’s server-side behavior, authentication, production persistence, and real satellite-monitoring operation are not established by these inputs. Script excerpts establish the existence of preparation and index-computation tools, but not their runtime connection to the app. Several source excerpts are partial, so relationships not shown above may exist.

Main entry points: [`src/App.tsx`](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/App.tsx) (Routes and app state), [`src/services/hydrosnapService.ts`](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/hydrosnapService.ts) (HydroSnap service), [`src/pages/ImageUploadPage.tsx`](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/ImageUploadPage.tsx) (Evidence capture), [`src/hooks/useHydroSnap.ts`](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/hooks/useHydroSnap.ts) (Query and mutation hooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser workflows"]
  node_entry["Browser entry<br/>React entry point"]
  node_routes["Routes and app state<br/>React routes"]
  node_upload["Evidence capture<br/>Upload workflow"]
  node_dashboard["Dashboard and workspace<br/>User screens"]
  node_passport["Asset passport<br/>Asset screen"]
  node_map["Map analysis<br/>Map screen"]
end

subgraph group_data["Data and sync"]
  node_hooks["Query and mutation hooks<br/>React Query"]
  node_service["HydroSnap service<br/>Domain data service"]
  node_demo["Demo records<br/>Mock data"]
  node_offline[("Offline queue<br/>IndexedDB store")]
  node_sync["Sync orchestration<br/>Sync service"]
  node_http["HTTP client<br/>REST client"]
end

subgraph group_spatial["Spatial and evidence"]
  node_trust["Evidence trust rules<br/>Client-side assessment"]
  node_geo["Spatial operations<br/>Geospatial utilities"]
  node_maprender["Map rendering<br/>MapLibre component"]
  node_pdf["Inspection PDF<br/>Browser PDF utility"]
  node_timeline["Timeline calculations<br/>Timeline utility"]
end

node_officer(("Field officer<br/>External actor"))

node_officer -->|"starts observation"| node_entry
node_entry -->|"renders app"| node_routes
node_routes -->|"routes to"| node_upload
node_routes -->|"routes to"| node_dashboard
node_routes -->|"routes to"| node_passport
node_routes -->|"routes to"| node_map
node_upload -->|"uses data hooks"| node_hooks
node_map -->|"uses data hooks"| node_hooks
node_passport -->|"uses data hooks"| node_hooks
node_hooks -->|"calls service"| node_service
node_service -->|"uses mock data"| node_demo
node_service -->|"queues observations"| node_offline
node_service -->|"triggers sync"| node_sync
node_service -->|"uses API client"| node_http
node_sync -->|"reads and updates"| node_offline
node_sync -->|"uploads observations"| node_http
node_upload -->|"assesses evidence"| node_trust
node_upload -->|"uses spatial helpers"| node_geo
node_maprender -->|"uses geometry helpers"| node_geo
node_passport -->|"generates report"| node_pdf
node_map -->|"uses timeline utilities"| node_timeline

click node_entry "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/main.tsx"
click node_routes "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/App.tsx"
click node_upload "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/ImageUploadPage.tsx"
click node_dashboard "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/DashboardPage.tsx"
click node_passport "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/AssetPassportPage.tsx"
click node_map "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/MapAnalysisPage.tsx"
click node_hooks "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/hooks/useHydroSnap.ts"
click node_service "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/hydrosnapService.ts"
click node_demo "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/mock/mockData.ts"
click node_offline "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/offlineStore.ts"
click node_sync "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/syncService.ts"
click node_http "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/apiClient.ts"
click node_trust "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/trust.ts"
click node_geo "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/geo.ts"
click node_maprender "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/components/maps/WatershedMap.tsx"
click node_pdf "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/reportPdf.ts"
click node_timeline "https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/timeline.ts"

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_entry,node_routes,node_upload,node_dashboard,node_passport,node_map toneBlue
class node_hooks,node_service,node_demo,node_offline,node_sync,node_http toneAmber
class node_trust,node_geo,node_maprender,node_pdf,node_timeline toneMint
class node_officer toneIndigo
```

## Components

### Browser workflows

- [Browser entry](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/main.tsx): React entry point · `src/main.tsx`
- [Routes and app state](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/App.tsx): React routes · `src/App.tsx`
- [Evidence capture](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/ImageUploadPage.tsx): Upload workflow · Client-side evidence and location checks; observation save is local-first. · `src/pages/ImageUploadPage.tsx`
- [Dashboard and workspace](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/DashboardPage.tsx): User screens · `src/pages/DashboardPage.tsx`
- [Asset passport](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/AssetPassportPage.tsx): Asset screen · `src/pages/AssetPassportPage.tsx`
- [Map analysis](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/pages/MapAnalysisPage.tsx): Map screen · `src/pages/MapAnalysisPage.tsx`

### Data and sync

- [Query and mutation hooks](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/hooks/useHydroSnap.ts): React Query · `src/hooks/useHydroSnap.ts`
- [HydroSnap service](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/hydrosnapService.ts): Domain data service · Selects mock or API behavior and handles local-first observation saves. · `src/services/hydrosnapService.ts`
- [Demo records](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/mock/mockData.ts): Mock data · Illustrative records used by mock-mode reads. · `src/services/mock/mockData.ts`
- [Offline queue](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/offlineStore.ts): IndexedDB store · Stores queued observations in the browser. · `src/services/offlineStore.ts`
- [Sync orchestration](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/syncService.ts): Sync service · `src/services/syncService.ts`
- [HTTP client](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/services/apiClient.ts): REST client · API server-side behavior and production persistence are not established. · `src/services/apiClient.ts`

### Spatial and evidence

- [Evidence trust rules](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/trust.ts): Client-side assessment · `src/utils/trust.ts`
- [Spatial operations](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/geo.ts): Geospatial utilities · `src/utils/geo.ts`
- [Map rendering](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/components/maps/WatershedMap.tsx): MapLibre component · Renders watershed and asset layers with optional PMTiles boundaries. · `src/components/maps/WatershedMap.tsx`
- [Inspection PDF](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/reportPdf.ts): Browser PDF utility · `src/utils/reportPdf.ts`
- [Timeline calculations](https://github.com/omkar0816/hydrosnap-3d/blob/main/src/utils/timeline.ts): Timeline utility · `src/utils/timeline.ts`

### Other components

- **Field officer**: External actor

## Connections

- Field officer → Browser entry: starts observation (evidence: `README.md`)
- Browser entry → Routes and app state: renders app (evidence: `src/main.tsx`)
- Routes and app state → Evidence capture: routes to (evidence: `src/App.tsx`)
- Routes and app state → Dashboard and workspace: routes to (evidence: `src/App.tsx`)
- Routes and app state → Asset passport: routes to (evidence: `src/App.tsx`)
- Routes and app state → Map analysis: routes to (evidence: `src/App.tsx`)
- Evidence capture → Query and mutation hooks: uses data hooks (evidence: `src/pages/ImageUploadPage.tsx`)
- Map analysis → Query and mutation hooks: uses data hooks (evidence: `src/pages/MapAnalysisPage.tsx`)
- Asset passport → Query and mutation hooks: uses data hooks (evidence: `src/pages/AssetPassportPage.tsx`)
- Query and mutation hooks → HydroSnap service: calls service (evidence: `src/hooks/useHydroSnap.ts`)
- HydroSnap service → Demo records: uses mock data (evidence: `src/services/hydrosnapService.ts`)
- HydroSnap service → Offline queue: queues observations (evidence: `src/services/hydrosnapService.ts`)
- HydroSnap service → Sync orchestration: triggers sync (evidence: `src/services/hydrosnapService.ts`)
- HydroSnap service → HTTP client: uses API client (evidence: `src/services/hydrosnapService.ts`)
- Sync orchestration → Offline queue: reads and updates (evidence: `src/services/syncService.ts`)
- Sync orchestration → HTTP client: uploads observations (evidence: `src/services/syncService.ts`)
- Evidence capture → Evidence trust rules: assesses evidence (evidence: `src/pages/ImageUploadPage.tsx`)
- Evidence capture → Spatial operations: uses spatial helpers (evidence: `src/pages/ImageUploadPage.tsx`)
- Map rendering → Spatial operations: uses geometry helpers (evidence: `src/components/maps/WatershedMap.tsx`)
- Asset passport → Inspection PDF: generates report (evidence: `src/pages/AssetPassportPage.tsx`)
- Map analysis → Timeline calculations: uses timeline utilities (evidence: `src/pages/MapAnalysisPage.tsx`)
