# hotarouuu/orangedetect architecture

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

- Interactive diagram: https://gitdiagram.com/hotarouuu/orangedetect
- Repository: https://github.com/hotarouuu/orangedetect

## Overview

##### Project type and purpose
- This is a machine-learning pipeline with a web-based front end.
- Purpose: fine-tune a pre-trained ResNet model to detect orange diseases, track experiments via Weights & Biases, and expose inference through a Streamlit app.

##### File structure
- Top-level scripts and config:
- `.env-example`, `Makefile`, `requirements.txt`, `setup.py` → environment, build & install
- `app.py` → Streamlit entry point
- Data directories:
- `data/` → raw & ingested data
- `notebooks/` → exploratory/prototyping code
- Model artifacts:
- `models/` → saved PyTorch checkpoints
- Core src and scripts:
- `scripts/` (data_treatment.py, download_data.py, training.py) → batch data prep & model training
- `src/` (dataloader.py, model.py, train.py, predict.py) → reusable library modules

##### README for additional insights
- Key external services: Kaggle (data), Weights & Biases (experiment tracking)
- Deployment: Streamlit UI accepts image uploads, returns disease prediction

##### Sketch the main components and their interactions
a. Components
1. Data Ingestion & Storage
- External Data Source (Kaggle)
- Raw Data Folder (`data/`)
2. Data Processing
- `scripts/data_treatment.py` → cleans, augments, splits data
3. Model Training Pipeline
- `scripts/training.py` (or `src/train.py`)
- PyTorch + transfer learning (ResNet50/101)
- WandB integration for metrics & checkpoints
4. Model Registry & Storage
- Local `models/` directory
- WandB artifact store (optional external registry)
5. Inference & Serving
- Streamlit app (`app.py` + `src/predict.py`)
- Loads model from `models/` and .env config
6. Prototyping & Experimentation
- `notebooks/` for exploratory analysis

b. Relationships & Data Flow
1. Download raw images from Kaggle → store in `data/`
2. Run data treatment → produce processed datasets → still under `data/` or ephemeral
3. Training pipeline reads processed data → fine-tunes model → logs to WandB & saves checkpoint in `models/`
4. Streamlit app reads the final checkpoint from `models/` (path from .env) → user uploads image → `src/predict.py` processes the image → model inference → UI displays result

c. Architectural patterns & principles
- Modular layering: separation of data, processing, training, and serving
- Reusable library (`src/`) vs. orchestration scripts (`scripts/`)
- External service abstraction: treat WandB and Kaggle as interchangeable providers
- Environment-based configuration (.env) for paths and credentials

d. Key technologies
- Python 3.x, PyTorch, Torchvision
- Streamlit for UI
- Weights & Biases for tracking
- Kaggle API for data download

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        Kaggle["Kaggle (External)"]:::external
        Download["Data Ingestion\n(scripts/download_data.py)"]:::compute
        RawData["Raw Data Folder (data/)"]:::datastore
    end

    %% Processing Layer
    subgraph "Processing"
        Process["Data Processing & Preparation\n(scripts/data_treatment.py)"]:::compute
        ProcessedData["Processed Data"]:::datastore
    end

    %% Training Layer
    subgraph "Training"
        ScriptsTrain["Training Orchestration\n(scripts/training.py)"]:::compute
        DataLoader["DataLoader\n(src/dataloader.py)"]:::compute
        ModelDef["Model Definition\n(src/model.py)"]:::compute
        TrainLogic["Training Logic\n(src/train.py)"]:::compute
        WandB["Weights & Biases (External)"]:::external
    end

    %% Model Store
    ModelStore["Model Artifacts\n(models/)"]:::datastore

    %% Serving/UI Layer
    subgraph "Serving/UI"
        Env["Environment & Config\n(.env-example, Makefile,\nrequirements.txt, setup.py)"]:::config
        App["Streamlit App\n(app.py)"]:::ui
        Predict["Inference Module\n(src/predict.py)"]:::compute
    end

    %% Experimentation Zone
    subgraph "Experimentation" 
        style Experimentation stroke-dasharray: 5 5
        Notebooks["Notebooks\n(notebooks/)"]:::extdev
    end

    %% Data Flow
    Kaggle --> Download --> RawData --> Process --> ProcessedData
    ProcessedData --> ScriptsTrain
    ScriptsTrain --> DataLoader --> TrainLogic
    ScriptsTrain --> ModelDef --> TrainLogic
    TrainLogic -->|logs metrics| WandB
    TrainLogic -->|saves checkpoint| ModelStore

    %% Serving Flow
    Env --> ScriptsTrain
    Env --> App
    App -->|user uploads image| Predict
    Predict -->|loads model| ModelStore
    App --> Predict

    %% Experimentation Link
    RawData --> Notebooks
    ProcessedData --> Notebooks

    %% Click Events
    click Download "https://github.com/hotarouuu/orangedetect/blob/main/scripts/download_data.py"
    click RawData "https://github.com/hotarouuu/orangedetect/tree/main/data/"
    click Process "https://github.com/hotarouuu/orangedetect/blob/main/scripts/data_treatment.py"
    click ScriptsTrain "https://github.com/hotarouuu/orangedetect/blob/main/scripts/training.py"
    click DataLoader "https://github.com/hotarouuu/orangedetect/blob/main/src/dataloader.py"
    click ModelDef "https://github.com/hotarouuu/orangedetect/blob/main/src/model.py"
    click TrainLogic "https://github.com/hotarouuu/orangedetect/blob/main/src/train.py"
    click ModelStore "https://github.com/hotarouuu/orangedetect/tree/main/models/"
    click App "https://github.com/hotarouuu/orangedetect/blob/main/app.py"
    click Predict "https://github.com/hotarouuu/orangedetect/blob/main/src/predict.py"
    click Notebooks "https://github.com/hotarouuu/orangedetect/tree/main/notebooks/"
    click Env "https://github.com/hotarouuu/orangedetect/blob/main/.env-example"

    %% Styles
    classDef datastore fill:#ADD8E6,stroke:#000
    classDef compute fill:#90EE90,stroke:#000
    classDef external fill:#FFA500,stroke:#000
    classDef ui fill:#D3D3D3,stroke:#000
    classDef config fill:#E0E0E0,stroke:#000
    classDef extdev fill:#F5F5F5,stroke:#000
```
