# ludviglundgren/qbittorrent-cli architecture

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

- Interactive diagram: https://gitdiagram.com/ludviglundgren/qbittorrent-cli
- Repository: https://github.com/ludviglundgren/qbittorrent-cli

## Overview

1. **What this repo is**
   - `qbittorrent-cli` is a Go-based command-line tool, not a server or web app.
   - Its job is to automate qBittorrent administration through the qBittorrent WebUI API and by editing qBittorrent’s local state files.

2. **Top-level execution model**
   - The binary entrypoint is `cmd/qbt/main.go`.
   - Commands are organized with a Cobra-style CLI under `cmd/`, with subcommands for app info, categories, tags, torrent lifecycle actions, bencode editing, import/export, compare, and self-update.

3. **Configuration boundary**
   - Global config is loaded from `~/.config/qbt/.qbt.toml` by default, with `--config` override.
   - `internal/config` and `internal/domain/config.go` define config parsing and app-level settings.
   - Config is not just connection details; it also drives behavior rules such as limits on active downloads and automation defaults.

4. **Primary external system: qBittorrent WebUI API**
   - The main integration is in `pkg/qbittorrent/`.
   - `client.go`, `methods.go`, and `domain.go` form the API client and data model layer for qBittorrent requests/responses.
   - Most torrent/category/tag commands ultimately translate into WebUI API calls against one qBittorrent instance, and `torrent compare` uses two client connections.

5. **Core domain layer**
   - `pkg/torrent/torrent.go` is the repo’s generic torrent domain layer.
   - It likely normalizes torrent identity and metadata such as hash, name, category, tags, trackers, and state so higher-level commands can work across API results and local files.
   - This is the main abstraction between command logic and qBittorrent-specific wire formats.

6. **Filesystem and bencode operations**
   - `internal/fs/` contains local file utilities for copying and directory handling.
   - `cmd/bencode.go` and `pkg/qbittorrent/fastresume.go` show that the tool directly manipulates bencoded qBittorrent state, especially `.fastresume` files in `BT_backup`.
   - This is an important second boundary: some commands operate entirely on disk without calling the remote API.

7. **Import pipeline from other clients**
   - `internal/importer/deluge.go` and `internal/importer/rtorrent.go` convert Deluge and rTorrent state into qBittorrent-compatible state.
   - The import flow reads source client session/state files, maps torrent data into qBittorrent’s `BT_backup` format, and writes fastresume/torrent files into the target qBittorrent backup directory.
   - The README’s warnings reflect that this is a state migration workflow, not a full data move.

8. **Export/archive pipeline**
   - `pkg/archive/archive.go` supports exporting torrents and fastresume data out of qBittorrent storage.
   - The `torrent export` command filters by category/tag and writes a portable export set, optionally with a manifest of used tags/categories.
   - This forms the inverse of import: qBittorrent state on disk is packaged for backup or migration.

9. **Command families and data flow**
   - `category` and `tag` commands manage qBittorrent metadata objects.
   - `torrent add`, `pause`, `resume`, `remove`, `recheck`, `reannounce`, `tracker edit`, and `category set/move/unset` all act on torrents identified by hashes, names, categories, or tags.
   - `torrent list`, `compare`, and `hash` are read-heavy commands that inspect torrent state either from the API or from `.torrent`/magnet inputs.

10. **Automation-oriented flows**
   - `torrent add` can apply category, tags, path, speed limits, pause state, and skip-hash options, which makes it suitable for integration with autodl-irssi/rutorrent.
   - `torrent category move` supports seed-time and tag filters, enabling automated tiering such as moving torrents from fast storage to slower storage.
   - `torrent tag issues` and `torrent reannounce` are operational maintenance workflows for tracker health.

11. **Self-update and release distribution**
   - `cmd/update.go` suggests the CLI can update itself, and `.github/workflows/release.yml` plus `.goreleaser.yml` indicate GitHub Releases are the distribution channel.
   - That means the repo has a build/release pipeline separate from runtime behavior, but it directly affects how binaries are installed and updated.

12. **Testing and fixtures**
   - Tests under `cmd/` and `internal/importer/` use fixture data in `test/`.
   - The fixtures include real-looking qBittorrent `BT_backup`, Deluge state files, and torrent samples, which indicates the important edge cases are file-format and migration correctness rather than UI behavior.

Main entry points: [`cmd/torrent.go`](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent.go) (Torrent), [`cmd/qbt/main.go`](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/qbt/main.go) (Main), [`pkg/qbittorrent/client.go`](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/client.go) (Client), [`cmd/torrent_compare.go`](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_compare.go) (Compare)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_cli["CLI"]
  node_node_main["Main<br/>entrypoint<br/>[main.go]"]
  node_node_app["App info<br/>command<br/>[app.go]"]
  node_node_category["Category<br/>command family<br/>[category.go]"]
  node_node_tag["Tag<br/>command family<br/>[tag.go]"]
  node_node_torrent_root["Torrent<br/>command family<br/>[torrent.go]"]
  node_node_torrent_add["Add<br/>torrent command<br/>[torrent_add.go]"]
  node_node_torrent_category["Move set<br/>torrent command"]
  node_node_torrent_compare["Compare<br/>torrent command<br/>[torrent_compare.go]"]
  node_node_torrent_export["Export<br/>torrent command<br/>[torrent_export.go]"]
  node_node_torrent_import["Import<br/>torrent command<br/>[torrent_import.go]"]
  node_node_torrent_ops["Ops<br/>torrent commands"]
