How varbhat/exatorrent works
Project Type and Purpose
• exatorrent is a self‑hostable, full‑stack BitTorrent client.
• Backend: a single statically‑linked Go binary exposing an HTTP/REST + WebSocket API, managing torrent sessions.
• Frontend: a responsive Svelte/TypeScript web app embedded in the binary.
• Supports two deployment modes: local CLI/binary or containerized (Docker/Podman).
High‑Level File‑Structure Analysis
• Top‑level:
• exatorrent.go / go.mod/go.sum – the Go entrypoint and module.
• Dockerfile / Makefile / CI workflows – build, test, container scripts.
• docs/ – Markdown docs on API, config, database, usage, etc.
• internal/core: application logic
• auth, init, engine, connection, storage, cache, statsapi, WebSocket serve, CLI “get” commands.
• internal/db: data‑access layer abstraction
• Generic db.go interfaces, SQLite3 & PostgreSQL implementations for torrents, users, trackers, locks, file state, piece counts.
• internal/web: static frontend assets + Go embedding
• Svelte source (src/), package.json, build configs, web.go & web_noui.go to serve or disable UI embedding.
Key Components
a. User & Client
• Web Browser (UI)
• Optional CLI (exatorrent binary flags)
b. HTTP/REST + WebSocket API Layer
• Serves static UI assets
• Exposes endpoints for torrent CRUD, user auth, settings
• WebSocket for live stats & notifications
c. Core Engine
• Torrent session manager (anacrolix/torrent under the hood)
• Auth & session management
• Rate limiter, blocklist, auto‑tracker injection
• Storage & caching submodules
d. Data Store
• Configurable plug‑in to SQLite3 (default) or PostgreSQL
• Tables: torrents, users, trackers, file_state, locks, piece_counts
• Persists state across restarts
e. File Storage
• Local disk directory for torrent data + downloaded files
• ZIP / tarball generation on the fly
f. External Services
• BitTorrent network (peers, DHT, trackers)
• (Optional) external metainfo cache or trackers list URLs
Relationships & Data Flows
• Browser ↔ HTTP API: user actions (add torrent, auth)
• Browser ↔ WebSocket: live progress, notifications, stats
• HTTP API → Core Engine: request handling routes into engine routines
• Core Engine ↔ Data Store: read/write torrent & user state
• Core Engine ↔ File Storage: read/write torrent data, serve files/streams
• Core Engine ↔ BitTorrent P2P Network: connect to peers, exchange pieces
• Container/Docker orchestration wraps all above with port mappings (HTTP port 5000, torrent port 42069) and mounts
Architectural Patterns & Design Principles
• Layered (HTTP/API → Core → DB → Storage)
• Hexagonal/Ports-&‑Adapters in internal/db for RDBMS swapping
• Single binary embedding static assets for zero‑dependency deployment
• Separation of concerns: auth, storage, networking, UI are distinct modules
• Concurrency via Go routines in core/routine.go