# keshavadk/iris-flower-species-streamlit_fastapi architecture

> Architecture diagram of the GitHub repository keshavadk/iris-flower-species-streamlit_fastapi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keshavadk/iris-flower-species-streamlit_fastapi
- Repository: https://github.com/keshavadk/iris-flower-species-streamlit_fastapi

## Overview

##### Project type and purpose
- This is a simple full-stack machine-learning web application.
- The backend (FastAPI) serves an Iris predictor API and persists a trained model.
- The frontend (Streamlit) provides a UI with sliders and invokes the API to display predictions.

##### File structure
- Top-level:
- backend/ – contains app.py (FastAPI) and iris_model.joblib
- frontend/ – contains streamlit_app.py (Streamlit UI)
- requirements.txt – lists all Python dependencies
- Key patterns:
- Two-tier architecture (UI + API)
- Model persistence (joblib)
- One Python virtual environment

##### README for additional insights
- The README describes startup steps:
- Train or load model on first backend launch
- FastAPI exposes “/” (health) and “/predict” endpoints
- Streamlit frontend POSTs to /predict and renders results

a. Main components:
1. Client Browser (or local machine)
2. Streamlit Frontend
3. FastAPI Backend (app.py)
4. Model Trainer/Loader
5. Persisted Model File (iris_model.joblib)
6. Python Virtual Environment & Dependencies
b. Relationships and interactions:
- User interacts with Streamlit UI via browser.
- Streamlit sends HTTP POST requests to FastAPI /predict.
- FastAPI loads/trains the model (first run) via Model Trainer/Loader.
- Model Trainer/Loader reads/writes iris_model.joblib.
- FastAPI returns JSON response back to Streamlit, which displays results.
c. Architectural patterns/design principles:
- Separation of concerns: UI vs. API vs. ML logic
- Stateless API calls (each request uses the persisted model)
- Model persistence for faster subsequent predictions
d. Relevant technologies/frameworks:
- Python venv (isolated environment)
- FastAPI & Uvicorn (API server)
- scikit-learn & joblib (model training & serialization)
- Streamlit (frontend)

##### Detailed guidance
- Model Trainer/Loader
- iris_model.joblib storage
- At the bottom or corner, annotate the virtual environment & requirements.
- Notes on first-run training versus subsequent predictions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Frontend
    Browser["Client Browser"]:::ui
    Browser -->|"Interacts via localhost UI"| Streamlit["Streamlit Frontend"]:::ui

    %% Backend service group
    subgraph "Backend Service"
        direction TB
        FastAPI["FastAPI Backend"]:::api
        ModelLoader["Model Trainer/Loader"]:::api
        ModelFile["iris_model.joblib"]:::data
    end

    %% Interactions between Frontend and Backend
    Streamlit -->|"POST /predict"| FastAPI
    FastAPI --> ModelLoader
    ModelLoader -->|"loads/saves model"| ModelFile
    FastAPI -->|"JSON response"| Streamlit
    Streamlit --> Browser

    %% Environment and dependencies
    Requirements["requirements.txt\n(Python dependencies)"]:::env

    %% Dependencies arrow
    Requirements -.-> Backend["Backend Service"]

    %% Click events
    click Streamlit "https://github.com/keshavadk/iris-flower-species-streamlit_fastapi/blob/main/frontend/streamlit_app.py"
    click FastAPI "https://github.com/keshavadk/iris-flower-species-streamlit_fastapi/blob/main/backend/app.py"
    click ModelLoader "https://github.com/keshavadk/iris-flower-species-streamlit_fastapi/blob/main/backend/app.py"
    click ModelFile "https://github.com/keshavadk/iris-flower-species-streamlit_fastapi/blob/main/backend/iris_model.joblib"
    click Requirements "https://github.com/keshavadk/iris-flower-species-streamlit_fastapi/blob/main/requirements.txt"

    %% Styling
    classDef ui fill:#d0e7ff,stroke:#5b9bd5,color:#000;
    classDef api fill:#d7f2d4,stroke:#3c763d,color:#000;
    classDef data fill:#ffe5b4,stroke:#cc7a00,color:#000;
    classDef env fill:#f0f0f0,stroke:#555,color:#000;
```
