$ show BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot
This repository implements a comprehensive Telegram bot for managing VPN subscriptions via Remnawave panel integration, featuring a web-based admin cabinet (cabinet) and public API (webapi). The system handles user subscriptions, payments (20+ gateways), referrals, promotional systems, contests, news, and support tickets. Architected with modular layers: Telegram bot handlers (aiogram), cabinet/web API routes (FastAPI), service-layer business logic, and SQLAlchemy ORM with Alembic migrations. Key entry points include main.py (application bootstrap), bot.py (Telegram setup), and unified_app.py (combined web server). Data flows involve Telegram interactions → handler processing → service execution → database CRUD operations, with webhook handlers for payment gateway callbacks and panel synchronization. External dependencies include Telegram Bot API, Remnawave API, PostgreSQL, Redis, SMTP, and numerous payment processors (Yookassa, CryptoBot, etc.). The codebase demonstrates strong engineering practices: clean separation of concerns, dependency injection, structured logging (structlog), and reusable patterns like event emitters, caching utilities, and retry queues. Payment processing abstraction shows particular skill with uniform CRUD interfaces across gateways. Active maintenance is evident through frequent releases, Dependabot integration, and responsive issue triage. While complexity arises from extensive feature set and payment integrations, the modular design contains coupling effectively. Technical drift is low due to current Python version (3.13), updated dependencies, and proactive schema migrations.
The LLM identified 5 files worth highlighting for reuse:
Implements a lightweight, framework-agnostic event emitter service for decoupled internal communication. Allows services to subscribe to and emit events without direct dependencies, promoting loose coupling and testability. Self-contained with only standard library and typing imports, making it highly reusable in any Python async application.
Provides a simple yet effective caching utility with time-to-live (TTL) support. Offers both decorator and class-based interfaces for caching function results or arbitrary values. Thread-safe for single-process use, zero external dependencies beyond standard library, and easily adaptable to different caching backends. Demonstrates clean separation of concerns and minimal coupling.
Delivers generic pagination utilities using Pydantic models for request/response validation. Includes helper functions to paginate query results and generate pagination metadata. Decoupled from specific ORMs and data sources, requiring only slicing and counting capabilities. Shows strong use of Python generics and type safety for reusable data access patterns.
Contains essential security utilities including secure password hashing (HMAC-SHA256), token generation, and request signature verification. All functions are self-contained, rely only on standard library, and follow cryptographic best practices. Represents a reusable security toolkit applicable to various projects needing basic authentication and data protection mechanisms.
Implements an asynchronous retry queue with exponential backoff and jitter for handling transient external API failures. Manages a queue of failed requests and automatically retries with increasing delays, reducing impact of temporary outages. Designed as a generic service adaptable to any external integration, showcasing resilience patterns and async queue management.