# farishijazi/rarbgcli architecture

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

- Interactive diagram: https://gitdiagram.com/farishijazi/rarbgcli
- Repository: https://github.com/farishijazi/rarbgcli

## Overview

##### Project type and purpose
- This is a Python-based command-line interface (CLI) tool named `rarbgcli`.
- Its purpose is to scrape the RARBG torrent search engine (and its mirrors), solve CAPTCHAs if needed, and output torrent metadata as JSON or magnet links.

##### File structure
Top-level files and directories:
- `rarbgcli/` – core Python package
- `rarbgcli.py` – entry point and CLI argument parser
- `download_tesseract.py` – helper for downloading/installing Tesseract OCR
- `get_chrome_driver.py` – helper for installing or launching Chrome WebDriver
- `assets/` – usage and CAPTCHA-solving animations
- `test/` – unit tests for the CLI (`test_rarbgcli.py`)
- `requirements.txt`, `setup.py` – dependency and packaging metadata
- `build.sh`, `gittag-increment.sh` – build/release scripts
- `.pre-commit-config.yaml` – code-style checks
- `.gitignore`

##### README for additional insights
- Confirms the workflow: user runs `rarbgcli`, passes search term and flags, tool scrapes, solves CAPTCHA (via Selenium + Tesseract), then outputs JSON or magnet links (pipe-friendly).
- Mentions optional interactive mode.
- Highlights external dependencies: Selenium Chrome Driver and Tesseract OCR.

##### Main components to portray
a. CLI Interface
– Argument parsing (rarbgcli.py)
– Interactive menu logic (when `--interactive` is used)
b. Core Scraper Engine
– HTTP client module
– HTML parser (e.g., BeautifulSoup under the hood)
– Result formatter (JSON & magnet link extraction)
c. CAPTCHA Handler
– Selenium ChromeDriver (via get_chrome_driver.py)
– OCR component (Tesseract via download_tesseract.py)
– Cookie storage and management
d. External Services
– RARBG mirror domains (e.g., rargb.to)
– Selenium browser instance
– Tesseract OCR binary
e. Output/Integration
– Standard output (JSON stream)
– Piping to external programs (e.g., `jq`, torrent client)
– Browser invocation for `.torrent` downloads
f. Packaging & CI/CD
– `setup.py` / PyPI distribution
– `build.sh` / `gittag-increment.sh` release workflow
– Unit tests in `test/`

##### Relationships and interactions
- User invokes CLI → CLI Interface
- CLI Interface → Core Scraper Engine (passes flags & search term)
- Core Scraper Engine → External Service (HTTP GET to mirror)
- If CAPTCHA encountered → route to CAPTCHA Handler
→ Selenium ChromeDriver → Tesseract OCR → cookie retrieval → back to HTTP client
- Scraper Engine → parse HTML → build JSON objects or magnet links
- CLI Interface → writes JSON/magnets to stdout or pipes to browser/external client
- Packaging & CI/CD operate externally on the codebase for release management; tests validate the Scraper Engine and CLI logic.

##### Architectural patterns & design principles
- Separation of concerns:
- CLI parsing vs. scraping logic vs. CAPTCHA resolution
- Modular helpers for external dependencies (isolated install/get routines)
- Pipe-friendly design: single responsibility and standard I/O streams
- Test coverage: isolated unit tests for key behaviors

##### Detail but stay focused
- Every logical component and its interactions.
- Every drop-down of functionality (interactive, download, magnet) is clearly indicated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Core Modules
    subgraph "Internal Modules"
        direction TB
        CLI["CLI Interface\n(argument parsing & interactive mode)"]:::core
        Scraper["Core Scraper Engine\n(HTTP client, HTML parsing, result formatter)"]:::core
        subgraph "CAPTCHA Handler"
            direction TB
            DriverHelper["Selenium ChromeDriver Helper"]:::core
            OCRHelper["Tesseract OCR Installer/Downloader"]:::core
        end
    end

    %% External Dependencies
    subgraph "External Services & Binaries"
        direction TB
        RARBG["RARBG Mirror\n(e.g., rargb.to)"]:::ext
        SeleniumBrowser["Selenium Browser Instance"]:::ext
        TesseractBin["Tesseract OCR Binary"]:::ext
    end

    %% Output & I/O
    subgraph "Output & Integration"
        direction TB
        StdOut["Standard Output\n(JSON / magnet link stream)"]:::io
        PipeClient["Piped External Client\n(e.g., jq, torrent client)"]:::io
        BrowserInvoke["Browser Invocation\n(.torrent download)"]:::io
    end

    %% CI/CD & Packaging
    subgraph "CI/CD & Packaging"
        direction TB
        Requirements["requirements.txt"]:::ci
        Setup["setup.py"]:::ci
        BuildScripts["build.sh\ngittag-increment.sh"]:::ci
        Tests["Unit Tests\ntest/test_rarbgcli.py"]:::ci
        PreCommit[".pre-commit-config.yaml"]:::ci
        Gitignore[".gitignore"]:::ci
    end

    %% Flow Connections
    User -->|runs with search term & flags| CLI
    CLI -->|invokes| Scraper
    Scraper -->|HTTP GET request| RARBG
    RARBG -->|HTTP response| Scraper
    Scraper -->|parse HTML| Scraper
    Scraper -->|build JSON / magnet| Scraper
    Scraper -->|outputs data| StdOut
    StdOut -->|pipe| PipeClient
    CLI -->|--browser flag| BrowserInvoke

    Scraper -->|CAPTCHA encountered| DriverHelper
    DriverHelper -->|launch| SeleniumBrowser
    SeleniumBrowser -->|screenshot| OCRHelper
    OCRHelper -->|decode text| DriverHelper
    DriverHelper -->|cookies| Scraper

    %% CI/CD & Packaging Relationships
    Setup -->|installs dependencies| Requirements
    BuildScripts -->|release workflow| Setup
    Tests -->|validate| Scraper
    Tests -->|validate| CLI
    PreCommit -->|code style checks| CLI
    PreCommit -->|code style checks| Scraper
    Gitignore -->|VCS ignore rules| CI/CD

    %% Click Events
    click CLI "https://github.com/farishijazi/rarbgcli/blob/master/rarbgcli/rarbgcli.py"
    click Scraper "https://github.com/farishijazi/rarbgcli/blob/master/rarbgcli/rarbgcli.py"
    click DriverHelper "https://github.com/farishijazi/rarbgcli/blob/master/rarbgcli/get_chrome_driver.py"
    click OCRHelper "https://github.com/farishijazi/rarbgcli/blob/master/rarbgcli/download_tesseract.py"
    click Requirements "https://github.com/farishijazi/rarbgcli/blob/master/requirements.txt"
    click Setup "https://github.com/farishijazi/rarbgcli/blob/master/setup.py"
    click BuildScripts "https://github.com/farishijazi/rarbgcli/blob/master/build.sh"
    click Tests "https://github.com/farishijazi/rarbgcli/blob/master/test/test_rarbgcli.py"
    click PreCommit "https://github.com/farishijazi/rarbgcli/blob/master/.pre-commit-config.yaml"
    click Gitignore "https://github.com/farishijazi/rarbgcli/blob/master/.gitignore"

    %% Styles
    classDef core fill:#DAE8FC,stroke:#6C8EBF,color:#000000
    classDef ext fill:#FFE6CC,stroke:#D79B00,color:#000000
    classDef io fill:#E2F0D9,stroke:#82B366,color:#000000
    classDef ci fill:#F8CECC,stroke:#B85450,color:#000000
```
