# bhaskar10h/rustor architecture

> Architecture diagram of the GitHub repository bhaskar10h/rustor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhaskar10h/rustor
- Repository: https://github.com/bhaskar10h/rustor

## Overview

##### Project type and purpose
- This is a Rust-based BitTorrent client/library. It reads “.torrent” files or magnet URIs, parses them using Bencode, contacts trackers over UDP (and optionally HTTP), manages a peer list, and orchestrates peer‐to‐peer exchanges.

##### File structure
- Top-level
- Cargo.toml / Cargo.lock: Rust project manifest
- .github/workflows/rust.yml: CI build/test pipeline
- src/
- main.rs: CLI entrypoint
- bittorent.rs: core engine (state machine, high-level orchestration)
- Bencode/ (encode.rs, decode.rs): bencode parser/serializer
- Torrentfile/ (torrent.rs, magnet.rs): domain models for torrent metadata & magnet links
- Tracker/ (tracker.rs, udp.rs): tracker client implementations (UDP announce, HTTP announce if added)
- Peers/ (peer.rs): peer connection management

##### README
- (Empty in this case, so we inferred purpose from file names and conventions.)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Rust BitTorrent Client"
        subgraph "Input/Parsing Layer"
            CLI["CLI Interface"]:::input
            Loader["Torrent File Loader"]:::input
            Magnet["Magnet URI Parser"]:::input
            Decoder["Bencode Decoder"]:::input
            Encoder["Bencode Encoder"]:::input
        end
        subgraph "Domain Model"
            TFMod["Torrentfile Module"]:::domain
            Torrent["Torrent Model"]:::domain
            MagnetMod["Magnet Module"]:::domain
        end
        subgraph "Core Engine"
            Engine["Core Engine"]:::core
        end
        subgraph "Tracker Client"
            Tracker["Tracker Module"]:::network
            UDP["UDP Announce Handler"]:::network
            HTTP["HTTP Announce Handler (optional)"]:::network
        end
        subgraph "Peer Manager"
            PeersMod["Peers Module"]:::network
            Peer["Peer Manager"]:::network
        end
        Storage["Storage I/O"]:::storage
        subgraph "Project Files"
            Sample["Sample Torrent File"]:::project
            Manifest["Manifest & CI"]:::project
        end
    end

    CLI -->|"load/parses"| Loader
    CLI -->|"load/parses"| Magnet
    Loader -->|"bencode data"| Decoder
    Magnet -->|"bencode data"| Decoder
    Decoder -->|"parsed metadata"| TFMod
    Decoder -->|"parsed metadata"| MagnetMod
    TFMod -->|"metadata"| Engine
    MagnetMod -->|"metadata"| Engine
    Engine -->|"announce request"| Tracker
    Tracker -->|"UDP announce"| UDP
    Tracker -->|"HTTP announce"| HTTP
    UDP -->|UDP| TrackerSrv
    HTTP -->|HTTP| TrackerSrv
    Tracker -->|"tracker response"| Peer
    Engine -->|"manage peers"| Peer
    Peer -->|TCP| OtherClients
    Peer -->|"write pieces"| Storage
    Storage -->|FS I/O| Disk
    Sample -->|"example torrent"| Loader
    Manifest --- CLI

    classDef input fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef domain fill:#A3E4A,stroke:#333,stroke-width:1px
    classDef core fill:#B9F2A1,stroke:#333,stroke-width:1px
    classDef network fill:#F7C873,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#f5f5f5,stroke:#333,stroke-width:1px
    classDef project fill:#E5E4E2,stroke:#333,stroke-width:1px

    TrackerSrv["Tracker Servers"]:::external
    OtherClients["Other BitTorrent Clients"]:::external
    Net["Network (UDP/TCP)"]:::external
    Disk["Local Disk"]:::external

    click CLI "https://github.com/bhaskar10h/rustor/blob/main/src/main.rs"
    click Engine "https://github.com/bhaskar10h/rustor/blob/main/src/bittorent.rs"
    click Decoder "https://github.com/bhaskar10h/rustor/blob/main/src/Bencode/decode.rs"
    click Encoder "https://github.com/bhaskar10h/rustor/blob/main/src/Bencode/encode.rs"
    click TFMod "https://github.com/bhaskar10h/rustor/blob/main/src/Torrentfile/mod.rs"
    click Torrent "https://github.com/bhaskar10h/rustor/blob/main/src/Torrentfile/torrent.rs"
    click MagnetMod "https://github.com/bhaskar10h/rustor/blob/main/src/Torrentfile/magnet.rs"
    click Tracker "https://github.com/bhaskar10h/rustor/blob/main/src/Tracker/mod.rs"
    click UDP "https://github.com/bhaskar10h/rustor/blob/main/src/Tracker/udp.rs"
    click Tracker "https://github.com/bhaskar10h/rustor/blob/main/src/Tracker/tracker.rs"
    click PeersMod "https://github.com/bhaskar10h/rustor/blob/main/src/Peers/mod.rs"
    click Peer "https://github.com/bhaskar10h/rustor/blob/main/src/Peers/peer.rs"
    click Sample "https://github.com/bhaskar10h/rustor/blob/main/src/nasa.torrent"
    click Manifest "https://github.com/bhaskar10h/rustor/blob/main/Cargo.toml"
```
