# ruslanriabokin/news_bot_aiogram_dialog architecture

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

- Interactive diagram: https://gitdiagram.com/ruslanriabokin/news_bot_aiogram_dialog
- Repository: https://github.com/ruslanriabokin/news_bot_aiogram_dialog

## Overview

##### Overview of the Project
- This project is a Telegram news automation bot whose primary purpose is to automate retrieval, processing (translation and summarization), and scheduled publishing of news items into Telegram channels.
- The system uses various components such as a Telegram bot (powered by aiogram-dialog), a news processing module, a multi-technology database layer, and a web interface (also containing an alternative Azure SQL version) for administration or additional user interaction.

##### Main Components
a. Telegram Bot Module:
- Files: news_bot.py, bot_create_news_aiogram_dialog.py, bot_router_aiogram_dialog.py, edit_subscriptions_aiogram_dialog.py, states_class_aiogram_dialog.py, subscription_list_aiogram_dialog.py.
- Function: Manages interactions with users via Telegram. It handles input for news topics, ensures admin rights, and triggers dialogues using the aiogram-dialog library.

b. News Processing Module:
- Files: Items under news_processing/ (news_API.py, news_bot_show_topics.py, news_image_processing.py, news_pre_publisher.py, news_publisher.py, processing_API.py, scheduler.py, scrapers.py, ttl_cache_class.py).
- Function: Responsible for interacting with external news APIs, processing the fetched news (including translation and summarization), caching results, and managing schedule/publishing of news content.

c. Database Abstraction Layer:
- Files: Under the db_layer/ directory (abstract_database.py, azure_sql_database.py, my_sql_database.py, sqlite_database.py, db_factory.py, sql_data_service.py).
- Function: Provides an abstraction for different database engines (SQLite, MySQL, Azure SQL) to store topics, subscriptions, and possibly logs or configuration data.

d. Configuration:
- File: config.py.
- Function: Contains necessary API keys, tokens, and settings that link together the various modules such as the Telegram Bot and the news processing integration as well as DB connection details.

e. Web Interface:
- Files: Located in the web_interface/ directory (app.py, app_azure_sql.py, plus static assets and template files).
- Function: Provides a GUI for interacting with the bot’s functionalities, potentially an administrative portal for managing news channels or subscriptions and perhaps monitoring bot performance.

f. Deployment & Auxiliary Scripts:
- Dockerfile and .dockerignore: Used for containerizing the application ensuring consistent deployment.
- Additional instruction files (instruction.pdf, instruction.py) provide usage and deployment guidelines that are also essential design references for deployment strategy.
- requirements.txt: Lists all dependencies relevant to each module.

##### Understanding the Component Interactions
- The Telegram Bot Module handles user inputs and dispatches commands to the News Processing Module.
- The News Processing Module fetches news through external APIs and then processes the news (translation, summarization, caching) before handing off to the scheduled publishing engine.
- The scheduled publishing component (scheduler.py) ensures that processed news items are published at predetermined intervals or per user specification.
- Database interactions, abstracted in the db_layer, occur both from the Telegram bot and the processing modules to manage dynamic content such as subscription lists, topics, and publishing logs.
- The Web Interface module provides another point of interaction enabling users or administrators to view details and possibly manage configurations, often interacting with the database as well.
- Docker and configuration files tie all components together and allow for well-defined environmental setups.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each module (dialog bot, news processing, database layer, web interface) is responsible for a distinct part of the functionality.
- Abstraction Layer for Databases: The db_layer uses abstract classes and a factory pattern (db_factory.py) to handle multiple database backends.
- API-Driven Processing: The system relies on external news APIs which necessitate a clear definition of the API integration points.
- Modular Design: Distinct directories for news processing, database interactions, and web components suggest a modular approach that can be further decomposed if the project scales.
- Scheduler Component: Following a scheduled-based pattern to trigger periodic publishing.

