# aminilay/crop-yield-prediction-system architecture

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

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

## Overview

This is an Indian crop-yield prediction product: a farmer supplies crop, location, season, year, area, and optional farm-specific inputs; the system assembles weather and agricultural features, predicts yield, and presents results through a dashboard or REST API. The graph also preserves the training pipeline, forecast and risk capabilities, and explainability. Source excerpts establish several data and inference relationships; other product capabilities are included where documented in the README, without assuming unsampled implementation details.

Main entry points: [`src/pipeline/predict_pipeline.py`](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/pipeline/predict_pipeline.py) (Prediction Pipeline), [`dashboard/app.py`](https://github.com/aminilay/crop-yield-prediction-system/blob/main/dashboard/app.py) (Streamlit Dashboard), [`src/components/data_transformation.py`](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/data_transformation.py) (Data Transformation), [`src/components/weather_data.py`](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/weather_data.py) (Historical Weather)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_dashboard["Streamlit Dashboard<br/>[app.py]"]
  node_api["REST API<br/>[main.py]"]
end

subgraph group_inference["Prediction Runtime"]
  node_predict["Prediction Pipeline"]
  node_model["Yield Model<br/>[model.json]"]
  node_preprocessor["Feature Preprocessor<br/>[preprocessor.pkl]"]
  node_explain["SHAP Explainability<br/>[app.py]"]
  node_risk["Weather Risk Assessment<br/>[weather_risk.py]"]
end

subgraph group_features["Agricultural Features"]
  node_historical["Historical Weather<br/>[weather_data.py]"]
  node_forecast["Seasonal Forecast<br/>[forecast_data.py]"]
  node_coordinates["State Coordinates<br/>[geo_coords.py]"]
  node_irrigation["Irrigation Data<br/>[irrigation_data.py]"]
  node_fertilizer["Fertilizer Data<br/>[fertilizer_data.py]"]
  node_rawdata["Agricultural Datasets"]
end

subgraph group_training["Model Training"]
  node_trainpipeline["Training Pipeline<br/>[train_pipeline.py]"]
  node_ingestion["Data Ingestion<br/>[data_ingestion.py]"]
  node_transformation["Data Transformation"]
  node_trainer["Model Trainer<br/>[model_trainer.py]"]
end

subgraph group_shared["Shared Utilities"]
  node_common["Model Utilities<br/>[common.py]"]
end

node_farmer(("Farmer"))
node_externalweather(("Weather Services"))

node_farmer -->|"enters inputs"| node_dashboard
node_farmer -->|"submits request"| node_api
node_dashboard -.->|"requests prediction"| node_predict
node_api -.->|"requests prediction"| node_predict
node_predict -->|"fetches weather"| node_historical
node_predict -->|"gets irrigation"| node_irrigation
node_predict -->|"gets NPK"| node_fertilizer
node_historical -->|"looks up coordinates"| node_coordinates
node_forecast -->|"looks up coordinates"| node_coordinates
node_historical -->|"queries NASA POWER"| node_externalweather
node_forecast -->|"queries Open-Meteo"| node_externalweather
node_predict -.->|"transforms features"| node_preprocessor
node_predict -.->|"predicts yield"| node_model
node_dashboard -->|"presents explanations"| node_explain
node_api -->|"serves risk results"| node_risk
node_dashboard -->|"shows risk alerts"| node_risk
node_trainpipeline -->|"runs ingestion"| node_ingestion
node_trainpipeline -->|"runs transformation"| node_transformation
node_trainpipeline -->|"runs training"| node_trainer
node_transformation -->|"enriches with weather"| node_historical
node_transformation -->|"enriches irrigation"| node_irrigation
node_transformation -->|"enriches fertilizer"| node_fertilizer
node_trainer -.->|"produces model"| node_model
node_common -->|"loads model"| node_model
node_ingestion -.->|"reads datasets"| node_rawdata

click node_dashboard "https://github.com/aminilay/crop-yield-prediction-system/blob/main/dashboard/app.py"
click node_api "https://github.com/aminilay/crop-yield-prediction-system/blob/main/api/main.py"
click node_predict "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/pipeline/predict_pipeline.py"
click node_model "https://github.com/aminilay/crop-yield-prediction-system/blob/main/models/model.json"
click node_preprocessor "https://github.com/aminilay/crop-yield-prediction-system/blob/main/models/preprocessor.pkl"
click node_explain "https://github.com/aminilay/crop-yield-prediction-system/blob/main/dashboard/app.py"
click node_risk "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/weather_risk.py"
click node_historical "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/weather_data.py"
click node_forecast "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/forecast_data.py"
click node_coordinates "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/utils/geo_coords.py"
click node_irrigation "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/irrigation_data.py"
click node_fertilizer "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/fertilizer_data.py"
click node_rawdata "https://github.com/aminilay/crop-yield-prediction-system/tree/main/data/raw"
click node_trainpipeline "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/pipeline/train_pipeline.py"
click node_ingestion "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/data_ingestion.py"
click node_transformation "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/data_transformation.py"
click node_trainer "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/model_trainer.py"
click node_common "https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/utils/common.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_dashboard,node_api toneBlue
class node_predict,node_model,node_preprocessor,node_explain,node_risk toneAmber
class node_historical,node_forecast,node_coordinates,node_irrigation,node_fertilizer,node_rawdata toneMint
class node_trainpipeline,node_ingestion,node_transformation,node_trainer toneRose
class node_common,node_farmer,node_externalweather toneIndigo
```

## Components

### User Interfaces

- [Streamlit Dashboard](https://github.com/aminilay/crop-yield-prediction-system/blob/main/dashboard/app.py): `dashboard/app.py`
- [REST API](https://github.com/aminilay/crop-yield-prediction-system/blob/main/api/main.py): `api/main.py`

### Prediction Runtime

- [Prediction Pipeline](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/pipeline/predict_pipeline.py): `src/pipeline/predict_pipeline.py`
- [Yield Model](https://github.com/aminilay/crop-yield-prediction-system/blob/main/models/model.json): `models/model.json`
- [Feature Preprocessor](https://github.com/aminilay/crop-yield-prediction-system/blob/main/models/preprocessor.pkl): `models/preprocessor.pkl`
- [SHAP Explainability](https://github.com/aminilay/crop-yield-prediction-system/blob/main/dashboard/app.py): `dashboard/app.py`
- [Weather Risk Assessment](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/weather_risk.py): `src/components/weather_risk.py`

### Agricultural Features

- [Historical Weather](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/weather_data.py): `src/components/weather_data.py`
- [Seasonal Forecast](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/forecast_data.py): `src/components/forecast_data.py`
- [State Coordinates](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/utils/geo_coords.py): `src/utils/geo_coords.py`
- [Irrigation Data](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/irrigation_data.py): `src/components/irrigation_data.py`
- [Fertilizer Data](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/fertilizer_data.py): `src/components/fertilizer_data.py`
- [Agricultural Datasets](https://github.com/aminilay/crop-yield-prediction-system/tree/main/data/raw): `data/raw`

### Model Training

- [Training Pipeline](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/pipeline/train_pipeline.py): `src/pipeline/train_pipeline.py`
- [Data Ingestion](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/data_ingestion.py): `src/components/data_ingestion.py`
- [Data Transformation](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/data_transformation.py): `src/components/data_transformation.py`
- [Model Trainer](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/components/model_trainer.py): `src/components/model_trainer.py`

### Shared Utilities

- [Model Utilities](https://github.com/aminilay/crop-yield-prediction-system/blob/main/src/utils/common.py): `src/utils/common.py`

### Other components

- **Farmer**
- **Weather Services**

## Connections

- Farmer → Streamlit Dashboard: enters inputs (evidence: `README.md`)
- Farmer → REST API: submits request (evidence: `README.md`)
- Streamlit Dashboard → Prediction Pipeline: requests prediction
- REST API → Prediction Pipeline: requests prediction
- Prediction Pipeline → Historical Weather: fetches weather (evidence: `src/pipeline/predict_pipeline.py`)
- Prediction Pipeline → Irrigation Data: gets irrigation (evidence: `src/pipeline/predict_pipeline.py`)
- Prediction Pipeline → Fertilizer Data: gets NPK (evidence: `src/pipeline/predict_pipeline.py`)
- Historical Weather → State Coordinates: looks up coordinates (evidence: `src/components/weather_data.py`)
- Seasonal Forecast → State Coordinates: looks up coordinates (evidence: `src/components/forecast_data.py`)
- Historical Weather → Weather Services: queries NASA POWER (evidence: `README.md`)
- Seasonal Forecast → Weather Services: queries Open-Meteo (evidence: `README.md`)
- Prediction Pipeline → Feature Preprocessor: transforms features
- Prediction Pipeline → Yield Model: predicts yield
- Streamlit Dashboard → SHAP Explainability: presents explanations (evidence: `README.md`)
- REST API → Weather Risk Assessment: serves risk results (evidence: `README.md`)
- Streamlit Dashboard → Weather Risk Assessment: shows risk alerts (evidence: `README.md`)
- Training Pipeline → Data Ingestion: runs ingestion (evidence: `src/pipeline/train_pipeline.py`)
- Training Pipeline → Data Transformation: runs transformation (evidence: `src/pipeline/train_pipeline.py`)
- Training Pipeline → Model Trainer: runs training (evidence: `src/pipeline/train_pipeline.py`)
- Data Transformation → Historical Weather: enriches with weather (evidence: `src/components/data_transformation.py`)
- Data Transformation → Irrigation Data: enriches irrigation (evidence: `src/components/data_transformation.py`)
- Data Transformation → Fertilizer Data: enriches fertilizer (evidence: `src/components/data_transformation.py`)
- Model Trainer → Yield Model: produces model
- Model Utilities → Yield Model: loads model (evidence: `src/utils/common.py`)
- Data Ingestion → Agricultural Datasets: reads datasets
