# arunscode2002/youtube-virality-predictor architecture

> Architecture diagram of the GitHub repository arunscode2002/youtube-virality-predictor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arunscode2002/youtube-virality-predictor
- Repository: https://github.com/arunscode2002/youtube-virality-predictor

## Overview

This is a YouTube virality prediction service. A user submits a video URL through the dashboard or REST API; the API fetches video data, derives temporal and sentiment features, and returns a model-based or heuristic prediction. Separate collection and training paths build historical data and train models, while history and health endpoints expose service state. Edges reflect the excerpts, SOURCE INDEX references, and README; dashboard-to-API wiring is not shown in source excerpts, so that relationship is marked unverified.

Main entry points: [`ml/train.py`](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/train.py) (Training pipeline), [`api/main.py`](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/main.py) (REST API), [`data/collector.py`](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/data/collector.py) (Snapshot collector), [`features/extractor.py`](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/extractor.py) (Temporal features)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_dashboard["Web dashboard<br/>[app.js]"]
  node_api["REST API<br/>[main.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_collection["Data Collection"]
  node_youtube["YouTube client<br/>[youtube_client.py]"]
  node_collector["Snapshot collector<br/>[collector.py]"]
  node_database[("Engagement database<br/>[database.py]")]
end

subgraph group_analysis["Feature Analysis"]
  node_extractor["Temporal features<br/>[extractor.py]"]
  node_sentiment["Comment sentiment<br/>[sentiment.py]"]
  node_labeler["Virality labels<br/>[labeler.py]"]
end

subgraph group_learning["Model Training"]
  node_training["Training pipeline<br/>[train.py]"]
  node_randomforest["Random forest<br/>[random_forest.py]"]
  node_boosting["Gradient boosting"]
  node_lstm["LSTM model<br/>[lstm_model.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_models[("Saved models")]
end

subgraph group_platform["Service Platform"]
  node_settings["Configuration<br/>[settings.py]"]
  node_helpers["Shared helpers<br/>[helpers.py]"]
end

node_user(("Video analyst"))
node_youtubeapi["YouTube Data API"]

node_user -->|"submits video"| node_dashboard
node_dashboard -.->|"requests prediction"| node_api
node_api -->|"validates and responds"| node_schemas
node_api -->|"fetches video data"| node_youtube
node_youtube -->|"queries"| node_youtubeapi
node_api -->|"extracts features"| node_extractor
node_extractor -->|"analyzes comments"| node_sentiment
node_api -->|"predicts with models"| node_training
node_api -->|"reads history"| node_database
node_api -->|"collects engagement"| node_collector
node_collector -->|"fetches statistics"| node_youtube
node_collector -->|"stores snapshots"| node_database
node_training -->|"loads training data"| node_database
node_training -->|"generates demo data"| node_collector
node_training -->|"builds features"| node_extractor
node_training -->|"creates labels"| node_labeler
node_labeler -->|"uses features"| node_extractor
node_training -->|"trains model"| node_randomforest
node_training -->|"trains model"| node_boosting
node_training -->|"trains model"| node_lstm
node_training -->|"saves model files"| node_models
node_evaluation -.->|"evaluates models"| node_models
node_api -->|"loads configuration"| node_settings
node_collector -->|"reads collection settings"| node_settings
node_training -->|"reads model settings"| node_settings
node_extractor -->|"uses utilities"| node_helpers
node_youtube -->|"reads API key"| node_settings

click node_dashboard "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/dashboard/app.js"
click node_api "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/main.py"
click node_schemas "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/schemas.py"
click node_youtube "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/youtube_client.py"
click node_collector "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/data/collector.py"
click node_database "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/data/database.py"
click node_extractor "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/extractor.py"
click node_sentiment "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/sentiment.py"
click node_labeler "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/labeler.py"
click node_training "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/train.py"
click node_randomforest "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/random_forest.py"
click node_boosting "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/gradient_boosting.py"
click node_lstm "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/lstm_model.py"
click node_evaluation "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/evaluate.py"
click node_models "https://github.com/arunscode2002/youtube-virality-predictor/tree/main/models"
click node_settings "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/config/settings.py"
click node_helpers "https://github.com/arunscode2002/youtube-virality-predictor/blob/main/utils/helpers.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard,node_api,node_schemas toneBlue
class node_youtube,node_collector,node_database toneAmber
class node_extractor,node_sentiment,node_labeler,node_youtubeapi toneMint
class node_training,node_randomforest,node_boosting,node_lstm,node_evaluation,node_models toneRose
class node_settings,node_helpers,node_user toneIndigo
```

## Components

### User Experience

- [Web dashboard](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/dashboard/app.js): `dashboard/app.js`
- [REST API](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/main.py): `api/main.py`
- [API schemas](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/schemas.py): `api/schemas.py`

### Data Collection

- [YouTube client](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/api/youtube_client.py): `api/youtube_client.py`
- [Snapshot collector](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/data/collector.py): `data/collector.py`
- [Engagement database](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/data/database.py): `data/database.py`

### Feature Analysis

- [Temporal features](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/extractor.py): `features/extractor.py`
- [Comment sentiment](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/sentiment.py): `features/sentiment.py`
- [Virality labels](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/features/labeler.py): `features/labeler.py`

### Model Training

- [Training pipeline](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/train.py): `ml/train.py`
- [Random forest](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/random_forest.py): `ml/random_forest.py`
- [Gradient boosting](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/gradient_boosting.py): `ml/gradient_boosting.py`
- [LSTM model](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/lstm_model.py): `ml/lstm_model.py`
- [Model evaluation](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/ml/evaluate.py): `ml/evaluate.py`
- [Saved models](https://github.com/arunscode2002/youtube-virality-predictor/tree/main/models): `models`

### Service Platform

- [Configuration](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/config/settings.py): `config/settings.py`
- [Shared helpers](https://github.com/arunscode2002/youtube-virality-predictor/blob/main/utils/helpers.py): `utils/helpers.py`

### Other components

- **Video analyst**
- **YouTube Data API**

## Connections

- Video analyst → Web dashboard: submits video (evidence: `README.md`)
- Web dashboard → REST API: requests prediction
- REST API → API schemas: validates and responds (evidence: `api/main.py`)
- REST API → YouTube client: fetches video data (evidence: `api/main.py`)
- YouTube client → YouTube Data API: queries (evidence: `api/youtube_client.py`)
- REST API → Temporal features: extracts features (evidence: `api/main.py`)
- Temporal features → Comment sentiment: analyzes comments (evidence: `features/extractor.py`)
- REST API → Training pipeline: predicts with models (evidence: `api/main.py`)
- REST API → Engagement database: reads history (evidence: `api/main.py`)
- REST API → Snapshot collector: collects engagement (evidence: `api/main.py`)
- Snapshot collector → YouTube client: fetches statistics (evidence: `data/collector.py`)
- Snapshot collector → Engagement database: stores snapshots (evidence: `data/collector.py`)
- Training pipeline → Engagement database: loads training data (evidence: `ml/train.py`)
- Training pipeline → Snapshot collector: generates demo data (evidence: `ml/train.py`)
- Training pipeline → Temporal features: builds features (evidence: `ml/train.py`)
- Training pipeline → Virality labels: creates labels (evidence: `ml/train.py`)
- Virality labels → Temporal features: uses features (evidence: `features/labeler.py`)
- Training pipeline → Random forest: trains model (evidence: `ml/train.py`)
- Training pipeline → Gradient boosting: trains model (evidence: `ml/train.py`)
- Training pipeline → LSTM model: trains model (evidence: `ml/train.py`)
- Training pipeline → Saved models: saves model files (evidence: `README.md`)
- Model evaluation → Saved models: evaluates models
- REST API → Configuration: loads configuration (evidence: `api/main.py`)
- Snapshot collector → Configuration: reads collection settings (evidence: `data/collector.py`)
- Training pipeline → Configuration: reads model settings (evidence: `ml/train.py`)
- Temporal features → Shared helpers: uses utilities (evidence: `features/extractor.py`)
- YouTube client → Configuration: reads API key (evidence: `api/youtube_client.py`)
