# anil-matcha/ai-youtube-shorts-generator architecture

> Architecture diagram of the GitHub repository anil-matcha/ai-youtube-shorts-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anil-matcha/ai-youtube-shorts-generator
- Repository: https://github.com/anil-matcha/ai-youtube-shorts-generator

## Overview

#### Purpose and entry points
This is a Python CLI/library that converts a YouTube URL or local video into ranked, rendered short-form clips. `main.py` is the command-line entry point; library consumers import `generate_shorts` from `shorts_generator/__init__.py`. The pipeline supports a hosted MuAPI path (`api`, default) and a self-hosted processing path (`local`).

#### Pipeline orchestration and mode boundary
`shorts_generator/pipeline.py` is the central dispatcher: it normalizes request options and routes each stage to API-backed or local implementations while preserving a common result shape: source metadata, timestamped transcript, highlight candidates, and final shorts. The mode boundary is explicit:
- `shorts_generator/pipeline.py`
- `shorts_generator/__init__.py`
- `main.py`

#### Source acquisition
Input is either a remote YouTube URL or, in local mode, a direct filesystem/file URL. API mode delegates download to MuAPI; local mode uses `yt-dlp` and caches downloaded source video under the configured output directory. This stage produces a video URL/path consumed by transcription and rendering.
- `shorts_generator/downloader.py`
- `shorts_generator/local/downloader.py`
- `shorts_generator/muapi.py`

#### Transcription boundary
Both modes produce a timestamped, segmented transcript with compatible downstream structure. API mode calls MuAPI’s Whisper endpoint; local mode runs `faster-whisper` on CPU or CUDA and reuses a newer cached SRT transcript where possible. Transcript timing is the primary contract for highlight selection and clip boundaries.
- `shorts_generator/transcriber.py`
- `shorts_generator/local/transcriber.py`
- `shorts_generator/config.py`

#### Highlight analysis and selection
`shorts_generator/highlights.py` owns content classification, long-video chunking, virality-oriented LLM prompting, candidate parsing, overlap deduplication, and top-N selection. Videos beyond the threshold are analyzed as overlapping chunks to avoid boundary misses. The LLM backend is MuAPI in API mode or an OpenAI/Gemini selector locally; selected candidates carry start/end times, score, title, hook, and rationale.
- `shorts_generator/highlights.py`
- `shorts_generator/local/llm.py`
- `shorts_generator/pipeline.py`

#### Clip rendering
Final selected intervals are rendered at the requested aspect ratio. API mode submits autocrop/render work to MuAPI and returns hosted clip URLs. Local mode cuts with ffmpeg and vertically reframes via OpenCV face tracking, producing MP4 files in the configured output directory.
- `shorts_generator/clipper.py`
- `shorts_generator/local/clipper.py`
- `shorts_generator/muapi.py`

#### Infrastructure and external services
API mode depends on MuAPI for asynchronous download, Whisper transcription, LLM ranking, and autocrop; `shorts_generator/muapi.py` provides generic submit-and-poll behavior governed by timeout/poll settings. Local mode requires ffmpeg, yt-dlp, faster-whisper, and optionally CUDA; it still calls either OpenAI or Gemini for highlight ranking. Credentials and runtime choices are environment-driven through:
- `shorts_generator/config.py`
- `.env.example`
- `requirements.txt`

