https://github.com/timnekk/copier-telegram-bot
π Copier Template for Telegram Bot using Aiogram, Postgres, Redis, Docker, Coolify Ready
https://github.com/timnekk/copier-telegram-bot
aiogram copier-template database docker docker-compose poerty postgresql pydantic python redis ruff sqlalchemy telegram telegram-bot telegrambot template uv
Last synced: 5 months ago
JSON representation
π Copier Template for Telegram Bot using Aiogram, Postgres, Redis, Docker, Coolify Ready
- Host: GitHub
- URL: https://github.com/timnekk/copier-telegram-bot
- Owner: TimNekk
- License: apache-2.0
- Created: 2025-01-19T12:33:58.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-03-08T11:25:22.000Z (7 months ago)
- Last Synced: 2025-03-08T12:24:37.213Z (7 months ago)
- Topics: aiogram, copier-template, database, docker, docker-compose, poerty, postgresql, pydantic, python, redis, ruff, sqlalchemy, telegram, telegram-bot, telegrambot, template, uv
- Language: Jinja
- Homepage:
- Size: 119 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## π Quickstart
Ensure [uv](https://docs.astral.sh/uv/getting-started/installation/) is installed, then create a new Telegram bot project with:
```bash
uvx --with copier-templates-extensions copier copy --trust -r HEAD gh:TimNekk/copier-telegram-bot ~/path/to/your/project
```## β¨ Features
Built with [Copier](https://copier.readthedocs.io/), this template lets you toggle features during setup - choose what you need and generate files instantly! Ready for [Docker](https://www.docker.com/) π³ and [Coolify](https://coolify.io/) βοΈ deployment.
#### Core Infrastructure
- [x] [**`Docker Compose`**](https://docs.docker.com/compose/) π³ Launch bot + services with one command
- [x] [**`Python 3.9β3.13`**](https://www.python.org/) π Choose your Python version easily
- [x] [**`uv`**](https://docs.astral.sh/uv/) π Fast dependency management powered by Rust
- [x] [**`Poetry`**](https://python-poetry.org/) π¦ Manage dependencies safely with virtual environments
- [x] [**`pip`**](https://pip.pypa.io/) π Classic Python package installer#### Telegram Bot Framework
- [x] [**`Aiogram`**](https://docs.aiogram.dev/) β‘ Modern async bot framework with state management
- [x] [**`Aiogram Dialog`**](https://github.com/Tishka17/aiogram_dialog) πΌοΈ Create menus and interactive interfaces
- [x] [**`Redis`**](https://redis.io/) β€οΈ Keep bot data safe between restarts#### Database & ORM
- [x] [**`PostgreSQL`**](https://www.postgresql.org/) π Powerful database for complex projects
- [x] [**`SQLAlchemy`**](https://www.sqlalchemy.org/) π οΈ Work with databases using Python code
- [x] [**`Alembic`**](https://alembic.sqlalchemy.org/) β³ Track and apply database changes easily#### Middlewares
- [x] [**`Dependency Injection`**](https://docs.aiogram.dev/en/latest/dispatcher/middlewares.html) π Share tools/data across bot handlers
- [x] [**`Throttling`**](https://docs.aiogram.dev/en/latest/dispatcher/middlewares.html) π Stop spam with automatic speed limits
- [x] [**`Database Sessions`**](https://docs.sqlalchemy.org/en/20/orm/session_basics.html) β»οΈ Auto-manage database connections
- [x] [**`Loguru`**](https://github.com/Delgan/loguru) π Simple logging with colors and fun#### Tooling
- [x] [**`Pydantic Settings`**](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) β Safe config management with type checking
- [x] [**`Dynaconf`**](https://www.dynaconf.com/) βοΈ Configs for dev/test/prod environments
- [x] [**`Ruff`**](https://docs.astral.sh/ruff/) πͺΆ Super-fast code linting and cleanup
- [x] [**`Justfile`**](https://just.systems/) πͺ Short commands for complex tasks
- [x] [**`Cache Decorator`**](https://pypi.org/project/orjson/) β‘ Speed up functions with Redis caching## π Project Structure
The **fully-featured** generated project can be found in the [example/](./example) directory.
Below is the folder structure of the generated project:
```sh
.
βββ bot # Main directory for the bot's source code
β βββ cache # Contains caching-related modules
β β βββ redis.py # Module for Redis-based caching functionality
β β βββ serialization.py # Handles serialization and deserialization for cached data
β β
β βββ core # Core components of the bot
β β βββ loader.py # Initializes and loads core components of the bot
β β βββ settings.py # Configuration and settings for the bot
β β
β βββ database # Database-related modules and models
β β βββ models # Directory for database model definitions
β β β βββ base.py # Base class for database models
β β βββ database.py # Database connection
β β
β βββ dialogs # Dialog flow and interaction logic
β β βββ example # Example implementation of dialogs
β β βββ dialogs.py # Defines dialogs
β β βββ getters.py # Retrieves data required for dialogs
β β βββ handlers.py # Handles user interactions within dialogs
β β
β βββ filters/ # Custom filters for handling specific bot commands or messages
β β
β βββ handlers # General handlers for bot events
β β βββ start.py # Handler for the /start command
β β
β βββ keyboards # Defines inline and reply keyboards for user interaction
β β βββ inline # Inline keyboards
β β βββ default_commands.py # Defualt commands setup
β β
β βββ middleware # Middleware modules to extend bot behavior
β β βββ database.py # Middleware to manage database interactions during eventxs
β β βββ dependency.py # Dependency injection middleware for shared resources
β β βββ logger.py # Middleware to log events
β β βββ throttling.py # Middleware to handle rate-limiting of requests
β β
β βββ services/ # Auxiliary services with business logic
β β
β βββ __main__.py # Entry point to run the bot application
β βββ states.py # FMS states
β
βββ migrations # Database migration files (managed by Alembic)
β βββ versions/ # Directory containing individual migration scripts
β βββ env.py # Alembic environment configuration file
β βββ script.py.mako # Template for generating new migration scripts
β
βββ .dockerignore # Specifies files and directories to ignore in Docker builds
βββ .gitignore # Specifies files and directories to ignore in Git version control
βββ .python-version # Python version specification file for version managers like pyenv
βββ .env # Environment variable settings file
βββ .template.env # Template file for environment variables
βββ alembic.ini # Alembic configuration file for database migrations
βββ compose.yaml # Docker Compose configuration file for multi-container setups
βββ Dockerfile # Instructions to build a Docker image for the application
βββ entrypoint.sh # Script executed as the container's entry point
βββ justfile # Task runner configuration file (for `just` command automation)
βββ pyproject.toml # Python project metadata and dependencies configuration (PEP-518)
βββ README.md # Documentation readme file describing the project
βββ uv.lock # Lock file generated by a dependency manager
```## π Usage
Before using the **Copier Telegram Bot** template, ensure you have the following installed:
- **Copier**: Refer to the [installation guide](https://copier.readthedocs.io/en/latest/#installation).
- **Copier Templates Extensions**: Refer to the [repository](https://github.com/copier-org/copier-templates-extensions?tab=readme-ov-file#installation) for installation instructions.Once these prerequisites are installed, you're ready to use the template!
```bash
copier copy --trust -r HEAD gh:TimNekk/copier-telegram-bot ~/path/to/your/project
```Copier will ask you a lot of questions. Answer them to properly generate the template.
## πΊοΈ Roadmap
Help shape the future! Planned improvements:
- [ ] [**`Bot Internationalization`**](https://docs.aiogram.dev/en/latest/dispatcher/i18n.html) π Support multiple languages for global audiences
- [ ] [**`Prompts Internationalization`**](https://github.com/aiogram/aiogram) π Translate copier prompts
- [ ] [**`Dependabot`**](https://github.com/dependabot) π€ Add dependencies auto-update to generated project for security and freshness
- [ ] [**`Testing`**](https://docs.pytest.org/) β Add testing framework
- [ ] [**`Flake8`**](https://flake8.pycqa.org/) / [**`wemake`**](https://wemake-python-styleguide.readthedocs.io/en/latest/) π§Ή Alternative strict linting for code quality fans*Got ideas? Star β the repo or open an issue to collaborate!* π
## β Star History
## π· Contributing
- For a small change, just send a PR.
- For bigger changes open an issue for discussion before sending a PR.
- PR should have:
- Test case
- Documentation
- Example (If it makes sense)## π License
Distributed under the Apache License 2.0. See [`LICENSE`](./LICENSE.md) for more information.