# tyrrrz/youtubedownloader architecture

> Architecture diagram of the GitHub repository tyrrrz/youtubedownloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tyrrrz/youtubedownloader
- Repository: https://github.com/tyrrrz/youtubedownloader

## Overview

##### Main Components
- User Interface (UI) Layer: Represented by the “YoutubeDownloader” project, this layer incorporates:
- Views (axaml files and their code-behinds in the Views folder)
- ViewModels (under ViewModels and its subdirectories)
- Converters (in YoutubeDownloader/Converters)
- Dialogs, custom controls, and any UI-related framework components (e.g., ThemeVariant, DialogManager, ViewManager in the Framework folder)
- Core Business Logic Layer: Found in “YoutubeDownloader.Core”, it is divided into:
- Downloading Component (handles video downloads, download options, and supported quality via classes like VideoDownloader, VideoQualityPreference, etc.)
- Query Resolving Component (in the Resolving directory for handling URL or search query parsing and results)
- Tagging Component (for managing media metadata injection using MusicBrainz, etc.)
- Utility Components (various helper methods and extensions located in the Utils subfolders)
- Services and Application Support: In the “YoutubeDownloader/Services” folder, services such as SettingsService and UpdateService manage configuration and update functionalities.
- External Dependencies:
- YoutubeExplode: Used indirectly within the core to interact with YouTube (as noted in the README).
- FFmpeg: Bundled (and optionally external) for processing video files.
- Other Dependencies: The project also utilizes community and language runtime libraries (reflected in .csproj and Directory.Build.props files).

##### Relationships and Interactions
- The UI Layer (views and viewmodels) interacts with the Services to request downloads and updates.
- The viewmodels delegate core functionalities (downloading, query resolution, and tagging) to the YoutubeDownloader.Core library.
- Within the Core layer:
- The Downloading module invokes FFmpeg (via DownloadFFmpeg.ps1 script and the FFmpeg integration class) for video processing.
- The Resolving module processes URLs or search queries and classifies the result (using QueryResult, QueryResultKind, etc.).
- The Tagging module enriches the downloaded media files with metadata obtained via external APIs (like MusicBrainz).
- Utility modules are used throughout both layers to support operations such as HTTP requests, path manipulations, and asynchronous patterns.

##### Architectural Patterns and Design Principles
- MVVM (Model-View-ViewModel): Evident from the separate Views and ViewModels folders, supporting UI/data binding.
- Layered Separation: The clear partition between the UI/application layer (YoutubeDownloader) and the business logic/core layer (YoutubeDownloader.Core) embodies separation of concerns.
- Modularity: Core functions (downloading, resolving, tagging) are wrapped in their own modules, and utilities are grouped separately.
- Dependency Management: Use of external libraries (YoutubeExplode, FFmpeg) is abstracted away inside core functionalities to keep a clean separation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface (Desktop GUI)
    subgraph "User Interface (Desktop GUI)"
        UI["\"UI: YoutubeDownloader\""]
        VIEWS["\"Views\""]
        VIEWMODELS["\"ViewModels\""]
        CONVERTERS["\"Converters\""]
        FRAMEWORK["\"Framework Components\""]
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        CORE["\"Core: YoutubeDownloader.Core\""]
        DOWNLOADING["\"Downloading Module\""]
        RESOLVING["\"Query Resolving Module\""]
        TAGGING["\"Tagging Module\""]
        UTILS["\"Utility Components\""]
    end

    %% Services & Application Support
    subgraph "Services & Application Support"
        SERVICES["\"Services\""]
        UIHELPERS["\"UI Helpers\""]
    end

    %% External Dependencies
    subgraph "External Dependencies"
        YTEX["\"YoutubeExplode\""]
        FFMPEG_CODE["\"FFmpeg Code\""]
        FFMPEG_SCRIPT["\"FFmpeg Script\""]
    end

    %% Connections between major layers
    UI -->|"initiatesDownload"| CORE
    UI -->|"callsServices"| SERVICES

    %% Connections within Core Business Logic
    RESOLVING -->|"parsesQuery"| DOWNLOADING
    DOWNLOADING -->|"invokesTagging"| TAGGING
    DOWNLOADING -->|"usesFFmpeg"| FFMPEG_CODE
    DOWNLOADING -->|"triggersScript"| FFMPEG_SCRIPT
    CORE -->|"integrates"| YTEX

    %% Connections from Services to UI Helpers (and vice versa if needed)
    SERVICES -->|"supportsConfiguration"| UIHELPERS

    %% Styles for visual differentiation
    class UI,VIEWS,VIEWMODELS,CONVERTERS,FRAMEWORK fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    class CORE,DOWNLOADING,RESOLVING,TAGGING,UTILS fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    class SERVICES,UIHELPERS fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    class YTEX,FFMPEG_CODE,FFMPEG_SCRIPT fill:#F5B7B1,stroke:#943126,stroke-width:2px;

    %% Click Events for User Interface (Desktop GUI)
    click UI "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader"
    click VIEWS "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader/Views"
    click VIEWMODELS "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader/ViewModels"
    click CONVERTERS "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader/Converters"
    click FRAMEWORK "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader/Framework"

    %% Click Events for Core Business Logic
    click CORE "https://github.com/tyrrrz/youtubedownloader/blob/master/YoutubeDownloader.Core"
    click DOWNLOADING "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader.Core/Downloading"
    click RESOLVING "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader.Core/Resolving"
    click TAGGING "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader.Core/Tagging"
    click UTILS "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader.Core/Utils"

    %% Click Events for Services & Application Support
    click SERVICES "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader/Services"
    click UIHELPERS "https://github.com/tyrrrz/youtubedownloader/tree/master/YoutubeDownloader/Utils"

    %% Click Events for External Dependencies
    click FFMPEG_CODE "https://github.com/tyrrrz/youtubedownloader/blob/master/YoutubeDownloader.Core/Downloading/FFmpeg.cs"
    click FFMPEG_SCRIPT "https://github.com/tyrrrz/youtubedownloader/blob/master/YoutubeDownloader/DownloadFFmpeg.ps1"
```
