# vanivarun/crop-recommendation-system architecture

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

- Interactive diagram: https://gitdiagram.com/vanivarun/crop-recommendation-system
- Repository: https://github.com/vanivarun/crop-recommendation-system

## Overview

AgriSense is a Streamlit crop-recommendation app with Farmer and Expert input modes. Both lead to validation and Random Forest predictions; Farmer Mode can also use location-based weather. Results include ranked crops, confidence information, crop explanations, and model analytics. The repository also contains a separate training pipeline that reads the crop dataset and exports model artifacts. The app and prediction module overlap in artifact access. Some app behavior is documented in the README but not visible in the partial source excerpts, so uncertain internal links are omitted.

Main entry points: [`app.py`](https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py) (Farmer / expert inputs), [`src/predict.py`](https://github.com/vanivarun/crop-recommendation-system/blob/master/src/predict.py) (Validate and predict), [`src/weather.py`](https://github.com/vanivarun/crop-recommendation-system/blob/master/src/weather.py) (Weather lookup), [`models`](https://github.com/vanivarun/crop-recommendation-system/tree/master/models) (Trained model artifacts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_app_inputs["Farmer / expert inputs<br/>[app.py]"]
  node_app_weather_ui["Weather auto-fill<br/>[app.py]"]
  node_app_results["Ranked results<br/>[app.py]"]
  node_app_explanation["Crop explanation<br/>[app.py]"]
  node_app_analytics["Model analytics<br/>[app.py]"]
end

subgraph group_recommendation["Recommendation runtime"]
  node_predict["Validate and predict<br/>[predict.py]"]
end

subgraph group_model_lifecycle["Model lifecycle"]
  node_artifacts[("Trained model artifacts")]
  node_training["Train and evaluate<br/>[train_model.py]"]
  node_dataset["Crop training data<br/>[crop_data.csv]"]
end

subgraph group_integrations["External information"]
  node_weather["Weather lookup<br/>[weather.py]"]
end

node_farmer(("Farmer"))
node_expert(("Agricultural expert"))
node_nominatim["Nominatim geocoding"]
node_open_meteo["Open-Meteo weather"]
node_wiki["Wikipedia summaries"]

node_farmer -->|"enters field details"| node_app_inputs
node_expert -->|"enters lab values"| node_app_inputs
node_app_inputs -.->|"requests weather"| node_app_weather_ui
node_app_weather_ui -.->|"fetches location weather"| node_weather
node_weather -.->|"geocodes location"| node_nominatim
node_weather -.->|"fetches conditions"| node_open_meteo
node_app_inputs -->|"submits field values"| node_predict
node_predict -->|"loads model files"| node_artifacts
node_predict -->|"returns ranked crops"| node_app_results
node_app_results -->|"enriches top crop"| node_app_explanation
node_app_explanation -.->|"requests crop summary"| node_wiki
node_app_analytics -->|"loads metrics and model"| node_artifacts
node_training -->|"reads samples"| node_dataset
node_training -->|"exports trained files"| node_artifacts

click node_app_inputs "https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py"
click node_app_weather_ui "https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py"
click node_app_results "https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py"
click node_app_explanation "https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py"
click node_app_analytics "https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py"
click node_weather "https://github.com/vanivarun/crop-recommendation-system/blob/master/src/weather.py"
click node_predict "https://github.com/vanivarun/crop-recommendation-system/blob/master/src/predict.py"
click node_artifacts "https://github.com/vanivarun/crop-recommendation-system/tree/master/models"
click node_training "https://github.com/vanivarun/crop-recommendation-system/blob/master/src/train_model.py"
click node_dataset "https://github.com/vanivarun/crop-recommendation-system/blob/master/data/crop_data.csv"

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_app_inputs,node_app_weather_ui,node_app_results,node_app_explanation,node_app_analytics toneBlue
class node_predict toneAmber
class node_artifacts,node_training,node_dataset toneMint
class node_weather toneRose
class node_farmer,node_expert,node_nominatim,node_open_meteo,node_wiki toneIndigo
```

## Components

### User experience

- [Farmer / expert inputs](https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py): `app.py`
- [Weather auto-fill](https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py): `app.py`
- [Ranked results](https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py): `app.py`
- [Crop explanation](https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py): `app.py`
- [Model analytics](https://github.com/vanivarun/crop-recommendation-system/blob/master/app.py): `app.py`

### Recommendation runtime

- [Validate and predict](https://github.com/vanivarun/crop-recommendation-system/blob/master/src/predict.py): `src/predict.py`

### Model lifecycle

- [Trained model artifacts](https://github.com/vanivarun/crop-recommendation-system/tree/master/models): `models`
- [Train and evaluate](https://github.com/vanivarun/crop-recommendation-system/blob/master/src/train_model.py): `src/train_model.py`
- [Crop training data](https://github.com/vanivarun/crop-recommendation-system/blob/master/data/crop_data.csv): `data/crop_data.csv`

### External information

- [Weather lookup](https://github.com/vanivarun/crop-recommendation-system/blob/master/src/weather.py): `src/weather.py`

### Other components

- **Farmer**
- **Agricultural expert**
- **Nominatim geocoding**
- **Open-Meteo weather**
- **Wikipedia summaries**

## Connections

- Farmer → Farmer / expert inputs: enters field details
- Agricultural expert → Farmer / expert inputs: enters lab values
- Farmer / expert inputs → Weather auto-fill: requests weather
- Weather auto-fill → Weather lookup: fetches location weather
- Weather lookup → Nominatim geocoding: geocodes location
- Weather lookup → Open-Meteo weather: fetches conditions
- Farmer / expert inputs → Validate and predict: submits field values
- Validate and predict → Trained model artifacts: loads model files
- Validate and predict → Ranked results: returns ranked crops
- Ranked results → Crop explanation: enriches top crop
- Crop explanation → Wikipedia summaries: requests crop summary
- Model analytics → Trained model artifacts: loads metrics and model
- Train and evaluate → Crop training data: reads samples
- Train and evaluate → Trained model artifacts: exports trained files
