# sarthakgarg1204/cropgenie architecture

> Architecture diagram of the GitHub repository sarthakgarg1204/cropgenie, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sarthakgarg1204/cropgenie
- Repository: https://github.com/sarthakgarg1204/cropgenie

## Overview

Step 1: Identify the Project Type and Purpose
- CropGenie is a single-page, ML-powered web application built with Streamlit.
- Purpose: provide crop and fertilizer recommendations using a trained Decision Tree model and a lookup dataset.

Step 2: Analyze the File Structure
Top-level files:
- app.py             – Streamlit app entry point (UI + controller logic)
- crop_model.pkl     – Serialized Decision Tree Classifier
- crop_scaler.sav    – Serialized StandardScaler for feature normalization
- Fertilizer Prediction.csv – CSV lookup table for fertilizer recommendations
- requirements.txt   – Python dependencies
- README.md, LICENSE, .gitignore

Step 3: Pull Insights from README
- Frontend: Streamlit
- ML Model: scikit-learn Decision Tree
- Data handling: pandas, numpy
- Deployment: Streamlit Cloud or local

a. Main Components
1. User Browser
2. Streamlit Server (app.py)
- UI Layer (sidebar, tabs, input widgets)
- Controller Layer (handles user inputs, orchestrates calls)
3. ML Inference Layer
- Feature Scaler (crop_scaler.sav)
- Decision Tree Model (crop_model.pkl)
4. Data Lookup Layer
- Fertilizer Prediction CSV
5. Optional Persistence/Logging (could be a file or external database, not present today)
6. Deployment Infrastructure
- Localhost or Streamlit Cloud

b. Relationships & Data Flow
1. User enters soil/crop parameters in the browser →
2. Streamlit Server captures inputs →
3. Controller sends raw inputs to the Scaler →
4. Scaled features feed the Decision Tree →
5. Controller retrieves fertilizer info from the CSV lookup →
6. Combined recommendation pushed back to the UI →
7. Results rendered in the browser

c. Architectural Patterns & Principles
- Layered Monolith: clear separation of UI, business logic, ML inference, and data lookup.
- Single Responsibility: app.py orchestrates but model/scaler/data are external resources.
- Configuration-as-Code: dependencies in requirements.txt, models as artifacts.

d. Key Technologies & Frameworks
- Streamlit: UI framework
- scikit-learn: model + scaler
- pandas/numpy: data ingestion & manipulation
- CSV file: static dataset
- Streamlit Cloud / local server: hosting

- “Frontend vs. Backend” even though both run in the same Python process.
- CSV lookup as a distinct “Data Source” component.
- Deployment target (Streamlit Cloud).

Step 6: Diagramming Guidelines
- Use clear, consistent labels:
- “User Browser”
- “Streamlit App (UI + Controller)”
- “Feature Scaler”
- “Decision Tree Model”
- “Fertilizer Lookup CSV”
- “Streamlit Cloud / Localhost”
- Inputs → UI → Controller → Scaler → Model → Controller → UI → Browser
- Controller → CSV → Controller
- UI components (e.g., blue rectangles)
- Processing/inference (e.g., green rounded rectangles)

Step 7: Final Notes
- Be as granular as needed: you could even split the Controller into “Input Validation,” “Model Invocation,” and “Result Formatting.”
- Don’t over-engineer—capture all moving parts: UI widgets, model artifacts, data lookup, and hosting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    A["User Browser"]:::ui

    %% Application Layer
    subgraph "Streamlit App (UI + Controller Layer)"
        B["UI Layer (Streamlit widgets)"]:::ui
        C["Controller Layer"]:::process
    end

    %% ML Inference Layer
    subgraph "ML Inference"
        D["Feature Scaler"]:::process
        E["Decision Tree Model"]:::process
    end

    %% Data Source Layer
    F["Fertilizer Lookup CSV"]:::data

    %% Deployment Layer
    G["Streamlit Cloud / Localhost"]:::infra

    %% Artifacts & Config
    subgraph "Project Artifacts & Config"
        H1["requirements.txt"]:::data
        H2["README.md"]:::data
        H3["LICENSE"]:::data
        H4[".gitignore"]:::data
    end

    %% Data Flow
    A -->|"Inputs"| B
    B -->|"User inputs"| C
    C -->|"raw inputs"| D
    D -->|"scaled features"| E
    E -->|"predictions"| C
    C -->|"lookup query"| F
    F -->|"fertilizer info"| C
    C -->|"recommendation"| B
    B -->|"render results"| A
    G -->|"hosts"| B

    %% Click Events
    click C "https://github.com/sarthakgarg1204/cropgenie/blob/main/app.py"
    click D "https://github.com/sarthakgarg1204/cropgenie/blob/main/crop_scaler.sav"
    click E "https://github.com/sarthakgarg1204/cropgenie/blob/main/crop_model.pkl"
    click F "https://github.com/sarthakgarg1204/cropgenie/blob/main/Fertilizer Prediction.csv"
    click H1 "https://github.com/sarthakgarg1204/cropgenie/blob/main/requirements.txt"
    click H2 "https://github.com/sarthakgarg1204/cropgenie/blob/main/README.md"
    click H3 "https://github.com/sarthakgarg1204/cropgenie/tree/main/LICENSE"
    click H4 "https://github.com/sarthakgarg1204/cropgenie/blob/main/.gitignore"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef process fill:#90EE90,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef data fill:#FFA500,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
