# rasalshubhamsr/crop-satellite architecture

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

- Interactive diagram: https://gitdiagram.com/rasalshubhamsr/crop-satellite
- Repository: https://github.com/rasalshubhamsr/crop-satellite

## Overview

1. **Repository shape**
   This repo is a small Python geospatial ML app with three main surfaces: a FastAPI backend, a static browser frontend, and an offline ML/document-processing sidecar. The README describes a richer “production” architecture, but the actual tree is closer to a demo/reference implementation with a local model and mocked geodata.

2. **Backend entry points**
   `src/api/main.py` is the likely ASGI application module used by Uvicorn, and the root `main.py` is probably a convenience launcher or thin wrapper. This is the runtime boundary where HTTP requests enter the system.

3. **Frontend boundary**
   `frontend/index.html`, `frontend/app.js`, and `frontend/style.css` form a vanilla JS single-page dashboard. It is the client-side presentation layer that talks to the FastAPI API and likely renders map/query results rather than performing heavy computation itself.

4. **Inference path**
   The inference subsystem lives under `src/models/`. `src/models/train.py` indicates a training pipeline, while `src/models/weights/rf_model.pkl` is the persisted model artifact used at runtime. The presence of a Random Forest pickle suggests the shipped inference path is lightweight and local, not a remote ML service.

5. **Geospatial/data ingestion layer**
   `src/data/mock_gee.py` is the key clue that external satellite ingestion is mocked or simulated in this repo. Conceptually it stands in for Google Earth Engine / Sentinel-style data access described in the README, but the checked-in code suggests a deterministic local data provider rather than a live cloud ingestion stack.

6. **End-to-end request flow**
   The main data flow is: browser submits a lat/lng or bounding-box request → FastAPI receives it → the data layer supplies mocked or derived geospatial inputs → the model layer loads `rf_model.pkl` and produces a crop classification response → JSON goes back to the frontend for display. That is the core architecture to diagram.

7. **Training vs serving boundary**
   `src/models/train.py` is separated from the runtime API, so training is an offline concern and serving is a read-only consumer of saved weights. That means model updates are likely manual/periodic rather than continuous or service-managed.

8. **Fallback / heuristic story**
   The README describes a deterministic agronomic fallback path for cloudy or missing imagery, but the file tree does not show a dedicated `engine/` package. For architecture purposes, treat fallback logic as part of the intended design rather than a clearly isolated runtime subsystem in the current repository.

9. **Testing and external integration**
   `test_esri.py` suggests integration testing against an Esri/geospatial endpoint or API contract. This indicates at least one external-service boundary in the project, likely used to validate map or spatial-query behavior.

10. **Supporting assets and docs**
   `refer-docs/` contains PDF reports and extracted text files, and `extract_pdfs.py` is a utility for document extraction/parsing. These are offline support assets, not part of the request-serving path, but they appear to inform the crop-classification domain and may feed experimentation or documentation workflows.

11. **Tooling/runtime**
   The project is Python-based (`pyproject.toml`, `requirements.txt`, `.python-version`) and is intended to run under a FastAPI/Uvicorn stack per the README. The architecture is therefore a local Python service with a static browser client and a serialized ML model artifact, rather than a multi-service distributed system in the checked-in code.

Main entry points: [`src/api/main.py`](https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/api/main.py) (API app), [`frontend/app.js`](https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/app.js) (Client app), [`frontend/index.html`](https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/index.html) (Dashboard), [`src/data/mock_gee.py`](https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/data/mock_gee.py) (Mock geodata)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Frontend"]
  node_node_frontend_index["Dashboard<br/>static html<br/>[index.html]"]
  node_node_frontend_js["Client app<br/>vanilla js<br/>[app.js]"]
  node_node_frontend_css["Styles<br/>css assets<br/>[style.css]"]
end

subgraph group_group_backend["Backend"]
  node_node_root_launcher["Launcher<br/>python entrypoint<br/>[main.py]"]
  node_node_api_main["API app<br/>FastAPI ASGI<br/>[main.py]"]
end

subgraph group_group_data["Data layer"]
  node_node_mock_gee[("Mock geodata<br/>data provider<br/>[mock_gee.py]")]
  node_node_request_inputs["Geo query<br/>request payload"]
  node_node_response["Prediction JSON<br/>api response"]
end

subgraph group_group_ml["ML pipeline"]
  node_node_model_train["Training<br/>offline train<br/>[train.py]"]
  node_node_model_weights[("RF model<br/>serialized model<br/>[rf_model.pkl]")]
  node_node_inference{{"Inference<br/>model runtime"}}
end

subgraph group_group_docs["Docs assets"]
  node_node_extract_pdfs["PDF extractor<br/>utility script<br/>[extract_pdfs.py]"]
  node_node_refer_docs["Reference docs<br/>report corpus"]
end

subgraph group_group_validation["Validation"]
  node_node_test_esri["Esri test<br/>integration test<br/>[test_esri.py]"]
end

