A modern, production-ready template for creating Telegram bots using Aiogram π
This template includes essential setup for Docker π³, PostgreSQL π, and Alembic for database migrations, making it easy to bootstrap your next Telegram bot project with best practices and clean architecture.
- π€ Aiogram Framework: A modern and efficient async framework for Telegram bots
- ποΈ Database Integration: Pre-configured with PostgreSQL and SQLAlchemy ORM
- π Database Migrations: Integrated with Alembic for schema migrations
- π³ Dockerized Setup: Docker Compose configuration for easy deployment
- π§ Environment Variables: Centralized configuration using a
.env
file - π Structured Logging: Loguru-based logging with file rotation
- π‘οΈ Anti-Flood Protection: Built-in middleware to prevent spam
- π₯ User Management: Automatic user tracking and activity monitoring
- π Admin Panel: Built-in admin commands and user management
- π― Clean Architecture: Modular design with separation of concerns
jessy/
βββ π app/ # Main application code
β βββ π€ bot.py # Bot entry point and dispatcher setup
β βββ π buttons/ # Telegram keyboard/button definitions
β βββ βοΈ config/ # Configuration and environment loading
β βββ ποΈ database/ # Database models, access, and admin/user logic
β βββ π handlers/ # Message handlers for users and admins
β βββ π middlewares/ # Custom aiogram middlewares
β βββ π οΈ utils/ # Filters, states, and utility code
βββ π migrations/ # Alembic migration scripts
βββ π logs/ # Log files (created at runtime)
βββ π docs/ # Documentation
β βββ π CODE.md # Code principles and project structure
βββ π main.py # Simple hello-world entry (for testing)
βββ π run.sh # Shell script to run the bot
βββ π requirements.txt # Python dependencies
βββ βοΈ pyproject.toml # Project metadata and dependencies
βββ π³ Dockerfile # Docker build instructions
βββ π docker-compose.yml # Docker Compose setup for bot and DB
βββ π alembic.ini # Alembic configuration
βββ π README.md # Main project documentation
βββ π LICENSE # License file
π Want to learn more about the code structure? Check out our π CODE.md for detailed code principles and architecture guidelines!
- π Python 3.10+
- π³ Docker & Docker Compose
- π PostgreSQL (if running locally without Docker)
git clone https://github.com/right-git/jessy.git
cd jessy
Create a .env
file in the project root with your configuration:
# Bot Configuration
BOT_TOKEN=your_bot_token_here
ADMINS_ID=123456789,987654321
# Database Configuration
DATABASE_URL_ASYNC=postgresql+asyncpg://user:password@localhost:5432/dbname
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=your_db_name
DB_PORT=5432
Using Docker Compose (recommended):
docker-compose up --build
This will:
- ποΈ Build the
bot
service - π Spin up a PostgreSQL database
- π€ Run the Telegram bot automatically
The bot starts automatically when the bot
container is running.
To view logs:
docker-compose logs -f bot
docker-compose down
If you prefer running the bot locally:
- π Set up PostgreSQL database and configure
.env
file - π¦ Install dependencies:
or using
pip install -r requirements.txt
uv
(faster):oruv sync
uv add -r requirements.txt
- π Apply database migrations:
alembic upgrade head
- π Start the bot:
bash run.sh
This template is designed for easy deployment via Docker. You can use platforms like:
- βοΈ Heroku
- βοΈ AWS
- βοΈ DigitalOcean
- βοΈ Railway
- βοΈ Render
We welcome contributions! Here's how you can help:
- π΄ Fork the repository
- πΏ Create a feature branch:
git checkout -b feature/your-feature-name
- πΎ Commit your changes:
git commit -m "β¨ Add your commit message"
- π€ Push to the branch:
git push origin feature/your-feature-name
- π Create a Pull Request
- π Read our CODE.md for coding standards
- π§ͺ Write tests for new features
- π Update documentation when needed
- π¨ Follow the existing code style
This project is licensed under the MIT License. See the LICENSE
file for details.
- π Aiogram Documentation
- π³ Docker Documentation
- π Alembic Documentation
- π Python Documentation
Need help? Here's how to get support:
- π Bug Reports: Open an issue
- π‘ Feature Requests: Create a feature request issue
- π Documentation: Check our CODE.md for detailed guides
- π¬ Discussions: Use GitHub Discussions for questions
If this project helped you, please give it a star! β
Made with β€οΈ for the Telegram Bot Community