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.7.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.7-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: boundless_aiogram-1.0.7.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.7.tar.gz
Algorithm Hash digest
SHA256 e2a0f59c4823558e4c36afca9fa57abf54347fa7274c7c1f77e5fa661deaa7ba
MD5 faded08ed6b986f49ebdc718ba4bb942
BLAKE2b-256 323e0f13e1f3a8e74dbf56dd89eb29d142fbe09ff7c94e69eb1b52a242baefac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for boundless_aiogram-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 dfa485439f337fcabb16989e0cde8bb70c6461b7d1a806de309791e478ee2bac
MD5 337173ba6e6dd83f956ad78467b9cec1
BLAKE2b-256 3412b75ee54c77f1e72eb6c0e140d33e2219cd258f6f5c225c23e290b65b9167

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