# anandnet/youtube_explode_dart architecture

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

- Interactive diagram: https://gitdiagram.com/anandnet/youtube_explode_dart
- Repository: https://github.com/anandnet/youtube_explode_dart

## Overview

#### Purpose and public entry point
YoutubeExplodeDart is a Dart/Flutter-compatible library for querying YouTube metadata and resolving downloadable media streams, captions, comments, playlists, channels, and search results without the official YouTube API or an API key. Consumers import `lib/youtube_explode_dart.dart` and create the main facade in `lib/src/youtube_explode_base.dart`; they must close it to release its HTTP client.

#### Facade and domain API surface
The root facade composes feature-specific clients into a consumer-facing API: videos, playlists, channels, and search. Each feature exposes typed IDs, immutable domain models, and paginated/list-like result abstractions rather than raw YouTube payloads.
- `lib/src/youtube_explode_base.dart`
- `lib/src/videos/videos.dart`
- `lib/src/playlists/playlists.dart`

#### HTTP and failure boundary
All communication with YouTube is centralized behind a custom HTTP layer. It encapsulates request behavior, retries, client closure, rate limits, transient failures, and translation into library-specific exceptions. This is the key boundary between unstable external responses and the typed public API.
- `lib/src/reverse_engineering/youtube_http_client.dart`
- `lib/src/retry.dart`
- `lib/src/exceptions/exceptions.dart`

#### Reverse-engineering retrieval pipeline
Feature clients obtain raw YouTube pages and internal AJAX-style responses, then page/parser classes extract structured data. The implementation intentionally depends on reverse-engineered page shapes and heuristics, making this layer the primary maintenance hotspot when YouTube changes.
- `lib/src/reverse_engineering/pages/watch_page.dart`
- `lib/src/reverse_engineering/pages/search_page.dart`
- `lib/src/reverse_engineering/heuristics.dart`

#### Video metadata, related content, and interactions
Video retrieval is orchestrated through dedicated video clients/controllers and maps watch-page data into `Video`. Related videos, comments, and caption APIs are separate subdomains, backed by reverse-engineered internal clients and paged result types where applicable.
- `lib/src/videos/video_client.dart`
- `lib/src/videos/video_controller.dart`
- `lib/src/videos/comments/comments_client.dart`

#### Stream resolution and download flow
For a video ID, the stream client retrieves and merges player responses from selectable YouTube client profiles, builds a typed stream manifest, and exposes byte streams for the selected stream. Manifest parsing covers muxed, audio-only, video-only, DASH, and HLS variants; callers handle persistence and any external muxing such as FFmpeg.
- `lib/src/videos/streams/stream_client.dart`
- `lib/src/videos/streams/stream_manifest.dart`
- `lib/src/reverse_engineering/player/player_response.dart`

#### Cipher and JavaScript execution boundary
Some playable stream URLs require deciphering signatures from YouTube player JavaScript. The cipher subsystem extracts operations and uses an embedded JavaScript parser/engine abstraction, with separate Dart and Flutter player-source implementations. This isolates platform/runtime-specific player acquisition from stream models.
- `lib/src/reverse_engineering/cipher/cipher_operations.dart`
- `lib/src/js/js_engine.dart`
- `lib/src/reverse_engineering/player/player_source_flutter.dart`

#### Runtime and delivery
The package runs on Dart and supports Flutter usage; it relies on direct YouTube web/player endpoints rather than official Google APIs. Generated Freezed and JSON serialization artifacts sit beside models. CI publishes/tests the Dart package through GitHub Actions.
- `pubspec.yaml`
- `lib/src/reverse_engineering/player/player_source_dart.dart`
- `.github/workflows/publish.yml`

