# chandruthangadurai2005/crop-yield-prediction-system architecture

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

- Interactive diagram: https://gitdiagram.com/chandruthangadurai2005/crop-yield-prediction-system
- Repository: https://github.com/chandruthangadurai2005/crop-yield-prediction-system

## Overview

#### Purpose and Entry Points
This is a local AI decision-support application for crop-yield prediction and crop recommendation. The backend entry point is `api/app.py`, run as a Flask server on port 5001. The browser client is the standalone page `ui/index.html`; it communicates with the Flask REST API rather than requiring a packaged web-server frontend.

#### API and Application Orchestration
`api/app.py` is the architectural center: it hosts REST endpoints, accepts farm/environment inputs, applies domain logic, invokes ML artifacts, and returns prediction/recommendation results. It also forms the boundary between the browser client and external location/weather services. CORS support allows `ui/index.html` to call the local API across origins.

#### Input Intelligence and Normalization
The application’s request-processing stage converts agricultural inputs into model-ready values: land-area standardization, rainfall/climate handling, seasonal detection from date/month, and categorical context such as crop, region, and season. GPS-derived location and reverse-geocoded context feed this stage when available. This logic is expected in `api/app.py`; no separate domain module is present in the tree.

#### Machine-Learning Inference
Yield estimation uses a scikit-learn Random Forest regression model. Runtime inference depends on externally downloaded serialized model binaries placed in `models/`; the repository includes the persisted feature schema at `models/feature_columns.pkl`. The feature-column artifact is a key compatibility boundary: normalized request data must match the training-time feature set and ordering before prediction.

#### Recommendation Flow
The system combines predicted productivity with crop-selection logic to recommend a suitable crop for the supplied environmental and agricultural conditions. Recommendation is application-level orchestration in `api/app.py`, likely evaluating candidate crop contexts through the same feature-engineering and inference path rather than exposing a separately stored recommendation model.

#### Data and Training Provenance
Raw agricultural data resides at `data/raw/crop_data.csv`; prepared training data is at `data/processed/cleaned_crop_yield_data.csv`. Exploratory and preprocessing workflows are notebook-based in `notebooks/preprocessing.ipynb` and `notebooks/check.ipynb`. These are offline training/preparation assets, distinct from serving; production inference consumes serialized artifacts under `models/`.

#### Runtime, External Dependencies, and Boundaries
The serving runtime is Python with Flask/Flask-CORS, pandas/NumPy, scikit-learn, and joblib. The client runtime is plain HTML/CSS/JavaScript in `ui/index.html`. External integrations include OpenWeather for climate/rainfall information and a reverse-geocoding API for location context. Model binaries are not versioned in this repository and must be obtained from the linked Google Drive source, making artifact availability a deployment prerequisite.

Main entry points: [`api/app.py`](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py) (Flask API), [`data/processed/cleaned_crop_yield_data.csv`](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/data/processed/cleaned_crop_yield_data.csv) (Prepared training data), [`ui/index.html`](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/ui/index.html) (Standalone UI), [`models/feature_columns.pkl`](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/models/feature_columns.pkl) (Feature schema)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_ui["Standalone UI<br/>HTML/CSS/JavaScript<br/>[index.html]"]
end

subgraph group_serving["Serving Runtime"]
  node_api["Flask API<br/>REST application<br/>[app.py]"]
  node_cors["CORS boundary<br/>Flask-CORS<br/>[app.py]"]
  node_normalization["Input normalization<br/>domain logic<br/>[app.py]"]
  node_feature_engineering["Feature assembly<br/>model compatibility<br/>[app.py]"]
  node_yield_inference["Yield inference<br/>Random Forest regression<br/>[app.py]"]
  node_recommendation["Crop recommendation<br/>application logic<br/>[app.py]"]
end

subgraph group_ml["ML Artifacts"]
  node_feature_schema["Feature schema<br/>persisted columns"]
  node_model_binaries[("Downloaded model binaries<br/>serialized ML artifacts")]
end

subgraph group_offline["Offline Data Preparation"]
  node_raw_data[("Raw crop data<br/>CSV dataset<br/>[crop_data.csv]")]
  node_prepared_data[("Prepared training data<br/>CSV dataset")]
  node_preprocessing["Preprocessing workflow<br/>notebook"]
  node_exploration["Data checks<br/>notebook<br/>[check.ipynb]"]
end

subgraph group_external["External Services"]
  node_weather{{"OpenWeather<br/>weather API"}}
  node_geocoding{{"Reverse geocoding API<br/>location API"}}
end

