# manthan89-py/plant-disease-detection architecture

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

- Interactive diagram: https://gitdiagram.com/manthan89-py/plant-disease-detection
- Repository: https://github.com/manthan89-py/plant-disease-detection

## Overview

##### Project Type and Purpose
- This is a full-stack application that integrates a deep learning component for classifying leaf images into 39 disease categories.
- The primary purpose is to detect plant diseases using a Convolutional Neural Network (CNN) built in PyTorch and served via a Flask web application.
- The project supports both a deployed web app (with a downloadable pre-trained model) and a standalone model exploration via Jupyter Notebook in the Model folder.

##### File Structure to Unearth Architectural Clues
- Under “Flask Deployed App,” you have:
- app.py: The main Flask application that handles web requests, routing, and API logic.
- CNN.py: Likely contains helper functions or the neural network definitions for inference.
- Procfile: Configuration for deployment (e.g. on Heroku), indicating a cloud-based deployment.
- requirements.txt: Lists the dependencies which include Flask, PyTorch, etc.
- Templates folder: Contains the HTML files such as home.html, contact-us.html, and so on. This represents the user interface layer.
- Static folder: Serves assets like images and uploaded files, indicating that user input (leaf images) is collected and processed.
- Supplementary CSV files (disease_info.csv, supplement_info.csv): Provide metadata/details, likely enhancing the app’s information display.
- Under “Model,” you have:
- Jupyter Notebook (.ipynb), markdown, and PDF files showing that this is where deep learning model training, evaluation, and experimentation occur.
- Additional folders like demo_images and test_images are used for demonstration and validation.

a. Main Components to Identify:
- Web Frontend: Represent the HTML templates, static assets, and contact pages.
- Web Backend: The Flask application (app.py) which routes requests and communicates with the model.
- Deep Learning Model: The CNN defined in CNN.py and the pre-trained PyTorch model (plant_disease_model_1.pt).
- Data Sources: CSV files that provide disease and supplement information.
- User Input and Output: The mechanism by which users upload images and view predictions.
- Deployment Configuration: Procfile and deployment guidelines indicating cloud deployment (Heroku).

b. Relationships and Interactions:
- The user interacts with the web frontend (via HTML templates) which sends image data to the Flask backend.
- The Flask backend processes the image, calls the CNN model (via CNN.py and the pre-trained model file) to classify the input.
- Predictions are returned from the deep learning model to the backend and then rendered on the result page.
- Additional interactions might include displaying supplementary information from CSV files and handling static content (uploads, CSS, JS).

c. Architectural Patterns and Design Principles:
- Separation of Concerns: Clear split between frontend (UI based on HTML, CSS in the static folder) and backend (Flask app handling business logic).
- Modular Design: Distinct modules for model inference (CNN.py and pre-trained model file) and web-serving.
- Deployment Readiness: Use of configuration files (Procfile) for cloud deployment.

d. Relevant Technologies and Frameworks:
- Python and Flask for the backend web framework.
- PyTorch for the deep learning (CNN) components.
- HTML/CSS (templates and static assets) for the frontend.
- Supporting tools: Jupyter for model testing and demonstration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("User/Browser"):::user

    subgraph "Presentation Layer"
        B("Templates (UI)"):::frontend
        C("Static Assets"):::frontend
        K("Uploads"):::frontend
    end

    D("Flask App (app.py)"):::backend

    subgraph "Machine Learning Layer"
        E("CNN Inference (CNN.py)"):::ml
        F("Model Exploration (Notebook)"):::ml
    end

    subgraph "Data & Configuration"
        G("Disease Info (CSV)"):::datasource
        H("Supplement Info (CSV)"):::datasource
        I("Procfile"):::config
        J("Requirements"):::config
    end

    A -->|"Requests"| B
    A -->|"Uploads"| K
    B -->|"Submits Data"| D
    K -->|"Provides Uploaded Content"| D
    D -->|"Processes Image"| E
    E -->|"Returns Prediction"| D
    D -->|"Renders Result"| B
    D -->|"Fetches_Metadata"| G
    D -->|"Fetches_Metadata"| H
    D -.->|"Deployment_Config"| I
    D -.->|"Deployment_Config"| J
    E -.->|"Shared_Interface"| F

    classDef user fill:#f9c74f,stroke:#000,stroke-width:2px;
    classDef frontend fill:#90be6d,stroke:#000,stroke-width:2px;
    classDef backend fill:#577590,stroke:#fff,stroke-width:2px;
    classDef ml fill:#f94144,stroke:#000,stroke-width:2px;
    classDef datasource fill:#277da1,stroke:#fff,stroke-width:2px;
    classDef config fill:#f3722c,stroke:#000,stroke-width:2px;

    click B "https://github.com/manthan89-py/plant-disease-detection/tree/main/Flask Deployed App/templates"
    click C "https://github.com/manthan89-py/plant-disease-detection/tree/main/Flask Deployed App/static"
    click K "https://github.com/manthan89-py/plant-disease-detection/tree/main/Flask Deployed App/static/uploads"
    click D "https://github.com/manthan89-py/plant-disease-detection/blob/main/Flask Deployed App/app.py"
    click E "https://github.com/manthan89-py/plant-disease-detection/blob/main/Flask Deployed App/CNN.py"
    click F "https://github.com/manthan89-py/plant-disease-detection/blob/main/Model/Plant Disease Detection Code.ipynb"
    click G "https://github.com/manthan89-py/plant-disease-detection/blob/main/Flask Deployed App/disease_info.csv"
    click H "https://github.com/manthan89-py/plant-disease-detection/blob/main/Flask Deployed App/supplement_info.csv"
    click I "https://github.com/manthan89-py/plant-disease-detection/tree/main/Flask Deployed App/Procfile"
    click J "https://github.com/manthan89-py/plant-disease-detection/blob/main/Flask Deployed App/requirements.txt"
```
