# aarayann/catch-bait architecture

> Architecture diagram of the GitHub repository aarayann/catch-bait, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aarayann/catch-bait
- Repository: https://github.com/aarayann/catch-bait

## Overview

1. **Repository shape**
   - This repo is split into three clear boundaries: **data extraction**, **model training**, and **serving**.
   - The pipeline is mostly **offline/batch** until the final `app/` folder, which is the only user-facing runtime.

2. **Data acquisition boundary: `dataset_extraction/`**
   - This is the ETL layer that builds the supervised dataset from YouTube.
   - It interacts with external YouTube sources to collect **video metadata, thumbnails, transcripts, and channel/video manifests**.
   - The reusable logic lives in `dataset_extraction/clickbait_pipeline/`, with modules for API access, transcript fetching, thumbnail handling, JSONL I/O, schema definitions, and summaries.

3. **Extraction workflow**
   - The numbered scripts `01_...` through `09_...` show the intended end-to-end flow:
     1. collect videos,
     2. download thumbnails,
     3. fetch transcripts,
     4. generate heuristic auto-labels,
     5. merge labels,
     6. assemble a complete dataset,
     7. export CSV,
     8. balance the dataset,
     9. package it for portable use.
   - This makes the pipeline a staged batch job rather than a single monolithic ETL script.

4. **Labeling and human-in-the-loop curation**
   - The repo supports both **automatic heuristics** and **manual validation**.
   - `dataset_extraction/scripts/label_ui_streamlit.py` indicates a local Streamlit-based labeling interface used to review ambiguous samples.
   - `dataset_extraction/data/manual_labels.jsonl` is the explicit human-labeled ground truth source that gets merged into the final dataset.

5. **Configuration and external dependencies for extraction**
   - `dataset_extraction/.env.example` and `clickbait_pipeline/env.py` suggest the extraction stage depends on environment-provided secrets or API configuration.
   - `dataset_extraction/config/channels.csv` is a curated list of source channels, which acts as the starting scope for collection.
   - This implies the extraction pipeline is configured around a fixed channel set rather than open-ended crawling.

6. **Dataset contract**
   - `clickbait_pipeline/schema.py` and `feature_config.json` indicate the project has a defined feature/label schema.
   - `jsonl.py`, `manifest.py`, and `summary.py` suggest structured intermediate artifacts and dataset summaries are first-class outputs.
   - The architecture likely depends on a stable tabular contract so training and serving can share the same feature interpretation.

7. **Training boundary: `training/`**
   - Training is centered in a single notebook: `training/click_bait.ipynb`.
   - That notebook likely performs EDA, feature engineering, train/test splitting, model fitting, and evaluation in one exploratory workflow.
   - This is an analysis-and-model-building stage, not an online service.

8. **Model artifact**
   - The trained model is serialized as `app/src/clickbait_xgb_v1.pkl`, which implies the chosen estimator is **XGBoost** or an XGBoost-based pipeline.
   - The notebook produces the artifact that is later consumed by the app; there is no separate model server layer.

9. **Serving boundary: `app/`**
   - `app/src/streamlit_app.py` is the runtime entry point for inference.
   - The app loads the serialized model plus `feature_config.json`, then exposes an interactive Streamlit UI for predictions.
   - This is a lightweight serving layer, not a REST API or containerized microservice in the repo structure.

10. **Runtime inference flow**
    - The serving app appears to take a YouTube link or similar input, derive features at runtime, and feed them into the loaded model.
    - The important architectural boundary is that **feature extraction at inference time must match training-time feature definitions**.
    - That shared contract is enforced by the fixed config/artifact pair in `app/src/`.

11. **Artifact handoff between phases**
    - The main data flow is: **YouTube sources → extracted/cleaned dataset → trained model artifact → Streamlit inference app**.
    - Intermediate outputs are likely CSV/JSONL-based, while the final model output is a pickle file for direct loading.
    - The repo therefore encodes a classic ML lifecycle: collection, labeling, training, packaging, serving.

12. **Technologies that materially shape the architecture**
    - **Streamlit** is used both for labeling support and for end-user inference UI.
    - **Jupyter Notebook** is the training environment.
    - **YouTube APIs** are the external data source.
    - The model artifact format is **pickle**, which keeps deployment simple but couples serving to the exact Python/model environment.

13. **How to draw the architecture**
    - Draw three main boxes: **Extraction**, **Training**, **Serving**.
    - Put **YouTube APIs / transcripts / thumbnails** outside the repo feeding into Extraction.
    - Show **manual labeling** as a human-in-the-loop branch inside Extraction.
    - Show **training notebook** consuming the curated dataset and producing the **pickled model**.
    - Show **Streamlit app** consuming the model and feature config to produce predictions for users.

