# vishruthb/melo architecture

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

- Interactive diagram: https://gitdiagram.com/vishruthb/melo
- Repository: https://github.com/vishruthb/melo

## Overview

##### Project Type and Purpose
- This is a single-page, ML-driven web application built on Streamlit that allows end users (patients) to upload images of skin lesions, get an on-the-fly melanoma risk assessment, track history, and generate referral packages.
- It combines a Streamlit frontend, Python business‐logic modules for model loading and PDF/ZIP generation, a custom EfficientNet inference model, secure Auth0 authentication, MongoDB Atlas storage, and the Gemini external API for email drafting.

##### File Structure
- Top-level files:
- `.streamlit/config.yml`: Streamlit and secrets configuration (Auth0 client ID/secret, MongoDB URI, Gemini API keys).
- `main.py`: The Streamlit UI definition (pages, widgets, sidebar, session state management).
- `loader.py`: Model‐loading utility, wraps the EfficientNet B0 checkpoint (`best.pt`) in a cached resource.
- `pdfgen.py`: Functions to assemble referral PDFs (ReportLab) and ZIP archives.
- `requirements.txt`: Lists Python dependencies (Streamlit, pymongo, reportlab, Auth0 component, PIL, etc.).
- `model.ipynb`: Experiment notebook (not part of deployment).
- No separate “frontend”/“backend” folders—Streamlit serves both UI and business logic in one process.

##### Extract Architecture from README
- Authentication via Auth0 (OAuth/OIDC flows).
- MongoDB Atlas used to store scan history (`results` collection, grouped by user).
- Real-time inference via custom EfficientNet model.
- External Gemini API for generating referral emails.
- ReportLab + in-memory PIL buffers for PDF creation; ZIP packaging for downloads.

##### Main Components
a. Client Layer
- User’s Web Browser (HTTP/S over Streamlit Cloud or localhost)
b. Application Server (Streamlit Process)
- UI Module (`main.py`)
- Model Loader (`loader.py` + `best.pt`)
- PDF/ZIP Generator (`pdfgen.py`)
- Session & State Manager (`st.session_state`)
c. Data Layer
- MongoDB Atlas (hosted, HIPAA-compatible)
d. Authentication Service
- Auth0 (OAuth/OIDC endpoints)
e. External AI Service
- Gemini API (email generation)

##### Relationships and Data Flows
- From the Streamlit server:
- Internal flow from PDF Generator to user-download endpoint (ZIP/PDF).

##### Architectural Patterns and Design Principles
- Monolithic Streamlit server that uses modular Python files for separation of concerns (UI vs. model vs. PDF logic).
- Cache pattern (`@st.cache_resource`) for efficient model reuse.
- OAuth security boundary between front end and Auth0.
- Layered architecture: presentation (Streamlit UI), business logic (inference, PDFgen), data persistence (MongoDB), external services.

##### Relevant Technologies and Libraries
- Streamlit (UI framework)
- Python 3.x modules: `pymongo`, `auth0‐component`, `reportlab`, `PIL`, `BytesIO`
- EfficientNet B0 model (`torch` or `tensorflow` depending on loader)
- MongoDB Atlas (SRV connection string)
- Gemini API (HTTP/REST with streaming responses)

##### Detail Without Overthinking
- Data flows—authentication tokens, images, inference results, PDF streams—are represented.
- Keep the layout clean: group related components (all external services on one side, data stores on another) and minimize crossing lines.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Browser["User's Web Browser"]:::client

    %% Streamlit Application
    subgraph "Streamlit App"
        UI["UI Module (main.py)"]:::internal
        Config["Config (.streamlit/config.yml)"]:::internal
        Loader["Model Loader (loader.py)"]:::internal
        Checkpoint["Checkpoint (best.pt)"]:::internal
        PDF["PDF/ZIP Generator (pdfgen.py)"]:::internal
        State["Session State Manager"]:::internal
        Req["Dependencies (requirements.txt)"]:::internal
    end

    %% External Services
    Auth0["Auth0 OAuth/OIDC"]:::external
    Mongo["MongoDB Atlas"]:::datastore
    Gemini["Gemini API"]:::external

    %% Experiment Notebook and Docs
    Notebook["Experiment Notebook (model.ipynb)"]:::external
    README["README.md"]:::internal

    %% Data Flows and Interactions
    Browser -->|"UI interactions\nupload, results"| UI
    UI -->|"POST /login, token exchange"| Auth0
    UI -->|"Query & update user scans"| Mongo
    UI -->|"Inference(image)"| Loader
    Loader -->|"Load & cache model"| Checkpoint
    UI -->|"Draft referral email"| Gemini
    UI -->|"Generate PDF/ZIP"| PDF
    PDF -->|"Download stream"| Browser

    %% Click Events
    click UI "https://github.com/vishruthb/melo/blob/main/main.py"
    click Config "https://github.com/vishruthb/melo/blob/main/.streamlit/config.yml"
    click Loader "https://github.com/vishruthb/melo/blob/main/loader.py"
    click Checkpoint "https://github.com/vishruthb/melo/blob/main/best.pt"
    click PDF "https://github.com/vishruthb/melo/blob/main/pdfgen.py"
    click Req "https://github.com/vishruthb/melo/blob/main/requirements.txt"
    click Notebook "https://github.com/vishruthb/melo/blob/main/model.ipynb"
    click README "https://github.com/vishruthb/melo/blob/main/README.md"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef datastore fill:#90EE90,stroke:#333,stroke-width:1px
    classDef client fill:#D3D3D3,stroke:#333,stroke-width:1px
```