end

subgraph group_group_core["Core"]
  node_node_config["Config<br/>settings<br/>[config.go]"]
  node_node_domain_config["Rules<br/>domain config<br/>[config.go]"]
  node_node_fs["FS utils<br/>filesystem"]
  node_node_torrent_domain["Torrent model<br/>domain<br/>[torrent.go]"]
end

subgraph group_group_qbt["qBittorrent"]
  node_node_client["Client<br/>[client.go]"]
  node_node_qbt_domain["QBT model<br/>api model<br/>[domain.go]"]
end

subgraph group_group_io["Disk flows"]
  node_node_fastresume["Fastresume<br/>bencode<br/>[fastresume.go]"]
  node_node_archive["Archive<br/>export pipeline<br/>[archive.go]"]
  node_node_import_deluge["Deluge import<br/>importer<br/>[deluge.go]"]
  node_node_import_rtorrent["rTorrent import<br/>importer<br/>[rtorrent.go]"]
end

subgraph group_group_delivery["Delivery"]
  node_node_update["Update<br/>[update.go]"]
end

node_node_main -->|"wires"| node_node_app
node_node_main -->|"wires"| node_node_category
node_node_main -->|"wires"| node_node_tag
node_node_main -->|"wires"| node_node_torrent_root
node_node_main -->|"wires"| node_node_update
node_node_torrent_root -->|"contains"| node_node_torrent_add
node_node_torrent_root -->|"contains"| node_node_torrent_category
node_node_torrent_root -->|"contains"| node_node_torrent_compare
node_node_torrent_root -->|"contains"| node_node_torrent_export
node_node_torrent_root -->|"contains"| node_node_torrent_import
node_node_torrent_root -->|"contains"| node_node_torrent_ops
node_node_app -->|"loads"| node_node_config
node_node_category -->|"uses"| node_node_client
node_node_tag -->|"uses"| node_node_client
node_node_torrent_ops -->|"uses"| node_node_client
node_node_torrent_compare -->|"uses"| node_node_client
node_node_torrent_add -->|"normalizes"| node_node_torrent_domain
node_node_torrent_compare -->|"reads"| node_node_torrent_domain
node_node_torrent_export -->|"packages"| node_node_archive
node_node_torrent_import -->|"uses"| node_node_import_deluge
node_node_torrent_import -->|"uses"| node_node_import_rtorrent
node_node_import_deluge -->|"writes"| node_node_fastresume
node_node_import_rtorrent -->|"writes"| node_node_fastresume
node_node_import_deluge -->|"reads/writes"| node_node_fs
node_node_import_rtorrent -->|"reads/writes"| node_node_fs
node_node_archive -->|"packages"| node_node_fs
node_node_fastresume -->|"encodes"| node_node_qbt_domain
node_node_client -->|"serializes"| node_node_qbt_domain
node_node_torrent_domain -->|"bridges"| node_node_qbt_domain
node_node_config -->|"defines"| node_node_domain_config

