# boyasaikiran/crop_recommendation_system architecture

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

- Interactive diagram: https://gitdiagram.com/boyasaikiran/crop_recommendation_system
- Repository: https://github.com/boyasaikiran/crop_recommendation_system

## Overview

This is a Streamlit crop-recommendation application backed by a previously trained Random Forest model. The workflow runs from user-entered soil and weather conditions, through NPK feature calculation and scaling, to crop prediction and display. A separate training script prepares the CSV data, fits and evaluates the model, then saves the model and scaler used by the app. The README documents these capabilities; the training and app source excerpts show the principal calls and data transfers. The empty main.py and image contents provide no additional runtime behavior to map.

Main entry points: [`crop_recommendation.py`](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py) (Fit scaler), [`app.py`](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py) (Scale input), [`crop_recommendation_model.pkl`](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation_model.pkl) (Trained model), [`scaler.pkl`](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/scaler.pkl) (Fitted scaler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Training pipeline"]
  node_data_prep["Data preparation"]
  node_features["Feature engineering"]
  node_scaler_training["Fit scaler"]
  node_model_training["Train classifier"]
  node_evaluation["Model evaluation"]
end

subgraph group_application["Recommendation app"]
  node_input_form["Condition inputs<br/>[app.py]"]
  node_input_features["NPK feature build<br/>[app.py]"]
  node_input_scaling["Scale input<br/>[app.py]"]
  node_crop_prediction["Crop prediction<br/>[app.py]"]
  node_recommendation["Recommendation display<br/>[app.py]"]
end

subgraph group_resources["Data and assets"]
  node_dataset["Crop dataset"]
  node_model_artifact["Trained model"]
  node_scaler_artifact["Fitted scaler<br/>[scaler.pkl]"]
  node_crop_images["Crop images"]
end

node_grower(("Grower"))

node_grower -->|"enters conditions"| node_input_form
node_input_form -->|"provides values"| node_input_features
node_input_features -->|"passes features"| node_input_scaling
node_scaler_artifact -->|"transforms with"| node_input_scaling
node_input_scaling -->|"passes scaled input"| node_crop_prediction
node_model_artifact -->|"predicts with"| node_crop_prediction
node_crop_prediction -->|"displays result"| node_recommendation
node_recommendation -->|"loads matching image"| node_crop_images
node_dataset -->|"loads data"| node_data_prep
node_data_prep -->|"engineers features"| node_features
node_features -->|"fits on features"| node_scaler_training
node_scaler_training -->|"scales data"| node_model_training
node_model_training -->|"evaluates predictions"| node_evaluation
node_model_training -->|"saves model"| node_model_artifact
node_scaler_training -->|"saves scaler"| node_scaler_artifact

click node_dataset "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/Crop_recommendation.csv"
click node_data_prep "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py"
click node_features "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py"
click node_scaler_training "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py"
click node_model_training "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py"
click node_evaluation "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py"
click node_model_artifact "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation_model.pkl"
click node_scaler_artifact "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/scaler.pkl"
click node_input_form "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py"
click node_input_features "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py"
click node_input_scaling "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py"
click node_crop_prediction "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py"
click node_recommendation "https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py"
click node_crop_images "https://github.com/boyasaikiran/crop_recommendation_system/tree/main/images"

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_data_prep,node_features,node_scaler_training,node_model_training,node_evaluation toneBlue
class node_input_form,node_input_features,node_input_scaling,node_crop_prediction,node_recommendation toneAmber
class node_dataset,node_model_artifact,node_scaler_artifact,node_crop_images toneMint
class node_grower toneIndigo
```

## Components

### Training pipeline

- [Data preparation](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py): `crop_recommendation.py`
- [Feature engineering](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py): `crop_recommendation.py`
- [Fit scaler](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py): `crop_recommendation.py`
- [Train classifier](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py): `crop_recommendation.py`
- [Model evaluation](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation.py): `crop_recommendation.py`

### Recommendation app

- [Condition inputs](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py): `app.py`
- [NPK feature build](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py): `app.py`
- [Scale input](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py): `app.py`
- [Crop prediction](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py): `app.py`
- [Recommendation display](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/app.py): `app.py`

### Data and assets

- [Crop dataset](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/Crop_recommendation.csv): `Crop_recommendation.csv`
- [Trained model](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/crop_recommendation_model.pkl): `crop_recommendation_model.pkl`
- [Fitted scaler](https://github.com/boyasaikiran/crop_recommendation_system/blob/main/scaler.pkl): `scaler.pkl`
- [Crop images](https://github.com/boyasaikiran/crop_recommendation_system/tree/main/images): `images`

### Other components

- **Grower**

## Connections

- Grower → Condition inputs: enters conditions (evidence: `app.py`)
- Condition inputs → NPK feature build: provides values (evidence: `app.py`)
- NPK feature build → Scale input: passes features (evidence: `app.py`)
- Fitted scaler → Scale input: transforms with (evidence: `app.py`)
- Scale input → Crop prediction: passes scaled input (evidence: `app.py`)
- Trained model → Crop prediction: predicts with (evidence: `app.py`)
- Crop prediction → Recommendation display: displays result (evidence: `app.py`)
- Recommendation display → Crop images: loads matching image (evidence: `app.py`)
- Crop dataset → Data preparation: loads data (evidence: `crop_recommendation.py`)
- Data preparation → Feature engineering: engineers features (evidence: `crop_recommendation.py`)
- Feature engineering → Fit scaler: fits on features (evidence: `crop_recommendation.py`)
- Fit scaler → Train classifier: scales data (evidence: `crop_recommendation.py`)
- Train classifier → Model evaluation: evaluates predictions (evidence: `crop_recommendation.py`)
- Train classifier → Trained model: saves model (evidence: `crop_recommendation.py`)
- Fit scaler → Fitted scaler: saves scaler (evidence: `crop_recommendation.py`)
