# leandjb/python-yt-downloader architecture

> Architecture diagram of the GitHub repository leandjb/python-yt-downloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leandjb/python-yt-downloader
- Repository: https://github.com/leandjb/python-yt-downloader

## Overview

##### Project type and purpose
- This is a small desktop GUI application written in Python.
- Purpose: allow users to download progressive (video+audio) YouTube streams up to 720p via a simple GUI built with CustomTkinter and Pytube.

##### Top-level file structure and architectural hints
- src/main.py – entry point, spins up the CustomTkinter window, handles UI events.
- src/test_main.py – unit tests for main.py logic.
- README.md – describes GUI flow and external dependencies (CustomTkinter, Pytube).

##### Core components
A. Presentation Layer (CustomTkinter GUI)
- Input field for URL
- “Download” button
- Progress bar + status label
B. Application Logic / Service Layer
- DownloadManager (in main.py)
- URL validation, error handling
- Progress-update callbacks
C. External Libraries and Services
- Pytube (network client fetching YouTube streams)
- YouTube servers (HTTP requests/responses)
D. Local File System
- Storage of downloaded .mp4 files

##### Data flow and relationships
1. User pastes URL → GUI component
2. GUI calls DownloadManager.download(url)
3. DownloadManager uses Pytube API → sends HTTP request to YouTube
4. YouTube responds with stream data → Pytube streams to memory or tempfile
5. DownloadManager writes bytes to local disk
6. Progress updates flow back via callback → GUI progress bar
7. On success/failure → GUI displays message

##### Architectural patterns and separation of concerns
- MVC-lite:
- View = CustomTkinter widgets
- Controller/Service = DownloadManager logic in main.py
- Single process, event-driven GUI
- Clear boundary between UI and download logic

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        MainWindow["MainWindow\n(CustomTkinter GUI)"]:::ui
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        DownloadManager["DownloadManager\n(src/main.py)"]:::service
    end

    %% External Libraries & Services
    subgraph "External Systems"
        direction TB
        PytubeLib["Pytube Library"]:::external
        YouTubeCloud("YouTube Cloud"):::external
    end

    %% Local File System
    LocalStorage["Local Storage\n(.mp4 files)"]:::storage

    %% Test Harness
    TestMain["test_main.py\n(Unit Tests)"]:::test

    %% Documentation
    README["README.md\n(Project Overview)"]:::docs

    %% Data Flows
    MainWindow -->|"download(url)"| DownloadManager
    DownloadManager -->|"uses API" | PytubeLib
    PytubeLib -->|"HTTP request/response"| YouTubeCloud
    DownloadManager -->|"write(.mp4)"| LocalStorage
    DownloadManager -->|"on_progress(bytes)"| MainWindow
    TestMain -->|"tests download logic"| DownloadManager
    README -.-> MainWindow

    %% Click Events
    click MainWindow "https://github.com/leandjb/python-yt-downloader/blob/main/src/main.py"
    click DownloadManager "https://github.com/leandjb/python-yt-downloader/blob/main/src/main.py"
    click TestMain "https://github.com/leandjb/python-yt-downloader/blob/main/src/test_main.py"
    click README "https://github.com/leandjb/python-yt-downloader/blob/main/README.md"

    %% Styles
    classDef ui fill:#9f6,stroke:#333,stroke-width:2px;
    classDef service fill:#6cf,stroke:#333,stroke-width:2px;
    classDef external fill:#fc6,stroke:#333,stroke-width:2px;
    classDef storage fill:#ccc,stroke:#333,stroke-width:2px;
    classDef test fill:#c6f,stroke:#333,stroke-width:2px;
    classDef docs fill:#f99,stroke:#333,stroke-width:2px;
```
