# emrtasknn/youtube-shorts-bot-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/emrtasknn/youtube-shorts-bot-v2
- Repository: https://github.com/emrtasknn/youtube-shorts-bot-v2

## Overview

This is a production-oriented YouTube Shorts automation service. Its primary workflow generates a Short from a topic, renders and quality-checks it, then requires Telegram human approval before YouTube publishing. Separate capabilities handle provider reliability and performance-driven experimentation; experiment results are policy-gated rather than automatically promoted. The README documents the broad pipeline and safety boundaries; some subsystem wiring is not shown in the sampled source, so those links are omitted or marked unverified.

Main entry points: [`app/application/use_cases/generate_custom_short.py`](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/use_cases/generate_custom_short.py) (Generation orchestrator), [`app/application/services/telegram_control.py`](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/telegram_control.py) (Approval control plane), [`app/application/services/scene_contract.py`](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/scene_contract.py) (Scene planning), [`app/infrastructure/video/ffmpeg.py`](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/video/ffmpeg.py) (Video rendering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Short generation"]
  node_cli["Custom Short command<br/>[__main__.py]"]
  node_generator["Generation orchestrator"]
  node_script["Script and narrative<br/>[hook_engine.py]"]
  node_visuals["Visual retrieval"]
  node_scene["Scene planning<br/>[scene_contract.py]"]
  node_timing["Scene timing<br/>[scene_timing.py]"]
  node_motion["Camera motion<br/>[camera_motion.py]"]
  node_beats["Visual beats<br/>[visual_beat.py]"]
  node_voice["Speech synthesis<br/>[tts.py]"]
  node_render["Video rendering<br/>[ffmpeg.py]"]
  node_qc["Video quality checks<br/>[video_judge.py]"]
end

subgraph group_control["Review and publishing"]
  node_telegram_control["Approval control plane"]
  node_telegram_worker["Telegram worker<br/>[telegram_worker.py]"]
  node_youtube["YouTube publishing<br/>[youtube.py]"]
  node_database[("PostgreSQL state<br/>[models.py]")]
end

subgraph group_reliability["Provider reliability"]
  node_runtime["Runtime assembly<br/>[runtime.py]"]
  node_provider_reliability["Provider reliability<br/>[reliability.py]"]
end

subgraph group_intelligence["Learning and optimization"]
  node_performance["Performance memory"]
  node_experiments["Experiments and policy<br/>[optimization.py]"]
  node_production_adapter["Production policy adapter"]
end

node_creator(("Content creator"))
node_media_provider["Text, media and TTS providers"]
node_telegram(("Telegram reviewer"))

node_creator -->|"requests generation"| node_cli
node_cli -->|"starts generation"| node_generator
node_generator -->|"creates narrative"| node_script
node_generator -->|"retrieves visuals"| node_visuals
node_generator -->|"plans scenes"| node_scene
node_generator -->|"synthesizes speech"| node_voice
node_generator -->|"renders video"| node_render
node_generator -->|"quality checks"| node_qc
node_visuals -.->|"searches media"| node_media_provider
node_generator -.->|"requests generation"| node_media_provider
node_scene -->|"allocates timing"| node_timing
node_scene -->|"defines beats"| node_beats
node_render -->|"uses motion plans"| node_motion
node_render -->|"uses visual timelines"| node_beats
node_qc -.->|"informs retry"| node_generator
node_generator -->|"submits for approval"| node_telegram_control
node_telegram -->|"sends review response"| node_telegram_worker
node_telegram_worker -->|"handles updates"| node_telegram_control
node_telegram_control -->|"publishes approved video"| node_youtube
node_telegram_control -->|"persists approval state"| node_database
node_runtime -->|"assembles reliability"| node_provider_reliability
node_provider_reliability -.->|"routes provider calls"| node_media_provider
node_youtube -->|"persists upload state"| node_database
node_performance -->|"informs experiments"| node_experiments
node_experiments -->|"gates policy changes"| node_production_adapter
node_production_adapter -->|"supplies generation input"| node_generator
node_telegram_control -->|"uses performance memory"| node_performance

click node_cli "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/__main__.py"
click node_generator "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/use_cases/generate_custom_short.py"
click node_script "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/hook_engine.py"
click node_visuals "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/use_cases/search_stock_media.py"
click node_scene "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/scene_contract.py"
click node_timing "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/scene_timing.py"
click node_motion "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/camera_motion.py"
click node_beats "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/visual_beat.py"
click node_voice "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/ports/tts.py"
click node_render "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/video/ffmpeg.py"
click node_qc "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/video_judge.py"
click node_telegram_control "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/telegram_control.py"
click node_telegram_worker "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/telegram_worker.py"
click node_youtube "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/providers/youtube.py"
click node_database "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/database/models.py"
click node_runtime "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/runtime.py"
click node_provider_reliability "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/providers/reliability.py"
click node_performance "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/domain/performance_memory.py"
click node_experiments "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/domain/optimization.py"
click node_production_adapter "https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/optimization_production_adapter.py"

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_generator,node_script,node_visuals,node_scene,node_timing,node_motion,node_beats,node_voice,node_render,node_qc,node_telegram toneBlue
class node_telegram_control,node_telegram_worker,node_youtube,node_database toneAmber
class node_runtime,node_provider_reliability toneMint
class node_performance,node_experiments,node_production_adapter toneRose
class node_creator,node_media_provider toneIndigo
```

## Components

### Short generation

- [Custom Short command](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/__main__.py): `app/__main__.py`
- [Generation orchestrator](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/use_cases/generate_custom_short.py): `app/application/use_cases/generate_custom_short.py`
- [Script and narrative](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/hook_engine.py): `app/application/services/hook_engine.py`
- [Visual retrieval](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/use_cases/search_stock_media.py): `app/application/use_cases/search_stock_media.py`
- [Scene planning](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/scene_contract.py): `app/application/services/scene_contract.py`
- [Scene timing](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/scene_timing.py): `app/application/services/scene_timing.py`
- [Camera motion](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/camera_motion.py): `app/application/services/camera_motion.py`
- [Visual beats](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/visual_beat.py): `app/application/services/visual_beat.py`
- [Speech synthesis](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/ports/tts.py): `app/application/ports/tts.py`
- [Video rendering](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/video/ffmpeg.py): `app/infrastructure/video/ffmpeg.py`
- [Video quality checks](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/video_judge.py): `app/application/services/video_judge.py`

### Review and publishing

- [Approval control plane](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/telegram_control.py): `app/application/services/telegram_control.py`
- [Telegram worker](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/telegram_worker.py): `app/application/services/telegram_worker.py`
- [YouTube publishing](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/providers/youtube.py): `app/infrastructure/providers/youtube.py`
- [PostgreSQL state](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/database/models.py): `app/infrastructure/database/models.py`

### Provider reliability

- [Runtime assembly](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/runtime.py): `app/runtime.py`
- [Provider reliability](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/infrastructure/providers/reliability.py): `app/infrastructure/providers/reliability.py`

### Learning and optimization

- [Performance memory](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/domain/performance_memory.py): `app/domain/performance_memory.py`
- [Experiments and policy](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/domain/optimization.py): `app/domain/optimization.py`
- [Production policy adapter](https://github.com/emrtasknn/youtube-shorts-bot-v2/blob/main/app/application/services/optimization_production_adapter.py): `app/application/services/optimization_production_adapter.py`

### Other components

- **Content creator**
- **Text, media and TTS providers**
- **Telegram reviewer**

## Connections

- Content creator → Custom Short command: requests generation (evidence: `README.md`)
- Custom Short command → Generation orchestrator: starts generation (evidence: `app/__main__.py`)
- Generation orchestrator → Script and narrative: creates narrative (evidence: `README.md`)
- Generation orchestrator → Visual retrieval: retrieves visuals (evidence: `README.md`)
- Generation orchestrator → Scene planning: plans scenes (evidence: `README.md`)
- Generation orchestrator → Speech synthesis: synthesizes speech (evidence: `README.md`)
- Generation orchestrator → Video rendering: renders video (evidence: `README.md`)
- Generation orchestrator → Video quality checks: quality checks (evidence: `README.md`)
- Visual retrieval → Text, media and TTS providers: searches media
- Generation orchestrator → Text, media and TTS providers: requests generation
- Scene planning → Scene timing: allocates timing (evidence: `app/application/services/visual_beat.py`)
- Scene planning → Visual beats: defines beats (evidence: `app/application/services/visual_beat.py`)
- Video rendering → Camera motion: uses motion plans (evidence: `app/infrastructure/video/ffmpeg.py`)
- Video rendering → Visual beats: uses visual timelines (evidence: `app/infrastructure/video/ffmpeg.py`)
- Video quality checks → Generation orchestrator: informs retry (evidence: `app/application/use_cases/generate_custom_short.py`)
- Generation orchestrator → Approval control plane: submits for approval (evidence: `README.md`)
- Telegram reviewer → Telegram worker: sends review response (evidence: `README.md`)
- Telegram worker → Approval control plane: handles updates (evidence: `app/application/services/telegram_worker.py`)
- Approval control plane → YouTube publishing: publishes approved video (evidence: `README.md`)
- Approval control plane → PostgreSQL state: persists approval state (evidence: `README.md`)
- Runtime assembly → Provider reliability: assembles reliability (evidence: `app/runtime.py`)
- Provider reliability → Text, media and TTS providers: routes provider calls
- YouTube publishing → PostgreSQL state: persists upload state (evidence: `README.md`)
- Performance memory → Experiments and policy: informs experiments (evidence: `README.md`)
- Experiments and policy → Production policy adapter: gates policy changes (evidence: `README.md`)
- Production policy adapter → Generation orchestrator: supplies generation input (evidence: `README.md`)
- Approval control plane → Performance memory: uses performance memory (evidence: `app/application/services/telegram_control.py`)
