# mrsakine/clean_tg_channel architecture

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

- Interactive diagram: https://gitdiagram.com/mrsakine/clean_tg_channel
- Repository: https://github.com/mrsakine/clean_tg_channel

## Overview

##### Main Components
- Configuration Loader: This component is responsible for reading the user's configuration from the config.json file (created from config.example.json), including the API_ID, API_HASH, and CHANNEL_ID.
- Authentication & Session Manager: Represented in the main.py script, this component handles:
- Prompting the user for their phone number.
- Receiving the confirmation code (and 2FA password if needed).
- Maintaining and reusing the Pyrogram session.
- Pyrogram Client Library: This library wraps interactions with the Telegram API. It establishes a secure connection and abstracts complexities related to network calls and session management.
- Command Processor (Cleaning Logic): When the user sends the "/delete" command in the channel, this triggers the cleaning process. This module is orchestrated through the script logic in main.py, directing calls to the appropriate API functionality via Pyrogram.
- User Interface / Input Mechanism: This reflects the command-line interaction where the user enters their phone number, confirmation code, and commands (like /delete).

##### Relationships and Interactions
- The Authentication & Session Manager then interacts with the user (via CLI) to authenticate and establish a session, storing session data for reuse.
- Once authenticated, the Pyrogram Client communicates with the Telegram API Server using the provided credentials and session data.
- Finally, when the user issues the "/delete" command, the Command Processor triggers cleaning actions that involve sending commands via the Pyrogram Client to the Telegram API (affecting the given channel).

##### Architectural Patterns / Design Principles
- Separation of Concerns: The configuration, authentication, API interaction, and command processing are distinct, even if they’re implemented in a single main.py file.
- Persistence: The saved session helps streamline subsequent interactions, reducing redundant authentication steps.
- Reliance on a well-maintained external library (Pyrogram) for the heavy lifting of networking and session management.

##### Relevant Technologies
- Python: The core programming language.
- Pyrogram: The Telegram client library.
- Telegram API: The external service the utility interacts with for channel management.

- Start from the user’s perspective (CLI inputs).
- Branch out to the configuration and authentication components.
- Internal management by the Pyrogram library, and then the outbound communication to the Telegram API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Local Components"
        CFG["Configuration Loader (config.json)"]:::local
        AUTH["Authentication & Session Manager (main.py)"]:::local
        CMD["Command Processor (Cleaning Logic) (main.py)"]:::local
        UI["User Input/CLI (main.py)"]:::local
        PYR["Pyrogram Client Library"]:::dependency
    end

    subgraph "External Components"
        TELE["Telegram API Server"]:::external
    end

    UI -->|"provides_input"| AUTH
    UI -->|"issues_/delete"| CMD
    CFG -->|"config_data"| AUTH
    AUTH -->|"authenticate"| PYR
    CMD -->|"delete_command"| PYR
    PYR -->|"API_request"| TELE
    TELE -->|"API_response"| PYR
    PYR -->|"session_feedback"| AUTH

    click CFG "https://github.com/mrsakine/clean_tg_channel/blob/main/config.example.json"
    click AUTH "https://github.com/mrsakine/clean_tg_channel/blob/main/main.py"
    click CMD "https://github.com/mrsakine/clean_tg_channel/blob/main/main.py"
    click UI "https://github.com/mrsakine/clean_tg_channel/blob/main/main.py"
    click PYR "https://github.com/mrsakine/clean_tg_channel/blob/main/requirements.txt"

    classDef local fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef dependency fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
