# nano-a/medicinal-plant-classifier architecture

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

- Interactive diagram: https://gitdiagram.com/nano-a/medicinal-plant-classifier
- Repository: https://github.com/nano-a/medicinal-plant-classifier

## Overview

##### Project type and purpose
- Type: Full-stack web application with an embedded Machine Learning component (RandomForest)
- Purpose: Classify plants as medicinal or non-medicinal based on user-entered botanical features via a Flask web interface; also generate evaluation visuals (ROC, confusion matrix, feature importance).

##### File structure
- Top-level
- app.py: Flask entry point (“main”)
- requirements.txt, .gitignore, devbook.md, Tache.txt
- data/: CSV datasets (plants.csv, plants_extended.csv)
- model/: ML logic and pipeline (plant_classifier.py)
- controller/: Flask routes (routes.py) – implements MVC “Controller”
- view/: Optional Jinja result template (results.html)
- templates/: Main Jinja template (index.html) – “View”
- static/: CSS, images, visualization outputs
- generate_images.py: Standalone script to regenerate static evaluation graphics
- Architectural pattern: Monolithic Flask app following MVC conventions, single process, file-based data store, no external DB or microservice.

##### Extract insights from README
- Tech stack: Python 3.10, Flask, pandas, scikit-learn, matplotlib, seaborn, Tailwind-inspired CSS
- Workflow:
1. User fills web form (index.html)
2. Controller routes.py processes POST → calls plant_classifier
3. plant_classifier performs preprocessing, model inference, evaluation metrics
4. Controller returns results (json or through view template) + visual assets (static/images)
- Additional: generate_images.py can be run offline to produce ROC, confusion, feature importance plots stored in static/images.

- Client / Browser (UI)
- Flask App Server
- app.py (Bootstrap & Configuration)
- Controller (routes.py)
- Model Layer (plant_classifier.py)
- Visualization Generator (generate_images.py)
- Data Store (CSV files in data/)
- Static Assets Server (CSS, JS, images under static/)
1. Client → HTTP(S) GET → Flask Server → Serve index.html + style.css
2. Client submits form → HTTP POST → Controller
3. Controller reads data (plants.csv), invokes Model Layer → model.predict()
4. Model Layer applies preprocessing, returns prediction + metrics
5. Controller assembles results, embeds dynamic visualizations or links to static plots
6. Flask Server → HTTP response → Client (renders results.html or JSON)
c. Architectural patterns & design principles
- MVC separation: Templates (View), routes.py (Controller), plant_classifier.py (Model)
- Single-process, modular code organization
- File-based data store for simplicity; can swap for a database if needed
- Offline batch visualization script decoupled from request cycle
d. Key technologies/frameworks
- Flask (web framework & routing)
- pandas, scikit-learn (data processing & ML)
- matplotlib, seaborn (charts)
- Jinja2 (templating)
- Tailwind-inspired CSS (static/css/style.css)

##### Elements
- Clear, concise labels for each component (e.g., “plant_classifier.py”)
- Rectangle for code modules

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Client
    Browser["Browser"]:::frontend

    %% Flask Server Components
    subgraph "Flask Server" 
        App["app.py"]:::backend
        Controller["routes.py"]:::backend
        Model["plant_classifier.py"]:::model
        TemplateIndex["templates/index.html"]:::backend
        TemplateResults["view/results.html"]:::backend
    end

    %% Data Store
    PlantsCSV["plants.csv"]:::data
    PlantsExt["plants_extended.csv"]:::data

    %% Static Assets
    CSS["static/css/style.css"]:::static
    Images["static/images/"]:::static

    %% Offline Script
    Script["generate_images.py"]:::script

    %% User Request Flow
    Browser -->|"GET /"| App
    App -->|"render index"| TemplateIndex
    App -->|"serve CSS"| CSS
    TemplateIndex -->|form input| Browser

    Browser -->|"POST /classify"| App
    App --> Controller
    Controller -->|"load data"| PlantsCSV
    Controller -->|"load data"| PlantsExt
    Controller --> Model
    Model -->|"predict & metrics"| Controller
    Controller --> TemplateResults
    Controller --> Images
    Controller -->|"200 OK"| Browser

    %% Offline Visualization Workflow
    Script -->|"generate plots"| Images

    %% Click Events
    click App "https://github.com/nano-a/medicinal-plant-classifier/blob/main/app.py"
    click Controller "https://github.com/nano-a/medicinal-plant-classifier/blob/main/controller/routes.py"
    click Model "https://github.com/nano-a/medicinal-plant-classifier/blob/main/model/plant_classifier.py"
    click PlantsCSV "https://github.com/nano-a/medicinal-plant-classifier/blob/main/data/plants.csv"
    click PlantsExt "https://github.com/nano-a/medicinal-plant-classifier/blob/main/data/plants_extended.csv"
    click TemplateIndex "https://github.com/nano-a/medicinal-plant-classifier/blob/main/templates/index.html"
    click TemplateResults "https://github.com/nano-a/medicinal-plant-classifier/blob/main/view/results.html"
    click CSS "https://github.com/nano-a/medicinal-plant-classifier/blob/main/static/css/style.css"
    click Images "https://github.com/nano-a/medicinal-plant-classifier/tree/main/static/images/"
    click Script "https://github.com/nano-a/medicinal-plant-classifier/blob/main/generate_images.py"

    %% Styles
    classDef frontend fill:#FFD580,stroke:#333,stroke-width:1px;
    classDef backend fill:#B3E5FC,stroke:#333,stroke-width:1px;
    classDef model fill:#C8E6C9,stroke:#333,stroke-width:1px;
    classDef data fill:#FFCDD2,stroke:#333,stroke-width:1px,shape:cylinder;
    classDef static fill:#E1BEE7,stroke:#333,stroke-width:1px,shape:folder;
    classDef script fill:#D1C4E9,stroke:#333,stroke-width:1px;
```