click node_node_main "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/qbt/main.go"
click node_node_app "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/app.go"
click node_node_category "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/category.go"
click node_node_tag "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/tag.go"
click node_node_torrent_root "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent.go"
click node_node_torrent_add "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_add.go"
click node_node_torrent_category "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_category.go"
click node_node_torrent_compare "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_compare.go"
click node_node_torrent_export "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_export.go"
click node_node_torrent_import "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_import.go"
click node_node_config "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/config/config.go"
click node_node_domain_config "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/domain/config.go"
click node_node_fs "https://github.com/ludviglundgren/qbittorrent-cli/tree/master/internal/fs"
click node_node_client "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/client.go"
click node_node_qbt_domain "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/domain.go"
click node_node_fastresume "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/fastresume.go"
click node_node_torrent_domain "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/torrent/torrent.go"
click node_node_archive "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/archive/archive.go"
click node_node_import_deluge "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/importer/deluge.go"
click node_node_import_rtorrent "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/importer/rtorrent.go"
click node_node_update "https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/update.go"

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_node_main,node_node_app,node_node_category,node_node_tag,node_node_torrent_root,node_node_torrent_add,node_node_torrent_category,node_node_torrent_compare,node_node_torrent_export,node_node_torrent_import,node_node_torrent_ops toneBlue
class node_node_config,node_node_domain_config,node_node_fs,node_node_torrent_domain toneAmber
class node_node_client,node_node_qbt_domain toneMint
class node_node_fastresume,node_node_archive,node_node_import_deluge,node_node_import_rtorrent toneRose
class node_node_update toneIndigo
```

## Components

### CLI

Cobra command entrypoints and command families

- [Main](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/qbt/main.go): entrypoint · Binary entrypoint and root command setup · `cmd/qbt/main.go`
- [App info](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/app.go): command · Global app and status command · `cmd/app.go`
- [Category](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/category.go): command family · Category management commands · `cmd/category.go`
- [Tag](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/tag.go): command family · Tag management commands · `cmd/tag.go`
- [Torrent](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent.go): command family · Torrent lifecycle and inspection commands · `cmd/torrent.go`
- [Add](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_add.go): torrent command · Add torrents with automation options · `cmd/torrent_add.go`
- [Move set](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_category.go): torrent command · Set, move, and unset torrent categories · `cmd/torrent_category.go`
- [Compare](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_compare.go): torrent command · Compare torrent state across clients or inputs · `cmd/torrent_compare.go`
- [Export](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_export.go): torrent command · Export qBittorrent torrents and backup state · `cmd/torrent_export.go`
- [Import](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/torrent_import.go): torrent command · Import state from other clients into qBittorrent format · `cmd/torrent_import.go`
- **Ops**: torrent commands · Pause, resume, remove, recheck, reannounce, list, hash, tracker, and tag issue workflows

### Core

Shared configuration, domain, and filesystem support

- [Config](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/config/config.go): settings · Config loading and app settings · `internal/config/config.go`
- [Rules](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/domain/config.go): domain config · Application-level configuration domain · `internal/domain/config.go`
- [FS utils](https://github.com/ludviglundgren/qbittorrent-cli/tree/master/internal/fs): filesystem · Local file and directory helpers · `internal/fs`
- [Torrent model](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/torrent/torrent.go): domain · Repository-wide torrent abstraction and normalization · `pkg/torrent/torrent.go`

### qBittorrent

Remote API client and qBittorrent-specific models

- [Client](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/client.go): api client · qBittorrent WebUI API client and request wiring · `pkg/qbittorrent/client.go`
- [QBT model](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/domain.go): api model · qBittorrent request and response domain types · `pkg/qbittorrent/domain.go`

### Disk flows

Local bencode, archive, and migration workflows

- [Fastresume](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/qbittorrent/fastresume.go): bencode · qBittorrent fastresume parsing and writing · `pkg/qbittorrent/fastresume.go`
- [Archive](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/pkg/archive/archive.go): export pipeline · Portable torrent and backup export packaging · `pkg/archive/archive.go`
- [Deluge import](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/importer/deluge.go): importer · Deluge state conversion into qBittorrent backup format · `internal/importer/deluge.go`
- [rTorrent import](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/internal/importer/rtorrent.go): importer · rTorrent state conversion into qBittorrent backup format · `internal/importer/rtorrent.go`

### Delivery

Build, release, and self-update mechanics

- [Update](https://github.com/ludviglundgren/qbittorrent-cli/blob/master/cmd/update.go): self-update · Self-update and release channel command · `cmd/update.go`

## Connections

- Main → App info: wires · Root command includes global app info command
- Main → Category: wires · Root command includes category commands
- Main → Tag: wires · Root command includes tag commands
- Main → Torrent: wires · Root command includes torrent command family
- Main → Update: wires · Root command includes self-update command
- Torrent → Add: contains · Torrent family includes add workflow
- Torrent → Move set: contains · Torrent family includes category mutation workflow
- Torrent → Compare: contains · Torrent family includes comparison workflow
- Torrent → Export: contains · Torrent family includes export workflow
- Torrent → Import: contains · Torrent family includes import workflow
- Torrent → Ops: contains · Torrent family includes operational actions and inspection
- App info → Config: loads · Commands read global configuration
- Category → Client: uses · Category commands call qBittorrent API
- Tag → Client: uses · Tag commands call qBittorrent API
- Ops → Client: uses · Torrent operations are primarily API-driven
- Compare → Client: uses · Comparison can connect to one or two qBittorrent instances
- Add → Torrent model: normalizes · Add command maps inputs into shared torrent domain
- Compare → Torrent model: reads · Compare works across torrent identity and metadata
- Export → Archive: packages · Export command writes portable archive sets
- Import → Deluge import: uses · Import flow supports Deluge source state
- Import → rTorrent import: uses · Import flow supports rTorrent source state
- Deluge import → Fastresume: writes · Deluge migration emits qBittorrent fastresume data
- rTorrent import → Fastresume: writes · rTorrent migration emits qBittorrent fastresume data
- Deluge import → FS utils: reads/writes · Import pipeline handles local state files and directories
- rTorrent import → FS utils: reads/writes · Import pipeline handles local state files and directories
- Archive → FS utils: packages · Archive flow reads and writes local backup files
- Fastresume → QBT model: encodes · Fastresume handling is qBittorrent-specific
- Client → QBT model: serializes · API client marshals qBittorrent wire models
- Torrent model → QBT model: bridges · Shared torrent abstraction normalizes qBittorrent results
- Config → Rules: defines · Config parsing feeds application config rules
