# pyara-singh/bittorrent architecture

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

- Interactive diagram: https://gitdiagram.com/pyara-singh/bittorrent
- Repository: https://github.com/pyara-singh/bittorrent

## Overview

This repository combines a Go BitTorrent backend with a Tauri/React desktop shell. The backend’s demonstrated user workflow is HTTP torrent CRUD: the server registers routes, handlers validate requests, and an in-memory manager stores and returns torrent records. The tree also contains parsing, tracker, peer-transfer, scheduling, and storage subsystems, but the excerpts do not show them wired into that CRUD workflow. The frontend is still the default Tauri greeting screen, not a torrent client interface. The architecture of unsampled subsystems is represented without guessed connections.

Main entry points: [`backend/cmd/app/main.go`](https://github.com/pyara-singh/bittorrent/blob/main/backend/cmd/app/main.go) (Server startup), [`backend/internal/api/routes.go`](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/api/routes.go) (HTTP routes), [`backend/internal/api/handlers.go`](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/api/handlers.go) (CRUD handlers), [`backend/internal/parser/torrent_parser.go`](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/parser/torrent_parser.go) (Torrent parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["HTTP backend"]
  node_server_entry["Server startup<br/>[main.go]"]
  node_routes["HTTP routes<br/>[routes.go]"]
  node_handlers["CRUD handlers<br/>[handlers.go]"]
  node_torrent_manager[("Torrent manager<br/>[manager.go]")]
end

subgraph group_metadata["Torrent metadata"]
  node_torrent_models["Torrent models<br/>[torrent.go]"]
  node_magnet_model["Magnet model<br/>[magnet.go]"]
  node_meta_model["Torrent metadata<br/>[torrent_meta.go]"]
  node_torrent_parser["Torrent parser<br/>[torrent_parser.go]"]
  node_magnet_parser["Magnet parser<br/>[magnet_parser.go]"]
  node_bencode_decoder["Bencode decoder<br/>[decoder.go]"]
  node_bencode_encoder["Bencode encoder<br/>[encoder.go]"]
end

subgraph group_transfer["BitTorrent transfer"]
  node_peer_model["Peer model<br/>[peer.go]"]
  node_tracker["Tracker client<br/>[client.go]"]
  node_scheduler["Download scheduler<br/>[scheduler.go]"]
  node_torrent_service["Torrent service<br/>[service.go]"]
  node_torrent_repository["Torrent repository<br/>[repository.go]"]
  node_torrent_downloader["Piece downloader<br/>[downloader.go]"]
  node_peer_handshake["Peer handshake<br/>[handshake.go]"]
  node_peer_connection["Peer connection<br/>[peer_connection.go]"]
  node_peer_client["Peer client<br/>[client.go]"]
  node_peer_messages["Peer messages<br/>[message.go]"]
  node_peer_io["Peer I/O<br/>[io.go]"]
  node_piece_work["Piece work<br/>[piece_work.go]"]
  node_file_store[("File store<br/>[file_store.go]")]
  node_file_writer["File writer<br/>[writer.go]"]
end

subgraph group_desktop["Desktop shell"]
  node_desktop_entry["Desktop bootstrap<br/>[main.rs]"]
  node_desktop_lib["Tauri runtime<br/>[lib.rs]"]
  node_react_mount["React mount<br/>[main.tsx]"]
  node_greeting_ui["Greeting screen<br/>[App.tsx]"]
end

node_http_user(("HTTP client"))

node_http_user -->|"sends requests"| node_routes
node_server_entry -->|"creates"| node_torrent_manager
node_server_entry -->|"creates"| node_handlers
node_server_entry -->|"registers"| node_routes
node_routes -->|"dispatches to"| node_handlers
node_handlers -->|"reads and writes"| node_torrent_manager
node_torrent_parser -->|"decodes with"| node_bencode_decoder
node_magnet_parser -->|"returns"| node_magnet_model
node_torrent_parser -->|"returns"| node_meta_model
node_tracker -->|"decodes with"| node_bencode_decoder
node_tracker -->|"returns"| node_peer_model
node_peer_client -->|"formats messages"| node_peer_messages
node_desktop_entry -->|"starts"| node_desktop_lib
node_react_mount -->|"renders"| node_greeting_ui

click node_server_entry "https://github.com/pyara-singh/bittorrent/blob/main/backend/cmd/app/main.go"
click node_routes "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/api/routes.go"
click node_handlers "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/api/handlers.go"
click node_torrent_manager "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/manager.go"
click node_torrent_models "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/torrent.go"
click node_magnet_model "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/magnet.go"
click node_peer_model "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/peer.go"
click node_meta_model "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/torrent_meta.go"
click node_torrent_parser "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/parser/torrent_parser.go"
click node_magnet_parser "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/parser/magnet_parser.go"
click node_bencode_decoder "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/bencode/decoder.go"
click node_bencode_encoder "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/bencode/encoder.go"
click node_tracker "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/tracker/client.go"
click node_scheduler "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/download/scheduler.go"
click node_torrent_service "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/service.go"
click node_torrent_repository "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/repository.go"
click node_torrent_downloader "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/downloader.go"
click node_peer_handshake "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/handshake.go"
click node_peer_connection "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/peer_connection.go"
click node_peer_client "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/client.go"
click node_peer_messages "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/message.go"
click node_peer_io "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/io.go"
click node_piece_work "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/piece_work.go"
click node_file_store "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/storage/file_store.go"
click node_file_writer "https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/storage/writer.go"
click node_desktop_entry "https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src-tauri/src/main.rs"
click node_desktop_lib "https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src-tauri/src/lib.rs"
click node_react_mount "https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src/main.tsx"
click node_greeting_ui "https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src/App.tsx"

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_server_entry,node_routes,node_handlers,node_torrent_manager,node_http_user toneBlue
class node_torrent_models,node_magnet_model,node_meta_model,node_torrent_parser,node_magnet_parser,node_bencode_decoder,node_bencode_encoder toneAmber
class node_peer_model,node_tracker,node_scheduler,node_torrent_service,node_torrent_repository,node_torrent_downloader,node_peer_handshake,node_peer_connection,node_peer_client,node_peer_messages,node_peer_io,node_piece_work,node_file_store,node_file_writer toneMint
class node_desktop_entry,node_desktop_lib,node_react_mount,node_greeting_ui toneRose
```

## Components

### HTTP backend

- [Server startup](https://github.com/pyara-singh/bittorrent/blob/main/backend/cmd/app/main.go): `backend/cmd/app/main.go`
- [HTTP routes](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/api/routes.go): `backend/internal/api/routes.go`
- [CRUD handlers](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/api/handlers.go): `backend/internal/api/handlers.go`
- [Torrent manager](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/manager.go): `backend/internal/torrent/manager.go`

### Torrent metadata

- [Torrent models](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/torrent.go): `backend/internal/models/torrent.go`
- [Magnet model](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/magnet.go): `backend/internal/models/magnet.go`
- [Torrent metadata](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/torrent_meta.go): `backend/internal/models/torrent_meta.go`
- [Torrent parser](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/parser/torrent_parser.go): `backend/internal/parser/torrent_parser.go`
- [Magnet parser](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/parser/magnet_parser.go): `backend/internal/parser/magnet_parser.go`
- [Bencode decoder](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/bencode/decoder.go): `backend/internal/bencode/decoder.go`
- [Bencode encoder](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/bencode/encoder.go): `backend/internal/bencode/encoder.go`

### BitTorrent transfer

- [Peer model](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/models/peer.go): `backend/internal/models/peer.go`
- [Tracker client](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/tracker/client.go): `backend/internal/tracker/client.go`
- [Download scheduler](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/download/scheduler.go): `backend/internal/download/scheduler.go`
- [Torrent service](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/service.go): `backend/internal/torrent/service.go`
- [Torrent repository](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/repository.go): `backend/internal/torrent/repository.go`
- [Piece downloader](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/downloader.go): `backend/internal/torrent/downloader.go`
- [Peer handshake](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/handshake.go): `backend/internal/torrent/handshake.go`
- [Peer connection](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/peer_connection.go): `backend/internal/torrent/peer_connection.go`
- [Peer client](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/client.go): `backend/internal/torrent/client.go`
- [Peer messages](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/message.go): `backend/internal/torrent/message.go`
- [Peer I/O](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/io.go): `backend/internal/torrent/io.go`
- [Piece work](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/torrent/piece_work.go): `backend/internal/torrent/piece_work.go`
- [File store](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/storage/file_store.go): `backend/internal/storage/file_store.go`
- [File writer](https://github.com/pyara-singh/bittorrent/blob/main/backend/internal/storage/writer.go): `backend/internal/storage/writer.go`

### Desktop shell

- [Desktop bootstrap](https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src-tauri/src/main.rs): `frontend/torrent-ui/src-tauri/src/main.rs`
- [Tauri runtime](https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src-tauri/src/lib.rs): `frontend/torrent-ui/src-tauri/src/lib.rs`
- [React mount](https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src/main.tsx): `frontend/torrent-ui/src/main.tsx`
- [Greeting screen](https://github.com/pyara-singh/bittorrent/blob/main/frontend/torrent-ui/src/App.tsx): `frontend/torrent-ui/src/App.tsx`

### Other components

- **HTTP client**

## Connections

- HTTP client → HTTP routes: sends requests (evidence: `backend/internal/api/routes.go`)
- Server startup → Torrent manager: creates (evidence: `backend/cmd/app/main.go`)
- Server startup → CRUD handlers: creates (evidence: `backend/cmd/app/main.go`)
- Server startup → HTTP routes: registers (evidence: `backend/cmd/app/main.go`)
- HTTP routes → CRUD handlers: dispatches to (evidence: `backend/internal/api/routes.go`)
- CRUD handlers → Torrent manager: reads and writes (evidence: `backend/internal/api/handlers.go`)
- Torrent parser → Bencode decoder: decodes with (evidence: `backend/internal/parser/torrent_parser.go`)
- Magnet parser → Magnet model: returns (evidence: `backend/internal/parser/magnet_parser.go`)
- Torrent parser → Torrent metadata: returns (evidence: `backend/internal/parser/torrent_parser.go`)
- Tracker client → Bencode decoder: decodes with (evidence: `backend/internal/tracker/client.go`)
- Tracker client → Peer model: returns (evidence: `backend/internal/tracker/client.go`)
- Peer client → Peer messages: formats messages (evidence: `backend/internal/torrent/client.go`)
- Desktop bootstrap → Tauri runtime: starts (evidence: `frontend/torrent-ui/src-tauri/src/main.rs`)
- React mount → Greeting screen: renders (evidence: `frontend/torrent-ui/src/main.tsx`)