Main entry points: [`lib/src/reverse_engineering/youtube_http_client.dart`](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/youtube_http_client.dart) (YouTube HTTP client), [`lib/src/videos/streams/stream_client.dart`](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/streams/stream_client.dart) (Stream client), [`lib/src/youtube_explode_base.dart`](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/youtube_explode_base.dart) (YoutubeExplode facade), [`lib/src/videos/video_client.dart`](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/video_client.dart) (Video client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public library API"]
  node_entry["Package entry point<br/>Dart export"]
  node_facade["YoutubeExplode facade<br/>API facade"]
  node_feature_apis["Videos, playlists, channels, search<br/>feature APIs<br/>[videos.dart]"]
  node_playlists["Playlist API<br/>feature API<br/>[playlists.dart]"]
end

subgraph group_video["Video and streams"]
  node_video_client["Video client<br/>retrieval client<br/>[video_client.dart]"]
  node_video_controller["Video controller<br/>mapping layer"]
  node_comments["Comments client<br/>interaction API"]
  node_stream_client["Stream client<br/>stream resolver<br/>[stream_client.dart]"]
  node_manifest["Stream manifest<br/>typed stream model"]
end

subgraph group_reverse["Reverse engineering"]
  node_http["YouTube HTTP client<br/>HTTP boundary"]
  node_retry["Retry policy<br/>resilience<br/>[retry.dart]"]
  node_exceptions["Library exceptions<br/>failure model<br/>[exceptions.dart]"]
  node_pages["Watch and search pages<br/>page parsers<br/>[watch_page.dart]"]
  node_search_page["Search page parser<br/>[search_page.dart]"]
  node_heuristics["Extraction heuristics<br/>parser support<br/>[heuristics.dart]"]
  node_player_response["Player response<br/>player parser"]
  node_cipher["Cipher operations<br/>signature deciphering"]
  node_js_engine{{"JavaScript engine<br/>JS abstraction<br/>[js_engine.dart]"}}
end

subgraph group_runtime["Runtime and delivery"]
  node_player_sources["Platform player sources<br/>runtime adapter"]
  node_flutter_source["Flutter player source<br/>runtime adapter"]
  node_package["Package manifest<br/>package delivery<br/>[pubspec.yaml]"]
  node_publish_ci["Publish CI<br/>GitHub Actions workflow<br/>[publish.yml]"]
end

node_entry -->|"exports"| node_facade
node_facade -->|"exposes"| node_feature_apis
node_facade -->|"exposes"| node_playlists
node_facade -->|"owns / closes"| node_http
node_feature_apis -->|"uses"| node_video_client
node_video_client -->|"orchestrates"| node_video_controller
node_video_client -->|"subdomain"| node_comments
node_video_controller -->|"reads"| node_pages
node_feature_apis -->|"queries via"| node_search_page
node_pages -->|"uses"| node_heuristics
node_search_page -->|"uses"| node_heuristics
node_video_client -->|"requests through"| node_http
node_stream_client -->|"requests through"| node_http
node_stream_client -->|"merges"| node_player_response
node_stream_client -->|"builds"| node_manifest
node_stream_client -->|"deciphers URLs"| node_cipher
node_cipher -->|"executes via"| node_js_engine
node_cipher -->|"gets player JS"| node_player_sources
node_player_sources -.->|"platform variant"| node_flutter_source
node_http -->|"applies"| node_retry
node_http -->|"translates failures"| node_exceptions
node_package -->|"published by"| node_publish_ci

click node_entry "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/youtube_explode_dart.dart"
click node_facade "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/youtube_explode_base.dart"
click node_feature_apis "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/videos.dart"
click node_playlists "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/playlists/playlists.dart"
click node_video_client "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/video_client.dart"
click node_video_controller "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/video_controller.dart"
click node_comments "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/comments/comments_client.dart"
click node_stream_client "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/streams/stream_client.dart"
click node_manifest "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/streams/stream_manifest.dart"
click node_http "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/youtube_http_client.dart"
click node_retry "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/retry.dart"
click node_exceptions "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/exceptions/exceptions.dart"
click node_pages "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/pages/watch_page.dart"
click node_search_page "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/pages/search_page.dart"
click node_heuristics "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/heuristics.dart"
click node_player_response "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/player/player_response.dart"
click node_cipher "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/cipher/cipher_operations.dart"
click node_js_engine "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/js/js_engine.dart"
click node_player_sources "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/player/player_source_dart.dart"
click node_flutter_source "https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/player/player_source_flutter.dart"
click node_package "https://github.com/anandnet/youtube_explode_dart/blob/master/pubspec.yaml"
click node_publish_ci "https://github.com/anandnet/youtube_explode_dart/blob/master/.github/workflows/publish.yml"

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_entry,node_facade,node_feature_apis,node_playlists toneBlue
class node_video_client,node_video_controller,node_comments,node_stream_client,node_manifest toneAmber
class node_http,node_retry,node_exceptions,node_pages,node_search_page,node_heuristics,node_player_response,node_cipher,node_js_engine toneMint
class node_player_sources,node_flutter_source,node_package,node_publish_ci toneRose
```

## Components

### Public library API

- [Package entry point](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/youtube_explode_dart.dart): Dart export · Consumer import surface. · `lib/youtube_explode_dart.dart`
- [YoutubeExplode facade](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/youtube_explode_base.dart): API facade · Composes clients and owns the closable HTTP client. · `lib/src/youtube_explode_base.dart`
- [Videos, playlists, channels, search](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/videos.dart): feature APIs · Typed models and paged results for public domains. · `lib/src/videos/videos.dart`
- [Playlist API](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/playlists/playlists.dart): feature API · `lib/src/playlists/playlists.dart`

### Video and streams

- [Video client](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/video_client.dart): retrieval client · Orchestrates video metadata retrieval. · `lib/src/videos/video_client.dart`
- [Video controller](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/video_controller.dart): mapping layer · Maps watch data into Video models. · `lib/src/videos/video_controller.dart`
- [Comments client](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/comments/comments_client.dart): interaction API · Retrieves paged comment results. · `lib/src/videos/comments/comments_client.dart`
- [Stream client](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/streams/stream_client.dart): stream resolver · Selects player profiles and resolves playable streams. · `lib/src/videos/streams/stream_client.dart`
- [Stream manifest](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/videos/streams/stream_manifest.dart): typed stream model · Represents muxed, adaptive, DASH, and HLS streams. · `lib/src/videos/streams/stream_manifest.dart`

### Reverse engineering

Unstable YouTube page and player integration.

- [YouTube HTTP client](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/youtube_http_client.dart): HTTP boundary · Centralizes endpoint requests, limits, retries, and closure. · `lib/src/reverse_engineering/youtube_http_client.dart`
- [Retry policy](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/retry.dart): resilience · `lib/src/retry.dart`
- [Library exceptions](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/exceptions/exceptions.dart): failure model · Translates external and transient failures. · `lib/src/exceptions/exceptions.dart`
- [Watch and search pages](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/pages/watch_page.dart): page parsers · Extract structured data from YouTube page shapes. · `lib/src/reverse_engineering/pages/watch_page.dart`
- [Search page parser](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/pages/search_page.dart): page parser · `lib/src/reverse_engineering/pages/search_page.dart`
- [Extraction heuristics](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/heuristics.dart): parser support · Maintenance hotspot for changing page structures. · `lib/src/reverse_engineering/heuristics.dart`
- [Player response](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/player/player_response.dart): player parser · Normalizes internal player payloads. · `lib/src/reverse_engineering/player/player_response.dart`
- [Cipher operations](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/cipher/cipher_operations.dart): signature deciphering · Extracts signature operations for protected stream URLs. · `lib/src/reverse_engineering/cipher/cipher_operations.dart`
- [JavaScript engine](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/js/js_engine.dart): JS abstraction · Executes extracted player logic. · `lib/src/js/js_engine.dart`

### Runtime and delivery

- [Platform player sources](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/player/player_source_dart.dart): runtime adapter · Dart and Flutter implementations acquire player JavaScript. · `lib/src/reverse_engineering/player/player_source_dart.dart`
- [Flutter player source](https://github.com/anandnet/youtube_explode_dart/blob/master/lib/src/reverse_engineering/player/player_source_flutter.dart): runtime adapter · `lib/src/reverse_engineering/player/player_source_flutter.dart`
- [Package manifest](https://github.com/anandnet/youtube_explode_dart/blob/master/pubspec.yaml): package delivery · Dart package with Flutter compatibility. · `pubspec.yaml`
- [Publish CI](https://github.com/anandnet/youtube_explode_dart/blob/master/.github/workflows/publish.yml): GitHub Actions workflow · Tests and publishes the package. · `.github/workflows/publish.yml`

## Connections

- Package entry point → YoutubeExplode facade: exports
- YoutubeExplode facade → Videos, playlists, channels, search: exposes
- YoutubeExplode facade → Playlist API: exposes
- YoutubeExplode facade → YouTube HTTP client: owns / closes
- Videos, playlists, channels, search → Video client: uses
- Video client → Video controller: orchestrates
- Video client → Comments client: subdomain
- Video controller → Watch and search pages: reads
- Videos, playlists, channels, search → Search page parser: queries via
- Watch and search pages → Extraction heuristics: uses
- Search page parser → Extraction heuristics: uses
- Video client → YouTube HTTP client: requests through
- Stream client → YouTube HTTP client: requests through
- Stream client → Player response: merges
- Stream client → Stream manifest: builds
- Stream client → Cipher operations: deciphers URLs
- Cipher operations → JavaScript engine: executes via
- Cipher operations → Platform player sources: gets player JS
- Platform player sources → Flutter player source: platform variant
- YouTube HTTP client → Retry policy: applies
- YouTube HTTP client → Library exceptions: translates failures
- Package manifest → Publish CI: published by
