# iray/teletor architecture

> Architecture diagram of the GitHub repository iray/teletor, 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/iray/teletor
- Repository: https://github.com/iray/teletor

## Overview

##### Main Components

a) External Services:
- Telegram Bot API
- Transmission BitTorrent Client

b) Core Application Components:
- Main Bot Application (teletor.py)
- Message Handler System (handlers/)
- Configuration Management (config/)
- File Management System (files/)

**[User/Telegram Client] <---> [Telegram Bot API] <---> [TeleTor Bot] <---> [Transmission Client]**

##### Detailed Component Breakdown

a) External Layer:
- User's Telegram Client
- Telegram Bot API
- Transmission BitTorrent Daemon

b) Application Layer:
- Main Bot Process (teletor.py)
- Message Handler (handlers/message.py)
- Utility Functions (handlers/utils.py)
- Configuration Manager (config/settings.py)

##### Data Flow Representation

- Incoming messages from Telegram (commands, torrent files, magnet links)
- Outgoing responses and status updates
- Configuration data flow
- Transmission client commands and responses

##### Implementation Details

- The bot's role as a bridge between Telegram and Transmission
- The configuration management system
- The message handling pipeline
- The file processing system

##### Key Interactions to Highlight

- User authentication process
- Command processing
- Torrent management operations
- Status monitoring and updates

**[User/Telegram Client] → [Telegram Bot API]**
- ↓
- [Authentication Layer]
- ↓
- [Main Bot Application]
- ↙     ↓     ↘
- [Config Manager] ← [Message Handler] → [File Handler]
- ↓
- [Transmission Client]

Additional Notes:
- Notes for important configuration points (auth, paths, etc.)
- Command processing pipeline

Remember to include error handling flows and the configuration feedback loop, as these are critical for the bot's operation.

This system design should clearly communicate how the bot serves as a bridge between Telegram users and their local Transmission client, while maintaining security through the authentication system defined in the config.yaml file.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Layer
    subgraph External
        User(("User/Telegram Client"))
        TG["Telegram Bot API"]:::external
        TR["Transmission Client"]:::external
    end

    %% Authentication Layer
    subgraph Auth
        AL["Authentication Layer"]:::auth
        CF["Config File"]:::config
    end

    %% Application Layer
    subgraph Application
        MB["Main Bot Process"]:::core
        MH["Message Handler"]:::core
        UF["Utility Functions"]:::core
        CM["Configuration Manager"]:::config
        FH["File Handler"]:::core
    end

    %% Control Layer
    subgraph Control
        SB["Start Bot Script"]:::control
        SP["Stop Bot Script"]:::control
        IS["Install Script"]:::control
    end

    %% Relationships
    User --> TG
    TG --> AL
    AL --> MB
    CF -.-> AL
    MB --> MH
    MH --> UF
    MH --> FH
    CM --> MB
    CM -.-> CF
    MH --> TR
    
    %% Click Events
    click MB "https://github.com/iRay/TeleTor/blob/master/teletor.py"
    click MH "https://github.com/iRay/TeleTor/blob/master/handlers/message.py"
    click UF "https://github.com/iRay/TeleTor/blob/master/handlers/utils.py"
    click CM "https://github.com/iRay/TeleTor/blob/master/config/settings.py"
    click CF "https://github.com/iRay/TeleTor/blob/master/config/config.yaml"
    click FH "https://github.com/iRay/TeleTor/tree/master/files/"
    click SB "https://github.com/iRay/TeleTor/tree/master/start_bot"
    click SP "https://github.com/iRay/TeleTor/tree/master/stop_bot"
    click IS "https://github.com/iRay/TeleTor/blob/master/install.sh"

    %% Styles
    classDef external fill:#68a1fc,stroke:#333,stroke-width:2px
    classDef auth fill:#ffd700,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef config fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef control fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["External Services"]:::external
        L2["Authentication"]:::auth
        L3["Core Components"]:::core
        L4["Configuration"]:::config
        L5["Control Scripts"]:::control
    end
```
