# abess96/youtube-sentiment-analysis architecture

> Architecture diagram of the GitHub repository abess96/youtube-sentiment-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abess96/youtube-sentiment-analysis
- Repository: https://github.com/abess96/youtube-sentiment-analysis

## Overview

##### Project type and purpose
- This is a machine-learning pipeline with an online inference component plus a browser extension front end.
- It ingests YouTube comment data, runs preprocessing, trains and registers models (via DVC), exposes a Flask API for live inference, and offers a Chrome plugin UI to call that API.

##### Top-level components
- Data Pipeline (DVC)
– dvc.yaml + dvc.lock define stages
– .dvc directory holds local config
- Core ML code (src/)
– data_ingestion.py
– data_preprocessing.py
– model_building.py
– model_evaluation.py
– register_model.py
- Experiment notebooks (notebooks/)
– EDA, feature engineering, modeling experiments
- Model artifact store/registry
– managed by DVC (and optionally remote storage)
- Flask service (flask_api/main.py)
– loads latest registered model
– accepts HTTP requests, returns sentiment predictions
- Chrome plugin front end (yt-chrome-plugin-frontend/)
– popup.html + popup.js + manifest.json
– UI for entering or scraping comments and calling Flask API

##### Relationships and data flows
- Offline pipeline:
Raw data → DVC stages: ingestion → preprocessing → training → evaluation → register_model → DVC stores versioned artifacts
- Runtime/inference:
Browser plugin ←→ Flask API ← loads model artifact from local DVC checkout (or remote)
- Dependencies:
– requirements.txt / setup.py list Python packages
– params.yaml holds configurable hyperparameters

##### Architectural patterns and principles
- Separation of concerns:
– Data pipeline separate from model training code
– API separate from training
– UI (Chrome extension) decoupled from API
- Versioned reproducibility via DVC
- Modular ML code under src/model and src/data
- Minimal runtime dependencies for production (Flask + model)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source
    RawData["YouTube API Raw Data"]:::external

    subgraph "Offline ML Pipeline"
        direction TB
        %% DVC Configuration
        DVCYaml["dvc.yaml"]:::config
        DVCLock["dvc.lock"]:::config
        DVCdir[".dvc/"]:::config
        DVCignore[".dvcignore"]:::config

        Params["params.yaml"]:::config
        Requirements["requirements.txt"]:::config
        Setup["setup.py"]:::config

        %% DVC Orchestrator
        DVC["DVC Pipeline"]:::offline

        %% Source Modules
        subgraph "src/data"
            direction TB
            DI["data_ingestion.py"]:::offline
            DP["data_preprocessing.py"]:::offline
        end

        subgraph "src/model"
            direction TB
            MB["model_building.py"]:::offline
            ME["model_evaluation.py"]:::offline
            RM["register_model.py"]:::offline
        end

        %% Notebooks
        subgraph "notebooks"
            direction TB
            NB1["1_Preprocessing_EDA.ipynb"]:::offline
            NB2["2_baseline_model.ipynb"]:::offline
            NB3["3_experiment_bow_tfidf.ipynb"]:::offline
            NB4["4_experiment_tfidf_maxFeature.ipynb"]:::offline
            NB5["5_handaling_imbalanced_data.ipynb"]:::offline
            NB6["6_experiment_5_xgboost_with_hpt.ipynb"]:::offline
            NB7["7_experiment_6_lightgbm_detailed_hpt.ipynb"]:::offline
            NB8["8_stacking.ipynb"]:::offline
        end

        %% Model Store
        ModelStore["Model Artifacts"]:::storage

        %% Orchestration and Flow
        RawData -->|input data| DVC
        DVCYaml --> DVC
        DVCLock --> DVC
        DVCdir --> DVC
        DVCignore --> DVC
        Params --> DVC
        Requirements --> DVC
        Setup --> DVC

        DVC -->|stage: ingestion| DI
        DVC -->|stage: preprocessing| DP
        DVC -->|stage: training| MB
        DVC -->|stage: evaluation| ME
        DVC -->|stage: register| RM

        RM -->|artifact| ModelStore
        NB1 --> DVC
        NB2 --> DVC
        NB3 --> DVC
        NB4 --> DVC
        NB5 --> DVC
        NB6 --> DVC
        NB7 --> DVC
        NB8 --> DVC
    end

    subgraph "Runtime Inference"
        direction TB
        Flask["Flask API"]:::runtime
        Plugin["Chrome Extension"]:::runtime
    end

    ModelStore -->|"load model"| Flask
    Plugin -->|"HTTP POST: comment→sentiment"| Flask

    %% Click events
    click DVCYaml "https://github.com/abess96/youtube-sentiment-analysis/blob/main/dvc.yaml"
    click DVCLock "https://github.com/abess96/youtube-sentiment-analysis/blob/main/dvc.lock"
    click DVCdir "https://github.com/abess96/youtube-sentiment-analysis/tree/main/.dvc/"
    click DVCignore "https://github.com/abess96/youtube-sentiment-analysis/blob/main/.dvcignore"
    click DI "https://github.com/abess96/youtube-sentiment-analysis/blob/main/src/data/data_ingestion.py"
    click DP "https://github.com/abess96/youtube-sentiment-analysis/blob/main/src/data/data_preprocessing.py"
    click MB "https://github.com/abess96/youtube-sentiment-analysis/blob/main/src/model/model_building.py"
    click ME "https://github.com/abess96/youtube-sentiment-analysis/blob/main/src/model/model_evaluation.py"
    click RM "https://github.com/abess96/youtube-sentiment-analysis/blob/main/src/model/register_model.py"
    click NB1 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/1_Preprocessing_EDA.ipynb"
    click NB2 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/2_baseline_model.ipynb"
    click NB3 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/3_experiment_bow_tfidf.ipynb"
    click NB4 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/4_experiment_tfidf_maxFeature.ipynb"
    click NB5 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/5_handaling_imbalanced_data.ipynb"
    click NB6 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/6_experiment_5_xgboost_with_hpt.ipynb"
    click NB7 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/7_experiment_6_lightgbm_detailed_hpt.ipynb"
    click NB8 "https://github.com/abess96/youtube-sentiment-analysis/blob/main/notebooks/8_stacking.ipynb"
    click Flask "https://github.com/abess96/youtube-sentiment-analysis/blob/main/flask_api/main.py"
    click Plugin "https://github.com/abess96/youtube-sentiment-analysis/blob/main/yt-chrome-plugin-frontend/manifest.json"
    click Plugin "https://github.com/abess96/youtube-sentiment-analysis/blob/main/yt-chrome-plugin-frontend/popup.html"
    click Plugin "https://github.com/abess96/youtube-sentiment-analysis/blob/main/yt-chrome-plugin-frontend/popup.js"
    click Params "https://github.com/abess96/youtube-sentiment-analysis/blob/main/params.yaml"
    click Requirements "https://github.com/abess96/youtube-sentiment-analysis/blob/main/requirements.txt"
    click Setup "https://github.com/abess96/youtube-sentiment-analysis/blob/main/setup.py"

    %% Styles
    classDef offline fill:#a1cfff,stroke:#000;
    classDef runtime fill:#b3ffb3,stroke:#000;
    classDef storage fill:#ffdf80,stroke:#000;
    classDef external fill:#ffb3b3,stroke:#000;
    classDef config fill:#d9d9d9,stroke:#000;
```
