# kidtomboy/remake-anisub architecture

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

- Interactive diagram: https://gitdiagram.com/kidtomboy/remake-anisub
- Repository: https://github.com/kidtomboy/remake-anisub

## Overview

##### Main Components
- User Interface: Represented by the command-line interface where users interact with the tool.
- CLI Controller/Orchestrator: The main script (anisub.sh) that parses user commands and directs application logic.
- Dependency Checker & Installer: A component that ensures necessary utilities (curl, jq, pup, fzf, mpv/VLC, yt-dlp, ffmpeg) are available and installs updates if needed.
- Anime Source Handler: Manages fetching anime data from the supported sources (e.g., OPhim, AniData) using HTTP calls through curl and processes JSON responses (with jq and pup).
- Media Player Integration: Interface that communicates with external media players like MPV or VLC to stream the video content.
- Download Manager & Video Processing: Module handling the downloading of episodes (using yt-dlp) and video manipulation tasks (using ffmpeg) such as cutting or joining video files.
- Configuration Manager: Reads and possibly writes settings (stored in ~/.config/anisub_cli/config.cfg) such as default media player, download directories, theme settings, etc.
- Update Module: Ability to self-update the script to newer versions.

##### Relationships and Data Flow
- From the CLI Controller, branch out:
- From the Anime Source Handler, data flows back to the CLI Controller and ultimately to the Media Player Integration for streaming.
- If downloading is chosen, data flows from the CLI Controller to the Download Manager/Videoprocessing module.
- The Update Module is triggered by specific user commands and interacts with the CLI Controller similarly.

##### Architectural Patterns and Design Principles
- Even though the implementation is a monolithic bash script, logically segment the workflow into modules to improve clarity.
- Modularity by separating concerns (e.g., network operations, media control, configuration management).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal CLI Tool Components
    subgraph "CLI Tool"
        UI["User Interface (CLI)"]:::ui
        Controller["CLI Controller/Orchestrator"]:::controller
        DepChecker["Dependency Checker & Installer"]:::depcheck
        AnimeSource["Anime Source Handler"]:::source
        ConfigManager["Configuration Manager"]:::config
        MediaPlayer["Media Player Integration"]:::player
        Downloader["Download Manager & Video Processing"]:::download
        Updater["Update Module"]:::update
    end

    %% External Utilities
    subgraph "External Utilities"
        CURL["curl"]:::utility
        JQ["jq"]:::utility
        PUP["pup"]:::utility
        FZF["fzf"]:::utility
        MPV["mpv/VLC"]:::utility
        YTDLP["yt-dlp"]:::utility
        FFMPEG["ffmpeg"]:::utility
    end

    %% Data and control flow between internal components
    UI -->|"command_input"| Controller
    Controller -->|"verify_dependencies"| DepChecker
    Controller -->|"fetch_anime_data"| AnimeSource
    AnimeSource -->|"return_data"| Controller
    Controller -->|"initiate_stream"| MediaPlayer
    Controller -->|"download_request"| Downloader
    Controller -->|"load_settings"| ConfigManager
    Controller -->|"check_updates"| Updater

    %% External utilities relationships
    DepChecker -->|"needs"| CURL
    DepChecker -->|"needs"| JQ
    DepChecker -->|"needs"| PUP
    DepChecker -->|"needs"| FZF

    AnimeSource -->|"uses"| CURL
    AnimeSource -->|"uses"| JQ
    AnimeSource -->|"uses"| PUP

    MediaPlayer -->|"invokes"| MPV

    Downloader -->|"calls"| YTDLP
    Downloader -->|"calls"| FFMPEG

    %% Click Events for internal components mapped to anisub.sh
    click UI "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"
    click Controller "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"
    click DepChecker "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"
    click AnimeSource "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"
    click MediaPlayer "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"
    click Downloader "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"
    click Updater "https://github.com/kidtomboy/remake-anisub/blob/main/anisub.sh"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef controller fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef depcheck fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef source fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef player fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef download fill:#E6E6FA,stroke:#000,stroke-width:1px;
    classDef update fill:#F0E68C,stroke:#000,stroke-width:1px;
    classDef utility fill:#F5DEB3,stroke:#000,stroke-width:1px;
```
