# madhan-oss/plant-disease-recognition-system architecture

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

- Interactive diagram: https://gitdiagram.com/madhan-oss/plant-disease-recognition-system
- Repository: https://github.com/madhan-oss/plant-disease-recognition-system

## Overview

##### Project type and purpose
- This is a full-stack, deep-learning web application (“Plant Disease Recognition System”) built with Flask for serving a pre-trained CNN model and offering a web UI for farmers or researchers to upload leaf images and receive disease predictions. It also includes a training pipeline (train_model.py) for model retraining on custom datasets.

##### File structure
- Top-level files/directories (from README):
- model/            ← stores pretrained model (.h5)
- static/           ← CSS, JavaScript, images (client-side assets)
- templates/        ← Jinja2 HTML pages (UI views)
- dataset/          ← optional folder with training images (organized by class)
- app.py            ← Flask application (inference server)
- train_model.py    ← training script (data loading, CNN definition, training loop, .h5 export)
- plant_disease.json← disease label mappings/config
- Build/config files: requirements.txt (dependency list), maybe .gitignore (not shown).
- Architectural pattern: monolithic Flask app with two main flows—inference (app.py) and training (train_model.py). No separate microservices.

##### README for additional insights
- Technology stack: Python, TensorFlow/Keras, OpenCV, Flask, HTML/CSS/JS
- Features: image upload → inference → display result + confidence; retraining option
- No external databases—model and JSON file serve as the “knowledge base.”

a. Main components
- Client (Web Browser) – UI in templates/, static assets
- Inference Server (Flask app.py)
- CNN Model (model/plant_disease_model.h5)
- Configuration Store (plant_disease.json)
- Training Pipeline (train_model.py + dataset/)
- (Optional) Local File Storage for uploaded images
b. Relationships and interactions
1. User → Browser UI (HTML in templates, JS/CSS in static/)
2. UI sends HTTP POST (image) → Flask app (app.py)
3. app.py reads the image (via OpenCV), loads JSON label map, loads model (.h5) into TensorFlow/Keras, runs inference
4. app.py returns prediction + confidence → UI
5. For retraining: train_model.py reads dataset/ (images & labels), trains CNN, writes new .h5 to model/
c. Architectural patterns / design principles
- Separation of concerns: static assets and templates separated from Python code
- Single-process monolith for simplicity (no message brokers or microservices)
- Reusable ML pipeline decoupled from serving logic
- Config stored externally in JSON for easy updates
d. Key technologies
- Flask (WSGI web server)
- TensorFlow/Keras (model loading & inference, training)
- OpenCV (image preprocessing)
- Jinja2 templates (dynamic HTML)
- plant_disease.json (label mapping)

##### Detailed capture of essential elements
- Be explicit about the two flows—**inference** (real-time serving) vs **training** (offline pipeline).
- Clearly separate front-end static/templates from back-end code.
- External dependencies (TensorFlow, OpenCV) as annotation notes on the serving and training components.
- Don’t overcomplicate: this is a monolithic app, so a single component block for the server is sufficient, with labeled sub-components.
- Annotations for ports (HTTP:5000) if desired.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client Side"
        BrowserUI["Browser UI\n(templates/, static/)"]:::client
    end

    %% Server Side
    subgraph "Server Side"
        Inference["Flask Inference Service\napp.py\n(TensorFlow, OpenCV)"]:::server
        ModelFile["CNN Model\nmodel/plant_disease_model.h5"]:::storage
        JSONStore["Configuration Store\nplant_disease.json"]:::storage
        Training["Training Pipeline\ntrain_model.py\n(TensorFlow, Keras, OpenCV)"]:::server
        Dataset["Dataset Storage\ndataset/"]:::storage
    end

    %% Documentation
    subgraph "Project Documentation"
        Readme["README.md"]:::doc
        License["LICENSE"]:::doc
        Archive["Source Archive\nPlant-Disease-Recognition-System-main.zip"]:::doc
    end

    %% Inference Flow
    BrowserUI -->|"HTTP POST Image upload"| Inference
    Inference -->|"Load model"| ModelFile
    Inference -->|"Load labels"| JSONStore
    Inference -->|"Return prediction + confidence"| BrowserUI

    %% Training Flow (dashed)
    Training -.->|"Reads images"| Dataset
    Training -.->|"Writes new .h5 model"| ModelFile

    %% Click Events
    click Inference "https://github.com/madhan-oss/plant-disease-recognition-system/blob/main/app.py"
    click JSONStore "https://github.com/madhan-oss/plant-disease-recognition-system/blob/main/plant_disease.json"
    click Readme "https://github.com/madhan-oss/plant-disease-recognition-system/blob/main/README.md"
    click License "https://github.com/madhan-oss/plant-disease-recognition-system/tree/main/LICENSE"
    click Archive "https://github.com/madhan-oss/plant-disease-recognition-system/blob/main/Plant-Disease-Recognition-System-main.zip"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0366d6;
    classDef server fill:#DFF5E1,stroke:#238636;
    classDef storage fill:#FFF5D1,stroke:#D4A72C,stroke-dasharray: 5 5;
    classDef doc fill:#F0F0F0,stroke:#CCCCCC;
```
