# ronalusuriano008-ux/ytdlp architecture

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

- Interactive diagram: https://gitdiagram.com/ronalusuriano008-ux/ytdlp
- Repository: https://github.com/ronalusuriano008-ux/ytdlp

## Overview

1. **Top-level shape**
   - This is a **monorepo** split into three runtime apps plus a shared package:
     - `apps/web` = browser frontend
     - `apps/api` = Node.js/Express backend
     - `apps/worker` = Python media-processing service
     - `packages/shared` = cross-app constants/contracts
   - The intended system flow is: **Web → API → Worker → yt-dlp/ffmpeg**.

2. **Frontend boundary: static, modular UI**
   - `apps/web` is not a React/Vue SPA; it is a **static HTML/CSS/JavaScript frontend**.
   - Public entry pages live in `apps/web/public/*.html` for the main user areas: search/home, music, history, favorites, downloads, profile.
   - The real behavior is organized under `apps/web/src`, with feature modules for **auth, search, player, download, history, voice, websocket, background, downloads page**.
   - This suggests a page-oriented UI with reusable client-side modules rather than a server-rendered app.

3. **API boundary: orchestration and transport**
   - `apps/api/src/server.js` is the Node entrypoint.
   - The API is organized as Express routes:
     - `auth.routes.js`
     - `search.routes.js`
     - `stream.routes.js`
     - `metadata.routes.js`
     - `download.routes.js`
     - `user.routes.js`
   - The API’s job is to **accept browser requests, validate/shape them, coordinate worker calls, and expose progress/status to the frontend**.

4. **Worker boundary: media execution**
   - `apps/worker` is the execution layer for the heavy lifting.
   - Python modules show the worker responsibilities clearly:
     - `ytdlp_runner.py` for downloading/extracting via **yt-dlp**
     - `ffmpeg_runner.py` for media conversion/remuxing via **ffmpeg**
     - `metadata.py` for content inspection
     - `models/job.py` for job state/data
   - This layer isolates external binaries and long-running media tasks away from the Node API.

5. **Job and queue flow**
   - The API contains `services/queue.js`, which implies **download/processing requests are queued** rather than handled synchronously.
   - `services/pythonClient.js` is the bridge from Node to the Python worker.
   - In practice, the architecture is likely: the web client submits a search/stream/download request, the API creates or forwards a job, and the worker processes it asynchronously.
   - This separation is important for an architecture diagram because the worker is not just a library; it is a distinct service boundary.

6. **Real-time progress**
   - `apps/api/src/websocket/progress.gateway.js` and `apps/web/src/features/websocket/websocket.js` indicate a **WebSocket channel for live progress updates**.
   - This is the main feedback path for long-running downloads/conversions, which is essential because yt-dlp/ffmpeg jobs can take time.
   - So the UI likely gets initial responses via REST, then listens on WebSockets for job progress and completion.

7. **User/file tracking and persistence**
   - `apps/api/src/services/userFileService.js` suggests the API manages some form of **user-associated file history or download records**.
   - The README mentions **temporary JSON persistence**, so this is probably lightweight state rather than a database-backed domain model.
   - There is also a `user.routes.js`, implying user-oriented records like profile, history, or favorites are exposed through the API.

8. **Shared contracts**
   - `packages/shared/constants` contains `events.js`, `roles.js`, and `routes.js`.
   - This package acts as the **contract layer** between frontend, API, and worker, reducing drift in event names and route constants.
   - For a diagram, this is a small but important boundary: it is not business logic, it is shared integration metadata.

9. **Feature decomposition on the frontend**
   - The frontend modules map closely to user workflows:
     - **search**: discovery and query history
     - **player**: preview playback, loading, prebuffering, UI
     - **download**: audio/video download state and status handling
     - **history** and **downloads**: user-visible records
     - **voice** and **background**: auxiliary UX features
     - **auth/session**: browser session handling
   - This makes the frontend a composition of feature islands around one shared API.

10. **Runtime and deployment boundaries**
   - The stack is intentionally split by runtime:
     - **Node.js 18+** for API and web tooling
     - **Python 3.10+** for the worker
     - **yt-dlp** and **ffmpeg** as external executables used only by the worker
   - The README’s deployment model implies independent serving:
     - static frontend via Nginx or similar
     - API as a Node service
     - worker as a Python service
   - That separation is one of the main architectural decisions in the repo.

11. **What to emphasize in a diagram**
   - Show **the browser as the entry point**.
   - Show **REST routes** for search, metadata, stream, download, auth, user.
   - Show **WebSocket progress** as a side channel from API back to browser.
   - Show **API-to-worker communication** as the async processing boundary.
   - Show the worker invoking **yt-dlp/ffmpeg** and returning structured results/progress.

