# yatichbrian99-svg/torrent-cdn architecture

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

- Interactive diagram: https://gitdiagram.com/yatichbrian99-svg/torrent-cdn
- Repository: https://github.com/yatichbrian99-svg/torrent-cdn

## Overview

TorrentCDN delivers uploaded video through browser-based WebTorrent peers, with origin fallback, and also offers live streaming and a separate decentralized-inference product. The graph preserves those product branches and the shared account/API layer. Relationship evidence is limited to the README and the supplied source excerpts and index; unsampled subsystems are included where the README documents them, but uncertain internal links are omitted.

Main entry points: [`backend/app/ai/service.py`](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/service.py) (AI coordinator), [`frontend/public/sdk.js`](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/public/sdk.js) (Embed SDK), [`backend/app/routes/upload.py`](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/upload.py) (Upload workflow), [`backend/app/routes/auth.py`](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/auth.py) (Authentication routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_delivery["Video Delivery"]
  node_upload_ui["Upload interface<br/>[UploadForm.tsx]"]
  node_upload_api["Upload workflow<br/>[upload.py]"]
  node_object_store[("Object storage")]
  node_torrent["Magnet generation<br/>[torrent_builder.py]"]
  node_embed_sdk["Embed SDK<br/>[sdk.js]"]
  node_video_player["Video player<br/>[VideoPlayer.tsx]"]
end

subgraph group_live["Live Streaming"]
  node_channel_ui["Channel interface<br/>[page.tsx]"]
  node_live_api["Live channel API<br/>[live.py]"]
  node_stream_ingest["Stream ingest"]
  node_mediamtx["MediaMTX"]
  node_live_delivery["Live P2P delivery<br/>[segments.ts]"]
  node_live_player["Live player<br/>[LivePlayer.tsx]"]
end

subgraph group_accounts["Platform Accounts"]
  node_account_ui["Account interface<br/>[AuthModal.tsx]"]
  node_auth_api["Authentication routes<br/>[auth.py]"]
  node_auth_service["Session authentication<br/>[auth.py]"]
  node_platform_db[("Platform database<br/>[database.py]")]
  node_app_router["API application<br/>[main.py]"]
end

subgraph group_ai["TCDN-AI"]
  node_ai_console["AI console routes<br/>[routes_console.py]"]
  node_ai_api["Inference API<br/>[routes.py]"]
  node_openai_api["OpenAI-compatible API<br/>[routes_openai.py]"]
  node_coordinator["AI coordinator<br/>[service.py]"]
  node_ai_store[("AI state and ledger<br/>[store.py]")]
  node_gpu_workers["Rented GPU workers<br/>[worker.py]"]
  node_ai_sdk["Inference SDK<br/>[client.py]"]
  node_ai_console_ui["AI console UI<br/>[aiConsole.ts]"]
end

node_creator(("Content creator"))
node_viewer(("Video viewer"))

node_creator -->|"submits video"| node_upload_ui
node_upload_ui -.->|"sends upload"| node_upload_api
node_upload_api -.->|"stores media"| node_object_store
node_upload_api -->|"builds magnet"| node_torrent
node_viewer -->|"opens embed"| node_embed_sdk
node_embed_sdk -->|"fetches media"| node_object_store
node_embed_sdk -.->|"delivers playback"| node_video_player
node_embed_sdk -->|"shares bytes"| node_viewer
node_creator -->|"manages channel"| node_channel_ui
node_channel_ui -.->|"configures channel"| node_live_api
node_stream_ingest -->|"sends RTMP"| node_mediamtx
node_mediamtx -->|"outputs HLS"| node_live_delivery
node_live_delivery -->|"serves segments"| node_live_player
node_live_player -.->|"plays stream"| node_viewer
node_account_ui -.->|"authenticates"| node_auth_api
node_auth_api -->|"uses sessions"| node_auth_service
node_auth_api -->|"reads and writes"| node_platform_db
node_app_router -->|"mounts routes"| node_auth_api
node_app_router -->|"mounts routes"| node_upload_api
node_ai_console_ui -.->|"calls console API"| node_ai_console
node_ai_console -->|"delegates operations"| node_coordinator
node_ai_api -->|"delegates requests"| node_coordinator
node_openai_api -->|"delegates requests"| node_coordinator
node_coordinator -->|"reads and writes"| node_ai_store
node_ai_sdk -->|"sends inference requests"| node_openai_api
node_coordinator -.->|"dispatches jobs"| node_gpu_workers

click node_upload_ui "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/UploadForm.tsx"
click node_upload_api "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/upload.py"
click node_torrent "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/torrent_builder.py"
click node_embed_sdk "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/public/sdk.js"
click node_video_player "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/VideoPlayer.tsx"
click node_channel_ui "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/app/live/channels/page.tsx"
click node_live_api "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/live.py"
click node_live_delivery "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/lib/live/segments.ts"
click node_live_player "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/LivePlayer.tsx"
click node_account_ui "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/AuthModal.tsx"
click node_auth_api "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/auth.py"
click node_auth_service "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/auth.py"
click node_platform_db "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/database.py"
click node_app_router "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/main.py"
click node_ai_console "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/routes_console.py"
click node_ai_api "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/routes.py"
click node_openai_api "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/routes_openai.py"
click node_coordinator "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/service.py"
click node_ai_store "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/store.py"
click node_gpu_workers "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/worker.py"
click node_ai_sdk "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/tcdn_ai_sdk/client.py"
click node_ai_console_ui "https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/lib/aiConsole.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_upload_ui,node_upload_api,node_object_store,node_torrent,node_embed_sdk,node_video_player,node_viewer toneBlue
class node_channel_ui,node_live_api,node_stream_ingest,node_mediamtx,node_live_delivery,node_live_player toneAmber
class node_account_ui,node_auth_api,node_auth_service,node_platform_db,node_app_router toneMint
class node_ai_console,node_ai_api,node_openai_api,node_coordinator,node_ai_store,node_gpu_workers,node_ai_sdk,node_ai_console_ui toneRose
class node_creator toneIndigo
```

## Components

### Video Delivery

- [Upload interface](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/UploadForm.tsx): `frontend/components/UploadForm.tsx`
- [Upload workflow](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/upload.py): `backend/app/routes/upload.py`
- **Object storage**
- [Magnet generation](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/torrent_builder.py): `backend/app/torrent_builder.py`
- [Embed SDK](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/public/sdk.js): `frontend/public/sdk.js`
- [Video player](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/VideoPlayer.tsx): `frontend/components/VideoPlayer.tsx`

### Live Streaming

- [Channel interface](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/app/live/channels/page.tsx): `frontend/app/live/channels/page.tsx`
- [Live channel API](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/live.py): `backend/app/routes/live.py`
- **Stream ingest**
- **MediaMTX**
- [Live P2P delivery](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/lib/live/segments.ts): `frontend/lib/live/segments.ts`
- [Live player](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/LivePlayer.tsx): `frontend/components/LivePlayer.tsx`

### Platform Accounts

- [Account interface](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/components/AuthModal.tsx): `frontend/components/AuthModal.tsx`
- [Authentication routes](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/routes/auth.py): `backend/app/routes/auth.py`
- [Session authentication](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/auth.py): `backend/app/auth.py`
- [Platform database](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/database.py): `backend/app/database.py`
- [API application](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/main.py): `backend/app/main.py`

### TCDN-AI

- [AI console routes](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/routes_console.py): `backend/app/ai/routes_console.py`
- [Inference API](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/routes.py): `backend/app/ai/routes.py`
- [OpenAI-compatible API](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/routes_openai.py): `backend/app/ai/routes_openai.py`
- [AI coordinator](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/service.py): `backend/app/ai/service.py`
- [AI state and ledger](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/store.py): `backend/app/ai/store.py`
- [Rented GPU workers](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/app/ai/worker.py): `backend/app/ai/worker.py`
- [Inference SDK](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/backend/tcdn_ai_sdk/client.py): `backend/tcdn_ai_sdk/client.py`
- [AI console UI](https://github.com/yatichbrian99-svg/torrent-cdn/blob/main/frontend/lib/aiConsole.ts): `frontend/lib/aiConsole.ts`

### Other components

- **Content creator**
- **Video viewer**

## Connections

- Content creator → Upload interface: submits video
- Upload interface → Upload workflow: sends upload
- Upload workflow → Object storage: stores media
- Upload workflow → Magnet generation: builds magnet (evidence: `backend/app/routes/upload.py`)
- Video viewer → Embed SDK: opens embed
- Embed SDK → Object storage: fetches media
- Embed SDK → Video player: delivers playback
- Embed SDK → Video viewer: shares bytes
- Content creator → Channel interface: manages channel
- Channel interface → Live channel API: configures channel
- Stream ingest → MediaMTX: sends RTMP
- MediaMTX → Live P2P delivery: outputs HLS
- Live P2P delivery → Live player: serves segments
- Live player → Video viewer: plays stream
- Account interface → Authentication routes: authenticates
- Authentication routes → Session authentication: uses sessions (evidence: `backend/app/routes/auth.py`)
- Authentication routes → Platform database: reads and writes (evidence: `backend/app/routes/auth.py`)
- API application → Authentication routes: mounts routes (evidence: `backend/app/main.py`)
- API application → Upload workflow: mounts routes (evidence: `backend/app/main.py`)
- AI console UI → AI console routes: calls console API
- AI console routes → AI coordinator: delegates operations (evidence: `backend/app/ai/routes_console.py`)
- Inference API → AI coordinator: delegates requests (evidence: `backend/app/ai/routes.py`)
- OpenAI-compatible API → AI coordinator: delegates requests (evidence: `backend/app/ai/routes_openai.py`)
- AI coordinator → AI state and ledger: reads and writes (evidence: `backend/app/ai/service.py`)
- Inference SDK → OpenAI-compatible API: sends inference requests
- AI coordinator → Rented GPU workers: dispatches jobs
