# 0011ashwin/advanced-crop-yield-prediction-system architecture

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

- Interactive diagram: https://gitdiagram.com/0011ashwin/advanced-crop-yield-prediction-system
- Repository: https://github.com/0011ashwin/advanced-crop-yield-prediction-system

## Overview

##### Project type and purpose
- This is a full-stack, data-centric AI platform with both a web interface (Streamlit) and a mobile interface (Kivy/KivyMD).
- Purpose: ingest agricultural CSV/geospatial data, run exploratory analyses, train/serve ML models (yield prediction), integrate with Google’s Gemini AI for advanced Q&A and image analysis, and deliver results via interactive dashboards or a mobile app.

##### File structure
- Top-level:
- app.py – Streamlit entry point
- data/ – raw CSV/JSON datasets
- models/ – serialized model artifacts & metrics
- static/ – images for encyclopedia
- src/ – modular code organized into components, data loaders, model training, utils, and visualizations
- Notebook/ – Jupyter explorations
- src/components: high-level feature modules (data_exploration, feature_analysis, crop_information, model_training, yield_prediction, gemini_ai)
- src/data: data_loader
- src/models: model_trainer
- src/utils: auth, config, preprocessing, reporting
- src/visualizations: plot generators

##### Key insights from README
- Two user interfaces: web (Streamlit) and Android (Kivy/KivyMD, offline mode)
- Core ML tech: Scikit-learn, XGBoost/LightGBM, TensorFlow/PyTorch
- Visualization: Matplotlib, Seaborn, Plotly, GeoPandas
- External integration: Google Generative AI (Gemini API)

