# aditya-pratap-bose/bhudrishti architecture

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

- Interactive diagram: https://gitdiagram.com/aditya-pratap-bose/bhudrishti
- Repository: https://github.com/aditya-pratap-bose/bhudrishti

## Overview

#### Purpose and Entry Points
This is a geospatial parcel-management platform with a Python API, browser dashboard, satellite/drone imagery workflows, and AI-assisted segmentation. The backend starts at `app/main.py`; API version routing is centralized in `app/api/v1/router.py`. Static browser entry pages are `frontend/login.html`, `frontend/dashboard.html`, and `frontend/workspace.html`.

#### API and Request Boundary
Versioned HTTP endpoints divide the domain into authentication, parcel management, imagery, and drone operations:
- `app/api/v1/auth.py`
- `app/api/v1/parcel.py`
- `app/api/v1/satellite.py`
- `app/api/v1/drone.py`

`app/api/v1/router.py` composes these modules into the application-facing API contract. The frontend calls this boundary through `frontend/js/api.js`, with page-specific behavior in `frontend/js/dashboard.js` and `frontend/js/map.js`.

#### Identity, Security, and Persistence
User identity and authorization are represented by `app/models/user.py`, request/response structures by `app/schemas/auth.py`, and security primitives by `app/core/security.py`. Database lifecycle/configuration belongs to `app/core/database.py`; environment-driven settings are in `app/core/config.py`.

This layer separates authenticated API operations from underlying user and parcel records.

#### Parcel Domain and Spatial Records
Parcels are the core managed entity, persisted through `app/models/parcel.py` and exposed through `app/schemas/parcel.py`. Parcel endpoints in `app/api/v1/parcel.py` connect authenticated clients to parcel creation, retrieval, and spatial-analysis workflows. `app/services/ulpin_generator.py` provides a domain-specific identifier-generation capability for parcels.

#### GIS Acquisition and Transformation
GIS services isolate external geospatial data and format handling:
- `app/services/gis/stac_service.py` handles STAC-oriented satellite catalog/search access.
- `app/services/gis/raster_service.py` processes raster imagery.
- `app/services/gis/vector_service.py` processes vector/geometric data.

Satellite API requests enter at `app/api/v1/satellite.py`, flow through these services, and return data suitable for map display or downstream segmentation. This is the principal boundary between the application and remote geospatial catalog/imagery infrastructure.

#### AI Segmentation Pipeline
AI functionality is separated from route handlers:
- `app/services/ai/sam_engine.py`
- `app/services/ai/post_processing.py`

Drone or satellite imagery can be supplied to the segmentation engine, likely producing raw masks or regions, then passed through post-processing to create usable geospatial results. `app/api/v1/drone.py` is the likely API control point for drone-image-driven analysis. The setup guidance in `setup/COLAB_SAM_SERVER.md` indicates SAM inference may run as a separately provisioned service/runtime rather than entirely inside the main API process.

#### Deployment and Client Runtime
The backend is containerized via `Dockerfile` and `docker_compose.yml`, with Python dependencies declared in `requirements.txt`. The frontend is a lightweight static HTML/CSS/JavaScript client (`frontend/js/auth.js`, `frontend/js/export.js`, `frontend/css/style.css`) rather than a bundled SPA framework. Environment variables are documented by `.env.example`; local and administrator provisioning are supported by `setup/LOCAL_SETUP.md` and `setup/create_admin.py`.

