# fbarulli/mlflow architecture

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

- Interactive diagram: https://gitdiagram.com/fbarulli/mlflow
- Repository: https://github.com/fbarulli/mlflow

## Overview

##### Project Type and Purpose
- This is a machine-learning project built around MLflow.
- It trains two models (RandomForest, LogisticRegression) on wine data (wine_work.py, df.ipynb) and tracks experiments/artifacts with MLflow.
- It’s containerized: one container runs the MLflow tracking server, another hosts a prediction service (“app”), both orchestrated via docker-compose.

##### File Structure
Top-level artifacts:
- Dockerfile.server – builds the MLflow Tracking Server container
- Dockerfile.app – builds the Model Serving App container
- docker-compose.yml – orchestrates both containers + volume mounts
- MLproject – MLflow project definition for reproducible runs
- run.sh – script to launch MLflow runs (wine_work.py) against the tracking server
- mlruns/ – the local artifact store (metrics, model.pkl, environment specs)
- outputs/ – prediction CSVs generated by the training jobs
- wine_work.py & df.ipynb – data processing & model training code
- requirements.txt – Python dependencies

##### Major Components
A. Developer Workstation
- Codebase: wine_work.py, df.ipynb, MLproject, run.sh, requirements.txt
- Invokes “run.sh” which runs `mlflow run .` pointing at the MLflow server
B. Docker Compose Orchestrator
- Defines and connects two services: “mlflow-server” and “mlflow-app”
- Mounts host directories (mlruns/, outputs/) into the containers
C. MLflow Tracking Server Container
- Built from Dockerfile.server
- Exposes:
- REST API for logging experiments (port 5000)
- Web UI for viewing runs/artifacts
- Persists data to a volume (host’s mlruns/ directory)
D. Model Serving App Container
- Built from Dockerfile.app
- Loads the trained model artifact (model.pkl) from the MLflow server or local mount
- Exposes a REST endpoint for inference requests
- Writes prediction outputs back to outputs/ or returns them in HTTP responses
E. Artifact Store (mlruns Volume)
- Stores models, metrics, artifacts under /mlruns inside the server container
- Shared read-only into the app container for loading models
F. Outputs Volume
- Receives CSVs of predictions produced by training jobs or by the app

##### Interactions & Data Flow
1. Developer runs `./run.sh` → MLflow client on workstation
2. MLflow client → (HTTP) → Tracking Server API
- Sends training parameters, logs metrics, stores artifacts under mlruns/
3. Tracking Server writes to mlruns/ volume
4. Developer inspects runs via Tracking Server Web UI
5. App Container fetches model artifact (via MLflow API or direct volume mount)
6. Client (or testing script) → (HTTP) → App Container inference endpoint
7. App returns predictions (and/or writes to outputs/ volume)

##### Highlighted Architectural Patterns & Principles
- Micro-service separation: one service for experiment tracking (stateful), one for model serving (stateless)
- Reproducibility: MLproject file + conda/python_env yaml ensures consistent environments
- Volume mounting for persistent artifact storage & sharing between containers
- Clear separation of training (batch/script) vs serving (API)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Workstation
    subgraph "Developer Workstation"
        direction TB
        wine["wine_work.py"]:::code
        df["df.ipynb"]:::code
        mlproj["MLproject"]:::code
        runsh["run.sh"]:::code
        req["requirements.txt"]:::code
    end

    %% Docker Compose Orchestrator
    subgraph "Docker Compose Orchestrator"
        direction TB
        dockerCompose["docker-compose.yml"]:::orchestrator
        %% Containers & Volumes
        subgraph "Containers & Volumes"
            direction TB
            ServerAPI["MLflow Tracking Server"]:::service
            App["Model Serving App"]:::service
            VolArtifact["mlruns Volume"]:::volume
            VolOutput["outputs Volume"]:::volume
        end
    end

    %% External Client
    Client["External Client"]:::client

    %% Relationships
    runsh -->|"mlflow run . --> HTTP POST /api/2.0/mlflow/runs/create"| ServerAPI
    wine -->|uses data & code| runsh
    df -->|notebook for exploration| runsh
    mlproj -->|defines project| runsh
    req -->|dependencies| runsh

    dockerCompose -->|orchestrates| ServerAPI
    dockerCompose -->|orchestrates| App
    VolArtifact -->|mount /mlruns| ServerAPI
    VolArtifact -->|mount /mlruns read-only| App
    VolOutput -->|mount /outputs write| App

    Client -->|HTTP POST /predict| App
    App -->|HTTP response| Client

    %% Click Events
    click wine "https://github.com/fbarulli/mlflow/blob/main/wine_work.py"
    click df "https://github.com/fbarulli/mlflow/blob/main/df.ipynb"
    click mlproj "https://github.com/fbarulli/mlflow/tree/main/MLproject"
    click runsh "https://github.com/fbarulli/mlflow/blob/main/run.sh"
    click req "https://github.com/fbarulli/mlflow/blob/main/requirements.txt"
    click dockerCompose "https://github.com/fbarulli/mlflow/blob/main/docker-compose.yml"
    click ServerAPI "https://github.com/fbarulli/mlflow/blob/main/Dockerfile.server"
    click App "https://github.com/fbarulli/mlflow/blob/main/Dockerfile.app"
    click VolArtifact "https://github.com/fbarulli/mlflow/tree/main/mlruns/"
    click VolOutput "https://github.com/fbarulli/mlflow/tree/main/outputs/"

    %% Styles
    classDef code fill:#DDEEFF,stroke:#0000FF,color:#0000FF;
    classDef orchestrator fill:#F0F0F0,stroke:#999999,color:#666666;
    classDef service fill:#E0FFE0,stroke:#008000,color:#006400;
    classDef volume fill:#FFE0B2,stroke:#FF8C00,color:#A0522D;
    classDef client fill:#F3E5F5,stroke:#800080,color:#4B0082;
```
