# gladiator07/harvestify architecture

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

- Interactive diagram: https://gitdiagram.com/gladiator07/harvestify
- Repository: https://github.com/gladiator07/harvestify

## Overview

##### Project Overview & Main Components
- Harvestify is a full-stack web application that leverages ML and DL models to provide three core functionalities:
– Crop Recommendation (predicts which crop to grow based on soil inputs and environmental data)
– Fertilizer Suggestion (analyzes soil nutrient data to suggest fertilizer improvements)
– Plant Disease Detection (uses a deep learning-based image classifier to detect plant diseases)
- The architecture consists of a frontend user interface, a Flask-based backend, ML/DL model integrations, and data resources.

##### Breaking Down the File Structure & Its Impact
- App Layer (app folder):
– app.py: The main Flask application that handles web requests.
– config.py and Procfile/Runtime.txt: Configuration and deployment specifics (Heroku).
– Templates and Static folders: Hold the HTML, CSS, and JavaScript assets for user interface presentation.
– Utils folder: Contains helper modules (e.g., disease.py, fertilizer.py, model.py) to process input data and interface with ML models.
– Data and Models: The ML model files (e.g., RandomForest.pkl, plant_disease_model.pth) used for predictions.
- Models folder (outside the app subdirectory): Contains additional pre-trained ML models (e.g., DecisionTree, NBClassifier, SVMClassifier, XGBoost) which may support experimental or alternative prediction strategies.
- Data Folders (Data-raw and Data-processed):
– Provide the CSV inputs for training models and possibly reference datasets.
- Notebooks folder:
– Holds the experiments/notebooks used for model training and data preparation (not part of the production deployment but informative of the development process).

- Frontend (User Interface):
– Represented by the HTML templates, CSS, JavaScript, and static resources.
– Responsible for capturing user inputs (e.g., soil data, crop selection, uploaded image) and displaying results.
- Backend (Flask Application):
– Acts as the central orchestrator.
– Handles HTTP requests (routing for crop, fertilizer, and disease functionalities).
– Invokes utility functions (in app/utils) that pre-process inputs, call ML models, and format the outputs.
- ML/DL Models:
– Represent different pipelines:
º The Crop Recommendation and Fertilizer Suggestion pipelines use models like RandomForest (from app/models & models folder).
º Disease Detection uses a deep learning model (plant_disease_model.pth) to process image inputs.
– These components reside either within the app folder or in the models folder.
- Data Sources:
– CSV datasets stored in the Data-raw, Data-processed, and app/Data directories.
– These are used to feed inputs to training pipelines (as shown in the notebooks) and act as reference data at runtime.
- External Services:
– For instance, a Weather API is mentioned to fetch temperature and humidity data based on city names provided by users.
- Deployment Infrastructure:
– The presence of files like Procfile, Runtime.txt, and guidelines in the README indicate Heroku deployment.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend User Interface"
        HTMLTemplates["HTML Templates"]:::frontend
        StaticAssets["Static Assets"]:::frontend
    end

    %% Backend Layer (Flask Server)
    subgraph "Flask Web Server"
        FlaskApp["app.py"]:::backend
        ServerConfig["config.py"]:::backend
    end

    %% ML/DL Pipelines
    subgraph "ML/DL Pipelines"
        CropRec["Crop Recommendation"]:::pipeline
        Fertilizer["Fertilizer Suggestion"]:::pipeline
        DiseaseDetect["Plant Disease Detection"]:::pipeline
    end

    %% Data Layer
    DataSources["Data Sources"]:::data

    %% External Integration
    ExternalService["Weather API"]:::external

    %% Deployment Environment
    subgraph "Deployment Environment"
        DeployConfig["Deployment Configuration"]:::deployment
    end

    %% Experimentation (Not Production)
    Experiment["Model Training & Experimentation"]:::experiment

    %% Connections
    HTMLTemplates -->|"HTTP_req"| FlaskApp
    StaticAssets -->|"Load_assets"| FlaskApp

    FlaskApp -->|"invoke_CropRec"| CropRec
    FlaskApp -->|"invoke_Fertilizer"| Fertilizer
    FlaskApp -->|"invoke_DiseaseDetect"| DiseaseDetect

    CropRec -->|"send_result"| FlaskApp
    Fertilizer -->|"send_result"| FlaskApp
    DiseaseDetect -->|"send_result"| FlaskApp

    FlaskApp -->|"read_data"| DataSources
    DataSources -->|"send_data"| FlaskApp

    FlaskApp -->|"API_call"| ExternalService

    DeployConfig -->|"deploy"| FlaskApp

    Experiment -->|"train_data"| DataSources
    Experiment -->|"train_model"| CropRec

    %% Click Events
    click HTMLTemplates "https://github.com/gladiator07/harvestify/tree/master/app/templates"
    click StaticAssets "https://github.com/gladiator07/harvestify/tree/master/app/static"
    click FlaskApp "https://github.com/gladiator07/harvestify/blob/master/app/app.py"
    click ServerConfig "https://github.com/gladiator07/harvestify/blob/master/app/config.py"
    click CropRec "https://github.com/gladiator07/harvestify/blob/master/app/models/RandomForest.pkl"
    click CropRec "https://github.com/gladiator07/harvestify/blob/master/models/RandomForest.pkl"
    click Fertilizer "https://github.com/gladiator07/harvestify/blob/master/app/utils/fertilizer.py"
    click DiseaseDetect "https://github.com/gladiator07/harvestify/blob/master/app/models/plant_disease_model.pth"
    click DiseaseDetect "https://github.com/gladiator07/harvestify/blob/master/models/plant_disease_model.pth"
    click DataSources "https://github.com/gladiator07/harvestify/tree/master/Data-raw"
    click DataSources "https://github.com/gladiator07/harvestify/tree/master/Data-processed"
    click DataSources "https://github.com/gladiator07/harvestify/tree/master/app/Data"
    click DeployConfig "https://github.com/gladiator07/harvestify/tree/master/app/Procfile"
    click DeployConfig "https://github.com/gladiator07/harvestify/blob/master/app/Runtime.txt"
    click Experiment "https://github.com/gladiator07/harvestify/tree/master/notebooks"

    %% Styles
    classDef frontend fill:#9fdf9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#f9d18f,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef data fill:#fddc5c,stroke:#333,stroke-width:2px;
    classDef external fill:#f4cccc,stroke:#333,stroke-width:2px;
    classDef deployment fill:#d9d2e9,stroke:#333,stroke-width:2px;
    classDef experiment fill:#ececec,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
