A modern Telegram bot built with Python, FastAPI, aiogram, and PostgreSQL. This project is designed both as a learning project (to explore professional-grade software practices) and as a production-ready system to power community interactions.
- Telegram bot built with aiogram
- REST API with FastAPI
- PostgreSQL database with async SQLAlchemy
- Database migrations via Alembic
- Dockerized development setup
- Strict linting, type-checking, and testing culture
- Secure, scalable, open-source mindset
JDINBot is built with a modern, scalable architecture designed for high performance and maintainability:
- Python 3.13 with full async/await support
- FastAPI for high-performance REST API endpoints with automatic OpenAPI documentation
- Aiogram 3.x for modern Telegram Bot API integration
- PostgreSQL 16 with async support via asyncpg for persistent storage
- SQLAlchemy 2.0 with async ORM capabilities
- Poetry for dependency management and packaging
- Docker with multi-stage builds for optimized containerization
- Docker Compose for local development and production deployments
- VS Code DevContainers for consistent development environments
- Alembic for database migrations with autogenerate support
- Structlog for structured, production-ready logging
- Prometheus integration for metrics and monitoring
- Ruff for ultra-fast linting and formatting
- Mypy for strict static type checking
- Black for consistent code formatting
- Pytest with async support for comprehensive testing
- Bandit for security scanning
- Pre-commit hooks for quality control
The project follows a modular src layout with clear separation of concerns:
src/app/core/- Configuration and foundational utilitiessrc/app/api/- FastAPI routes and REST endpointssrc/app/bot/- Telegram bot handlers and middlewaresrc/app/db/- Database models and async session managementsrc/app/services/- Business logic and external integrationssrc/app/utils/- Shared utilities and helpers
This architecture ensures the application is:
- Highly scalable with async-first design
- Type-safe with comprehensive static analysis
- Well-tested with extensive test coverage
- Production-ready with proper logging and monitoring
- Developer-friendly with consistent tooling and environments
- Secure with built-in security scanning and best practices
- Copy configuration:
cp .env.example .envand fill values (TELEGRAM_TOKEN, WEBHOOK_SECRET_PATH, ENV, ADMIN_CHAT_ID, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD) - Start dev environment (hot reload):
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build - Visit the REST API at
http://localhost:8000and your bot in Telegram.
- Build & run production images:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d - Apply database migrations:
docker compose exec bot alembic upgrade head
This project includes a DevContainer configuration for VS Code. To use it:
- Install the Dev Containers extension in VS Code
- Open the command palette (Ctrl+Shift+P) and select "Dev Containers: Reopen in Container"
- The container will build and setup the development environment automatically
Migrations are handled via Alembic. To create and apply migrations:
# Create a new migration
docker compose exec bot alembic revision --autogenerate -m "description"
# Apply migrations
docker compose exec bot alembic upgrade head- See
CONTRIBUTING.mdfor details. TL;DR: - Tests required for new features.
- Document public API or bot commands in
docs/. - Use small, focused PRs.
We welcome contributions! Please:
- Follow PEP8 style guide.
-
Create an issue before major changes.
-
Open a feature branch
feature/short-description -
Run formatters & linters before pushing:
black . ruff check . mypy .
-Create a Pull Request referencing the issue; request 1+ reviews.
-
Secrets must be kept in .env files or environment variables
-
Do not hardcode API keys or credentials
-
Use least privilege when deploying in production
-
Report security issues privately following
SECURITY.md.
- If you get permission issues when mounting code in dev, set
UID/GIDenv vars (e.g.export UID=$(id -u) GID=$(id -g)).
- Use GitHub Issues for bugs & feature requests.
- Use Discussions (or a Telegram/Matrix room) for design conversations.
- Maintain a
MAINTAINERS.mdand aCODEOWNERSfile so community knows who to ping for reviews.
JDINBot is designed as a layered system: minimal features today, professional scaffolding for growth tomorrow.
-
M1 – Local MVP (Now)
Run the bot locally with Docker Compose.
Features:/startcommand,/balance, persistent Postgres storage. -
M2 – Core Features (Next)
Implement user economy:/transfer, admin commands (/promote,/ban).
Add REST API endpoints (/health,/users). -
M3 – Quality & Tooling (Soon)
Introduce automated linting, type-checking, and tests.
Align dev and prod environments with Docker. -
M4 – Scaling Up (Future)
Enable CI/CD pipelines, monitoring with Prometheus, contribution guidelines.
Secure and professionalize infrastructure for multi-developer collaboration.
This project is open-source under the MIT License.