The high-performance, drift-ready boilerplate for FastAPI.
Hatchback is a powerful CLI tool designed to bootstrap and manage production-ready FastAPI applications. It comes pre-loaded with best practices, security hardening, and a modular architecture that scales.
- π Production Ready: SQLAlchemy 2.0, Pydantic v2, and Alembic pre-configured.
- π‘οΈ Secure by Default: Rate limiting (SlowAPI), hardened Auth (JWT), secure secret generation, and non-root Docker containers.
- β‘ Blazing Fast: Optional
uvsupport for lightning-fast dependency management. - ποΈ Clean Architecture: Service-Repository pattern for maintainable code.
- β
Testing Ready: Integrated
pytestsetup withhbk test. - π³ Dockerized: Ready-to-deploy
docker-composesetup with healthchecks. - π€ AI-Powered: Built-in Agent Skills for GitHub Copilot and VS Code agent mode.
- ποΈ Drift Mode: A CLI that drives as good as it looks.
pip install hatchbackTip: Use
hbkas a shortcut forhatchbackβ all commands work with either. For example,hbk make productis equivalent tohatchback make product.
hbk init my_project_nameYou will be prompted for:
- Database Name
- Docker inclusion
uvusage (if installed, for faster setup)
Options:
--use-uv: Force usage ofuvfor virtualenv creation.--no-docker: Skip Docker file generation.
Before hitting the gas, ensure your database is running and the schema is initialized.
1. Start Database:
cd my_project_name
docker-compose up -d db(Or configure a local Postgres instance in .env)
2. Initialize Database: Create and apply the first migration for the built-in models (User, Tenant).
hbk migrate create -m "initial_setup"
hbk migrate apply3. Run Server: Start the development server with hot-reloading.
hbk runπ Success! Your API is now live.
- API Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Don't write boilerplate. Generate Models, Schemas, Repositories, Services, and Routes in one go. Hatchback automatically registers your new routes and services, so they are ready to use immediately.
hbk make productChanged your mind? Remove a scaffolded resource and clean up all imports automatically.
hbk remove product # asks for confirmation
hbk remove product --force # skips confirmationWrapper around Alembic to keep your database in sync.
# Create a migration
hbk migrate create -m "add products table"
# Apply migrations
hbk migrate apply
# Rollback the last migration
hbk migrate downgrade
# Rollback multiple steps
hbk migrate downgrade -r -2
# Rollback everything
hbk migrate downgrade -r basePopulate your database with initial data (default tenant and admin user).
hbk seedHave an existing database? Hatchback can inspect it and generate your entire project architecture automatically.
# Output models only to a file
hbk inspect --url postgresql://user:pass@localhost:5432/mydb --output app/models/legacy.py
# Full Scaffold Mode (Recommended)
# Generates Models, Services, Repositories, Schemas, and Routes for every table
hbk inspect --scaffold --url postgresql://user:pass@localhost:5432/mydbAfter upgrading Hatchback, sync the latest agent skills and infrastructure files into your project.
pip install --upgrade hatchback
hbk upgradeThis syncs new files (like agent skills) without touching your Docker config, user code, or environment files.
Hatchback projects come with pytest configured.
hbk testHatchback follows a Service-Repository pattern to keep your code modular and testable.
- Routes (
app/routes/): Handle HTTP requests/responses and dependency injection. They delegate business logic to Services. - Services (
app/services/): Contain the business logic. They orchestrate data operations using Repositories. - Repositories (
app/repositories/): Handle direct database interactions (CRUD). They abstract the SQL/ORM details from the rest of the app. - Models (
app/models/): SQLAlchemy database definitions. - Schemas (
app/schemas/): Pydantic validation and serialization schemas.
Hatchback projects ship with built-in Agent Skills in .github/skills/:
hatchbackβ Full project overview, CLI commands, database config, auth system, and conventions.clean-architectureβ Layered architecture rules, code examples, anti-patterns, and testing patterns.
These help AI coding assistants (GitHub Copilot, VS Code agent mode) understand your project structure and follow established patterns automatically.
my_project/
βββ .github/
β βββ skills/ # Agent Skills for AI assistants
βββ app/
β βββ config/ # Database, Security, Limiter config
β βββ models/ # SQLAlchemy Database Models
β βββ schemas/ # Pydantic Data Schemas
β βββ repositories/ # Data Access Layer (CRUD)
β βββ services/ # Business Logic
β βββ routes/ # API Endpoints
β βββ dependencies.py
β βββ main.py
βββ alembic/ # Database Migrations
βββ tests/ # Pytest Suite
βββ docker-compose.yml
βββ requirements.txt
- Rate Limiting: Built-in protection against brute-force attacks.
- Secure Headers: Trusted host middleware configuration.
- Password Hashing: Argon2/Bcrypt support via Passlib.
- Docker Security: Runs as a non-root user to prevent container breakout.
| Command | Description |
|---|---|
hbk init <name> |
Initialize a new project |
hbk run |
Start dev server with hot-reload |
hbk make <resource> |
Scaffold a new resource |
hbk remove <resource> |
Remove a resource and clean up imports |
hbk migrate create -m "msg" |
Create a new Alembic migration |
hbk migrate apply |
Apply pending migrations |
hbk migrate downgrade |
Rollback last migration (-r -2 for multiple) |
hbk seed |
Seed database with initial data |
hbk inspect --url <db_url> |
Inspect existing DB and generate models |
hbk upgrade |
Sync latest skills and infra files |
hbk test |
Run the test suite |
Built with π and ποΈ by Ignacio Bares(nachovoss) and the Hatchback Team.
Hatchback is an open-source project. If you'd like to support the development, you can donate via Bitcoin:
BTC Address: \bc1q9fznxyf0skq8ux5ysrggw3veuqf92xtr25cccq\
Thank you for your support!
