# alexey-goloburdin/telegram-finance-bot architecture

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

- Interactive diagram: https://gitdiagram.com/alexey-goloburdin/telegram-finance-bot
- Repository: https://github.com/alexey-goloburdin/telegram-finance-bot

## Overview

##### Main Components
- Telegram API Integration: Shows how incoming messages from Telegram are filtered by the provided TELEGRAM_ACCESS_ID and processed using the provided TELEGRAM_API_TOKEN. Also, include the proxy settings (TELEGRAM_PROXY_URL, TELEGRAM_PROXY_LOGIN, TELEGRAM_PROXY_PASSWORD) because they affect outbound connections.
- Server and Bot Engine (server.py): This is the central module that starts up the bot, handles incoming requests, and delegates work.
- Middlewares (middlewares.py): Represent the layers that intercept and process messages before they reach the business logic.
- Expense Management & Category Handling: Include components such as expenses.py and categories.py that encapsulate the core financial tracking logic.
- Database Module (db.py and createdb.sql): Illustrate the interactions with the SQLite database (e.g., reading, writing, initializing via SQL scripts) stored in the “db/” folder.

##### Relationships and Interactions
- Database Access: Link the business logic modules (expenses, categories) to the database module to indicate CRUD operations with the SQLite database.
- Error Handling Path: Optionally show a pathway to the exceptions module wherever errors might be raised during processing.
- Deployment: Overlay a container layer that encapsulates all the above on a Docker container. Indicate that the container uses volume mounts so that the database (“db/finance.db”) persists data outside the container.

##### Architectural Patterns and Technologies
- Docker Containerization: Emphasize that the entire application runs inside a Docker container as configured in the Dockerfile.
- Use of Environment Variables: Note that critical configuration (API tokens, proxy credentials) are injected via environment variables, which govern the behavior of the Telegram bot.
- SQLite as a local datastore: Make sure the persistence mechanism (SQLite DB) is visually distinct as a file-based database.

## Diagram (Mermaid)

```mermaid
graph TD
    telegram["Telegram API"]:::external
    dockerfile["Dockerfile"]:::docker

    subgraph "Docker Container"
        direction TB
        server["server.py"]:::logic
        middle["middlewares.py"]:::logic
        exp["expenses.py"]:::logic
        cat["categories.py"]:::logic
        exc["exceptions.py"]:::error
        dbpy["db.py"]:::db
        schema["createdb.sql"]:::db
        dbdir["db/"]:::db
    end

    dbNode["SQLite DB"]:::db

    telegram -->|"sendsMessage"| server
    dockerfile -->|"buildsContainer"| server
    server -->|"delegatesTo"| middle
    middle -->|"routesToExpense"| exp
    middle -->|"routesToCategory"| cat
    exp -->|"performsCRUD"| dbpy
    cat -->|"performsCRUD"| dbpy
    dbpy -->|"readsWrites"| dbNode
    server -->|"errorHandledBy"| exc

    click server "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/server.py"
    click dockerfile "https://github.com/alexey-goloburdin/telegram-finance-bot/tree/master/Dockerfile"
    click middle "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/middlewares.py"
    click exp "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/expenses.py"
    click cat "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/categories.py"
    click dbpy "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/db.py"
    click schema "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/createdb.sql"
    click dbdir "https://github.com/alexey-goloburdin/telegram-finance-bot/tree/master/db/"
    click exc "https://github.com/alexey-goloburdin/telegram-finance-bot/blob/master/exceptions.py"

    classDef external fill:#D1E8FF,stroke:#0066CC,stroke-width:2px;
    classDef logic fill:#F7D794,stroke:#E58E26,stroke-width:2px;
    classDef db fill:#F8C471,stroke:#E67E22,stroke-width:2px;
    classDef error fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef docker fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
```
