How rcbtst/video_stats_tg_bot works
This is a Telegram bot that answers Russian-language questions about video statistics. A message handler passes the question to a use case, which invokes a Pydantic AI processor; the processor supplies database schema and current time to the LLM, validates generated SQL, executes it, and returns a numeric result to the bot. The README documents the retry-on-error behavior. The graph includes the database and logging layers; some composition details are supported by indexed references rather than excerpts.
Main entry points: pydantic_ai_text_question_processor.py AI question processor · messages.py Message handler · di_config.py Dependency wiring · __init__.py Bot runtime
Components 17
Telegram interface
- Bot runtime
src/interfaces/telegram_bot/__init__.py - Message handler
src/interfaces/telegram_bot/handlers/messages.py
Question processing
- Question contract
src/application/contracts/process_text_question.py - Question use case
src/application/use_cases/process_text_question.py - AI question processor
src/infrastructure/llm/pydantic_ai_text_question_processor.py
Query infrastructure
- Schema provider
src/infrastructure/database/sqlalchemy_schema_description_provider.py - SQL checker
src/infrastructure/database/sqlglot_query_checker.py - Scalar query executor
src/infrastructure/database/sqlalchemy_db_query_executor.py - SQLAlchemy database
src/infrastructure/database/sqlalchemy_database.py - Video schema
src/infrastructure/database/schema/video.py - Snapshot schema
src/infrastructure/database/schema/video_snapshot.py
Configuration and logging
- Environment settings
src/config.py - Dependency wiring
src/infrastructure/di_config.py - Logging adapters
src/infrastructure/utils/stdlib_logger.py
Other components
- Telegram user
- OpenRouter LLM
- PostgreSQL
Connections 22
- Telegram user → Bot runtime: sends message
README.md - Bot runtime → Message handler: routes messages
src/interfaces/telegram_bot/__init__.py - Message handler → Question use case: invokes
src/interfaces/telegram_bot/handlers/messages.py - Message handler → Question contract: creates command
src/interfaces/telegram_bot/handlers/messages.py - Question use case → AI question processor: processes question
src/application/use_cases/process_text_question.py - AI question processor → OpenRouter LLM: requests generation
src/infrastructure/llm/pydantic_ai_text_question_processor.py - AI question processor → Schema provider: gets schema
src/infrastructure/llm/pydantic_ai_text_question_processor.py - Schema provider → Video schema: describes tables
src/infrastructure/database/sqlalchemy_schema_description_provider.py - Schema provider → Snapshot schema: describes tables
src/infrastructure/database/sqlalchemy_schema_description_provider.py - AI question processor → SQL checker: validates SQL
src/infrastructure/llm/pydantic_ai_text_question_processor.py - SQL checker → Video schema: allows table
src/infrastructure/database/sqlglot_query_checker.py - SQL checker → Snapshot schema: allows table
src/infrastructure/database/sqlglot_query_checker.py - AI question processor → Scalar query executor: executes SQL
src/infrastructure/llm/pydantic_ai_text_question_processor.py - Scalar query executor → PostgreSQL: runs scalar query
src/infrastructure/database/sqlalchemy_db_query_executor.py - SQLAlchemy database → PostgreSQL: opens connection
src/infrastructure/database/sqlalchemy_database.py - Dependency wiring → Question use case: constructs
src/infrastructure/di_config.py - Dependency wiring → AI question processor: constructs
src/infrastructure/di_config.py - Dependency wiring → SQLAlchemy database: configures
src/infrastructure/di_config.py - Environment settings → Dependency wiring: provides settings
src/infrastructure/di_config.py - Bot runtime → Environment settings: loads token
src/interfaces/telegram_bot/__init__.py - AI question processor → Logging adapters: logs activity
- Message handler → Telegram user: returns answer
src/interfaces/telegram_bot/handlers/messages.py