How devvsima/aiogram-peewee-template works
Project Type and Purpose
• This is a Telegram Bot service built with Aiogram 3.
• It uses Peewee as the ORM, supports i18n (multiple locales), Redis for caching/session storage, and PostgreSQL (or SQLite) for persistent storage.
• Its purpose is to respond to user commands via Telegram, handle admin operations, manage user sessions, translate messages, and store user data.
File Structure
Top‑level
• main.py – bootstrap and run the bot
• loader.py – load environment, configuration, and initialize subsystems
• requirements.txt / Dockerfile / .env.dist – deployment and dependency manifests
app/
• filters/ – custom Aiogram filters (e.g., message type, user roles)
• handlers/ – request handlers subdivided into admin and user flows; bot_utils and msg_text helper modules
• keyboards/ – default and inline keyboard generators
• middlewares/ – Aiogram middlewares for admin checks, i18n, session/state initialization
• others/ – shared constants (commands, FSM states)
• routers.py – assemble Aiogram routers from handlers and middlewares
data/
• config.py – configuration loader (dotenv)
• locales/ – gettext files (.po/.mo) for supported languages
database/
• .py – database connection factory (PostgreSQL/SQLite)
• models/ – Peewee model definitions (User model)
• service/ – data‐access layer (CRUD wrappers for models)
utils/ – shared utilities (base62 encoder, custom logging)
Pulling Insights from the README
• Highlights the stack (Aiogram 3, i18n, Redis, Peewee, PostgreSQL/SQLite).
• Describes environment variables for Redis, Postgres, Bot token, and Admin IDs.
Core Components
a. Telemetry & External Interfaces
• Telegram Bot API (via HTTPS long‐polling or webhooks)
• Redis Server (cache, sessions)
• Database Server (PostgreSQL or SQLite)
b. Application Layers
1. Loader / Config – reads .env, sets up Redis and DB connections
2. Router – Aiogram Dispatcher + Routers + Middlewares
3. Filters & Middlewares – pre‐process updates (auth, i18n, states)
4. Handlers – business logic (admin flows, user flows, help, start, invite, language switch)
5. Service Layer – database service modules wrap Peewee models
6. Utilities – logging, base62 encoding, message templating
c. Data Stores
• Redis – per‑user/session state, caching
• PostgreSQL/SQLite – persistent user records
• gettext locales on disk – translation files
d. External Flows
• Admins interact via Telegram → Bot → Admin Handlers → Service → DB
• Users interact → Bot → User Handlers → Service → DB
• Middlewares inject i18n context and guard routes
Architectural Patterns & Principles
• Layered architecture (Configuration → Routing → Processing → Data‐Access)
• Separation of concerns (handlers vs. service vs. models vs. utils)
• Dependency injection in loader: centralized init of Redis, DB, i18n, Dispatcher
• FSM pattern for user state management via Aiogram