# pystardust/ani-cli architecture

> Architecture diagram of the GitHub repository pystardust/ani-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pystardust/ani-cli
- Repository: https://github.com/pystardust/ani-cli

## Overview

#### Purpose and Entry Point
ani-cli is a Bash-based terminal application for searching, selecting, streaming, and downloading anime scraped from HiAnime. The executable implementation is the repository-root script at `ani-cli`; its user-facing interface and options are documented in `README.md` and the Unix manual page `ani-cli.1`.

#### Runtime Model
The application runs in a Unix-compatible shell, including Git Bash on Windows and Termux on Android. It is intentionally a single-script architecture: orchestration, scraping, interactive selection, URL extraction, playback, download, and update behavior are concentrated in `ani-cli`. This makes shell command availability and platform behavior a primary operational boundary.

#### Discovery and Selection Pipeline
The core flow begins from CLI arguments or an interactive search, retrieves and parses HiAnime content, then presents titles and episodes through `fzf`. Text extraction and request handling rely on shell utilities such as `curl`, `grep`, and `sed`; Cloudflare-compatible access may require `curl-impersonate`. The single script `ani-cli` owns this scrape-to-selection control flow.

#### Playback Boundary
After an episode/provider stream is resolved, ani-cli delegates media handling to an external player rather than embedding playback. `mpv` is the main target; IINA is the macOS-compatible mpv replacement, and VLC is an optional alternative. Player invocation must carry stream metadata such as the required referrer, notably on Android. Optional intro/outro skipping is delegated through mpv’s Lua integration to external ani-skip tooling. Relevant user contract: `README.md`, `ani-cli`.

#### Download Boundary
For `-d` download operations, the script hands stream acquisition to `yt-dlp`, with `ffmpeg` as a fallback for m3u8 content. Download location is controlled externally through `ANI_CLI_DOWNLOAD_DIR`; episode-range selection supports bulk downloading. The downloader/player dependency boundary keeps media protocol handling outside the Bash implementation. Core path: `ani-cli`.

#### Distribution and Self-Maintenance
The root script is installed directly by source-based instructions and packaged by OS ecosystems. `Formula/ani-cli.rb` provides the Homebrew formula. Self-update behavior (`-U`) depends on Git/network retrieval and `patch`, so updates are an operational capability of the executable rather than a separate release client. `ani-cli.1` is the packaged/manual-facing CLI specification.

#### Automation and Governance
GitHub Actions provide repository maintenance automation rather than runtime functionality: `inverse-ani.yml` and `inverse-md.yml` likely validate synchronization or inversions between the script and docs, while `version.yml` governs version-related checks. Contribution and ownership controls reside in `.github/CODEOWNERS`, `CONTRIBUTING.md`, and workflow definitions under `.github/workflows/`.

Main entry points: [`ani-cli`](https://github.com/pystardust/ani-cli/blob/master/ani-cli) (ani-cli), [`README.md`](https://github.com/pystardust/ani-cli/blob/master/README.md) (README and manual), [`ani-cli.1`](https://github.com/pystardust/ani-cli/blob/master/ani-cli.1) (ani-cli.1), [`Formula/ani-cli.rb`](https://github.com/pystardust/ani-cli/blob/master/Formula/ani-cli.rb) (Homebrew formula)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime pipeline"]
  node_cli["ani-cli<br/>Bash executable"]
  node_input["CLI arguments / search<br/>user input"]
  node_discovery["HiAnime discovery<br/>scrape pipeline"]
  node_selection["Interactive selection<br/>selection stage"]
  node_stream["Provider stream resolution<br/>URL extraction"]
  node_playback["Playback delegation<br/>media handoff"]
  node_download["Download delegation<br/>media handoff"]
end

subgraph group_external["External services &amp; tools"]
  node_hianime[("HiAnime<br/>content source")]
  node_shelltools["curl, grep, sed<br/>shell tools"]
  node_impersonate["curl-impersonate<br/>optional HTTP client"]
  node_fzf["fzf<br/>interactive selector"]
  node_player["mpv / IINA / VLC<br/>media player"]
  node_aniskip["ani-skip tooling<br/>mpv Lua integration"]
  node_downloader["yt-dlp / ffmpeg<br/>download tools"]
end

subgraph group_distribution["Distribution &amp; maintenance"]
  node_docs["README and manual<br/>CLI contract<br/>[README.md]"]
  node_manpage["ani-cli.1<br/>Unix manual page<br/>[ani-cli.1]"]
  node_homebrew["Homebrew formula<br/>package definition<br/>[ani-cli.rb]"]
  node_selfupdate["Self-update &#40;-U&#41;<br/>maintenance flow"]
  node_governance["GitHub governance<br/>contribution controls<br/>[CONTRIBUTING.md]"]
  node_workflows["GitHub Actions<br/>repository automation"]
end

node_input -->|"invokes"| node_cli
node_cli -->|"searches"| node_discovery
node_discovery -->|"requests content"| node_hianime
node_discovery -->|"uses"| node_shelltools
node_discovery -.->|"optionally uses"| node_impersonate
node_discovery -->|"produces choices"| node_selection
node_selection -->|"presents via"| node_fzf
node_selection -->|"selects episode"| node_stream
node_stream -->|"stream mode"| node_playback
node_stream -->|"-d mode"| node_download
node_playback -->|"launches"| node_player
node_player -.->|"optional Lua integration"| node_aniskip
node_download -->|"acquires media"| node_downloader
node_docs -->|"documents"| node_cli
node_manpage -->|"specifies"| node_cli
node_homebrew -->|"packages"| node_cli
node_cli -->|"-U triggers"| node_selfupdate
node_governance -.->|"maintained by"| node_workflows
node_workflows -.->|"validates synchronization"| node_docs
node_workflows -.->|"checks versions and inversions"| node_cli

click node_cli "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_discovery "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_selection "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_stream "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_playback "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_download "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_docs "https://github.com/pystardust/ani-cli/blob/master/README.md"
click node_manpage "https://github.com/pystardust/ani-cli/blob/master/ani-cli.1"
click node_homebrew "https://github.com/pystardust/ani-cli/blob/master/Formula/ani-cli.rb"
click node_selfupdate "https://github.com/pystardust/ani-cli/blob/master/ani-cli"
click node_governance "https://github.com/pystardust/ani-cli/blob/master/CONTRIBUTING.md"

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_input,node_discovery,node_selection,node_stream,node_playback,node_download toneBlue
class node_hianime,node_shelltools,node_impersonate,node_fzf,node_player,node_aniskip,node_downloader toneAmber
class node_docs,node_manpage,node_homebrew,node_selfupdate,node_governance,node_workflows toneMint
```

## Components

### Runtime pipeline

Single Bash script owns discovery through media delegation.

- [ani-cli](https://github.com/pystardust/ani-cli/blob/master/ani-cli): Bash executable · Single-script CLI orchestrator. · `ani-cli`
- **CLI arguments / search**: user input
- [HiAnime discovery](https://github.com/pystardust/ani-cli/blob/master/ani-cli): scrape pipeline · Searches and parses titles and episode data. · `ani-cli`
- [Interactive selection](https://github.com/pystardust/ani-cli/blob/master/ani-cli): selection stage · Chooses titles and episodes. · `ani-cli`
- [Provider stream resolution](https://github.com/pystardust/ani-cli/blob/master/ani-cli): URL extraction · Resolves episode streams and referrer metadata. · `ani-cli`
- [Playback delegation](https://github.com/pystardust/ani-cli/blob/master/ani-cli): media handoff · Invokes an external player with stream metadata. · `ani-cli`
- [Download delegation](https://github.com/pystardust/ani-cli/blob/master/ani-cli): media handoff · Handles -d and episode-range downloads. · `ani-cli`

### External services & tools

Network, shell utilities, and media clients are operational dependencies.

- **HiAnime**: content source
- **curl, grep, sed**: shell tools
- **curl-impersonate**: optional HTTP client · May be needed for Cloudflare-compatible access.
- **fzf**: interactive selector
- **mpv / IINA / VLC**: media player · mpv is primary; IINA and VLC are alternatives.
- **ani-skip tooling**: mpv Lua integration · Optional intro and outro skipping.
- **yt-dlp / ffmpeg**: download tools · ffmpeg is an m3u8 fallback.

### Distribution & maintenance

Installation, update, documentation, and repository automation.

- [README and manual](https://github.com/pystardust/ani-cli/blob/master/README.md): CLI contract · User-facing options and usage documentation. · `README.md`
- [ani-cli.1](https://github.com/pystardust/ani-cli/blob/master/ani-cli.1): Unix manual page · `ani-cli.1`
- [Homebrew formula](https://github.com/pystardust/ani-cli/blob/master/Formula/ani-cli.rb): package definition · `Formula/ani-cli.rb`
- [Self-update (-U)](https://github.com/pystardust/ani-cli/blob/master/ani-cli): maintenance flow · Uses Git, network retrieval, and patch. · `ani-cli`
- [GitHub governance](https://github.com/pystardust/ani-cli/blob/master/CONTRIBUTING.md): contribution controls · `CONTRIBUTING.md`
- **GitHub Actions**: repository automation · Documentation synchronization and version checks.

## Connections

- CLI arguments / search → ani-cli: invokes
- ani-cli → HiAnime discovery: searches
- HiAnime discovery → HiAnime: requests content
- HiAnime discovery → curl, grep, sed: uses
- HiAnime discovery → curl-impersonate: optionally uses
- HiAnime discovery → Interactive selection: produces choices
- Interactive selection → fzf: presents via
- Interactive selection → Provider stream resolution: selects episode
- Provider stream resolution → Playback delegation: stream mode
- Provider stream resolution → Download delegation: -d mode
- Playback delegation → mpv / IINA / VLC: launches
- mpv / IINA / VLC → ani-skip tooling: optional Lua integration
- Download delegation → yt-dlp / ffmpeg: acquires media
- README and manual → ani-cli: documents
- ani-cli.1 → ani-cli: specifies
- Homebrew formula → ani-cli: packages
- ani-cli → Self-update (-U): -U triggers
- GitHub governance → GitHub Actions: maintained by
- GitHub Actions → README and manual: validates synchronization
- GitHub Actions → ani-cli: checks versions and inversions