Main entry points: [`shorts_generator/pipeline.py`](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/pipeline.py) (Pipeline dispatcher), [`shorts_generator/highlights.py`](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/highlights.py) (Highlight analysis), [`shorts_generator/clipper.py`](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/clipper.py) (API render adapter), [`shorts_generator/local/clipper.py`](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/clipper.py) (Local clip renderer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_cli["CLI<br/>Python entry point<br/>[main.py]"]
  node_library["Library API<br/>Python package API<br/>[__init__.py]"]
end

subgraph group_core["Pipeline Core"]
  node_pipeline{{"Pipeline dispatcher<br/>orchestrator<br/>[pipeline.py]"}}
  node_config["Runtime config<br/>configuration<br/>[config.py]"]
  node_transcript["Timestamped transcript<br/>pipeline contract"]
  node_candidates["Ranked highlights<br/>pipeline contract"]
  node_shorts["Rendered shorts<br/>pipeline output"]
  node_highlight_analysis{{"Highlight analysis<br/>selection engine<br/>[highlights.py]"}}
end

subgraph group_api["Hosted API Mode"]
  node_api_download["API download adapter<br/>source adapter<br/>[downloader.py]"]
  node_api_transcribe["API transcription adapter<br/>[transcriber.py]"]
  node_api_clipper["API render adapter<br/>[clipper.py]"]
  node_muapi["MuAPI client<br/>async job client<br/>[muapi.py]"]
end

subgraph group_local["Self-hosted Local Mode"]
  node_local_download["Local downloader<br/>source adapter<br/>[downloader.py]"]
  node_local_transcribe["Local transcription<br/>transcription adapter<br/>[transcriber.py]"]
  node_local_llm["Local LLM selector<br/>LLM adapter<br/>[llm.py]"]
  node_local_clipper["Local clip renderer<br/>render adapter<br/>[clipper.py]"]
end

subgraph group_external["External Services"]
  node_muapi_service(("MuAPI<br/>hosted processing service"))
  node_local_toolchain(("Local media toolchain<br/>runtime dependencies"))
  node_llm_providers(("OpenAI / Gemini<br/>LLM providers"))
end

node_cli -->|"invokes"| node_pipeline
node_library -->|"calls"| node_pipeline
node_config -.->|"mode and settings"| node_pipeline
node_pipeline -->|"API source path"| node_api_download
node_pipeline -->|"local source path"| node_local_download
node_api_download -->|"delegates"| node_muapi
node_local_download -->|"uses yt-dlp"| node_local_toolchain
node_pipeline -->|"API transcription"| node_api_transcribe
node_pipeline -->|"local transcription"| node_local_transcribe
node_api_transcribe -->|"Whisper job"| node_muapi
node_local_transcribe -->|"uses faster-whisper"| node_local_toolchain
node_api_transcribe -->|"produces"| node_transcript
node_local_transcribe -->|"produces"| node_transcript
node_pipeline -->|"analyzes transcript"| node_highlight_analysis
node_transcript -->|"timed segments"| node_highlight_analysis
node_highlight_analysis -->|"API ranking"| node_muapi
node_highlight_analysis -->|"local ranking"| node_local_llm
node_local_llm -->|"calls"| node_llm_providers
node_highlight_analysis -->|"selects"| node_candidates
node_pipeline -->|"API rendering"| node_api_clipper
node_pipeline -->|"local rendering"| node_local_clipper
node_candidates -->|"clip intervals"| node_api_clipper
node_candidates -->|"clip intervals"| node_local_clipper
node_api_clipper -->|"autocrop job"| node_muapi
node_local_clipper -->|"uses ffmpeg and OpenCV"| node_local_toolchain
node_api_clipper -->|"hosted URLs"| node_shorts
node_local_clipper -->|"MP4 files"| node_shorts

click node_cli "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/main.py"
click node_library "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/__init__.py"
click node_pipeline "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/pipeline.py"
click node_config "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/config.py"
click node_api_download "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/downloader.py"
click node_api_transcribe "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/transcriber.py"
click node_api_clipper "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/clipper.py"
click node_muapi "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/muapi.py"
click node_local_download "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/downloader.py"
click node_local_transcribe "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/transcriber.py"
click node_highlight_analysis "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/highlights.py"
click node_local_llm "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/llm.py"
click node_local_clipper "https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/clipper.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_library toneBlue
class node_pipeline,node_config,node_transcript,node_candidates,node_shorts,node_highlight_analysis toneAmber
class node_api_download,node_api_transcribe,node_api_clipper,node_muapi toneMint
class node_local_download,node_local_transcribe,node_local_llm,node_local_clipper toneRose
class node_muapi_service,node_local_toolchain,node_llm_providers toneIndigo
```

## Components

### Entry Points

- [CLI](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/main.py): Python entry point · `main.py`
- [Library API](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/__init__.py): Python package API · Exports generate_shorts. · `shorts_generator/__init__.py`

### Pipeline Core

- [Pipeline dispatcher](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/pipeline.py): orchestrator · Normalizes options and preserves the shared pipeline result shape. · `shorts_generator/pipeline.py`
- [Runtime config](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/config.py): configuration · Environment-driven mode, credentials, and processing settings. · `shorts_generator/config.py`
- **Timestamped transcript**: pipeline contract · Segment timing drives highlight and clip boundaries.
- **Ranked highlights**: pipeline contract · Candidates include intervals, score, title, hook, and rationale.
- **Rendered shorts**: pipeline output · Hosted URLs in API mode or local MP4 files.
- [Highlight analysis](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/highlights.py): selection engine · Chunks long videos, prompts the LLM, deduplicates overlaps, and selects top-N. · `shorts_generator/highlights.py`

### Hosted API Mode

- [API download adapter](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/downloader.py): source adapter · `shorts_generator/downloader.py`
- [API transcription adapter](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/transcriber.py): transcription adapter · `shorts_generator/transcriber.py`
- [API render adapter](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/clipper.py): render adapter · `shorts_generator/clipper.py`
- [MuAPI client](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/muapi.py): async job client · Submits and polls hosted processing jobs. · `shorts_generator/muapi.py`

### Self-hosted Local Mode

- [Local downloader](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/downloader.py): source adapter · Downloads and caches remote video inputs. · `shorts_generator/local/downloader.py`
- [Local transcription](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/transcriber.py): transcription adapter · Runs faster-whisper and reuses newer cached SRT files. · `shorts_generator/local/transcriber.py`
- [Local LLM selector](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/llm.py): LLM adapter · `shorts_generator/local/llm.py`
- [Local clip renderer](https://github.com/anil-matcha/ai-youtube-shorts-generator/blob/main/shorts_generator/local/clipper.py): render adapter · Cuts with ffmpeg and reframes vertically using OpenCV face tracking. · `shorts_generator/local/clipper.py`

### External Services

- **MuAPI**: hosted processing service · Provides download, Whisper, ranking, and autocrop jobs.
- **Local media toolchain**: runtime dependencies · yt-dlp, faster-whisper, ffmpeg, OpenCV, and optional CUDA.
- **OpenAI / Gemini**: LLM providers

## Connections

- CLI → Pipeline dispatcher: invokes
- Library API → Pipeline dispatcher: calls
- Runtime config → Pipeline dispatcher: mode and settings
- Pipeline dispatcher → API download adapter: API source path
- Pipeline dispatcher → Local downloader: local source path
- API download adapter → MuAPI client: delegates
- Local downloader → Local media toolchain: uses yt-dlp
- Pipeline dispatcher → API transcription adapter: API transcription
- Pipeline dispatcher → Local transcription: local transcription
- API transcription adapter → MuAPI client: Whisper job
- Local transcription → Local media toolchain: uses faster-whisper
- API transcription adapter → Timestamped transcript: produces
- Local transcription → Timestamped transcript: produces
- Pipeline dispatcher → Highlight analysis: analyzes transcript
- Timestamped transcript → Highlight analysis: timed segments
- Highlight analysis → MuAPI client: API ranking
- Highlight analysis → Local LLM selector: local ranking
- Local LLM selector → OpenAI / Gemini: calls
- Highlight analysis → Ranked highlights: selects
- Pipeline dispatcher → API render adapter: API rendering
- Pipeline dispatcher → Local clip renderer: local rendering
- Ranked highlights → API render adapter: clip intervals
- Ranked highlights → Local clip renderer: clip intervals
- API render adapter → MuAPI client: autocrop job
- Local clip renderer → Local media toolchain: uses ffmpeg and OpenCV
- API render adapter → Rendered shorts: hosted URLs
- Local clip renderer → Rendered shorts: MP4 files