##### Essential Elements
- Components: Telegram Bot, News Processing (sub-components like API interactions, processing logic, scheduler), Database Abstraction Layer, Web Interface.
- Labels and Technology Stack: Annotate each component with references to technologies used (e.g., aiogram-dialog for Telegram, Python libraries for translation/summarization, Docker for deployment, specific DB libraries).
- Environment & Deployment: Represent Docker as a container boundary, and indicate the use of environment variables and configuration files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User("Telegram User"):::user

    subgraph "Telegram Bot Module"
        TB1["news_bot.py"]:::telegram
        TB2["bot_create_news_aiogram_dialog.py"]:::telegram
        TB3["bot_router_aiogram_dialog.py"]:::telegram
        TB4["edit_subscriptions_aiogram_dialog.py"]:::telegram
        TB5["states_class_aiogram_dialog.py"]:::telegram
        TB6["subscription_list_aiogram_dialog.py"]:::telegram
    end

    subgraph "News Processing Module"
        NP1["news_API.py"]:::news_processing
        NP2["news_bot_show_topics.py"]:::news_processing
        NP3["news_image_processing.py"]:::news_processing
        NP4["news_pre_publisher.py"]:::news_processing
        NP5["news_publisher.py"]:::news_processing
        NP6["processing_API.py"]:::news_processing
        NP7["scheduler.py"]:::news_processing
        NP8["scrapers.py"]:::news_processing
        NP9["ttl_cache_class.py"]:::news_processing
    end

    subgraph "Database Abstraction Layer"
        DB1["abstract_database.py"]:::database
        DB2["azure_sql_database.py"]:::database
        DB3["my_sql_database.py"]:::database
        DB4["sqlite_database.py"]:::database
        DB5["db_factory.py"]:::database
        DB6["sql_data_service.py"]:::database
    end

    subgraph "Web Interface"
        WI1["app.py"]:::web
        WI2["app_azure_sql.py"]:::web
        WI3["static assets"]:::web
        WI4["templates"]:::web
    end

    subgraph "Deployment & Auxiliary Scripts"
        D1["Dockerfile"]:::deployment
        D2[".dockerignore"]:::deployment
        D3["instruction.pdf"]:::deployment
        D4["instruction.py"]:::deployment
        D5["requirements.txt"]:::deployment
    end

    C1["config.py"]:::config

    ExternalNews["External News APIs"]:::external
    TelegramAPI["Telegram API"]:::external

    %% Connections between modules
    User -->|"sends command"| TB1
    TB1 -->|"dispatches"| NP1
    TB1 -->|"db access"| DB1
    NP1 -->|"db access"| DB1
    NP1 -->|"fetches"| ExternalNews
    NP1 -->|"schedules"| NP7
    NP7 -->|"publishes via"| TelegramAPI
    WI1 -->|"admin op"| DB1

    %% Config connections
    C1 -->|"configures"| TB1
    C1 -->|"configures"| NP1
    C1 -->|"configures"| DB1
    C1 -->|"configures"| WI1

    %% Deployment connection (containerizes main modules)
    D1 -->|"containerizes"| TB1
    D1 -->|"containerizes"| NP1
    D1 -->|"containerizes"| WI1

    %% Click Events for Telegram Bot Module
    click TB1 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_bot.py"
    click TB2 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/bot_create_news_aiogram_dialog.py"
    click TB3 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/bot_router_aiogram_dialog.py"
    click TB4 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/edit_subscriptions_aiogram_dialog.py"
    click TB5 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/states_class_aiogram_dialog.py"
    click TB6 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/subscription_list_aiogram_dialog.py"

    %% Click Events for News Processing Module
    click NP1 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/news_API.py"
    click NP2 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/news_bot_show_topics.py"
    click NP3 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/news_image_processing.py"
    click NP4 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/news_pre_publisher.py"
    click NP5 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/news_publisher.py"
    click NP6 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/processing_API.py"
    click NP7 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/scheduler.py"
    click NP8 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/scrapers.py"
    click NP9 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/news_processing/ttl_cache_class.py"

    %% Click Events for Database Abstraction Layer
    click DB1 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/db_layer/abstract_database.py"
    click DB2 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/db_layer/azure_sql_database.py"
    click DB3 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/db_layer/my_sql_database.py"
    click DB4 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/db_layer/sqlite_database.py"
    click DB5 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/db_layer/db_factory.py"
    click DB6 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/db_layer/sql_data_service.py"

    %% Click Event for Configuration
    click C1 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/config.py"

    %% Click Events for Web Interface
    click WI1 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/web_interface/app.py"
    click WI2 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/web_interface/app_azure_sql.py"
    click WI3 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/tree/main/web_interface/static"
    click WI4 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/tree/main/web_interface/templates"

    %% Click Events for Deployment & Auxiliary Scripts
    click D1 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/tree/main/Dockerfile"
    click D2 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/.dockerignore"
    click D3 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/instruction.pdf"
    click D4 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/instruction.py"
    click D5 "https://github.com/ruslanriabokin/news_bot_aiogram_dialog/blob/main/requirements.txt"

    %% Styles
    classDef telegram fill:#b3cde0,stroke:#333,stroke-width:2px;
    classDef news_processing fill:#ccebc5,stroke:#333,stroke-width:2px;
    classDef database fill:#decbe4,stroke:#333,stroke-width:2px;
    classDef config fill:#fed9a6,stroke:#333,stroke-width:2px;
    classDef web fill:#fbb4ae,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef user fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef external fill:#d9d9d9,stroke:#333,stroke-width:2px;
```