Main entry points: [`app/api/v1/router.py`](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/router.py) (v1 API router), [`app/api/v1/parcel.py`](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/parcel.py) (Parcel endpoints), [`app/api/v1/satellite.py`](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/satellite.py) (Satellite endpoints), [`app/services/ai/sam_engine.py`](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ai/sam_engine.py) (SAM inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_pages["Static pages<br/>HTML entry points<br/>[login.html]"]
  node_frontend_api["API client<br/>browser JS<br/>[api.js]"]
  node_map_ui["Dashboard &amp; map UI<br/>browser JS<br/>[map.js]"]
end

subgraph group_api["Python API"]
  node_backend["Application entry<br/>Python runtime<br/>[main.py]"]
  node_api_router["v1 API router<br/>route composition<br/>[router.py]"]
  node_auth_api["Auth endpoints<br/>HTTP routes<br/>[auth.py]"]
  node_parcel_api["Parcel endpoints<br/>HTTP routes<br/>[parcel.py]"]
  node_satellite_api["Satellite endpoints<br/>HTTP routes<br/>[satellite.py]"]
  node_drone_api["Drone endpoints<br/>HTTP routes<br/>[drone.py]"]
end

subgraph group_domain["Domain &amp; persistence"]
  node_security["Security primitives<br/>auth security<br/>[security.py]"]
  node_user["User identity<br/>data model<br/>[user.py]"]
  node_parcel[("Parcel records<br/>spatial data model<br/>[parcel.py]")]
  node_ulpin["ULPIN generator<br/>domain service<br/>[ulpin_generator.py]"]
end

subgraph group_gis["GIS workflows"]
  node_stac["STAC access<br/>GIS service<br/>[stac_service.py]"]
  node_raster["Raster processing<br/>GIS service<br/>[raster_service.py]"]
  node_vector["Vector processing<br/>GIS service<br/>[vector_service.py]"]
end

subgraph group_ai["AI segmentation"]
  node_sam{{"SAM inference<br/>AI service<br/>[sam_engine.py]"}}
  node_postprocess["Mask post-processing<br/>AI service<br/>[post_processing.py]"]
  node_sam_setup["SAM runtime setup<br/>provisioning guide"]
end

node_pages -->|"loads"| node_frontend_api
node_pages -->|"loads"| node_map_ui
node_frontend_api -->|"v1 HTTP calls"| node_api_router
node_map_ui -->|"uses"| node_frontend_api
node_backend -->|"mounts"| node_api_router
node_api_router -->|"composes"| node_auth_api
node_api_router -->|"composes"| node_parcel_api
node_api_router -->|"composes"| node_satellite_api
node_api_router -->|"composes"| node_drone_api
node_auth_api -->|"authenticates with"| node_security
node_auth_api -->|"manages"| node_user
node_parcel_api -->|"requires"| node_security
node_parcel_api -->|"manages"| node_parcel
node_parcel_api -->|"generates IDs"| node_ulpin
node_satellite_api -->|"searches"| node_stac
node_satellite_api -->|"processes imagery"| node_raster
node_satellite_api -->|"processes geometry"| node_vector
node_drone_api -->|"submits imagery"| node_sam
node_raster -->|"supplies imagery"| node_sam
node_sam -->|"raw masks"| node_postprocess
node_postprocess -->|"geospatial results"| node_vector
node_sam_setup -.->|"provisions"| node_sam

click node_pages "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/frontend/login.html"
click node_frontend_api "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/frontend/js/api.js"
click node_map_ui "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/frontend/js/map.js"
click node_backend "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/main.py"
click node_api_router "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/router.py"
click node_auth_api "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/auth.py"
click node_parcel_api "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/parcel.py"
click node_satellite_api "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/satellite.py"
click node_drone_api "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/drone.py"
click node_security "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/core/security.py"
click node_user "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/models/user.py"
click node_parcel "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/models/parcel.py"
click node_ulpin "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ulpin_generator.py"
click node_stac "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/gis/stac_service.py"
click node_raster "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/gis/raster_service.py"
click node_vector "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/gis/vector_service.py"
click node_sam "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ai/sam_engine.py"
click node_postprocess "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ai/post_processing.py"
click node_sam_setup "https://github.com/aditya-pratap-bose/bhudrishti/blob/main/setup/COLAB_SAM_SERVER.md"

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_pages,node_frontend_api,node_map_ui toneBlue
class node_backend,node_api_router,node_auth_api,node_parcel_api,node_satellite_api,node_drone_api toneAmber
class node_security,node_user,node_parcel,node_ulpin toneMint
class node_stac,node_raster,node_vector toneRose
class node_sam,node_postprocess,node_sam_setup toneIndigo
```

## Components

### Browser client

- [Static pages](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/frontend/login.html): HTML entry points · Login, dashboard, and workspace pages. · `frontend/login.html`
- [API client](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/frontend/js/api.js): browser JS · `frontend/js/api.js`
- [Dashboard & map UI](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/frontend/js/map.js): browser JS · `frontend/js/map.js`

### Python API

- [Application entry](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/main.py): Python runtime · `app/main.py`
- [v1 API router](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/router.py): route composition · `app/api/v1/router.py`
- [Auth endpoints](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/auth.py): HTTP routes · `app/api/v1/auth.py`
- [Parcel endpoints](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/parcel.py): HTTP routes · `app/api/v1/parcel.py`
- [Satellite endpoints](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/satellite.py): HTTP routes · `app/api/v1/satellite.py`
- [Drone endpoints](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/api/v1/drone.py): HTTP routes · `app/api/v1/drone.py`

### Domain & persistence

- [Security primitives](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/core/security.py): auth security · `app/core/security.py`
- [User identity](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/models/user.py): data model · `app/models/user.py`
- [Parcel records](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/models/parcel.py): spatial data model · `app/models/parcel.py`
- [ULPIN generator](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ulpin_generator.py): domain service · `app/services/ulpin_generator.py`

### GIS workflows

- [STAC access](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/gis/stac_service.py): GIS service · External satellite catalog and imagery boundary. · `app/services/gis/stac_service.py`
- [Raster processing](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/gis/raster_service.py): GIS service · `app/services/gis/raster_service.py`
- [Vector processing](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/gis/vector_service.py): GIS service · `app/services/gis/vector_service.py`

### AI segmentation

- [SAM inference](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ai/sam_engine.py): AI service · May run as separately provisioned inference runtime. · `app/services/ai/sam_engine.py`
- [Mask post-processing](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/app/services/ai/post_processing.py): AI service · Converts raw masks into usable geospatial results. · `app/services/ai/post_processing.py`
- [SAM runtime setup](https://github.com/aditya-pratap-bose/bhudrishti/blob/main/setup/COLAB_SAM_SERVER.md): provisioning guide · `setup/COLAB_SAM_SERVER.md`

## Connections

- Static pages → API client: loads
- Static pages → Dashboard & map UI: loads
- API client → v1 API router: v1 HTTP calls
- Dashboard & map UI → API client: uses
- Application entry → v1 API router: mounts
- v1 API router → Auth endpoints: composes
- v1 API router → Parcel endpoints: composes
- v1 API router → Satellite endpoints: composes
- v1 API router → Drone endpoints: composes
- Auth endpoints → Security primitives: authenticates with
- Auth endpoints → User identity: manages
- Parcel endpoints → Security primitives: requires
- Parcel endpoints → Parcel records: manages
- Parcel endpoints → ULPIN generator: generates IDs
- Satellite endpoints → STAC access: searches
- Satellite endpoints → Raster processing: processes imagery
- Satellite endpoints → Vector processing: processes geometry
- Drone endpoints → SAM inference: submits imagery
- Raster processing → SAM inference: supplies imagery
- SAM inference → Mask post-processing: raw masks
- Mask post-processing → Vector processing: geospatial results
- SAM runtime setup → SAM inference: provisions
