# omgbox/rsd architecture

> Architecture diagram of the GitHub repository omgbox/rsd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omgbox/rsd
- Repository: https://github.com/omgbox/rsd

## Overview

##### Main Components

a) Client Layer:
- Web Browsers
- Media Players
- Any HTTP-capable clients

b) Server Components:
- HTTP Server Module
- Torrent Client Module
- Stream Handler
- File Management System

c) External Components:
- BitTorrent Network
- Torrent Peers

**[Client Layer]**
- ↕
**[Application Layer]**
- ↕
**[BitTorrent Network]**

##### Component Details

- Port listener (default 8080)
- /stream endpoint handler
- Range request processor

- Magnet link processor
- Metadata fetcher
- Peer connection manager

- Video file identifier
- Content type detector
- Chunk manager
- Buffer manager

- Download directory manager
- Cleanup scheduler
- Storage monitor

##### Data Flow Indicators

**Client → HTTP Server (/stream?magnet=...)**
**HTTP Server → Torrent Client (magnet link processing)**
**Torrent Client ↔ BitTorrent Network (peer connections)**
**Torrent Client → Stream Handler (video data)**
**Stream Handler → Client (HTTP streaming)**

##### Technical Details

Notes about:
- HTTP range request support
- Video format support (.mp4, .mkv)
- Storage optimization
- Periodic cleanup process

##### Implementation Notes

- Command-line parameters (-port, -dir)
- Static binary compilation options
- Platform support (Linux/Windows/Mac)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        WB[Web Browsers]:::client
        MP[Media Players]:::client
        HC[HTTP Clients]:::client
    end

    %% Application Layer
    subgraph Application
        %% HTTP Server Module
        subgraph HTTP
            HS[HTTP Server<br>Port 8080]:::server
            SE["/stream Endpoint"]:::server
            RR[Range Request<br>Processor]:::server
        end

        %% Torrent Client Module
        subgraph Torrent
            TC[Torrent Client]:::torrent
            MP1[Magnet Processor]:::torrent
            MF[Metadata Fetcher]:::torrent
            PC[Peer Connection<br>Manager]:::torrent
        end

        %% Stream Handler
        subgraph Streaming
            SH[Stream Handler]:::stream
            VF[Video File<br>Identifier]:::stream
            CT[Content Type<br>Detector]:::stream
            CM[Chunk Manager]:::stream
            BM[Buffer Manager]:::stream
        end

        %% File Management
        subgraph Storage
            FM[File Management]:::storage
            DM[Download Directory<br>Manager]:::storage
            CS[Cleanup Scheduler]:::storage
            SM[Storage Monitor]:::storage
        end

        %% Main Application Components
        MA[Main Application]:::core
        DEP[Dependencies]:::core
    end

    %% External Layer
    subgraph External
        BN[BitTorrent Network]:::external
        TP[Torrent Peers]:::external
    end

    %% Relationships
    WB & MP & HC --> HS
    HS --> SE
    SE --> RR
    RR --> TC
    TC <--> PC
    PC <--> BN
    BN <--> TP
    TC --> SH
    SH --> FM
    FM --> DM
    DM --> CS
    CS --> SM
    SH --> RR

    %% Click Events
    click MA "https://github.com/omgbox/rsd/blob/main/main.go"
    click DEP "https://github.com/omgbox/rsd/blob/main/go.mod"

    %% Styles
    classDef client fill:#6495ED,stroke:#333,stroke-width:2px
    classDef server fill:#4CAF50,stroke:#333,stroke-width:2px
    classDef torrent fill:#FFA500,stroke:#333,stroke-width:2px
    classDef stream fill:#9C27B0,stroke:#333,stroke-width:2px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px
    classDef external fill:#FF4444,stroke:#333,stroke-width:2px
    classDef core fill:#2196F3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Client Components]:::client
        L2[Server Components]:::server
        L3[Torrent Components]:::torrent
        L4[Stream Components]:::stream
        L5[Storage Components]:::storage
        L6[External Components]:::external
        L7[Core Components]:::core
    end
```
