# shukur-alom/leaf-diseases-detect architecture

> Architecture diagram of the GitHub repository shukur-alom/leaf-diseases-detect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shukur-alom/leaf-diseases-detect
- Repository: https://github.com/shukur-alom/leaf-diseases-detect

## Overview

##### Project type and purpose
- This is a full-stack AI-powered leaf disease detection system.
- Purpose: Provide dual interfaces (FastAPI REST API + Streamlit web UI) that accept leaf images, forward them to an AI core (Meta Llama Vision via Groq API) for disease detection, and return structured analysis (disease type, severity, confidence, treatment recommendations).

##### File structure
- Top-level:
- app.py           → FastAPI backend
- main.py          → Streamlit frontend
- utils.py         → shared image-processing helpers
- test_api.py      → API integration tests
- requirements.txt
- vercel.json      → cloud deployment config
- .streamlit/config.toml → Streamlit settings
- Subdirectory “Leaf Disease/”:
- config.py        → AI model & environment configuration
- main.py          → Core AI detection engine (LeafDiseaseDetector, dataclasses, Groq API integration)
- Media/            → Example images for testing

##### README for additional insights
- Clearly states a three-tier logical architecture:
a. Streamlit Web Application (UI/UX)
b. FastAPI Backend (REST endpoints)
c. Core AI Engine (Groq-powered Llama Vision)
- External dependency: Groq API
- No persistent database—stateless image processing

a. Main components to represent:
1. Client Layer:
– Web browser (Streamlit UI)
– API client (cURL/requests)
2. Presentation Layer:
– Streamlit App (main.py)
– FastAPI Service (app.py)
3. Business Logic Layer:
– LeafDiseaseDetector (Leaf Disease/main.py)
– utils.py (image preprocessing, base64 encoding)
4. External Service:
– Groq API (Meta Llama Vision inference)
5. Supporting:
– Test suite (test_api.py)
– Deployment config (vercel.json, .streamlit)

b. Relationships & interactions:
- Streamlit UI → POST multipart/form-data → FastAPI endpoint `/disease-detection-file`
- FastAPI handler → calls utils.py to preprocess → encodes as base64 → invokes LeafDiseaseDetector.analyze_leaf_image_base64()
- LeafDiseaseDetector → sends REST/gRPC call to Groq API → receives JSON response → parses into DiseaseAnalysisResult → returns to FastAPI
- FastAPI → transforms dataclass to JSON → returns to Streamlit UI (or other API client)
- Streamlit → renders results (confidence, severity, treatment)
- All components stateless—horizontal scaling via Vercel or other cloud

c. Architectural patterns & design principles:
– Layered architecture (Presentation / API / Core AI)
– Separation of concerns (UI vs. API vs. AI engine vs. utilities)
– Stateless, horizontally scalable micro-service style
– Dependency injection via config.py and .env variables
– Automated testing (test_api.py) for contract validation

d. Key technologies/frameworks:
– Python 3.8+
– FastAPI (REST, OpenAPI docs)
– Streamlit (web UI)
– Groq API & Meta Llama Vision models
– Pydantic/dataclasses for structured responses
– Vercel & Streamlit Cloud for deployment

##### Diagramming conventions
- Blue rectangles for UI components (Streamlit, Browser)
- Green rectangles for API services (FastAPI)
- Orange rectangles for core engine (LeafDiseaseDetector, utils)
- UI → API (HTTP POST)
- API → Core Engine (method call)
- Core Engine → Groq API (HTTPS request)
- “Presentation Layer” containing Streamlit/UI
- “Application Layer” containing FastAPI
- “AI Layer” containing LeafDiseaseDetector & external Groq

##### Detail level
– Capture utility module’s role (image pre-processing).
– Show test suite and deployment config as side artifacts.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Web Browser"]:::frontend
        StreamlitApp["main.py - Streamlit App"]:::frontend
        APIClient["API Client (cURL/requests)"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FastAPI["app.py - FastAPI Backend"]:::api
    end

    %% AI Layer
    subgraph "AI Layer"
        direction TB
        Utils["utils.py - Image Processing Utilities"]:::core
        Config["Leaf Disease/config.py - AI Model & Env Config"]:::core
        LeafCore["Leaf Disease/main.py - LeafDiseaseDetector"]:::core
    end

    %% External Service
    Groq["Groq API - Meta Llama Vision"]:::external

    %% Supporting Artifacts
    TestSuite["test_api.py - API Integration Tests"]:::support
    VercelConf["vercel.json - Deployment Config"]:::support
    StreamlitConf[".streamlit/config.toml - Streamlit Settings"]:::support
    MediaAssets["Media/ - Example Media"]:::support

    %% Connections
    Browser -->|"loads Streamlit UI"| StreamlitApp
    StreamlitApp -->|"POST /disease-detection-file\nmultipart/form-data"| FastAPI
    APIClient -->|"HTTP POST"| FastAPI

    FastAPI -->|"preprocess image"| Utils
    FastAPI -->|"base64 image"| LeafCore
    LeafCore -->|"uses Env Config"| Config
    LeafCore -->|"inference request"| Groq
    Groq -->|"JSON response"| LeafCore
    LeafCore -->|"DiseaseAnalysisResult"| FastAPI
    FastAPI -->|"JSON response"| StreamlitApp

    %% Click Events
    click StreamlitApp "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/main.py"
    click StreamlitConf "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/.streamlit/config.toml"
    click FastAPI "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/app.py"
    click Utils "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/utils.py"
    click LeafCore "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/Leaf Disease/main.py"
    click Config "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/Leaf Disease/config.py"
    click TestSuite "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/test_api.py"
    click VercelConf "https://github.com/shukur-alom/leaf-diseases-detect/blob/main/vercel.json"
    click MediaAssets "https://github.com/shukur-alom/leaf-diseases-detect/tree/main/Media/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef api fill:#E2F0D9,stroke:#22863A,color:#000
    classDef core fill:#FFE5B4,stroke:#D2691E,color:#000
    classDef external fill:#EDE7F6,stroke:#6F42C1,color:#000
    classDef support fill:#F0F0F0,stroke:#999,color:#000
```
