# shreyashkumar07/crop-yield-prediction-app architecture

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

- Interactive diagram: https://gitdiagram.com/shreyashkumar07/crop-yield-prediction-app
- Repository: https://github.com/shreyashkumar07/crop-yield-prediction-app

## Overview

##### Main Modules/Components
- User Interface (UI): Represented by the Streamlit app (app.py) which accepts user inputs (e.g., area, crop type, year, rainfall, pesticides, and temperature) and displays results.
- Data Processing Components:
- Preprocessing objects — scaler (scaler.pkl), label encoder (label_encoder_area.pkl), and one-hot encoder (one_hot_encoder_item.pkl) – used to properly format user input.
- Prediction Engine: The pre-trained MLP regressor model (mlp_regressor.pkl) that receives processed inputs and outputs a crop yield prediction.
- Data Source: The historical dataset file (yield_df.csv) is the foundation on which the model was trained (also referenced in the “Crop Prediction MLP.ipynb” notebook).
- Supplementary Materials:
- The Jupyter Notebook showing data preprocessing and model training.
- A demo video (“Crop Cast Demo.mp4”) that explains usage or showcases the system in action.
- License and README showing setup instructions and project overview.

##### Interactions/Flow
- That user inputs collected from the UI are first sent to the preprocessing block:
- Prediction Engine: Using the pre-trained MLP model, this component takes the transformed input data and returns a crop yield prediction.
- Finally, the prediction is passed back to the UI where it is displayed to the user.

##### Architectural Patterns and Design Principles
- Modular Design: Each step (UI, preprocessing, prediction) is separated into distinct components for clarity and maintenance.
- Reusability and Extensibility: The design incorporates pre-trained assets so that the prediction pipeline can be updated with improved models or preprocessing techniques without major rework.

##### Technologies and Key Files
- Streamlit (app.py) for building the interactive web interface.
- Scikit-learn / Joblib for handling the serialization and deserialization of the model and preprocessor objects.
- Jupyter Notebook (Crop Prediction MLP.ipynb) provides background on training and evaluation, which supports the production deployment.
- CSV dataset (yield_df.csv) as the data source for model training.
- Additionally, the demo video and license documentation are part of the repository, giving context to usage and rights.

- Below that, branch into two flows:
- Side notes for offline components like the “Crop Prediction MLP.ipynb” demonstrating model training and evaluation, and “yield_df.csv” indicating data sources.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction Layer
    subgraph "User Interaction Layer"
        User["User (Web Browser)"]:::user
        UI["Streamlit App (app.py)"]:::ui
        User -->|"sends_input"| UI
    end

    %% Backend Inference Pipeline
    subgraph "Backend Inference Pipeline"
        UI -->|"forwards_input"| Preproc["Data Preprocessing Module"]:::preprocessing
        %% Preprocessing sub-components
        Preproc --> SC["Scaler (scaler.pkl)"]:::preprocessing
        Preproc --> LE["Label Encoder (label_encoder_area.pkl)"]:::preprocessing
        Preproc --> OHE["One-Hot Encoder (one_hot_encoder_item.pkl)"]:::preprocessing
        %% Aggregated processed data output node
        SC -->|"outputs"| Processed["Processed Features"]:::preprocessing
        LE -->|"outputs"| Processed
        OHE -->|"outputs"| Processed
        Processed -->|"feeds"| Pred["MLP Prediction Engine (mlp_regressor.pkl)"]:::ml
        Pred -->|"returns_prediction"| UI
    end

    %% Artifacts and Documentation
    subgraph "Artifacts & Documentation"
        Data["Historical Crop Data (yield_df.csv)"]:::data
        Notebook["Training Notebook (Crop Prediction MLP.ipynb)"]:::notebook
        Data -->|"used_for_training"| Notebook
        Notebook -->|"develops_model"| Pred
        Demo["Demo Video (Crop Cast Demo.mp4)"]:::demo
        Doc["Documentation (README.md & LICENSE)"]:::doc
    end

    %% Click Events
    click UI "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/app.py"
    click SC "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/scaler.pkl"
    click LE "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/label_encoder_area.pkl"
    click OHE "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/one_hot_encoder_item.pkl"
    click Pred "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/mlp_regressor.pkl"
    click Data "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/yield_df.csv"
    click Notebook "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/Crop Prediction MLP.ipynb"
    click Demo "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/Crop Cast Demo.mp4"
    click Doc "https://github.com/shreyashkumar07/crop-yield-prediction-app/blob/main/README.md"

    %% Styles
    classDef user fill:#fde2e2,stroke:#b30000,stroke-width:2px;
    classDef ui fill:#e2f7fd,stroke:#0066cc,stroke-width:2px;
    classDef preprocessing fill:#e2f9e1,stroke:#228b22,stroke-width:2px;
    classDef ml fill:#fff2cc,stroke:#ff9900,stroke-width:2px;
    classDef data fill:#e6e6fa,stroke:#663399,stroke-width:2px;
    classDef notebook fill:#fff0f5,stroke:#db7093,stroke-width:2px;
    classDef demo fill:#ffe6e6,stroke:#cc3300,stroke-width:2px;
    classDef doc fill:#e0e0ff,stroke:#00008b,stroke-width:2px;
```
