A CLI to generate a FastAPI + Alembic + SQLAlchemy boilerplate
Project description
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.
โจ Features
- ๐ 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.
๐ฆ Installation
pip install hatchback
Tip: Use
hbkas a shortcut forhatchbackโ all commands work with either. For example,hbk make productis equivalent tohatchback make product.
๐ Quick Start
1. Initialize a new project
hbk init my_project_name
You 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.
2. Start the Engine
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 apply
3. 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
3. Scaffold Resources
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 product
4. Remove Resources
Changed your mind? Remove a scaffolded resource and clean up all imports automatically.
hbk remove product # asks for confirmation
hbk remove product --force # skips confirmation
5. Manage Migrations
Wrapper around Alembic to keep your database in sync.
# Create a migration
hbk migrate create -m "add products table"
# Apply migrations
hbk migrate apply
6. Seed Data
Populate your database with initial data (default tenant and admin user).
hbk seed
7. Import Existing Database
Have 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/mydb
8. Upgrade Existing Projects
After upgrading Hatchback, sync the latest agent skills and infrastructure files into your project.
pip install --upgrade hatchback
hbk upgrade
This syncs new files (like agent skills) without touching your Docker config, user code, or environment files.
9. Run Tests
Hatchback projects come with pytest configured.
hbk test
๐๏ธ Architecture Explained
Hatchback 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.
๐ค Agent Skills
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.
๐ Project Structure
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
๐ก๏ธ Security Features
- 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.
๐ง CLI Reference
| 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 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatchback-0.1.9.tar.gz.
File metadata
- Download URL: hatchback-0.1.9.tar.gz
- Upload date:
- Size: 48.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ad99d1ec1d3754d889a6a99bf09a9960c803e2115e4929d6dcb19850fd75428
|
|
| MD5 |
f3c5152f6dd4742d8eab362de9a87b89
|
|
| BLAKE2b-256 |
f8a2ebbff237b80a5e9450eed87e186f78303295ed87038805caa923f2403c37
|
Provenance
The following attestation bundles were made for hatchback-0.1.9.tar.gz:
Publisher:
publish.yml on nachovoss/hatchback
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatchback-0.1.9.tar.gz -
Subject digest:
3ad99d1ec1d3754d889a6a99bf09a9960c803e2115e4929d6dcb19850fd75428 - Sigstore transparency entry: 937072899
- Sigstore integration time:
-
Permalink:
nachovoss/hatchback@3e835727ac5c7bc8a2eebfa619db33d08ecb1358 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/nachovoss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e835727ac5c7bc8a2eebfa619db33d08ecb1358 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hatchback-0.1.9-py3-none-any.whl.
File metadata
- Download URL: hatchback-0.1.9-py3-none-any.whl
- Upload date:
- Size: 64.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
662c264568498ac916172a2dca24cae03e89f55b6efe0d3de0469241d4397ed5
|
|
| MD5 |
39d3b74b3329c06e7d0344cff6ab4c20
|
|
| BLAKE2b-256 |
fe5c07844e38e18ba7c8461994fe1100d0b8f4d1041d16d213ab548879e96d3f
|
Provenance
The following attestation bundles were made for hatchback-0.1.9-py3-none-any.whl:
Publisher:
publish.yml on nachovoss/hatchback
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatchback-0.1.9-py3-none-any.whl -
Subject digest:
662c264568498ac916172a2dca24cae03e89f55b6efe0d3de0469241d4397ed5 - Sigstore transparency entry: 937072905
- Sigstore integration time:
-
Permalink:
nachovoss/hatchback@3e835727ac5c7bc8a2eebfa619db33d08ecb1358 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/nachovoss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e835727ac5c7bc8a2eebfa619db33d08ecb1358 -
Trigger Event:
release
-
Statement type: