# prsh11/manga-cli architecture

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

- Interactive diagram: https://gitdiagram.com/prsh11/manga-cli
- Repository: https://github.com/prsh11/manga-cli

## Overview

##### Project type and purpose
- From the file tree and README, this is a single-file, command-line interface (CLI) tool named “manga-cli.”
- Purpose: fetch manga chapters from the web, package them (CBZ/PDF), and open them in a viewer (zathura).

##### File structure
- Top-level items:
- .gitignore, LICENSE, README.md – meta files
- manga-cli – the executable script (likely Bash)
- No frontend/backend split; it’s a standalone CLI wrapper orchestrating external utilities.
- No config directory or library code – it delegates parsing, downloading, conversion, and viewing to dependencies.

##### README for additional insights
- Dependencies: curl (HTTP client), pup (HTML parser), zathura (+ plugins for CBZ/PDF), imagemagick (image conversion)
- Installation instructions emphasize copying the manga-cli script into /usr/local/bin
- Workflow hints: fetch page → parse links → download images → convert/zip → open viewer

a. Main components
- User/Terminal
- manga-cli script (orchestrator)
- HTTP client (curl)
- HTML parser (pup)
- Image processing (imagemagick for PDF)
- Archive format support (zathura-cb for CBZ, zathura-pdf-mupdf)
- PDF/CBZ viewer (zathura)
- Local filesystem for temporary files (images, archives)
b. Relationships & interactions
1. User invokes manga-cli in a terminal.
2. manga-cli calls curl to download the manga chapter page.
3. Output HTML flows into pup, which extracts image URLs.
4. manga-cli loops over URLs, uses curl to fetch each image to disk.
5. Depending on user flags, manga-cli either:
- packages images into a .cbz (zip) and calls zathura-cb, or
- uses imagemagick to convert images into a .pdf and calls zathura-pdf-mupdf.
6. zathura opens the archive for reading.
c. Architectural patterns & principles
- “Pipe and filter”: the script chains simple command-line tools, each responsible for one task.
- Separation of concerns: parsing, downloading, packaging, and viewing are delegated.
- Stateless orchestration: manga-cli doesn’t maintain state beyond temporary files.
d. Relevant technologies/frameworks
- Bash (scripting language)
- curl (network I/O)
- pup (CSS-selector parsing)
- imagemagick (image→PDF)
- zip (CBZ creation)
- zathura + plugins (display)

##### Detail without over-splitting
- Even though there’s a single script, break it into logical sub-components (fetch, parse, download, package, view).
- Ephemeral filesystem storage as an explicit node.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Project Metadata
    subgraph "Project Files"
        direction TB
        README["README.md"]:::meta
        LICENSE["LICENSE"]:::meta
        GITIGNORE[".gitignore"]:::meta
    end

    %% User Interaction
    Terminal["User Terminal"]:::terminal
    Terminal -->|"invoke"| CLI

    %% Orchestration Script
    subgraph "manga-cli (Bash script)"
        direction TB
        Fetch["Fetch Page"]:::script
        Parse["Parse Links"]:::script
        DownloadStep["Download Images"]:::script
        PackageStep["Package Images"]:::script
        ViewStep["Open Viewer"]:::script
    end

    CLI["manga-cli\n(orchestrator)"]:::script
    CLI --> Fetch
    Fetch --> Parse
    Parse --> DownloadStep
    DownloadStep --> PackageStep
    PackageStep --> ViewStep

    %% External Tools & File System
    Curl1["curl (HTTP Client)"]:::network
    Curl2["curl (HTTP Client)"]:::network
    PUP["pup (HTML Parser)"]:::parse
    Scratch["Local File System\n(temp files)"]:::disk
    ZIP["zip (CBZ Packaging)"]:::packaging
    IMAGEMAGICK["ImageMagick\n(PDF Conversion)"]:::packaging
    ZATHURA["zathura Viewer"]:::viewer

    Fetch -->|"download page"| Curl1
    Curl1 --> Parse
    Parse -->|"extract URLs"| PUP
    PUP --> DownloadStep
    DownloadStep -->|"fetch images"| Curl2
    Curl2 --> Scratch
    Scratch --> PackageStep
    PackageStep --> ZIP
    PackageStep --> IMAGEMAGICK
    ZIP --> ViewStep
    IMAGEMAGICK --> ViewStep
    ViewStep --> ZATHURA

    %% Click Events
    click README "https://github.com/prsh11/manga-cli/blob/master/README.md"
    click LICENSE "https://github.com/prsh11/manga-cli/tree/master/LICENSE"
    click GITIGNORE "https://github.com/prsh11/manga-cli/blob/master/.gitignore"
    click CLI "https://github.com/prsh11/manga-cli/tree/master/manga-cli"

    %% Styles
    classDef terminal fill:#ffe4b5,stroke:#cc8400,color:#000
    classDef script fill:#e0ffff,stroke:#5abdb5,color:#000
    classDef network fill:#f0f8ff,stroke:#5f9ea0,color:#000
    classDef parse fill:#fff0f5,stroke:#db7093,color:#000
    classDef packaging fill:#f5f5dc,stroke:#a0522d,color:#000
    classDef viewer fill:#e6e6fa,stroke:#9370db,color:#000
    classDef disk fill:#fafad2,stroke:#bdb76b,color:#000
    classDef meta fill:#f5f5f5,stroke:#d3d3d3,color:#000,stroke-dasharray: 5 5
```
