# varghq/social-media-video-downloader architecture

> Architecture diagram of the GitHub repository varghq/social-media-video-downloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varghq/social-media-video-downloader
- Repository: https://github.com/varghq/social-media-video-downloader

## Overview

This Bun CLI and TypeScript library turns video URLs into local media files: the CLI validates and dispatches commands, the download layer parses platform identity and builds yt-dlp work, and the yt-dlp runner resolves and executes the external binary while streaming progress and results. It also supports metadata-only lookup, audio/playlist/quality/cookie options, binary updates, and optional varg uploads. Arrows reflect calls shown in excerpts or README; broader yt-dlp site coverage is documented, not implemented as per-site code here.

Main entry points: [`src/download.ts`](https://github.com/varghq/social-media-video-downloader/blob/main/src/download.ts) (Download and metadata), [`src/cli.ts`](https://github.com/varghq/social-media-video-downloader/blob/main/src/cli.ts) (Command interface), [`src/index.ts`](https://github.com/varghq/social-media-video-downloader/blob/main/src/index.ts) (Library exports), [`src/ytdlp.ts`](https://github.com/varghq/social-media-video-downloader/blob/main/src/ytdlp.ts) (yt-dlp process runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["Command interface<br/>[cli.ts]"]
  node_library_api["Library exports<br/>[index.ts]"]
end

subgraph group_download["Download workflow"]
  node_platforms["URL and platform parsing<br/>[platforms.ts]"]
  node_download_api["Download and metadata<br/>[download.ts]"]
end

subgraph group_runtime["Runtime integrations"]
  node_yt_runner["yt-dlp process runner<br/>[ytdlp.ts]"]
  node_yt_binary["yt-dlp executable"]
end

subgraph group_upload["Optional upload"]
  node_varg_upload["Varg upload client<br/>[varg.ts]"]
end

node_user(("CLI user"))
node_library_user(("Library caller"))
node_platform_sites["Video sites"]
node_local_files[("Downloaded media")]
node_ffmpeg["ffmpeg"]
node_varg_service["varg file API"]

node_user -->|"runs commands"| node_cli
node_library_user -->|"calls exports"| node_library_api
node_cli -->|"requests download"| node_download_api
node_cli -->|"requests metadata"| node_download_api
node_cli -->|"detects platform"| node_platforms
node_cli -->|"uploads files"| node_varg_upload
node_cli -->|"updates binary"| node_yt_runner
node_library_api -->|"exports functions"| node_download_api
node_library_api -->|"exports helpers"| node_platforms
node_library_api -->|"exports uploader"| node_varg_upload
node_library_api -->|"exports runtime"| node_yt_runner
node_download_api -->|"parses URLs"| node_platforms
node_download_api -->|"runs arguments"| node_yt_runner
node_yt_runner -->|"spawns process"| node_yt_binary
node_yt_binary -->|"extracts media"| node_platform_sites
node_yt_binary -->|"writes downloads"| node_local_files
node_download_api -->|"returns file paths"| node_local_files
node_yt_runner -->|"configures location"| node_ffmpeg
node_download_api -->|"checks availability"| node_ffmpeg
node_varg_upload -->|"reads file"| node_local_files
node_varg_upload -->|"posts file"| node_varg_service

click node_cli "https://github.com/varghq/social-media-video-downloader/blob/main/src/cli.ts"
click node_library_api "https://github.com/varghq/social-media-video-downloader/blob/main/src/index.ts"
click node_platforms "https://github.com/varghq/social-media-video-downloader/blob/main/src/platforms.ts"
click node_download_api "https://github.com/varghq/social-media-video-downloader/blob/main/src/download.ts"
click node_yt_runner "https://github.com/varghq/social-media-video-downloader/blob/main/src/ytdlp.ts"
click node_varg_upload "https://github.com/varghq/social-media-video-downloader/blob/main/src/varg.ts"

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_cli,node_library_api,node_user toneBlue
class node_platforms,node_download_api,node_local_files toneAmber
class node_yt_runner,node_yt_binary,node_varg_service toneMint
class node_varg_upload toneRose
class node_library_user,node_platform_sites,node_ffmpeg toneIndigo
```

## Components

### Entry points

- [Command interface](https://github.com/varghq/social-media-video-downloader/blob/main/src/cli.ts): `src/cli.ts`
- [Library exports](https://github.com/varghq/social-media-video-downloader/blob/main/src/index.ts): `src/index.ts`

### Download workflow

- [URL and platform parsing](https://github.com/varghq/social-media-video-downloader/blob/main/src/platforms.ts): `src/platforms.ts`
- [Download and metadata](https://github.com/varghq/social-media-video-downloader/blob/main/src/download.ts): `src/download.ts`

### Runtime integrations

- [yt-dlp process runner](https://github.com/varghq/social-media-video-downloader/blob/main/src/ytdlp.ts): `src/ytdlp.ts`
- **yt-dlp executable**

### Optional upload

- [Varg upload client](https://github.com/varghq/social-media-video-downloader/blob/main/src/varg.ts): `src/varg.ts`

### Other components

- **CLI user**
- **Library caller**
- **Video sites**
- **Downloaded media**
- **ffmpeg**
- **varg file API**

## Connections

- CLI user → Command interface: runs commands (evidence: `README.md`)
- Library caller → Library exports: calls exports (evidence: `README.md`)
- Command interface → Download and metadata: requests download (evidence: `src/cli.ts`)
- Command interface → Download and metadata: requests metadata (evidence: `src/cli.ts`)
- Command interface → URL and platform parsing: detects platform (evidence: `src/cli.ts`)
- Command interface → Varg upload client: uploads files (evidence: `src/cli.ts`)
- Command interface → yt-dlp process runner: updates binary (evidence: `src/cli.ts`)
- Library exports → Download and metadata: exports functions (evidence: `src/index.ts`)
- Library exports → URL and platform parsing: exports helpers (evidence: `src/index.ts`)
- Library exports → Varg upload client: exports uploader (evidence: `src/index.ts`)
- Library exports → yt-dlp process runner: exports runtime (evidence: `src/index.ts`)
- Download and metadata → URL and platform parsing: parses URLs (evidence: `src/download.ts`)
- Download and metadata → yt-dlp process runner: runs arguments (evidence: `src/download.ts`)
- yt-dlp process runner → yt-dlp executable: spawns process (evidence: `src/ytdlp.ts`)
- yt-dlp executable → Video sites: extracts media (evidence: `README.md`)
- yt-dlp executable → Downloaded media: writes downloads (evidence: `README.md`)
- Download and metadata → Downloaded media: returns file paths (evidence: `src/download.ts`)
- yt-dlp process runner → ffmpeg: configures location (evidence: `src/ytdlp.ts`)
- Download and metadata → ffmpeg: checks availability (evidence: `src/download.ts`)
- Varg upload client → Downloaded media: reads file (evidence: `src/varg.ts`)
- Varg upload client → varg file API: posts file (evidence: `src/varg.ts`)
