Skip to content

Commit b86803e

Browse files
committed
docs: full pass for v0.18, add CLI section, slim README
1 parent f8e7a77 commit b86803e

44 files changed

Lines changed: 8552 additions & 12550 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 65 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center"> Benav Labs FastAPI boilerplate</h1>
22
<p align="center" markdown=1>
3-
<i><b>Batteries-included FastAPI starter</b> with production-ready defaults, optional modules, and clear docs.</i>
3+
<i><b>Batteries-included FastAPI starter</b> — vertical-slice modules, swappable infrastructure, plugin-ready CLI.</i>
44
</p>
55

66
<p align="center">
@@ -32,168 +32,118 @@
3232

3333
* ⚡️ Fully async FastAPI + SQLAlchemy 2.0
3434
* 🧱 Pydantic v2 models & validation
35-
* 🔐 JWT auth (access + refresh), cookies for refresh
36-
* 👮 Rate limiter + tiers (free/pro/etc.)
35+
* 🔐 Server-side sessions + CSRF; OAuth (Google wired, GitHub scaffolded); API keys
36+
* 👮 Rate limiter with per-tier, per-path rules
3737
* 🧰 FastCRUD for efficient CRUD & pagination
38-
* 🧑‍💼 **CRUDAdmin**: minimal admin panel (optional)
39-
* 🚦 ARQ background jobs (Redis)
40-
* 🧊 Redis caching (server + client-side headers)
41-
* 🌐 Configurable CORS middleware for frontend integration
42-
* 🐳 One-command Docker Compose
43-
* 🚀 NGINX & Gunicorn recipes for prod
38+
* 🧑‍💼 **SQLAdmin**-based admin panel (optional, env-toggled)
39+
* 🚦 [Taskiq](https://taskiq-python.github.io/) workers (Redis or RabbitMQ broker)
40+
* 🧊 Redis or Memcached caching (`@cache` decorator + provider API)
41+
* 🛠 **Plugin-ready `bp` CLI** — generate compose files, audit env, mount third-party command/feature plugins
42+
* 🐳 Docker Compose for local / prod / nginx-fronted (generated by the CLI)
4443

4544
## Why and When to use it
4645

4746
**Perfect if you want:**
4847

4948
* A pragmatic starter with auth, CRUD, jobs, caching and rate-limits
5049
* **Sensible defaults** with the freedom to opt-out of modules
51-
* **Docs over boilerplate** in README - depth lives in the site
50+
* **A foundation that grows** — vertical-slice modules + a plugin-aware CLI for code generators
51+
* **Docs over boilerplate** in this README — depth lives on the [docs site](https://benavlabs.github.io/FastAPI-boilerplate/)
5252

53-
> **Not a fit** if you need a monorepo microservices scaffold - [see the docs](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/project-structure/) for pointers.
53+
> **Not a fit** if you need a monorepo microservices scaffold [see the docs](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/project-structure/) for pointers.
5454
5555
**What you get:**
5656

57-
* **App**: FastAPI app factory, [env-aware docs](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/development/) exposure
58-
* **Auth**: [JWT access/refresh](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/authentication/), logout via token blacklist
59-
* **DB**: Postgres + SQLAlchemy 2.0, [Alembic migrations](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/database/)
60-
* **CRUD**: [FastCRUD generics](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/database/crud/) (get, get_multi, create, update, delete, joins)
61-
* **Caching**: [decorator-based endpoints cache](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/caching/); client cache headers
62-
* **Queues**: [ARQ worker](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/background-tasks/) (async jobs), Redis connection helpers
57+
* **App**: FastAPI [app factory](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/project-structure/), env-aware docs exposure
58+
* **Auth**: [server-side sessions](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/authentication/sessions/), CSRF, [OAuth](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/authentication/), [API keys](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/authentication/permissions/)
59+
* **DB**: Postgres + SQLAlchemy 2.0, [Alembic migrations](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/database/migrations/) with prod-confirm gate
60+
* **CRUD**: [FastCRUD generics](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/database/crud/)
61+
* **Caching**: [decorator + provider API](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/caching/) (Redis or Memcached)
62+
* **Queues**: [Taskiq workers](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/background-tasks/) (Redis or RabbitMQ)
6363
* **Rate limits**: [per-tier + per-path rules](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/rate-limiting/)
64-
* **Admin**: [CRUDAdmin views](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/admin-panel/) for common models (optional)
64+
* **Admin**: [SQLAdmin views](https://benavlabs.github.io/FastAPI-boilerplate/user-guide/admin-panel/) (optional, env-toggled)
65+
* **CLI**: [`bp` tool](https://benavlabs.github.io/FastAPI-boilerplate/cli/) for compose scaffolding, env audits, and plugin extensions
6566

66-
This is what we've been using in production apps. Several applications running in production started from this boilerplate as their foundation - from SaaS platforms to internal tools. It's proven, stable technology that works together reliably. Use this as the foundation for whatever you want to build on top.
67+
> **Building an AI SaaS?** Skip even more setup with [**FastroAI**](https://fastro.ai) — our production-ready template with AI integration, payments, and frontend included.
6768
68-
> **Building an AI SaaS?** Skip even more setup with [**FastroAI**](https://fastro.ai) - our production-ready template with AI integration, payments, and frontend included.
69+
## Repo Layout
6970

70-
## TL;DR - Quickstart
71+
This is a [uv workspace](https://docs.astral.sh/uv/concepts/projects/workspaces/) with two members. One venv at the root covers both.
7172

72-
Use the template on GitHub, create your repo, then:
73+
```text
74+
fastapi-boilerplate/
75+
├── pyproject.toml # workspace root (uv workspace metadata)
76+
├── backend/ # the deployable application
77+
│ ├── src/ # interfaces/, infrastructure/, modules/
78+
│ ├── pyproject.toml
79+
│ └── Dockerfile # multi-stage: dev / migrate / prod
80+
└── cli/ # `bp` — developer/operator tool (never ships in prod)
81+
└── src/cli/
82+
```
83+
84+
## Quickstart
7385

7486
```bash
7587
git clone https://github.com/<you>/FastAPI-boilerplate
7688
cd FastAPI-boilerplate
89+
uv sync --all-extras # one venv at the root, both members installed
7790
```
7891

79-
**Quick setup:** Run the interactive setup script to choose your deployment configuration:
92+
Generate a compose file for the deployment shape you want:
8093

8194
```bash
82-
./setup.py
95+
uv run bp deploy generate local # hot-reload dev stack
96+
# or: uv run bp deploy generate prod # production single-host
97+
# or: uv run bp deploy generate nginx # production behind nginx
8398
```
8499

85-
Or directly specify the deployment type: `./setup.py local`, `./setup.py staging`, or `./setup.py production`.
86-
87-
The script copies the right files for your deployment scenario. Here's what each option sets up:
88-
89-
### Option 1: Local development with Uvicorn
90-
91-
Best for: **Development and testing**
92-
93-
**Copies:**
94-
95-
- `scripts/local_with_uvicorn/Dockerfile``Dockerfile`
96-
- `scripts/local_with_uvicorn/docker-compose.yml``docker-compose.yml`
97-
- `scripts/local_with_uvicorn/.env.example``src/.env`
98-
99-
Sets up Uvicorn with auto-reload enabled. The example environment values work fine for development.
100-
101-
**Manual setup:** `./setup.py local` or copy the files above manually.
102-
103-
### Option 2: Staging with Gunicorn managing Uvicorn workers
104-
105-
Best for: **Staging environments and load testing**
106-
107-
**Copies:**
108-
109-
- `scripts/gunicorn_managing_uvicorn_workers/Dockerfile``Dockerfile`
110-
- `scripts/gunicorn_managing_uvicorn_workers/docker-compose.yml``docker-compose.yml`
111-
- `scripts/gunicorn_managing_uvicorn_workers/.env.example``src/.env`
112-
113-
Sets up Gunicorn managing multiple Uvicorn workers for production-like performance testing.
114-
115-
> [!WARNING]
116-
> Change `SECRET_KEY` and passwords in the `.env` file for staging environments.
117-
118-
**Manual setup:** `./setup.py staging` or copy the files above manually.
119-
120-
### Option 3: Production with NGINX
121-
122-
Best for: **Production deployments**
123-
124-
**Copies:**
125-
126-
- `scripts/production_with_nginx/Dockerfile``Dockerfile`
127-
- `scripts/production_with_nginx/docker-compose.yml``docker-compose.yml`
128-
- `scripts/production_with_nginx/.env.example``src/.env`
129-
130-
Sets up NGINX as reverse proxy with Gunicorn + Uvicorn workers for production.
131-
132-
> [!CAUTION]
133-
> You MUST change `SECRET_KEY`, all passwords, and sensitive values in the `.env` file before deploying!
134-
135-
**Manual setup:** `./setup.py production` or copy the files above manually.
136-
137-
---
138-
139-
**Start your application:**
100+
Configure your env (the CLI helps with secrets and validation):
140101

141102
```bash
142-
docker compose up
103+
cp backend/.env.example backend/.env
104+
uv run bp env gen-secret # print a fresh SECRET_KEY
105+
uv run bp env validate # audit .env against the production validator
143106
```
144107

145-
**Access your app:**
146-
- **Local**: http://127.0.0.1:8000 (auto-reload enabled) → [API docs](http://127.0.0.1:8000/docs)
147-
- **Staging**: http://127.0.0.1:8000 (production-like performance)
148-
- **Production**: http://localhost (NGINX reverse proxy)
149-
150-
### Next steps
151-
152-
**Create your first admin user:**
153-
```bash
154-
docker compose run --rm create_superuser
155-
```
108+
Bring it up:
156109

157-
**Run database migrations** (if you add models):
158110
```bash
159-
cd src && uv run alembic revision --autogenerate && uv run alembic upgrade head
111+
docker compose up --build
112+
# → http://127.0.0.1:8000 (Swagger at /docs)
160113
```
161114

162-
**Test background jobs:**
163-
```bash
164-
curl -X POST 'http://127.0.0.1:8000/api/v1/tasks/task?message=hello'
165-
```
115+
**Without Docker** (Postgres + Redis required locally):
166116

167-
**Or run locally without Docker:**
168117
```bash
169-
uv sync && uv run uvicorn src.app.main:app --reload
118+
cd backend
119+
uv run alembic upgrade head
120+
uv run python -m scripts.setup_initial_data # creates the first admin user + default tier
121+
uv run fastapi dev src/interfaces/main.py # API
122+
uv run taskiq worker infrastructure.taskiq.worker:default_broker # in a second terminal
170123
```
171124

172-
> Full setup (from-scratch, .env examples, PostgreSQL & Redis, gunicorn, nginx) lives in the [docs](https://benavlabs.github.io/FastAPI-boilerplate/getting-started/installation/).
173-
174-
## Configuration (minimal)
175-
176-
Create `src/.env` and set **app**, **database**, **JWT**, and **environment** settings. See the [docs](https://benavlabs.github.io/FastAPI-boilerplate/getting-started/configuration/) for a copy-pasteable example and production guidance.
177-
178-
[https://benavlabs.github.io/FastAPI-boilerplate/getting-started/configuration/](https://benavlabs.github.io/FastAPI-boilerplate/getting-started/configuration/)
179-
180-
* `ENVIRONMENT=local|staging|production` controls API docs exposure
181-
* Set `ADMIN_*` to enable the first admin user
125+
> Full setup, env-var reference, and per-environment deployment guides live in the [docs](https://benavlabs.github.io/FastAPI-boilerplate/getting-started/installation/).
182126
183127
## Common tasks
184128

185129
```bash
186-
# run locally with reload (without Docker)
187-
uv sync && uv run uvicorn src.app.main:app --reload
130+
# generate a fresh production-ready compose file
131+
uv run bp deploy generate prod --workers 8
132+
133+
# audit your .env against the production security validator
134+
uv run bp env validate
188135

189136
# run Alembic migrations
190-
cd src && uv run alembic revision --autogenerate && uv run alembic upgrade head
137+
cd backend && uv run alembic revision --autogenerate -m "<msg>" && uv run alembic upgrade head
138+
139+
# run tests
140+
cd backend && uv run pytest
191141

192-
# enqueue a background job (example endpoint)
193-
curl -X POST 'http://127.0.0.1:8000/api/v1/tasks/task?message=hello'
142+
# install bp as a global tool (optional)
143+
uv tool install --editable ./cli
194144
```
195145

196-
More examples (superuser creation, tiers, rate limits, admin usage) in the [docs](https://benavlabs.github.io/FastAPI-boilerplate/getting-started/first-run/).
146+
More examples (superuser creation, tiers, rate limits, admin usage, plugin authoring) in the [docs](https://benavlabs.github.io/FastAPI-boilerplate/).
197147

198148
## Contributing
199149

0 commit comments

Comments
 (0)