Skip to content

benavlabs/FastAPI-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

477 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Benav Labs FastAPI boilerplate

Batteries-included FastAPI starter โ€” vertical-slice modules, swappable infrastructure, plugin-ready CLI.

Purple Rocket with FastAPI Logo as its window.

๐Ÿ“š Docs ยท ๐Ÿง  DeepWiki ยท ๐Ÿ’ฌ Discord

FastAPI PostgreSQL Redis DeepWiki

Features

  • โšก๏ธ Fully async FastAPI + SQLAlchemy 2.0
  • ๐Ÿงฑ Pydantic v2 models & validation
  • ๐Ÿ” Server-side sessions + CSRF; OAuth (Google wired, GitHub scaffolded); API keys
  • ๐Ÿ‘ฎ Rate limiter with per-tier, per-path rules
  • ๐Ÿงฐ FastCRUD for efficient CRUD & pagination
  • ๐Ÿง‘โ€๐Ÿ’ผ SQLAdmin-based admin panel (optional, env-toggled)
  • ๐Ÿšฆ Taskiq workers (Redis or RabbitMQ broker)
  • ๐ŸงŠ Redis or Memcached caching (@cache decorator + provider API)
  • ๐Ÿ›  Plugin-ready bp CLI โ€” generate compose files, audit env, mount third-party command/feature plugins
  • ๐Ÿณ Docker Compose for local / prod / nginx-fronted (generated by the CLI)

Why and When to use it

Perfect if you want:

  • A pragmatic starter with auth, CRUD, jobs, caching and rate-limits
  • Sensible defaults with the freedom to opt-out of modules
  • A foundation that grows โ€” vertical-slice modules + a plugin-aware CLI for code generators
  • Docs over boilerplate in this README โ€” depth lives on the docs site

Not a fit if you need a monorepo microservices scaffold โ€” see the docs for pointers.

What you get:

Building an AI SaaS? Skip even more setup with FastroAI โ€” our production-ready template with AI integration, payments, and frontend included.

Repo Layout

This is a uv workspace with two members. One venv at the root covers both.

fastapi-boilerplate/
โ”œโ”€โ”€ pyproject.toml          # workspace root (uv workspace metadata)
โ”œโ”€โ”€ backend/                # the deployable application
โ”‚   โ”œโ”€โ”€ src/                # interfaces/, infrastructure/, modules/
โ”‚   โ”œโ”€โ”€ pyproject.toml
โ”‚   โ””โ”€โ”€ Dockerfile          # multi-stage: dev / migrate / prod
โ””โ”€โ”€ cli/                    # `bp` โ€” developer/operator tool (never ships in prod)
    โ””โ”€โ”€ src/cli/

Quickstart

git clone https://github.com/<you>/FastAPI-boilerplate
cd FastAPI-boilerplate
uv sync --all-packages --all-extras           # one venv at the root, both members installed

Generate a compose file for the deployment shape you want:

uv run bp deploy generate local               # hot-reload dev stack
# or: uv run bp deploy generate prod          # production single-host
# or: uv run bp deploy generate nginx         # production behind nginx

Configure your env (the CLI helps with secrets and validation):

cp backend/.env.example backend/.env
uv run bp env gen-secret                      # print a fresh SECRET_KEY
uv run bp env validate                        # audit .env against the production validator

Bring it up:

docker compose up --build
# โ†’ http://127.0.0.1:8000  (Swagger at /docs)

Without Docker (Postgres + Redis required locally):

cd backend
uv run alembic upgrade head
uv run python -m scripts.setup_initial_data   # creates the first admin user + default tier
uv run fastapi dev src/interfaces/main.py     # API
uv run taskiq worker infrastructure.taskiq.worker:default_broker  # in a second terminal

Full setup, env-var reference, and per-environment deployment guides live in the docs.

Common tasks

# generate a fresh production-ready compose file
uv run bp deploy generate prod --workers 8

# audit your .env against the production security validator
uv run bp env validate

# run Alembic migrations
cd backend && uv run alembic revision --autogenerate -m "<msg>" && uv run alembic upgrade head

# run tests
cd backend && uv run pytest

# install bp as a global tool (optional)
uv tool install --editable ./cli

More examples (superuser creation, tiers, rate limits, admin usage, plugin authoring) in the docs.

Contributing

Read contributing.

References

This project was inspired by a few projects, it's based on them with things changed to the way I like (and pydantic, sqlalchemy updated)

License

MIT

Contact

Benav Labs โ€“ benav.io, discord server


Powered by Benav Labs - benav.io

Packages

 
 
 

Contributors

Languages