# sidhant-1299/youtube-sentiment-analysis architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack machine-learning–powered Chrome extension.
- Frontend: a YouTube plugin (JavaScript/HTML) that scrapes comments and displays sentiment results.
- Backend: a Dockerized Flask API serving a pretrained LightGBM sentiment model.
- Data/ML pipeline: implemented in `src/` plus Jupyter notebooks and managed with DVC.

##### File structure
- Top level
- Dockerfile, .dockerignore: containerize the Flask API
- dvc.yaml, dvc.lock, .dvc/: version-control for datasets/models
- flask-requirements.txt, pyproject.toml: Python dependencies
- Frontend
- yt-chrome-plugin-frontend/: manifest.json, popup.js/html
- Backend API
- flask_api/app.py: Flask routes for `/predict`
- lgbm_model.pkl, tfidf_vectorizer.pkl: serialized model artifacts
- ML pipeline
- src/data: ingestion & preprocessing
- src/model: building, evaluation, registration
- src/config: parameter/config management
- notebooks/: exploratory experiments
- Lock files (uv.lock) ensure reproducible dev environment.

##### README
- Describes workflow: extension fetches comments → sends to Flask container (port 5555) → returns sentiment data → extension renders interactive pie chart.
- Usage instructions for Docker build/run and extension developer mode.

##### Components & interactions
a. Main components
- User’s Chrome browser with YouTube page
- Chrome extension (popup + content script)
- External YouTube site (source of comments)
- Docker container hosting Flask API
- Flask application (REST endpoint)
- Model artifacts: TF-IDF vectorizer + LightGBM model
- (Optional/training) ML pipeline & DVC store
b. Relationships & data flow
1. User navigates to YouTube, extension content script scrapes visible comments.
2. Extension issues HTTP POST to Flask `/predict` with comment text.
3. Docker network routes request to Flask server.
4. Flask loads vectorizer & model, transforms text → model.predict → JSON response.
5. Extension receives sentiment scores & displays chart on YouTube page.
6. (Training path) Data ingestion → preprocessing → model training (src/data → src/model) → register new model via DVC & update lgbm_model.pkl.
c. Architectural patterns/design principles
- Separation of concerns: Browser plugin vs. backend inference service
- Containerization for environment consistency
- Version-controlled data/model pipeline (DVC)
- Config management under `src/config` for reproducible parameters
d. Key technologies/frameworks
- Chrome Extension APIs (manifest.json, content scripts)
- Flask (flask_api/app.py)
- Docker
- DVC for data/model versioning
- LightGBM + scikit-learn TF-IDF
- Python project tooling (pyproject.toml)

## Diagram (Mermaid)

```mermaid
flowchart TD
    YT["YouTube Site"]:::external

    subgraph "Chrome Extension (yt-chrome-plugin-frontend)"
        Manifest["manifest.json"]:::frontend
        PopupHTML["popup.html"]:::frontend
        PopupJS["popup.js"]:::frontend
    end

    YT -->|"Visible comments scraped"| PopupJS
    Manifest --> PopupHTML
    Manifest --> PopupJS
    PopupJS -->|"POST /predict"| APP

    subgraph "Flask API Container (port 5555)"
        APP["Flask /predict API"]:::backend
        DockerfileNode["Dockerfile"]:::backend
        DockerIgnore[".dockerignore"]:::backend
        Req["flask-requirements.txt"]:::backend
        TFIDF["tfidf_vectorizer.pkl"]:::model
        LGBM["lgbm_model.pkl"]:::model
        ConfigNode["config.py\nparams.yaml"]:::config
    end

    APP --> TFIDF
    APP --> LGBM
    APP --> ConfigNode
    TFIDF --> APP
    LGBM --> APP
    APP -->|"JSON response"| PopupJS

    subgraph "ML Training Pipeline"
        DI["data_ingestion.py"]:::pipeline
        DP["data_preprocessing.py"]:::pipeline
        MB["model_building.py"]:::pipeline
        ME["model_evaluation.py"]:::pipeline
        RM["register_model.py"]:::pipeline
        DVCStore["DVC Store\n(dvc.yaml, dvc.lock, .dvc/)"]:::pipeline
        subgraph "Jupyter Notebooks"
            NB1["Baseline_Model_experiment.ipynb"]:::pipeline
            NB2["Experiment_2_BOW_TFIDF.ipynb"]:::pipeline
            NB3["experiment_3_tfidf_(1,3)_max_features.ipynb"]:::pipeline
            NB4["experiment_4_handling_imbalanced_dataset.ipynb"]:::pipeline
            NB5["experiment_5_lightgbm_detailed_hpt.ipynb"]:::pipeline
            NB6["dataset_preprocessed.csv"]:::pipeline
        end
    end

    DI --> DP --> MB --> ME --> RM --> DVCStore
    NB1 -.-> DI
    NB2 -.-> DP
    NB3 -.-> DP
    NB4 -.-> DP
    NB5 -.-> MB
    NB6 -.-> DP
    ConfigNode --> DI
    ConfigNode --> DP
    ConfigNode --> MB
    ConfigNode --> ME

    click Manifest "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/yt-chrome-plugin-frontend/manifest.json"
    click PopupHTML "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/yt-chrome-plugin-frontend/popup.html"
    click PopupJS "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/yt-chrome-plugin-frontend/popup.js"
    click APP "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/flask_api/app.py"
    click DockerfileNode "https://github.com/sidhant-1299/youtube-sentiment-analysis/tree/main/Dockerfile"
    click DockerIgnore "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/.dockerignore"
    click Req "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/flask-requirements.txt"
    click TFIDF "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/tfidf_vectorizer.pkl"
    click LGBM "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/lgbm_model.pkl"
    click DI "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/src/data/data_ingestion.py"
    click DP "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/src/data/data_preprocessing.py"
    click MB "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/src/model/model_building.py"
    click ME "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/src/model/model_evaluation.py"
    click RM "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/src/model/register_model.py"
    click ConfigNode "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/src/config/config.py"
    click DVCStore "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/dvc.yaml"
    click DVCStore "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/dvc.lock"
    click DVCStore "https://github.com/sidhant-1299/youtube-sentiment-analysis/tree/main/.dvc/"
    click NB1 "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/notebooks/Baseline_Model_experiment.ipynb"
    click NB2 "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/notebooks/Experiment_2_BOW_TFIDF.ipynb"
    click NB3 "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/notebooks/experiment_3_tfidf_(1,3)_max_features.ipynb"
    click NB4 "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/notebooks/experiment_4_handling_imbalanced_dataset.ipynb"
    click NB5 "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/notebooks/experiment_5_lightgbm_detailed_hpt.ipynb"
    click NB6 "https://github.com/sidhant-1299/youtube-sentiment-analysis/blob/main/notebooks/dataset_preprocessed.csv"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#F0E68C,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef model fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef pipeline fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef config fill:#FFD700,stroke:#333,stroke-width:1px
```
