How rasalshubhamsr/crop-satellite works
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: main.py API app · app.js Client app · index.html Dashboard · mock_gee.py Mock geodata
Components 14
Frontend
Static browser UI for interacting with the service
- Dashboard · Browser entry page for the UI
frontend/index.html - Client app · Frontend logic and API calls
frontend/app.js - Styles · Presentation styling for the dashboard
frontend/style.css
Backend
FastAPI request handling and application entrypoints
Data layer
Mocked geospatial data and request inputs
- Mock geodata · Local stand-in for satellite/geospatial ingestion
src/data/mock_gee.py - Geo query · Lat/lng or bounding-box inputs from the client
- Prediction JSON · Classification or analysis result returned to the client
ML pipeline
Offline training and runtime model artifact
Docs assets
Reference reports and extraction utilities
- PDF extractor · Offline document extraction and text conversion
extract_pdfs.py - Reference docs · Background reports and extracted text files
refer-docs
Validation
External integration checks
- Esri test · Checks geospatial/external service behavior
test_esri.py
Connections 14
- 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