Main entry points: [`dataset_extraction/scripts/01_collect_videos.py`](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/01_collect_videos.py) (Batch pipeline), [`dataset_extraction/scripts/05_merge_labels.py`](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/05_merge_labels.py) (Label merge), [`app/src/streamlit_app.py`](https://github.com/aarayann/catch-bait/blob/main/app/src/streamlit_app.py) (Streamlit app), [`dataset_extraction/clickbait_pipeline/yt_api.py`](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/yt_api.py) (YouTube API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_external["External sources"]
  node_youtube_sources(("YouTube<br/>external source"))
  node_human_reviewer(("Reviewer<br/>human labeler"))
  node_end_user(("User<br/>consumer"))
end

subgraph group_extraction["Extraction"]
  node_channels_csv["Channel list<br/>scope config<br/>[channels.csv]"]
  node_yt_api["YouTube API<br/>fetch module<br/>[yt_api.py]"]
  node_transcripts["Transcripts<br/>ingest module<br/>[transcripts.py]"]
  node_thumbs["Thumbnails<br/>ingest module<br/>[thumbs.py]"]
  node_dataset_contract["Dataset contract<br/>schema layer<br/>[schema.py]"]
  node_label_merge["Label merge<br/>curation stage<br/>[05_merge_labels.py]"]
  node_batch_pipeline["Batch pipeline<br/>etl workflow"]
  node_label_ui["Label UI<br/>streamlit tool"]
  node_manual_labels["Manual labels<br/>ground truth"]
  node_complete_dataset[("Curated dataset<br/>dataset artifact")]
end

subgraph group_training["Training"]
  node_notebook["Training notebook<br/>analysis notebook<br/>[click_bait.ipynb]"]
  node_model_artifact[("Model artifact<br/>pickle model")]
end

subgraph group_serving["Serving"]
  node_feature_config["Feature config<br/>runtime schema"]
  node_streamlit_app["Streamlit app<br/>inference app<br/>[streamlit_app.py]"]
end

node_youtube_sources -->|"metadata"| node_yt_api
node_youtube_sources -->|"transcripts"| node_transcripts
node_youtube_sources -->|"thumbnails"| node_thumbs
node_channels_csv -->|"scope"| node_batch_pipeline
node_yt_api -->|"ingest"| node_batch_pipeline
node_transcripts -->|"enrich"| node_batch_pipeline
node_thumbs -->|"enrich"| node_batch_pipeline
node_dataset_contract -->|"shape"| node_batch_pipeline
node_batch_pipeline -->|"stage"| node_label_merge
node_human_reviewer -->|"review"| node_label_ui
node_label_ui -->|"write"| node_manual_labels
node_manual_labels -->|"merge"| node_label_merge
node_label_merge -->|"build"| node_complete_dataset
node_complete_dataset -->|"train"| node_notebook
node_notebook -->|"serialize"| node_model_artifact
node_model_artifact -->|"load"| node_streamlit_app
node_feature_config -->|"align"| node_streamlit_app
node_end_user -->|"predict"| node_streamlit_app

click node_channels_csv "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/config/channels.csv"
click node_yt_api "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/yt_api.py"
click node_transcripts "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/transcripts.py"
click node_thumbs "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/thumbs.py"
click node_dataset_contract "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/schema.py"
click node_label_merge "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/05_merge_labels.py"
click node_batch_pipeline "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/01_collect_videos.py"
click node_label_ui "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/label_ui_streamlit.py"
click node_manual_labels "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/data/manual_labels.jsonl"
click node_complete_dataset "https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/09_make_portable_package.py"
click node_notebook "https://github.com/aarayann/catch-bait/blob/main/training/click_bait.ipynb"
click node_model_artifact "https://github.com/aarayann/catch-bait/blob/main/app/src/clickbait_xgb_v1.pkl"
click node_feature_config "https://github.com/aarayann/catch-bait/blob/main/app/src/feature_config.json"
click node_streamlit_app "https://github.com/aarayann/catch-bait/blob/main/app/src/streamlit_app.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_youtube_sources,node_human_reviewer,node_end_user toneBlue
class node_channels_csv,node_yt_api,node_transcripts,node_thumbs,node_dataset_contract,node_label_merge,node_batch_pipeline,node_label_ui,node_manual_labels,node_complete_dataset toneAmber
class node_notebook,node_model_artifact toneMint
class node_feature_config,node_streamlit_app toneRose
```

## Components

### External sources

Inputs and human actors outside the repository.

- **YouTube**: external source · Video metadata, thumbnails, transcripts, and channel/video manifests.
- **Reviewer**: human labeler · Manually validates ambiguous samples and supplies ground truth labels.
- **User**: consumer · Interacts with the Streamlit app to request predictions.

### Extraction

Offline ETL that builds the supervised dataset from YouTube.

- [Channel list](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/config/channels.csv): scope config · Curated source-channel input that defines collection scope. · `dataset_extraction/config/channels.csv`
- [YouTube API](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/yt_api.py): fetch module · API access and source retrieval for video/channel metadata. · `dataset_extraction/clickbait_pipeline/yt_api.py`
- [Transcripts](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/transcripts.py): ingest module · Transcript fetching and normalization. · `dataset_extraction/clickbait_pipeline/transcripts.py`
- [Thumbnails](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/thumbs.py): ingest module · Thumbnail download and handling. · `dataset_extraction/clickbait_pipeline/thumbs.py`
- [Dataset contract](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/clickbait_pipeline/schema.py): schema layer · Schema, JSONL, manifests, and summaries used by all dataset stages. · `dataset_extraction/clickbait_pipeline/schema.py`
- [Label merge](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/05_merge_labels.py): curation stage · Combines heuristic auto-labels with manual labels into the final supervision set. · `dataset_extraction/scripts/05_merge_labels.py`
- [Batch pipeline](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/01_collect_videos.py): etl workflow · Staged scripts that collect, enrich, assemble, export, balance, and package the dataset. · `dataset_extraction/scripts/01_collect_videos.py`
- [Label UI](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/label_ui_streamlit.py): streamlit tool · Local Streamlit interface for reviewing and labeling ambiguous samples. · `dataset_extraction/scripts/label_ui_streamlit.py`
- [Manual labels](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/data/manual_labels.jsonl): ground truth · Human-authored JSONL labels merged into the dataset. · `dataset_extraction/data/manual_labels.jsonl`
- [Curated dataset](https://github.com/aarayann/catch-bait/blob/main/dataset_extraction/scripts/09_make_portable_package.py): dataset artifact · Completed, balanced, and portable training dataset exported from the ETL flow. · `dataset_extraction/scripts/09_make_portable_package.py`

### Training

Notebook-driven model development and artifact production.

- [Training notebook](https://github.com/aarayann/catch-bait/blob/main/training/click_bait.ipynb): analysis notebook · EDA, feature engineering, model fitting, and evaluation workflow. · `training/click_bait.ipynb`
- [Model artifact](https://github.com/aarayann/catch-bait/blob/main/app/src/clickbait_xgb_v1.pkl): pickle model · Serialized XGBoost-based model consumed by the app. · `app/src/clickbait_xgb_v1.pkl`

### Serving

Streamlit inference app for end users.

- [Feature config](https://github.com/aarayann/catch-bait/blob/main/app/src/feature_config.json): runtime schema · Shared feature definition used to align training and inference. · `app/src/feature_config.json`
- [Streamlit app](https://github.com/aarayann/catch-bait/blob/main/app/src/streamlit_app.py): inference app · User-facing runtime that loads the model and produces predictions. · `app/src/streamlit_app.py`

## Connections

- YouTube → YouTube API: metadata · Fetch video and channel metadata from external sources.
- YouTube → Transcripts: transcripts · Pull transcript content for candidate videos.
- YouTube → Thumbnails: thumbnails · Download thumbnail assets for each video.
- Channel list → Batch pipeline: scope · Defines the initial channel set for collection.
- YouTube API → Batch pipeline: ingest · Feeds collected metadata into the staged ETL workflow.
- Transcripts → Batch pipeline: enrich · Adds transcript data during dataset assembly.
- Thumbnails → Batch pipeline: enrich · Adds thumbnail assets during dataset assembly.
- Dataset contract → Batch pipeline: shape · Provides schema, manifests, and summaries for intermediate outputs.
- Batch pipeline → Label merge: stage · Produces auto-labeled records that are later merged with human labels.
- Reviewer → Label UI: review · Uses the Streamlit labeling interface to curate ambiguous samples.
- Label UI → Manual labels: write · Saves explicit manual labels as JSONL ground truth.
- Manual labels → Label merge: merge · Combines human labels with heuristic labels.
- Label merge → Curated dataset: build · Outputs the final curated dataset package.
- Curated dataset → Training notebook: train · Serves as the training data input for the notebook workflow.
- Training notebook → Model artifact: serialize · Produces the pickled model artifact after training and evaluation.
- Model artifact → Streamlit app: load · Loaded by the inference app at runtime.
- Feature config → Streamlit app: align · Keeps inference features consistent with training definitions.
- User → Streamlit app: predict · Submits inputs for interactive inference.