12. **Repository maturity signals**
   - The presence of `mainv1` files in both web and worker suggests an evolving codebase with legacy paths preserved during refactoring.
   - That usually means the current architecture is intentionally modular, but there may be older implementation variants still present.
   - For architecture purposes, treat the current split into `web / api / worker / shared` as the authoritative structure.

Main entry points: [`apps/api/src/server.js`](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/server.js) (Server), [`apps/web/src`](https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/src) (Feature modules), [`apps/api/src/websocket/progress.gateway.js`](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/websocket/progress.gateway.js) (Progress gateway), [`apps/web/public`](https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/public) (Public pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web app"]
  node_web_pages["Public pages<br/>static UI"]
  node_web_modules["Feature modules<br/>client modules"]
  node_web_styles["Styles<br/>assets"]
end

subgraph group_api["API service"]
  node_api_server["Server<br/>Express entry<br/>[server.js]"]
  node_api_auth["Auth routes<br/>REST routes<br/>[auth.routes.js]"]
  node_api_search["Search routes<br/>REST routes<br/>[search.routes.js]"]
  node_api_stream["Stream routes<br/>REST routes<br/>[stream.routes.js]"]
  node_api_metadata["Metadata routes<br/>REST routes<br/>[metadata.routes.js]"]
  node_api_download["Download routes<br/>REST routes<br/>[download.routes.js]"]
  node_api_user["User routes<br/>REST routes<br/>[user.routes.js]"]
  node_api_queue["Queue<br/>[queue.js]"]
  node_api_bridge["Python bridge<br/>service bridge<br/>[pythonClient.js]"]
  node_api_files["User files<br/>persistence service<br/>[userFileService.js]"]
  node_api_ws(("Progress gateway<br/>websocket"))
end

subgraph group_worker["Worker service"]
  node_worker_main["Worker entry<br/>Python service<br/>[main.py]"]
  node_worker_dl["Downloader<br/>media pipeline"]
  node_worker_job["Job model<br/>state model<br/>[job.py]"]
end

subgraph group_shared["Shared contracts"]
  node_shared_routes["Routes<br/>shared constants<br/>[routes.js]"]
  node_shared_events["Events<br/>shared constants<br/>[events.js]"]
  node_shared_roles["Roles<br/>shared constants<br/>[roles.js]"]
end

node_browser(("Browser<br/>client"))

node_browser -->|"loads"| node_web_pages
node_web_pages -->|"uses"| node_web_modules
node_web_pages -->|"styles"| node_web_styles
node_web_modules -->|"REST"| node_api_server
node_web_modules -->|"subscribes"| node_api_ws
node_api_server -->|"mounts"| node_api_auth
node_api_server -->|"mounts"| node_api_search
node_api_server -->|"mounts"| node_api_stream
node_api_server -->|"mounts"| node_api_metadata
node_api_server -->|"mounts"| node_api_download
node_api_server -->|"mounts"| node_api_user
node_api_download -->|"enqueues"| node_api_queue
node_api_queue -->|"dispatches"| node_api_bridge
node_api_bridge -->|"invokes"| node_worker_main
node_worker_main -->|"runs"| node_worker_dl
node_worker_dl -->|"updates"| node_worker_job
node_worker_dl -->|"progress"| node_api_ws
node_api_ws -->|"pushes"| node_browser
node_api_user -->|"persists"| node_api_files
node_api_server -->|"imports"| node_shared_routes
node_web_modules -->|"imports"| node_shared_events
node_api_ws -->|"publishes"| node_shared_events
node_api_server -->|"imports"| node_shared_roles

click node_web_pages "https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/public"
click node_web_modules "https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/src"
click node_web_styles "https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/assets/styles"
click node_api_server "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/server.js"
click node_api_auth "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/auth.routes.js"
click node_api_search "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/search.routes.js"
click node_api_stream "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/stream.routes.js"
click node_api_metadata "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/metadata.routes.js"
click node_api_download "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/download.routes.js"
click node_api_user "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/user.routes.js"
click node_api_queue "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/services/queue.js"
click node_api_bridge "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/services/pythonClient.js"
click node_api_files "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/services/userFileService.js"
click node_api_ws "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/websocket/progress.gateway.js"
click node_worker_main "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/worker/src/main.py"
click node_worker_dl "https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/worker/src/downloader"
click node_worker_job "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/worker/src/models/job.py"
click node_shared_routes "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/packages/shared/constants/routes.js"
click node_shared_events "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/packages/shared/constants/events.js"
click node_shared_roles "https://github.com/ronalusuriano008-ux/ytdlp/blob/main/packages/shared/constants/roles.js"

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_web_pages,node_web_modules,node_web_styles toneBlue
class node_api_server,node_api_auth,node_api_search,node_api_stream,node_api_metadata,node_api_download,node_api_user,node_api_queue,node_api_bridge,node_api_files,node_api_ws toneAmber
class node_worker_main,node_worker_dl,node_worker_job toneMint
class node_shared_routes,node_shared_events,node_shared_roles toneRose
class node_browser toneNeutral
```

## Components

### Web app

Static browser frontend and client-side modules

- [Public pages](https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/public): static UI · Page-oriented HTML entry points for main user areas · `apps/web/public`
- [Feature modules](https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/src): client modules · Reusable frontend logic for auth, search, player, downloads, history, voice, and websocket · `apps/web/src`
- [Styles](https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/web/assets/styles): assets · Shared CSS and legacy styling · `apps/web/assets/styles`

### API service

Node/Express orchestration layer

- [Server](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/server.js): Express entry · Node.js API bootstrap and HTTP composition · `apps/api/src/server.js`
- [Auth routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/auth.routes.js): REST routes · Authentication and session-related endpoints · `apps/api/src/routes/auth.routes.js`
- [Search routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/search.routes.js): REST routes · Search and discovery endpoints · `apps/api/src/routes/search.routes.js`
- [Stream routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/stream.routes.js): REST routes · Playback and stream delivery endpoints · `apps/api/src/routes/stream.routes.js`
- [Metadata routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/metadata.routes.js): REST routes · Track and media metadata endpoints · `apps/api/src/routes/metadata.routes.js`
- [Download routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/download.routes.js): REST routes · Download creation and status endpoints · `apps/api/src/routes/download.routes.js`
- [User routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/routes/user.routes.js): REST routes · User-facing records such as history, favorites, and profile data · `apps/api/src/routes/user.routes.js`
- [Queue](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/services/queue.js): job queue · Asynchronous coordination for long-running work · `apps/api/src/services/queue.js`
- [Python bridge](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/services/pythonClient.js): service bridge · Node-to-worker integration for job submission and results · `apps/api/src/services/pythonClient.js`
- [User files](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/services/userFileService.js): persistence service · Lightweight tracking for user-associated file and download records · `apps/api/src/services/userFileService.js`
- [Progress gateway](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/api/src/websocket/progress.gateway.js): websocket · Live progress channel back to the browser · `apps/api/src/websocket/progress.gateway.js`

### Worker service

Python media execution layer

- [Worker entry](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/worker/src/main.py): Python service · Worker process entrypoint for media jobs · `apps/worker/src/main.py`
- [Downloader](https://github.com/ronalusuriano008-ux/ytdlp/tree/main/apps/worker/src/downloader): media pipeline · yt-dlp and ffmpeg orchestration for fetch, extract, and convert · `apps/worker/src/downloader`
- [Job model](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/apps/worker/src/models/job.py): state model · Worker job state and payload structure · `apps/worker/src/models/job.py`

### Shared contracts

Cross-app constants and integration metadata

- [Routes](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/packages/shared/constants/routes.js): shared constants · Shared route identifiers · `packages/shared/constants/routes.js`
- [Events](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/packages/shared/constants/events.js): shared constants · Shared event names for realtime coordination · `packages/shared/constants/events.js`
- [Roles](https://github.com/ronalusuriano008-ux/ytdlp/blob/main/packages/shared/constants/roles.js): shared constants · Shared role definitions · `packages/shared/constants/roles.js`

### Other components

- **Browser**: client · User entry point for search, playback, and downloads

## Connections

- Browser → Public pages: loads · Browser opens the static entry pages
- Public pages → Feature modules: uses · Pages are powered by client-side feature modules
- Public pages → Styles: styles · Pages share the common stylesheet layer
- Feature modules → Server: REST · Frontend features call the API for search, playback, and downloads
- Feature modules → Progress gateway: subscribes · Frontend listens for live progress updates
- Server → Auth routes: mounts · Express server exposes auth endpoints
- Server → Search routes: mounts · Express server exposes search endpoints
- Server → Stream routes: mounts · Express server exposes stream endpoints
- Server → Metadata routes: mounts · Express server exposes metadata endpoints
- Server → Download routes: mounts · Express server exposes download endpoints
- Server → User routes: mounts · Express server exposes user endpoints
- Download routes → Queue: enqueues · Download requests are queued for async processing
- Queue → Python bridge: dispatches · Queued jobs are forwarded to the Python worker bridge
- Python bridge → Worker entry: invokes · Node service hands work to the Python runtime
- Worker entry → Downloader: runs · Worker executes download and conversion pipeline steps
- Downloader → Job model: updates · Pipeline reads and writes job state
- Downloader → Progress gateway: progress · Worker-originated progress is surfaced back through the API channel
- Progress gateway → Browser: pushes · Browser receives live job updates
- User routes → User files: persists · User-facing endpoints use lightweight file tracking
- Server → Routes: imports · API reuses shared route constants
- Feature modules → Events: imports · Frontend reuses shared event names
- Progress gateway → Events: publishes · Progress gateway uses shared realtime events
- Server → Roles: imports · API uses shared role definitions
