# comerc/budva43 architecture

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

- Interactive diagram: https://gitdiagram.com/comerc/budva43
- Repository: https://github.com/comerc/budva43

## Overview

Based on examining the file tree and the README, it’s clear that this project is a Telegram message forwarding tool built with Go and tdlib. Its primary purpose is to listen for Telegram events (like new messages), apply configurable forwarding and filtering rules, and then send messages to specific chat destinations. It also supports inline keyboard interactions, markdown formatting, and has a containerized deployment approach.

##### Main Components
a. Entry Point & Core Application (main.go):
- Represents the application’s startup and overall orchestration.

b. Configuration & Environment Module:
- That the system loads environment variables (BUDVA32_API_ID, BUDVA32_API_HASH, etc.) and a YAML configuration that defines rules such as "Forwards", "Sources", "Reports", "ReplaceMyselfLinks", etc.
- This part of the architecture informs the forwarding behavior.

c. Telegram Client Integration (tdlib and go-tdlib):
- Message retrieval, sending, and link generation functions as outlined in the README code examples.
- How updates (using a channel-based listener) trigger message processing.

d. Forwarding Engine & Filtering Logic:
- Processing pipeline where messages are first received via the Telegram client.
- That for each incoming message, the system checks conditions (Include, Exclude, CopyOnce, Indelible, etc.) and then routes the message as per configured “Forwards.”
- Subcomponents (or modules) for filtering rules, markdown parsing, and inline keyboard creation.

e. Deployment Components & CI/CD:

##### Relationships and Interactions
- The application startup (main.go) first loads configuration.
- Once configured, it initializes the Telegram Client.
- The Telegram Client listens for new messages (via a channel or callback mechanism).
- The Forwarding Engine receives these messages, applying filtering and then invoking functions from the Telegram Client to either forward or send copies (potentially with modifications like markdown formatting or inline keyboard attachments).
- Data flows: from configuration to Telegram API communication to message processing and finally to message forwarding.

##### Architectural Patterns and Design Principles
- Modular separation: Even though the file tree is flat, the design logically separates configuration, Telegram client interactions, and forwarding rules.
- Event-driven architecture: Emphasize the update-listener mechanism where the system reacts to Telegram events.
- Use of external libraries: Clearly denote use of tdlib (through go-tdlib) and other libraries handling markdown processing, inline keyboard building, etc.

##### Relevant Technologies & Frameworks
- Go programming language, with dependency management via go.mod and go.sum.
- Docker for containerized deployment.
- tdlib and its Go bindings (go-tdlib) for Telegram API interactions.
- YAML configuration processing for dynamic forwarding/filtering rules.
- GitHub Actions / Dependabot (from the .github folder and dependabot.yml) for automation and dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Core
    subgraph "Application Core"
        A["Entry Point (main.go)"]:::application
        A1["Configuration Loader (.env & .config.yml)"]:::config
        A --> A1
    end

    %% Telegram Client and Processing Modules
    subgraph "Processing Pipeline"
        B["Telegram Client Integration (tdlib)"]:::telegram
        C["Forwarding Engine & Filtering Logic"]:::forward
        A1 -->|"Initializes"| B
        B -->|"Receives Updates"| C
        C -->|"Forwards Processed Messages"| B
    end

    %% Deployment and CI/CD Infrastructure
    subgraph "Deployment & CI/CD"
        D["Dockerfile"]:::deployment
        E[".devcontainer (Directory)"]:::deployment
        F["Makefile"]:::deployment
        G[".github (Directory)"]:::deployment
    end

    %% External Services (Optional)
    subgraph "External Services"
        H["Telegram API"]:::external
    end

    %% Connections
    B -->|"Communicates with"| H

    %% Click Events
    click A "https://github.com/comerc/budva43/blob/main/main.go"
    click B "https://github.com/comerc/budva43/tree/main/tdlib"
    click D "https://github.com/comerc/budva43/tree/main/Dockerfile"
    click E "https://github.com/comerc/budva43/blob/main/.devcontainer"
    click F "https://github.com/comerc/budva43/tree/main/Makefile"
    click G "https://github.com/comerc/budva43/blob/main/.github"

    %% Styles
    classDef application fill:#ffcc99,stroke:#cc6600,stroke-width:2px;
    classDef config fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef telegram fill:#ccffcc,stroke:#339933,stroke-width:2px;
    classDef forward fill:#cce5ff,stroke:#3366cc,stroke-width:2px;
    classDef deployment fill:#f2d7d5,stroke:#a93226,stroke-width:2px;
    classDef external fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
```