node_node_root_launcher -->|"starts"| node_node_api_main
node_node_frontend_index -->|"loads"| node_node_frontend_js
node_node_frontend_index -->|"styles"| node_node_frontend_css
node_node_frontend_js -->|"calls API"| node_node_api_main
node_node_api_main -->|"receives"| node_node_request_inputs
node_node_api_main -->|"fetches data"| node_node_mock_gee
node_node_api_main -->|"predicts"| node_node_inference
node_node_inference -->|"loads"| node_node_model_weights
node_node_model_train -->|"writes"| node_node_model_weights
node_node_mock_gee -->|"features"| node_node_inference
node_node_inference -->|"returns"| node_node_response
node_node_response -->|"renders"| node_node_frontend_js
node_node_extract_pdfs -->|"processes"| node_node_refer_docs
node_node_test_esri -.->|"validates"| node_node_api_main

click node_node_root_launcher "https://github.com/rasalshubhamsr/crop-satellite/blob/master/main.py"
click node_node_api_main "https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/api/main.py"
click node_node_frontend_index "https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/index.html"
click node_node_frontend_js "https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/app.js"
click node_node_frontend_css "https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/style.css"
click node_node_mock_gee "https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/data/mock_gee.py"
click node_node_model_train "https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/models/train.py"
click node_node_model_weights "https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/models/weights/rf_model.pkl"
click node_node_extract_pdfs "https://github.com/rasalshubhamsr/crop-satellite/blob/master/extract_pdfs.py"
click node_node_refer_docs "https://github.com/rasalshubhamsr/crop-satellite/tree/master/refer-docs"
click node_node_test_esri "https://github.com/rasalshubhamsr/crop-satellite/blob/master/test_esri.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_node_frontend_index,node_node_frontend_js,node_node_frontend_css toneBlue
class node_node_root_launcher,node_node_api_main toneAmber
class node_node_mock_gee,node_node_request_inputs,node_node_response toneMint
class node_node_model_train,node_node_model_weights,node_node_inference toneRose
class node_node_extract_pdfs,node_node_refer_docs toneIndigo
class node_node_test_esri toneTeal
```

## Components

### Frontend

Static browser UI for interacting with the service

- [Dashboard](https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/index.html): static html · Browser entry page for the UI · `frontend/index.html`
- [Client app](https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/app.js): vanilla js · Frontend logic and API calls · `frontend/app.js`
- [Styles](https://github.com/rasalshubhamsr/crop-satellite/blob/master/frontend/style.css): css assets · Presentation styling for the dashboard · `frontend/style.css`

### Backend

FastAPI request handling and application entrypoints

- [Launcher](https://github.com/rasalshubhamsr/crop-satellite/blob/master/main.py): python entrypoint · Convenience top-level runner for the app · `main.py`
- [API app](https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/api/main.py): FastAPI ASGI · Main HTTP application module · `src/api/main.py`

### Data layer

Mocked geospatial data and request inputs

- [Mock geodata](https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/data/mock_gee.py): data provider · Local stand-in for satellite/geospatial ingestion · `src/data/mock_gee.py`
- **Geo query**: request payload · Lat/lng or bounding-box inputs from the client
- **Prediction JSON**: api response · Classification or analysis result returned to the client

### ML pipeline

Offline training and runtime model artifact

- [Training](https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/models/train.py): offline train · Builds the crop model outside the serving path · `src/models/train.py`
- [RF model](https://github.com/rasalshubhamsr/crop-satellite/blob/master/src/models/weights/rf_model.pkl): serialized model · Persisted Random Forest artifact used at runtime · `src/models/weights/rf_model.pkl`
- **Inference**: model runtime · Loads weights and produces crop predictions

### Docs assets

Reference reports and extraction utilities

- [PDF extractor](https://github.com/rasalshubhamsr/crop-satellite/blob/master/extract_pdfs.py): utility script · Offline document extraction and text conversion · `extract_pdfs.py`
- [Reference docs](https://github.com/rasalshubhamsr/crop-satellite/tree/master/refer-docs): report corpus · Background reports and extracted text files · `refer-docs`

### Validation

External integration checks

- [Esri test](https://github.com/rasalshubhamsr/crop-satellite/blob/master/test_esri.py): integration test · Checks geospatial/external service behavior · `test_esri.py`

## Connections

- Launcher → API app: starts · Launches the ASGI app
- Dashboard → Client app: loads · Browser page includes the client script
- Dashboard → Styles: styles · Browser page applies styles
- Client app → API app: calls API · Sends browser requests to the backend
- API app → Geo query: receives · Accepts geospatial query parameters
- API app → Mock geodata: fetches data · Uses mocked geospatial inputs instead of live ingestion
- API app → Inference: predicts · Routes processed data into model inference
- Inference → RF model: loads · Consumes the persisted model artifact
- Training → RF model: writes · Offline training produces the runtime weights
- Mock geodata → Inference: features · Provides inputs used for classification
- Inference → Prediction JSON: returns · Produces API-friendly prediction output
- Prediction JSON → Client app: renders · Client displays the returned result
- PDF extractor → Reference docs: processes · Extracts text from reference PDFs
- Esri test → API app: validates · Exercises geospatial/API integration behavior
