# entbappy/end-to-end-youtube-sentiment architecture

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

- Interactive diagram: https://gitdiagram.com/entbappy/end-to-end-youtube-sentiment
- Repository: https://github.com/entbappy/end-to-end-youtube-sentiment

## Overview

##### Main Components
- ML Pipeline and Experimentation:
- Data Ingestion and Preprocessing (found under src/data and notebooks).
- Model Building, Evaluation, and Registration (in src/model and pickled model files like lgbm_model.pkl and tfidf_vectorizer.pkl).
- Experiment tracking and reproducibility via DVC (dvc.yaml, dvc.lock, and the .dvc folder).
- API Layer:
- Main server scripts (app.py and flask_app/app.py) exposing a REST endpoint (/predict) for sentiment analysis.
- Frontend:
- A Chrome extension (yt-chrome-plugin-frontend) that interacts with the backend service.
- Deployment & Infrastructure:
- Docker containerization (Dockerfile).
- CI/CD through GitHub Actions (.github/workflows/cicd.yaml).
- AWS services for deployment (instructions in README regarding EC2 and ECR).

##### Relationships and Interactions
- The ML Pipeline (data ingestion, model building, evaluation) produces predictive models and vectorizers used by the API.
- The API layer receives JSON POST requests (see the sample in the README) from either a client or directly from the Chrome extension and uses the trained models to process inputs.
- The Chrome extension is a frontend client that sends user requests to the Flask API.
- DVC manages the data and experiment pipelines, ensuring that the correct versioned data and models are used.
- CI/CD pipelines build a Docker image, push it to AWS ECR, and deploy it on AWS EC2 – ensuring smooth integration and continuous deployment.
- The infrastructure orchestration (Dockerfile, GitHub Actions, and AWS deployment instructions) connects the dots between code, container image, and production deployment.

##### Architectural Patterns and Design Principles
- Modularity: Separation between the data pipeline (in src), API (Flask app), and the frontend (Chrome extension).
- Reproducibility: DVC tracks data, experiments, and dependencies.
- Containerization & CI/CD: Docker is used for packaging the application; GitHub Actions automate build and deployment to AWS.
- RESTful Design: The API follows REST principles for accepting and processing prediction requests.
- Integration: There is a clear boundary between ML model building and serving, making it easier to update either side independently.

##### Incorporate Relevant Technologies
- Programming Language & Frameworks: Python (Flask for API, ML libraries referenced in notebooks).
- Version Control and Experiment Tracking: Git and DVC.
- Deployment Tools: Docker, GitHub Actions, AWS (EC2, ECR).
- Frontend: Basic HTML/JS for the Chrome plugin (manifest.json, popup.html, popup.js).
- Model Artifacts: Pickled models (lgbm_model.pkl, tfidf_vectorizer.pkl).

## Diagram (Mermaid)

```mermaid
graph TD
    %% ML Pipeline & Experimentation Subgraph
    subgraph "ML Pipeline & Experimentation"
        A("Data Ingestion"):::ml
        B("Data Preprocessing"):::ml
        C("EDA Notebook"):::ml
        D("Model Building"):::ml
        E("Model Evaluation"):::ml
        F("Model Registration"):::ml
        G("LGBM Model"):::ml
        H("TFIDF Vectorizer"):::ml
        I("Experiment Tracking (dvc.yaml & dvc.lock)"):::ml
        J("DVC Folder"):::ml
    end

    %% API Server (Flask) Subgraph
    subgraph "API Server (Flask)"
        K("API Entry (app.py)"):::api
        L("Flask App Module"):::api
    end

    %% Chrome Extension Frontend Subgraph
    subgraph "Chrome Extension Frontend"
        M("Extension Directory"):::chrome
        N("Manifest"):::chrome
        O("Popup HTML"):::chrome
        P("Popup JS"):::chrome
    end

    %% Deployment & Infrastructure Subgraph
    subgraph "Deployment & Infrastructure"
        Q("Docker Containerization"):::dep
        R("CI/CD Pipeline"):::dep
        S("AWS Deployment"):::dep
    end

    %% Relationships between ML Pipeline and API Server
    D -->|"produces"| K
    E -->|"produces"| K
    F -->|"triggers"| K
    G -->|"artifact"| K
    H -->|"artifact"| K
    I --> D
    I --> E
    I --> F
    J --> I

    %% Relationship between Chrome Extension and API Server
    M -->|"sends_request"| K
    N --> M
    O --> M
    P --> M

    %% Relationships in Deployment & Infrastructure
    Q -->|"builds"| R
    R -->|"deploys_to"| S
    S -->|"hosts"| K

    %% Class Definitions for color styling
    classDef ml fill:#FFCCCC,stroke:#AA0000,stroke-width:2px;
    classDef api fill:#CCFFFF,stroke:#006666,stroke-width:2px;
    classDef chrome fill:#CCFFCC,stroke:#009900,stroke-width:2px;
    classDef dep fill:#FFE5CC,stroke:#CC6600,stroke-width:2px;

    %% Click Events for ML Pipeline & Experimentation
    click A "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/src/data/data_ingestion.py"
    click B "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/src/data/data_preprocessing.py"
    click C "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/notebooks/1_Preprocessing_&_EDA.ipynb"
    click D "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/src/model/model_building.py"
    click E "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/src/model/model_evaluation.py"
    click F "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/src/model/register_model.py"
    click G "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/lgbm_model.pkl"
    click H "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/tfidf_vectorizer.pkl"
    click I "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/dvc.yaml"
    click J "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/.dvc"

    %% Click Events for API Server (Flask)
    click K "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/app.py"
    click L "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/flask_app/app.py"

    %% Click Events for Chrome Extension Frontend
    click M "https://github.com/entbappy/end-to-end-youtube-sentiment/tree/main/yt-chrome-plugin-frontend"
    click N "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/yt-chrome-plugin-frontend/manifest.json"
    click O "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/yt-chrome-plugin-frontend/popup.html"
    click P "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/yt-chrome-plugin-frontend/popup.js"

    %% Click Events for Deployment & Infrastructure
    click Q "https://github.com/entbappy/end-to-end-youtube-sentiment/tree/main/Dockerfile"
    click R "https://github.com/entbappy/end-to-end-youtube-sentiment/blob/main/.github/workflows/cicd.yaml"
```
