# joe820730/youtube-dl-server architecture

> Architecture diagram of the GitHub repository joe820730/youtube-dl-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joe820730/youtube-dl-server
- Repository: https://github.com/joe820730/youtube-dl-server

## Overview

##### Project Type and Purpose
- This is a small, monolithic full-stack application packaged as a Docker service.
- Purpose: Provide a minimalist web UI and REST API to trigger video downloads from YouTube (and other sites supported by yt-dlp) on a server.

##### File Structure Analysis
- Top level:
- Dockerfile, requirements.txt → container build and Python deps
- youtube-dl-server.py → single FastAPI/Starlette app entrypoint
- templates/index.html → simple HTML UI
- .github/workflows/docker-image.yml → CI for building/publishing Docker image
- README.md → usage, architecture notes
- No separate “frontend” vs. “backend” directories; both live in the same service
- Volume mount (host ↔ /youtube-dl) for persisting downloaded videos

##### Key Components
a. Clients
- Web browser → HTML form
- Scripted clients (curl/fetch/bookmarklet) → REST endpoint
b. API/Web Server Container
- Docker container (python:alpine base) running uvicorn + Starlette app
- youtube-dl-server.py handles HTTP routes, serves index.html
- uses Starlette’s routing, templating, background task capabilities
c. Download Engine
- yt-dlp (Python library) invoked via its Python API
- Fetches media from external video hosting (YouTube)
d. Storage
- Local filesystem volume (/youtube-dl) for saving downloads
- Exposed as a Docker volume mount on the host
e. External Services
- YouTube (or other supported video sources)
- (Optional) VPN container for network isolation

##### Interactions & Data Flow
1. User submits URL via Web UI or HTTP POST →
2. Starlette route (“/youtube-dl/q”) receives request →
3. yt-dlp library downloads media from YouTube →
4. File written to /youtube-dl volume →
5. Server returns success/failure JSON or HTML response

##### Architectural Patterns & Design Principles
- Monolithic single‐service container
- Clear separation of concerns:
- HTTP layer (Starlette)
- Download logic (yt-dlp API)
- Storage (host volume)
- Containerization best practices (small base image, volume for persistence)
- CI/CD for Docker image build and publish

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        direction TB
        Browser["Web Browser"]:::client
        Scripted["Scripted Clients\n(curl/fetch/bookmarklet)"]:::client
    end

    %% Docker Container
    subgraph "Docker Container" 
        direction TB
        Starlette["Starlette App\n(youtube-dl-server.py)\nuvicorn"]:::app
        Template["templates/index.html"]:::app
        YTDLP["yt-dlp Python API\n(invoked in youtube-dl-server.py)"]:::app
        Volume["Volume\n/home/core/youtube-dl ↔ /youtube-dl"]:::infra
        Dockerfile["Dockerfile"]:::infra
        Req["requirements.txt"]:::infra
    end

    %% CI/CD
    subgraph "CI/CD Pipeline"
        Workflow[".github/workflows/docker-image.yml"]:::infra
        README["README.md"]:::infra
        License["LICENSE"]:::infra
        Gitignore[".gitignore"]:::infra
        Vscode[".vscode/"]:::infra
    end

    %% External Services
    subgraph "External"
        direction TB
        YouTube["YouTube"]:::ext
        VPN["Optional VPN Container"]:::infra
    end

    %% Data Flows
    Browser -->|"GET /"| Starlette
    Browser -->|"POST /youtube-dl/q"| Starlette
    Scripted -->|"POST /youtube-dl/q"| Starlette

    Starlette -->|"Renders index.html"| Template
    Starlette -->|"yt-dlp.fetch()"| YTDLP
    YTDLP -->|"Fetch media"| YouTube
    YTDLP -->|"writes file"| Volume

    Starlette -->|"JSON/HTML response"| Browser
    Starlette -->|"JSON response"| Scripted

    Dockerfile -->|"Builds image"| Starlette
    Req -->|"Dependencies"| Starlette

    Workflow -->|"Build & Publish"| Dockerfile
    README -->|"Docs & Volume Config"| Volume

    %% Click Events
    click Starlette "https://github.com/joe820730/youtube-dl-server/blob/master/youtube-dl-server.py"
    click Template "https://github.com/joe820730/youtube-dl-server/blob/master/templates/index.html"
    click YTDLP "https://github.com/joe820730/youtube-dl-server/blob/master/youtube-dl-server.py"
    click Req "https://github.com/joe820730/youtube-dl-server/blob/master/requirements.txt"
    click Dockerfile "https://github.com/joe820730/youtube-dl-server/tree/master/Dockerfile"
    click Workflow "https://github.com/joe820730/youtube-dl-server/blob/master/.github/workflows/docker-image.yml"
    click README "https://github.com/joe820730/youtube-dl-server/blob/master/README.md"
    click License "https://github.com/joe820730/youtube-dl-server/tree/master/LICENSE"
    click Gitignore "https://github.com/joe820730/youtube-dl-server/blob/master/.gitignore"
    click Vscode "https://github.com/joe820730/youtube-dl-server/tree/master/.vscode/"

    %% Legend
    subgraph Legend
        direction TB
        C1["Web & Scripted Clients"]:::client
        A1["Application Components"]:::app
        I1["Infrastructure"]:::infra
        E1["External Services"]:::ext
    end

    classDef client fill:#c6f6d5,stroke:#38a169,color:#1a202c
    classDef app fill:#bee3f8,stroke:#3182ce,color:#1a202c
    classDef infra fill:#e2e8f0,stroke:#4a5568,color:#1a202c
    classDef ext fill:#fed7aa,stroke:#dd6b20,color:#1a202c
```
