# baairon/torlink architecture

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

- Interactive diagram: https://gitdiagram.com/baairon/torlink
- Repository: https://github.com/baairon/torlink
- Video tour (about a minute): https://gitdiagram.com/baairon/torlink/video

## Overview

torlink is a terminal torrent finder, downloader, and seeding client. The principal workflow is: a terminal user submits a query, source adapters fetch and normalize results, the UI merges and presents them, selection enters the download queue, WebTorrent writes files, and persisted state enables resumption and later seeding. Headless search, watch, seed, HTTP serving, file streaming, configuration, and updates are separate product branches. The graph reflects sampled entry points and orchestration; some daemon internals are represented only by their exact tree paths.

Main entry points: [`src/index.tsx`](https://github.com/baairon/torlink/blob/main/src/index.tsx) (CLI entry), [`src/ui/App.tsx`](https://github.com/baairon/torlink/blob/main/src/ui/App.tsx) (Terminal UI), [`src/download/queue.ts`](https://github.com/baairon/torlink/blob/main/src/download/queue.ts) (Download queue), [`src/download/engine.ts`](https://github.com/baairon/torlink/blob/main/src/download/engine.ts) (Torrent engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and TUI"]
  node_cli_entry["CLI entry<br/>[index.tsx]"]
  node_terminal_ui["Terminal UI<br/>[App.tsx]"]
  node_search_flow["Concurrent search"]
  node_search_results["Results view<br/>[Results.tsx]"]
end

subgraph group_discovery["Torrent discovery"]
  node_cli_search["JSON search<br/>[search.ts]"]
  node_source_registry["Source registry<br/>[registry.ts]"]
  node_source_adapters["Source adapters"]
  node_search_cache["Search cache<br/>[cache.ts]"]
end

subgraph group_downloads["Downloads and seeding"]
  node_download_queue["Download queue<br/>[queue.ts]"]
  node_torrent_engine["Torrent engine<br/>[engine.ts]"]
  node_download_files["Download files<br/>[engine.ts]"]
  node_seed_lifecycle["Seed lifecycle<br/>[seed.ts]"]
end

subgraph group_headless["Headless services"]
  node_watch_service["Watch service<br/>[watch.ts]"]
  node_serve_api["Torrent API<br/>[serve.ts]"]
  node_files_api["Files API<br/>[files.ts]"]
  node_auth_guards["Auth guards<br/>[auth.ts]"]
end

subgraph group_operations["Operations and state"]
  node_state_files[("State files<br/>[persist.ts]")]
  node_config_store[("Configuration<br/>[config.ts]")]
  node_update_service["Update service<br/>[run.ts]"]
end

node_terminal_user(("Terminal user"))
node_http_client(("HTTP client"))
node_torrent_sources["Torrent sources"]
node_torrent_network["Torrent network"]
node_package_registry["Package registry"]

node_terminal_user -->|"submits commands"| node_cli_entry
node_cli_entry -->|"starts TUI"| node_terminal_ui
node_terminal_ui -->|"runs search"| node_search_flow
node_terminal_ui -->|"queues selection"| node_download_queue
node_terminal_ui -->|"renders results"| node_search_results
node_search_flow -->|"reads sources"| node_source_registry
node_search_flow -->|"searches sources"| node_search_cache
node_cli_entry -->|"dispatches search"| node_cli_search
node_cli_search -->|"selects sources"| node_source_registry
node_cli_search -->|"searches sources"| node_search_cache
node_search_cache -->|"calls adapters"| node_source_adapters
node_source_adapters -->|"fetches listings"| node_torrent_sources
node_download_queue -->|"starts torrents"| node_torrent_engine
node_download_queue -->|"persists state"| node_state_files
node_torrent_engine -->|"exchanges pieces"| node_torrent_network
node_torrent_engine -->|"writes files"| node_download_files
node_seed_lifecycle -->|"starts seeding"| node_torrent_engine
node_seed_lifecycle -->|"records seeds"| node_state_files
node_cli_entry -->|"dispatches watch"| node_watch_service
node_watch_service -->|"queues drops"| node_download_queue
node_cli_entry -->|"dispatches seed"| node_seed_lifecycle
node_cli_entry -->|"dispatches serve"| node_serve_api
node_cli_entry -->|"dispatches files"| node_files_api
node_http_client -->|"posts magnets"| node_serve_api
node_http_client -->|"requests files"| node_files_api
node_serve_api -->|"checks access"| node_auth_guards
node_files_api -->|"checks access"| node_auth_guards
node_serve_api -->|"adds torrents"| node_download_queue
node_files_api -->|"streams files"| node_download_files
node_terminal_ui -->|"loads config"| node_config_store
node_cli_entry -->|"dispatches update"| node_update_service
node_update_service -.->|"checks releases"| node_package_registry

click node_cli_entry "https://github.com/baairon/torlink/blob/main/src/index.tsx"
click node_terminal_ui "https://github.com/baairon/torlink/blob/main/src/ui/App.tsx"
click node_search_flow "https://github.com/baairon/torlink/blob/main/src/ui/hooks/useConcurrentSearch.ts"
click node_search_results "https://github.com/baairon/torlink/blob/main/src/ui/components/Results.tsx"
click node_cli_search "https://github.com/baairon/torlink/blob/main/src/cli/search.ts"
click node_source_registry "https://github.com/baairon/torlink/blob/main/src/sources/registry.ts"
click node_source_adapters "https://github.com/baairon/torlink/tree/main/src/sources"
click node_search_cache "https://github.com/baairon/torlink/blob/main/src/sources/cache.ts"
click node_download_queue "https://github.com/baairon/torlink/blob/main/src/download/queue.ts"
click node_torrent_engine "https://github.com/baairon/torlink/blob/main/src/download/engine.ts"
click node_download_files "https://github.com/baairon/torlink/blob/main/src/download/engine.ts"
click node_seed_lifecycle "https://github.com/baairon/torlink/blob/main/src/daemon/seed.ts"
click node_watch_service "https://github.com/baairon/torlink/blob/main/src/daemon/watch.ts"
click node_serve_api "https://github.com/baairon/torlink/blob/main/src/daemon/serve.ts"
click node_files_api "https://github.com/baairon/torlink/blob/main/src/daemon/files.ts"
click node_auth_guards "https://github.com/baairon/torlink/blob/main/src/daemon/auth.ts"
click node_state_files "https://github.com/baairon/torlink/blob/main/src/download/persist.ts"
click node_config_store "https://github.com/baairon/torlink/blob/main/src/config/config.ts"
click node_update_service "https://github.com/baairon/torlink/blob/main/src/update/run.ts"

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_entry,node_terminal_ui,node_search_flow,node_search_results,node_terminal_user,node_http_client toneBlue
class node_cli_search,node_source_registry,node_source_adapters,node_search_cache toneAmber
class node_download_queue,node_torrent_engine,node_download_files,node_seed_lifecycle toneMint
class node_watch_service,node_serve_api,node_files_api,node_auth_guards toneRose
class node_state_files,node_config_store,node_update_service,node_torrent_sources,node_torrent_network,node_package_registry toneIndigo
```

## Components

### Entry and TUI

- [CLI entry](https://github.com/baairon/torlink/blob/main/src/index.tsx): `src/index.tsx`
- [Terminal UI](https://github.com/baairon/torlink/blob/main/src/ui/App.tsx): `src/ui/App.tsx`
- [Concurrent search](https://github.com/baairon/torlink/blob/main/src/ui/hooks/useConcurrentSearch.ts): `src/ui/hooks/useConcurrentSearch.ts`
- [Results view](https://github.com/baairon/torlink/blob/main/src/ui/components/Results.tsx): `src/ui/components/Results.tsx`

### Torrent discovery

- [JSON search](https://github.com/baairon/torlink/blob/main/src/cli/search.ts): `src/cli/search.ts`
- [Source registry](https://github.com/baairon/torlink/blob/main/src/sources/registry.ts): `src/sources/registry.ts`
- [Source adapters](https://github.com/baairon/torlink/tree/main/src/sources): `src/sources`
- [Search cache](https://github.com/baairon/torlink/blob/main/src/sources/cache.ts): `src/sources/cache.ts`

### Downloads and seeding

- [Download queue](https://github.com/baairon/torlink/blob/main/src/download/queue.ts): `src/download/queue.ts`
- [Torrent engine](https://github.com/baairon/torlink/blob/main/src/download/engine.ts): `src/download/engine.ts`
- [Download files](https://github.com/baairon/torlink/blob/main/src/download/engine.ts): `src/download/engine.ts`
- [Seed lifecycle](https://github.com/baairon/torlink/blob/main/src/daemon/seed.ts): `src/daemon/seed.ts`

### Headless services

- [Watch service](https://github.com/baairon/torlink/blob/main/src/daemon/watch.ts): `src/daemon/watch.ts`
- [Torrent API](https://github.com/baairon/torlink/blob/main/src/daemon/serve.ts): `src/daemon/serve.ts`
- [Files API](https://github.com/baairon/torlink/blob/main/src/daemon/files.ts): `src/daemon/files.ts`
- [Auth guards](https://github.com/baairon/torlink/blob/main/src/daemon/auth.ts): `src/daemon/auth.ts`

### Operations and state

- [State files](https://github.com/baairon/torlink/blob/main/src/download/persist.ts): `src/download/persist.ts`
- [Configuration](https://github.com/baairon/torlink/blob/main/src/config/config.ts): `src/config/config.ts`
- [Update service](https://github.com/baairon/torlink/blob/main/src/update/run.ts): `src/update/run.ts`

### Other components

- **Terminal user**
- **HTTP client**
- **Torrent sources**
- **Torrent network**
- **Package registry**

## Connections

- Terminal user → CLI entry: submits commands
- CLI entry → Terminal UI: starts TUI
- Terminal UI → Concurrent search: runs search
- Terminal UI → Download queue: queues selection
- Terminal UI → Results view: renders results
- Concurrent search → Source registry: reads sources
- Concurrent search → Search cache: searches sources
- CLI entry → JSON search: dispatches search
- JSON search → Source registry: selects sources
- JSON search → Search cache: searches sources
- Search cache → Source adapters: calls adapters
- Source adapters → Torrent sources: fetches listings
- Download queue → Torrent engine: starts torrents
- Download queue → State files: persists state
- Torrent engine → Torrent network: exchanges pieces
- Torrent engine → Download files: writes files
- Seed lifecycle → Torrent engine: starts seeding
- Seed lifecycle → State files: records seeds
- CLI entry → Watch service: dispatches watch
- Watch service → Download queue: queues drops
- CLI entry → Seed lifecycle: dispatches seed
- CLI entry → Torrent API: dispatches serve
- CLI entry → Files API: dispatches files
- HTTP client → Torrent API: posts magnets
- HTTP client → Files API: requests files
- Torrent API → Auth guards: checks access
- Files API → Auth guards: checks access
- Torrent API → Download queue: adds torrents
- Files API → Download files: streams files
- Terminal UI → Configuration: loads config
- CLI entry → Update service: dispatches update
- Update service → Package registry: checks releases
