# swagath18/a-b-testing-recommender-system architecture

> Architecture diagram of the GitHub repository swagath18/a-b-testing-recommender-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swagath18/a-b-testing-recommender-system
- Repository: https://github.com/swagath18/a-b-testing-recommender-system

## Overview

##### Project Type and Purpose
- This is a full-stack, data-driven web application for simulating and visualizing an A/B test between two recommender engines.
- It combines a Streamlit frontend UI, Python modules for recommendation logic and evaluation, and MLflow for experiment tracking.

##### File Structure Analysis
- data/: Static CSV datasets (interactions.csv, item_metadata_tfidf.csv)
- src/: Core Python modules
- recommend_baseline.py – popularity-based recommender
- recommend_new.py – TF-IDF–based recommender
- ab_test.py – A/B assignment & CTR simulation
- evaluation.py – lift calculation and statistical tests
- streamlit_app.py: Entry point for the interactive UI
- main.py (mentioned in README): Offline batch evaluation script
- requirements.txt & MLflow config: Environment setup and experiment tracking

##### Main Components
a. Frontend (Streamlit UI)
- streamlit_app.py renders pages, collects user requests, displays recommendations and metrics.
b. Backend Logic
- A/B Test Controller (ab_test.py)
- Recommender Engines (baseline & TF-IDF modules)
- Evaluation Engine (evaluation.py)
c. Data Layer
- Datasets in data/
- In-memory Pandas DataFrames at runtime
d. Experiment Tracking
- MLflow server & local artifact store
e. Offline Batch Runner
- main.py triggers evaluation without UI

##### Component Interactions
- Streamlit UI → calls A/B Test Controller →
- fetches user group, invokes appropriate recommender → returns item list → UI shows recommendations
- UI records simulated clicks → passes results to evaluation module → calculates CTR & lift → logs all metrics to MLflow
- main.py orchestrates same calls in batch mode and prints results

##### Architectural Patterns and Principles
- Layered design:
- Presentation layer (Streamlit)
- Business logic layer (A/B, recommenders, evaluation)
- Data layer (CSV files, DataFrames)
- Infrastructure layer (MLflow tracking)
- Single-process monolith, clear separation of concerns by module
- Configurable components (e.g., switching in new recommenders)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Streamlit UI"]:::ui
        Main["Offline Runner (main.py)"]:::compute
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        AB["A/B Test Controller"]:::compute
        Baseline["Baseline Recommender"]:::compute
        TFIDF["TF-IDF Recommender"]:::compute
        Eval["Evaluation Engine"]:::compute
    end

    %% Data Layer
    subgraph "Data Layer"
        Interactions["interactions.csv"]:::data
        ItemMeta["item_metadata_tfidf.csv"]:::data
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        MLflow["MLflow Server"]:::infra
    end

    %% Connections
    UI -->|"request recommendations"| AB
    AB -->|"assign group & invoke"| Baseline
    AB -->|"assign group & invoke"| TFIDF
    Baseline -->|"read data"| Interactions
    TFIDF -->|"read data"| ItemMeta
    TFIDF -->|"read data"| Interactions
    Baseline -->|"return items"| AB
    TFIDF -->|"return items"| AB
    AB -->|"send recommendations"| UI
    UI -->|"record clicks"| Eval
    Eval -->|"log CTR & lift"| MLflow
    Main -->|"batch run"| AB
    Main -->|"batch evaluate"| Eval

    %% Click Events
    click UI "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/streamlit_app.py"
    click Main "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/main.py"
    click AB "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/src/ab_test.py"
    click Baseline "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/src/recommend_baseline.py"
    click TFIDF "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/src/recommend_new.py"
    click Eval "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/src/evaluation.py"
    click Interactions "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/data/interactions.csv"
    click ItemMeta "https://github.com/swagath18/a-b-testing-recommender-system/blob/main/data/item_metadata_tfidf.csv"

    %% Styles
    classDef ui fill:#9f6,stroke:#333,stroke-width:1px;
    classDef compute fill:#6cf,stroke:#333,stroke-width:1px;
    classDef data fill:#ffeb3b,stroke:#333,stroke-width:1px;
    classDef infra fill:#f90,stroke:#333,stroke-width:1px;
```