a. Main components
- Clients: Web Browser (interacts with Streamlit) & Android App (Kivy).
- Web Server: Streamlit application (app.py orchestrates feature modules).
- Mobile Runtime: Packaged Python/Kivy runtime on Android.
- Business Logic Modules (src/components):
– Data Exploration & Feature Analysis
– Crop Encyclopedia (crop_information)
– Model Training & Yield Prediction
– AI Assistant (gemini_ai)
- Data Layer:
– Local CSV/JSON files (data/)
– Model artifacts & metrics (models/)
- Visualization Layer (src/visualizations)
- Utility Layer (src/utils): config, auth, preprocessing, reporting
- External Services: Google Gemini AI API
b. Relationships & data flows
1. User (Browser/Mobile) → requests UI pages or mobile screens
2. UI → invokes backend modules via Streamlit/Kivy controllers
3. Data Loader reads CSV/JSON → Preprocessing → feeds Exploratory & Feature modules
4. Feature Analysis → Visualization → renders plots in UI
5. Model Training → persists model artifacts → updates metrics
6. Yield Prediction module loads model → predicts → results → UI
7. AI Assistant module → sends user queries/images to Gemini API → receives insights → UI
8. Reporting util generates downloadable reports from analysis results
c. Architectural patterns & design principles
- Modular Monolith: logically separated components but deployed as a single codebase
- Layered Pattern:
- Presentation (Streamlit/Kivy)
- Application (components orchestrating workflows)
- Domain (ML models, data logic)
- Infrastructure (file system, external API)
- Separation of Concerns: data loading, preprocessing, modeling, visualization, and integration each live in their own module
d. Relevant technologies/frameworks
- Presentation: Streamlit, Kivy/KivyMD
- Data Processing: Pandas, NumPy, GeoPandas
- Visualization: Matplotlib, Seaborn, Plotly
- ML: Scikit-learn, XGBoost, LightGBM, TensorFlow, PyTorch
- AI Integration: Google Generative AI (Gemini)
- Utils: Custom config/auth modules, reporting

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Browser["Web Browser"]:::ui
        Mobile["Android App (Kivy)"]:::ui
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        WebServer["Streamlit Server (app.py)"]:::ui
        MobileRuntime["Kivy Runtime"]:::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        subgraph "Utilities"
            Auth["Authentication Utility"]:::module
            Config["Configuration Utility"]:::module
            Preproc["Preprocessing Utility"]:::module
            Reporting["Reporting Utility"]:::module
        end
        subgraph "Data & ML Components"
            DataLoader["Data Loader Module"]:::module
            DataExploration["Data Exploration"]:::module
            FeatureAnalysis["Feature Analysis"]:::module
            CropInfo["Crop Encyclopedia"]:::module
            ModelTrainingComp["Model Training Component"]:::module
            CoreTrainer["Core Model Trainer"]:::module
            YieldPred["Yield Prediction"]:::module
            GeminiComp["AI Assistant (Gemini)"]:::module
            Visualization["Visualization Layer"]:::module
        end
    end

    %% Data Layer
    subgraph "Data Stores"
        direction TB
        RawData["Raw Datasets (CSV/JSON)"]:::datastore
        ModelArtifacts["Model Artifacts & Metrics"]:::datastore
        StaticImages["Static Images"]:::datastore
        Notebooks["Jupyter Notebooks"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GeminiAPI["Google Gemini AI API"]:::external
    end

    %% Flows
    Browser -->|requests UI| WebServer
    Mobile -->|screens| MobileRuntime

    WebServer -->|uses| Auth
    WebServer -->|loads config| Config
    WebServer -->|calls| DataLoader
    WebServer -->|invokes| DataExploration
    WebServer -->|invokes| FeatureAnalysis
    WebServer -->|invokes| CropInfo
    WebServer -->|invokes| ModelTrainingComp
    WebServer -->|invokes| YieldPred
    WebServer -->|invokes| GeminiComp
    WebServer -->|renders| Visualization
    MobileRuntime -->|offline data| DataLoader
    MobileRuntime -->|invokes| YieldPred
    MobileRuntime -->|calls| GeminiComp
    DataLoader -->|reads| RawData
    Preproc -->|processes| RawData
    DataLoader -->|uses| Preproc
    DataExploration -->|uses| Preproc
    FeatureAnalysis -->|uses| Preproc
    FeatureAnalysis -->|generates| Visualization
    DataExploration -->|generates| Visualization
    CropInfo -->|reads| StaticImages
    ModelTrainingComp -->|trains| CoreTrainer
    CoreTrainer -->|writes| ModelArtifacts
    YieldPred -->|loads| ModelArtifacts
    GeminiComp -->|requests| GeminiAPI
    GeminiAPI -->|responds| GeminiComp
    Reporting -->|generates| Notebooks
    Reporting -->|exports| ModelArtifacts

    Visualization -->|displays in| WebServer
    Visualization -->|displays in| MobileRuntime

    %% Click Events
    click WebServer "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/app.py"
    click RawData "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/tree/main/data/"
    click DataLoader "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/data/data_loader.py"
    click Preproc "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/utils/preprocessing.py"
    click Auth "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/utils/auth.py"
    click Config "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/utils/config.py"
    click Reporting "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/utils/reporting.py"
    click DataExploration "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/components/data_exploration.py"
    click FeatureAnalysis "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/components/feature_analysis.py"
    click CropInfo "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/components/crop_information.py"
    click ModelTrainingComp "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/components/model_training.py"
    click CoreTrainer "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/models/model_trainer.py"
    click YieldPred "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/components/yield_prediction.py"
    click GeminiComp "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/components/gemini_ai.py"
    click Visualization "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/blob/main/src/visualizations/plots.py"
    click ModelArtifacts "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/tree/main/models/"
    click StaticImages "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/tree/main/static/images/crops/"
    click Notebooks "https://github.com/0011ashwin/advanced-crop-yield-prediction-system/tree/main/Notebook/"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#4A90E2,stroke-width:1px
    classDef module fill:#E0F7E0,stroke:#34A853,stroke-width:1px
    classDef datastore fill:#FFF4CC,stroke:#F4B400,stroke-width:1px
    classDef external fill:#FDE0E0,stroke:#EA4335,stroke-width:1px
```
