# midblyte/tmnetbot architecture

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

- Interactive diagram: https://gitdiagram.com/midblyte/tmnetbot
- Repository: https://github.com/midblyte/tmnetbot

## Overview

##### Main Components

a) External Services Layer:
- Telegram API (MTProto)
- MongoDB Atlas
- User Telegram Channels

b) Core Application Components:
- Bot Interface
- Message Handler System
- Network Management
- Database Interface
- Scheduler System

##### Component Organization

**[External Services Layer]**
- ↕
**[Bot Interface Layer]**
- ↕
**[Core Processing Layer]**
- ↕
**[Data Layer]**

##### Specific Component Details

a) Bot Interface Layer (networkbot/telegram.py):
- Connection to Telegram API
- Authentication flow (API_ID, API_HASH, BOT_TOKEN)

b) Core Processing Layer:
- Handler System (networkbot/handlers/*)
- As a command router with multiple command handlers
- Main handlers: add_channel, forward, channels, settings
- Network Management (networkbot/network.py)
- Channel management flow
- Scheduler (networkbot/scheduler.py)
- Time-based operations

c) Data Layer:
- MongoDB Interface (networkbot/mongo.py)
- Channel/User Data Storage

##### Flow Representation

- User interactions → Bot Interface
- Command routing → Specific Handlers
- Data operations → MongoDB
- Message forwarding → Target Channels

##### Important Details

- Configuration Management (config.py)
- Filter System (filters.py)
- Utility Functions (utils/)
- Session Management

##### Specific Implementation Notes

- How messages flow from source channels to target channels
- Admin verification process
- Scheduling system's interaction with the main bot
- Database operations for channel management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        TG[Telegram API]
        MDB[(MongoDB Atlas)]
        UCH[User Telegram Channels]
    end

    subgraph Interface
        BOT["Bot Interface"]:::interface
        CFG["Configuration"]:::config
    end

    subgraph Core
        MH["Message Handler System"]:::core
        subgraph Handlers
            CH["Channel Management"]:::handler
            FH["Message Forwarding"]:::handler
            SH["Settings Handler"]:::handler
            AH["Admin Management"]:::handler
        end
        NM["Network Management"]:::core
        SCH["Scheduler System"]:::core
    end

    subgraph Data
        DBI["Database Interface"]:::data
        FIL["Filter System"]:::data
    end

    subgraph Utils
        CU["Channel Utils"]:::util
        KM["Keyboard Management"]:::util
        TO["Time Operations"]:::util
        DP["Document Processing"]:::util
    end

    TG <--> BOT
    BOT --> MH
    BOT --> CFG
    MH --> CH
    MH --> FH
    MH --> SH
    MH --> AH
    CH --> NM
    FH --> NM
    NM --> UCH
    NM <--> DBI
    SCH --> NM
    DBI --> MDB
    CH --> FIL
    FH --> FIL
    
    CH --> CU
    SH --> KM
    SCH --> TO
    FH --> DP

    click BOT "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/telegram.py"
    click MH "https://github.com/Midblyte/tmnetbot/tree/master/networkbot/handlers/"
    click CH "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/handlers/add_channel.py"
    click FH "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/handlers/forward.py"
    click SH "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/handlers/settings.py"
    click AH "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/handlers/get_admins.py"
    click NM "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/network.py"
    click DBI "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/mongo.py"
    click SCH "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/scheduler.py"
    click CFG "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/config.py"
    click FIL "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/filters.py"
    click CU "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/utils/channels.py"
    click KM "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/utils/keyboards.py"
    click TO "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/utils/time.py"
    click DP "https://github.com/Midblyte/tmnetbot/blob/master/networkbot/utils/documents.py"

    classDef interface fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef handler fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#e67e22,stroke:#d35400,color:white
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef config fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        L1["Interface Components"]:::interface
        L2["Core Components"]:::core
        L3["Handler Components"]:::handler
        L4["Data Components"]:::data
        L5["Utility Components"]:::util
        L6["Config Components"]:::config
    end
```