node_ui -->|"cross-origin REST requests"| node_cors
node_cors -->|"permits"| node_api
node_api -->|"processes inputs"| node_normalization
node_api -->|"fetches climate context"| node_weather
node_api -->|"resolves GPS context"| node_geocoding
node_weather -->|"rainfall and climate"| node_normalization
node_geocoding -->|"regional context"| node_normalization
node_normalization -->|"normalized fields"| node_feature_engineering
node_feature_schema -->|"column contract"| node_feature_engineering
node_feature_engineering -->|"ordered feature vector"| node_yield_inference
node_model_binaries -->|"loaded estimator"| node_yield_inference
node_yield_inference -->|"productivity estimates"| node_recommendation
node_recommendation -->|"recommendation result"| node_api
node_yield_inference -->|"yield result"| node_api
node_api -->|"JSON response"| node_ui
node_raw_data -->|"source data"| node_preprocessing
node_preprocessing -->|"cleaned training data"| node_prepared_data
node_prepared_data -->|"validation input"| node_exploration
node_prepared_data -.->|"training provenance"| node_model_binaries
node_prepared_data -.->|"feature provenance"| node_feature_schema

click node_ui "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/ui/index.html"
click node_api "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py"
click node_cors "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py"
click node_normalization "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py"
click node_feature_engineering "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py"
click node_yield_inference "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py"
click node_recommendation "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py"
click node_feature_schema "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/models/feature_columns.pkl"
click node_raw_data "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/data/raw/crop_data.csv"
click node_prepared_data "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/data/processed/cleaned_crop_yield_data.csv"
click node_preprocessing "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/notebooks/preprocessing.ipynb"
click node_exploration "https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/notebooks/check.ipynb"

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_ui toneBlue
class node_api,node_cors,node_normalization,node_feature_engineering,node_yield_inference,node_recommendation toneAmber
class node_feature_schema,node_model_binaries toneMint
class node_raw_data,node_prepared_data,node_preprocessing,node_exploration toneRose
class node_weather,node_geocoding toneIndigo
```

## Components

### Browser Client

- [Standalone UI](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/ui/index.html): HTML/CSS/JavaScript · Collects farm inputs and displays results. · `ui/index.html`

### Serving Runtime

- [Flask API](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py): REST application · Central request orchestration and inference boundary. · `api/app.py`
- [CORS boundary](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py): Flask-CORS · Allows the standalone browser page to call the local API. · `api/app.py`
- [Input normalization](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py): domain logic · Standardizes area, climate, season, and categorical inputs. · `api/app.py`
- [Feature assembly](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py): model compatibility · Builds ordered model-ready feature vectors. · `api/app.py`
- [Yield inference](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py): Random Forest regression · `api/app.py`
- [Crop recommendation](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/api/app.py): application logic · Evaluates crop contexts using predicted productivity. · `api/app.py`

### ML Artifacts

- [Feature schema](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/models/feature_columns.pkl): persisted columns · Defines training-time feature names and ordering. · `models/feature_columns.pkl`
- **Downloaded model binaries**: serialized ML artifacts · Deployment prerequisite not versioned in the repository.

### Offline Data Preparation

- [Raw crop data](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/data/raw/crop_data.csv): CSV dataset · `data/raw/crop_data.csv`
- [Prepared training data](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/data/processed/cleaned_crop_yield_data.csv): CSV dataset · `data/processed/cleaned_crop_yield_data.csv`
- [Preprocessing workflow](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/notebooks/preprocessing.ipynb): notebook · `notebooks/preprocessing.ipynb`
- [Data checks](https://github.com/chandruthangadurai2005/crop-yield-prediction-system/blob/main/notebooks/check.ipynb): notebook · `notebooks/check.ipynb`

### External Services

- **OpenWeather**: weather API · Supplies climate and rainfall context.
- **Reverse geocoding API**: location API · Converts GPS coordinates into location context.

## Connections

- Standalone UI → CORS boundary: cross-origin REST requests
- CORS boundary → Flask API: permits
- Flask API → Input normalization: processes inputs
- Flask API → OpenWeather: fetches climate context
- Flask API → Reverse geocoding API: resolves GPS context
- OpenWeather → Input normalization: rainfall and climate
- Reverse geocoding API → Input normalization: regional context
- Input normalization → Feature assembly: normalized fields
- Feature schema → Feature assembly: column contract
- Feature assembly → Yield inference: ordered feature vector
- Downloaded model binaries → Yield inference: loaded estimator
- Yield inference → Crop recommendation: productivity estimates
- Crop recommendation → Flask API: recommendation result
- Yield inference → Flask API: yield result
- Flask API → Standalone UI: JSON response
- Raw crop data → Preprocessing workflow: source data
- Preprocessing workflow → Prepared training data: cleaned training data
- Prepared training data → Data checks: validation input
- Prepared training data → Downloaded model binaries: training provenance
- Prepared training data → Feature schema: feature provenance
