# justfoolingaround/animdl architecture

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

- Interactive diagram: https://gitdiagram.com/justfoolingaround/animdl
- Repository: https://github.com/justfoolingaround/animdl

## Overview

##### Main Components and Layers
- • CLI Interface:
- The entry point is animdl/__main__.py, which is invoked when the tool is executed.
- It utilizes a CLI library (likely click) to parse commands.
- Shows the primary CLI commands defined under animdl/core/cli/commands.
- • Command Modules:
- Each CLI command (download, stream, grab, schedule, search) is implemented as a dedicated module (ex. animdl/core/cli/commands/download.py).
- These modules call helper functions from animdl/core/cli/helpers (including submodules for banner, fuzzy search, logging, process management, etc.).
- • Business Logic and Core Codebase:
- Under animdl/core/codebase there are two principal submodules:
- Extractors: Comprises various directories (like dailymotion, gogoanime, etc.) that contain the site-specific scraping logic.
- Providers: Contains provider logic (e.g. for animexin, animixplay, crunchyroll, etc.) that uses a unified interface to gather episode and stream details.
- Downloaders (in the downloader subfolder) provide specialized methods (e.g. HLS downloading, ffmpeg integration) required for handling media streams.
- The package_resolver.py and config submodules manage configuration and dependency resolution.
- • Utility Modules:
- Located in animdl/utils (and within core/cli/helpers), these provide support for HTTP requests, caching, logging, and media download facilitation.
- • External Dependencies & Integrations:
- External libraries such as httpx, click, tqdm, and pypresence (for Discord Rich Presence), which interact with the system.
- External player integration modules are discovered in animdl/core/cli/helpers/players, allowing selection among mpv, vlc, ffplay, etc.
- Third-party integrations like fzf for enhanced prompt experience are optionally supported.

##### Relationships and Data Flow
- User input → CLI Entry Point (main.py) → Command Module (e.g. stream.py)
- Command Module likely calls helper submodules to process arguments (range, quality, etc.)
- The request is forwarded to the Codebase, where provider selection occurs via the providers and extractors stacks.
- HTTP client utilities (both in animdl/core/cli/http_client.py and animdl/utils/http_client.py) are used by extractors to fetch web content and return stream URLs.
▪ For stream: selects a media player (via the helper players) and launches an external process.
▪ For download: employs downloader modules (HLS downloader, ffmpeg integration) to save media locally.
- The configuration module establishes defaults (for providers, quality, players, ffmpeg, etc.) and is used by almost every core component, so it should be visualized as providing global parameters.

##### Architectural Patterns and Design Principles
- The design clearly separates concerns into a modular structure (CLI, core business logic, providers/extractors, utility functions). This resembles a layered architecture:
- Presentation/CLI layer: interacts with the user.
- Application/Business Logic layer: interprets user's commands and selects provider modules.
- Integration layer: handles external communications (web scraping, HTTP requests, external players).
- Utility/Configuration layer: supports global settings and reusable functionalities.
- The approach of “provider adapters” (each provider lives in its own subfolder and follows a common interface) is an example of the Adapter pattern.
- Dependency injection might be implicitly used; for example, the configuration file path and player selection are injected into the command logic.

##### Final Checklist
- Use clear labels for each component: “CLI Interface (main.py)”, “Commands (stream, download, etc.)”, “Helper Modules”, “Provider/Extractor Adapters”, “Downloaders (HLS/ffmpeg)”, “Configuration & Utilities.”
- Interface layer (user input/CLI),
- Business logic (provider adapters, extraction, downloading),
- External integrations (Discord, external players, HTTP libraries).
- Modularity and extensibility of the system architecture by separating components clearly.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global User
    User["User"]:::external

    %% CLI Layer
    subgraph "CLI Layer"
        CLI_Interface["CLI Interface (main.py)"]:::cli
        CLI_Commands["CLI Commands (download, stream, grab, schedule, search, update)"]:::cli
        CLI_Helpers["CLI Helpers"]:::cli
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        Providers["Providers (Unified Provider Adapters)"]:::business
        Extractors["Extractors (Site-Specific Scraping)"]:::business
        Downloaders["Downloaders (HLS/ffmpeg Integration)"]:::business
    end

    %% Utilities & Configuration Layer
    subgraph "Utilities & Configuration"
        HTTP_CLI["HTTP Client (CLI)"]:::util
        Config["Configuration & Dependency Resolution"]:::util
        PR["Package Resolver"]:::util
        Utility["Utility Modules"]:::util
    end

    %% External Integrations
    External_Players["External Player Integrations"]:::external

    %% Data Flow Relationships
    User -->|"invokes"| CLI_Interface
    CLI_Interface -->|"launches"| CLI_Commands
    CLI_Commands -->|"utilizes"| CLI_Helpers
    CLI_Commands -->|"forwards_request"| Providers
    CLI_Commands -->|"forwards_request"| Extractors
    Providers -->|"fetches"| HTTP_CLI
    Extractors -->|"fetches"| HTTP_CLI
    Providers -->|"triggers_download"| Downloaders
    Extractors -->|"triggers_download"| Downloaders
    Downloaders -->|"downloads_via"| HTTP_CLI
    CLI_Helpers -->|"selects_player"| External_Players
    CLI_Helpers -->|"uses"| Utility
    Config -->|"applied_to"| CLI_Commands
    Config -->|"applied_to"| CLI_Helpers
    Config -->|"applied_to"| Providers
    Config -->|"applied_to"| Extractors
    Config -->|"applied_to"| Downloaders
    Config -->|"applied_to"| Utility
    Config -->|"includes"| PR
    Utility -->|"supports"| HTTP_CLI

    %% Click Events
    click CLI_Interface "https://github.com/justfoolingaround/animdl/blob/master/animdl/__main__.py"
    click CLI_Commands "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/cli/commands/"
    click CLI_Helpers "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/cli/helpers/"
    click External_Players "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/cli/helpers/players/"
    click HTTP_CLI "https://github.com/justfoolingaround/animdl/blob/master/animdl/core/cli/http_client.py"
    click Extractors "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/codebase/extractors/"
    click Providers "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/codebase/providers/"
    click Downloaders "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/codebase/downloader/"
    click Config "https://github.com/justfoolingaround/animdl/tree/master/animdl/core/config/"
    click PR "https://github.com/justfoolingaround/animdl/blob/master/animdl/core/package_resolver.py"
    click Utility "https://github.com/justfoolingaround/animdl/tree/master/animdl/utils/"

    %% Styles
    classDef cli fill:#AEDFF7,stroke:#036,stroke-width:2px;
    classDef business fill:#C8FACC,stroke:#0A3,stroke-width:2px;
    classDef util fill:#FFF4B3,stroke:#DAA,stroke-width:2px;
    classDef external fill:#F9E2E2,stroke:#B00,stroke-width:2px;
```
