# dolaposalim/web-based-macroalgae-active-learner architecture

> Architecture diagram of the GitHub repository dolaposalim/web-based-macroalgae-active-learner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dolaposalim/web-based-macroalgae-active-learner
- Repository: https://github.com/dolaposalim/web-based-macroalgae-active-learner

## Overview

##### Project type and purpose
- This is a monolithic “full-stack” Python web tool built with Streamlit.
- Purpose: let users upload underwater macroalgae images, auto-label them via a YOLO→SAM pipeline, compute per-class coverage percentages, display overlays interactively, and download annotations/masks.

##### File structure
- project/images/        ← raw input images
- project/scr/app.py     ← single Streamlit app (frontend + backend)
- project/output/        ← generated artifacts
- masks/             ← per-object segmentation masks
- overlays/          ← overlay visuals for display
- annotations.json   ← structured label + coverage data
- requirements.txt       ← Python dependencies (streamlit, opencv-python, ultralytics, etc.)

##### Main components
a. User Interface (Streamlit front end)
b. Application Server (app.py)
c. Image Processing Pipeline
- Pre-processing (OpenCV, NumPy)
- YOLO detection module (yolo_model.pt)
- SAM segmentation module (sam_b.pt)
- Coverage calculator (pixel-area per class)
d. Data stores
- Local file system: project/images, project/output
- Model artifacts: YOLO weights, SAM weights
e. Optional: External storage (e.g., Firebase/GCP bucket)

##### Relationships and data flow
1) User uploads image(s) via Streamlit UI →
2) app.py saves to project/images →
3) app.py invokes pipeline:
– Pre-process → YOLO inference → SAM segmentation → coverage calc →
4) Pipeline writes masks, overlays, annotations.json to project/output →
5) Streamlit UI reads outputs, renders overlays + stats →
6) User can trigger “Download JSON/masks ZIP”

##### Architectural patterns and principles
- Monolith with clear separation of concerns: “UI” vs “processing pipeline” vs “storage.”
- Modular pipeline functions (detect, segment, measure).
- File-based data interchange (images in → outputs out).
- Easy extension point: swap in cloud storage or additional models.

##### Technologies and frameworks to annotate
- Streamlit for UI + web server
- Python libraries: OpenCV, NumPy, Pillow
- ultralytics YOLO model
- Segment Anything Model (SAM)
- JSON for annotations
- (Optional) Firebase/GCP for storage

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef external fill:#e2e3e5,stroke:#868e96;
    classDef ui fill:#cce5ff,stroke:#004085;
    classDef module fill:#d4edda,stroke:#155724;
    classDef storage fill:#fff3cd,stroke:#856404;
    classDef storage_small fill:#fff3cd,stroke:#856404;
    classDef artifact fill:#f8d7da,stroke:#721c24;
    classDef external_storage fill:#f5f5f5,stroke:#6c757d,stroke-dasharray:5 5;

    User([User]):::external
    App["Streamlit UI / app.py"]:::ui
    click App "https://github.com/dolaposalim/web-based-macroalgae-active-learner/blob/main/project/scr/app.py"

    subgraph "Local File System"
        Images["Raw Images\n(project/images)"]:::storage
        click Images "https://github.com/dolaposalim/web-based-macroalgae-active-learner/tree/main/project/images/"
        Output["Output Artifacts\n(project/output)"]:::storage
        click Output "https://github.com/dolaposalim/web-based-macroalgae-active-learner/tree/main/project/output/"
        Annotations["annotations.json"]:::storage_small
        click Annotations "https://github.com/dolaposalim/web-based-macroalgae-active-learner/blob/main/project/output/annotations.json"
    end

    Pre["Pre-processing\n(OpenCV, NumPy)"]:::module
    YOLO["YOLO Detector"]:::module
    SAM["SAM Segmenter"]:::module
    Coverage["Coverage Calculator"]:::module

    ModelYOLO["yolo_model.pt"]:::artifact
    ModelSAM["sam_b.pt"]:::artifact

    ExternalStorage["Cloud Storage (optional)"]:::external_storage

    User -->|"uses"| App
    App -->|"upload images"| Images
    Images -->|"image file"| Pre
    Pre -->|"pre-processed image"| YOLO
    ModelYOLO -->|"weights"| YOLO
    YOLO -->|"detections"| SAM
    ModelSAM -->|"weights"| SAM
    SAM -->|"segment masks"| Coverage
    Coverage -->|"results"| Output
    Output -->|"reads masks, overlays, JSON"| App
    App -->|"download JSON/masks ZIP"| User
    Output -.->|"optional sync"| ExternalStorage

    Req["requirements.txt"]:::artifact
    click Req "https://github.com/dolaposalim/web-based-macroalgae-active-learner/blob/main/requirements.txt"
    Readme["readme.md"]:::artifact
    click Readme "https://github.com/dolaposalim/web-based-macroalgae-active-learner/blob/main/readme.md"
    Ignore[".gitignore"]:::artifact
    click Ignore "https://github.com/dolaposalim/web-based-macroalgae-active-learner/blob/main/.gitignore"
```
