# webtorrent/webtorrent-cli architecture

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

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

## Overview

WebTorrent CLI turns command-line torrent identifiers or input files into torrent operations: create, inspect, download, seed, or fetch metadata. The main download workflow uses WebTorrent, serves selected torrent files over HTTP for streaming, and can hand playback URLs to external players. The README documents peer discovery and streaming capabilities, but the excerpts do not expose their internal implementation, so those are represented as WebTorrent capabilities rather than speculative internal modules. Several command stages share bin/cmd.js; source excerpts are partial.

Main entry points: [`bin/cmd.js`](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js) (Command interface), [`version.cjs`](https://github.com/webtorrent/webtorrent-cli/blob/master/version.cjs) (Version output)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["CLI Interface"]
  node_cli["Command interface<br/>[cmd.js]"]
  node_version["Version output<br/>[version.cjs]"]
end

subgraph group_torrent_ops["Torrent Operations"]
  node_input_parse["Torrent input parsing<br/>[cmd.js]"]
  node_create["Torrent creation<br/>[cmd.js]"]
  node_inspect["Torrent info<br/>[cmd.js]"]
  node_metadata["Metadata download<br/>[cmd.js]"]
  node_download["Torrent download<br/>[cmd.js]"]
  node_seed["Torrent seeding<br/>[cmd.js]"]
end

subgraph group_streaming["Streaming and Playback"]
  node_file_select["File selection<br/>[cmd.js]"]
  node_http_server["HTTP file server<br/>[cmd.js]"]
  node_subtitle_server["Subtitle server<br/>[cmd.js]"]
  node_player_launch["Player launch<br/>[cmd.js]"]
end

subgraph group_network["Torrent Networking"]
  node_torrent_engine["WebTorrent client<br/>[cmd.js]"]
end

node_user(("CLI user"))
node_peer_network(("Torrent peers"))
node_players(("External players"))

node_user -->|"invokes"| node_cli
node_cli -->|"reads version"| node_version
node_cli -->|"parses input"| node_input_parse
node_cli -->|"routes create"| node_create
node_cli -->|"routes info"| node_inspect
node_cli -->|"routes metadata"| node_metadata
node_cli -->|"routes download"| node_download
node_cli -->|"routes seed"| node_seed
node_create -->|"creates torrent"| node_torrent_engine
node_download -->|"adds torrent"| node_torrent_engine
node_torrent_engine -.->|"discovers peers"| node_peer_network
node_download -->|"selects files"| node_file_select
node_torrent_engine -->|"creates server"| node_http_server
node_http_server -->|"provides stream URL"| node_player_launch
node_player_launch -->|"opens stream"| node_players
node_subtitle_server -->|"provides subtitles"| node_player_launch

click node_cli "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_version "https://github.com/webtorrent/webtorrent-cli/blob/master/version.cjs"
click node_input_parse "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_create "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_inspect "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_metadata "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_download "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_seed "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_torrent_engine "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_file_select "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_http_server "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_subtitle_server "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"
click node_player_launch "https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js"

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_version,node_user toneBlue
class node_input_parse,node_create,node_inspect,node_metadata,node_download,node_seed toneAmber
class node_file_select,node_http_server,node_subtitle_server,node_player_launch toneMint
class node_torrent_engine toneRose
class node_peer_network,node_players toneIndigo
```

## Components

### CLI Interface

- [Command interface](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Version output](https://github.com/webtorrent/webtorrent-cli/blob/master/version.cjs): `version.cjs`

### Torrent Operations

- [Torrent input parsing](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Torrent creation](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Torrent info](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Metadata download](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Torrent download](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Torrent seeding](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`

### Streaming and Playback

- [File selection](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [HTTP file server](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Subtitle server](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`
- [Player launch](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`

### Torrent Networking

- [WebTorrent client](https://github.com/webtorrent/webtorrent-cli/blob/master/bin/cmd.js): `bin/cmd.js`

### Other components

- **CLI user**
- **Torrent peers**
- **External players**

## Connections

- CLI user → Command interface: invokes (evidence: `README.md`)
- Command interface → Version output: reads version (evidence: `version.cjs`)
- Command interface → Torrent input parsing: parses input (evidence: `bin/cmd.js`)
- Command interface → Torrent creation: routes create (evidence: `README.md`)
- Command interface → Torrent info: routes info (evidence: `README.md`)
- Command interface → Metadata download: routes metadata (evidence: `README.md`)
- Command interface → Torrent download: routes download (evidence: `README.md`)
- Command interface → Torrent seeding: routes seed (evidence: `README.md`)
- Torrent creation → WebTorrent client: creates torrent (evidence: `bin/cmd.js`)
- Torrent download → WebTorrent client: adds torrent (evidence: `bin/cmd.js`)
- WebTorrent client → Torrent peers: discovers peers (evidence: `README.md`)
- Torrent download → File selection: selects files (evidence: `README.md`)
- WebTorrent client → HTTP file server: creates server (evidence: `bin/cmd.js`)
- HTTP file server → Player launch: provides stream URL (evidence: `bin/cmd.js`)
- Player launch → External players: opens stream (evidence: `README.md`)
- Subtitle server → Player launch: provides subtitles (evidence: `bin/cmd.js`)
