Skip to main content

A modern, production-ready framework for building scalable Telegram bots with Aiogram 3.x

Project description

Boundless-Aiogram ๐Ÿš€

Boundless-Aiogram is a modern, production-ready framework/template for building scalable Telegram bots with Aiogram 3.x. It provides a clean, structured architecture with built-in support for async/await, database migrations, FSM, and more.

โœจ Features

  • โšก Modern async/await syntax with Aiogram 3.x
  • ๐Ÿ—„ SQLAlchemy async ORM for database operations
  • ๐Ÿ”„ Alembic migrations for database versioning
  • ๐Ÿ“‚ Modular architecture with organized handlers, middlewares, and filters
  • ๐ŸŽฏ FSM (Finite State Machine) support for conversation flows
  • ๐Ÿ›ก๏ธ Built-in middleware for authentication and rate limiting
  • โš™๏ธ Configuration management with environment variables
  • ๐Ÿ“ Comprehensive logging system with file rotation
  • ๐Ÿงช Test-ready structure with dedicated test directory
  • ๐ŸŽจ Modern CLI with beautiful output and progress indicators

๐Ÿš€ Installation

Install Boundless-Aiogram via pip:

pip install boundless-aiogram

๐Ÿ“ฆ Quick Start

Create a new bot project with a single command:

boundless new mybot

Navigate to your project and set up:

cd mybot
cp .env.example .env
# Edit .env and add your BOT_TOKEN
python main.py

That's it! Your bot is now running.


๐Ÿ—๏ธ Project Structure

Boundless-Aiogram generates a clean, organized project structure:

mybot/
โ”œโ”€โ”€ bot/
โ”‚   โ”œโ”€โ”€ handlers/          # Message and callback handlers
โ”‚   โ”‚   โ”œโ”€โ”€ commands.py    # Command handlers (/start, /help)
โ”‚   โ”‚   โ”œโ”€โ”€ messages.py    # Text message handlers
โ”‚   โ”‚   โ””โ”€โ”€ callbacks.py   # Callback query handlers
โ”‚   โ”œโ”€โ”€ middlewares/       # Custom middlewares
โ”‚   โ”‚   โ”œโ”€โ”€ auth.py        # Authentication middleware
โ”‚   โ”‚   โ””โ”€โ”€ throttling.py  # Rate limiting middleware
โ”‚   โ”œโ”€โ”€ filters/           # Custom filters
โ”‚   โ”‚   โ””โ”€โ”€ custom.py      # Custom filter examples
โ”‚   โ”œโ”€โ”€ keyboards/         # Keyboard layouts
โ”‚   โ”‚   โ”œโ”€โ”€ inline.py      # Inline keyboards
โ”‚   โ”‚   โ””โ”€โ”€ reply.py       # Reply keyboards
โ”‚   โ””โ”€โ”€ states/            # FSM states
โ”‚       โ””โ”€โ”€ user.py        # User conversation states
โ”œโ”€โ”€ database/
โ”‚   โ”œโ”€โ”€ models/            # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ base.py        # Base model class
โ”‚   โ”‚   โ””โ”€โ”€ user.py        # User model
โ”‚   โ””โ”€โ”€ database.py        # Database configuration
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ””โ”€โ”€ logging.py         # Logging setup
โ”œโ”€โ”€ utils/                 # Helper functions
โ”‚   โ””โ”€โ”€ helpers.py         # Utility functions
โ”œโ”€โ”€ migrations/            # Alembic database migrations
โ”œโ”€โ”€ tests/                 # Unit tests
โ”œโ”€โ”€ logs/                  # Log files
โ”œโ”€โ”€ main.py                # Bot entry point
โ”œโ”€โ”€ .env.example           # Example environment variables
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿ”ง Configuration

Configure your bot using environment variables in .env:

# Telegram Bot Configuration
BOT_TOKEN=your_bot_token_here

# Database Configuration
DATABASE_URL=sqlite+aiosqlite:///./bot_database.db

# Optional: PostgreSQL
# DATABASE_URL=postgresql+asyncpg://user:password@localhost/dbname

# Admin User IDs (comma-separated)
ADMIN_IDS=123456789,987654321

๐Ÿ“š Usage Examples

Adding a New Command Handler

Create or edit bot/handlers/commands.py:

from aiogram import Router
from aiogram.filters import Command
from aiogram.types import Message

router = Router()

@router.message(Command("hello"))
async def cmd_hello(message: Message):
    await message.answer(f"Hello, {message.from_user.first_name}!")

Creating Custom Middleware

Edit bot/middlewares/auth.py:

from typing import Callable, Dict, Any, Awaitable
from aiogram import BaseMiddleware
from aiogram.types import Message

class AuthMiddleware(BaseMiddleware):
    async def __call__(
        self,
        handler: Callable[[Message, Dict[str, Any]], Awaitable[Any]],
        event: Message,
        data: Dict[str, Any]
    ) -> Any:
        # Your authentication logic here
        user_id = event.from_user.id
        # Check if user is authorized
        return await handler(event, data)

Using FSM States

Define states in bot/states/user.py:

from aiogram.fsm.state import State, StatesGroup

class RegistrationStates(StatesGroup):
    waiting_for_name = State()
    waiting_for_age = State()
    waiting_for_email = State()

Use in handlers:

from aiogram.fsm.context import FSMContext
from bot.states.user import RegistrationStates

@router.message(Command("register"))
async def start_registration(message: Message, state: FSMContext):
    await state.set_state(RegistrationStates.waiting_for_name)
    await message.answer("What's your name?")

@router.message(RegistrationStates.waiting_for_name)
async def process_name(message: Message, state: FSMContext):
    await state.update_data(name=message.text)
    await state.set_state(RegistrationStates.waiting_for_age)
    await message.answer("How old are you?")

๐Ÿ—„๏ธ Database Management

Creating Migrations

After modifying your models:

alembic revision --autogenerate -m "Added new field"

Applying Migrations

alembic upgrade head

Rolling Back

alembic downgrade -1

๐Ÿงช Testing

Run tests using pytest:

pytest tests/

๐Ÿ“– CLI Commands

boundless new <project_name>    # Create a new bot project
boundless help                  # Show help information

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


๐Ÿ“„ License

This project is licensed under the MIT License.


๐Ÿ”— Links


๐Ÿ’ก Support

If you find this project helpful, consider giving it a โญ on GitHub!

For issues and feature requests, please use the GitHub issue tracker.


Built with โค๏ธ for the Telegram bot development community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boundless_aiogram-1.0.5.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boundless_aiogram-1.0.5-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file boundless_aiogram-1.0.5.tar.gz.

File metadata

  • Download URL: boundless_aiogram-1.0.5.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for boundless_aiogram-1.0.5.tar.gz
Algorithm Hash digest
SHA256 adf19f50425461e115b0c61d855dbddf1d84715373176b8c816918969f8f3c81
MD5 985d6480172c1ab942921eb2eb1dfe29
BLAKE2b-256 0bc3a6fd99f4a7dcbc09f62f06895951e97d673c6fe64bf947f5dffd188bdfe4

See more details on using hashes here.

File details

Details for the file boundless_aiogram-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for boundless_aiogram-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 da2e07eaee8c0e1054d123d5f480601d62eab793fcabb2e47be3135f9b8927d1
MD5 4c06212b8c1d016872fb8b62bc39bfbb
BLAKE2b-256 8585b78a0b63b3b399b52ddd3841f4fd6b3c5d0e28182e3bda73292074a3bf9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page