A professional, production-ready REST API template built with FastAPI. Includes JWT authentication, full CRUD operations, a SQLAlchemy-backed database, Pydantic validation, and automatic Swagger documentation — all structured in a modular, scalable way.
- ✅ JWT authentication — registration, login, and route protection
- ✅ Full CRUD for users and items
- ✅ SQLAlchemy ORM with SQLite (swappable for PostgreSQL/MySQL)
- ✅ Automatic validation with Pydantic v2
- ✅ Secure password hashing with bcrypt
- ✅ Automatic Swagger UI at
/docs - ✅ Modular, scalable structure with routers
- ✅ CORS configured for frontend integration
- FastAPI — Modern, high-performance web framework
- SQLAlchemy — Database ORM
- Pydantic — Data validation and serialization
- python-jose — JWT token generation and validation
- passlib + bcrypt — Secure password hashing
- Uvicorn — ASGI server
fastapi-rest-boilerplate/
├── app/
│ ├── main.py # Entry point
│ ├── database.py # Database configuration
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas
│ ├── auth.py # JWT logic
│ └── routers/
│ ├── auth.py # Registration and login
│ ├── users.py # User endpoints
│ └── items.py # Item endpoints (CRUD)
├── tests/
├── .github/workflows/ci.yml
├── requirements.txt
├── requirements-dev.txt
├── .env.example
└── README.md
git clone https://github.com/LacerdaTraderCode/fastapi-rest-boilerplate.git
cd fastapi-rest-boilerplate
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
pip install -r requirements.txt
cp .env.example .env
# Edit .env and set SECRET_KEY
uvicorn app.main:app --reloadVisit http://localhost:8000/docs for the interactive documentation.
| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/register |
Register a new user |
POST |
/auth/login |
Login — returns a JWT token |
| Method | Endpoint | Description |
|---|---|---|
GET |
/users/me |
Authenticated user's data |
| Method | Endpoint | Description |
|---|---|---|
GET |
/items/ |
List all items |
POST |
/items/ |
Create a new item |
GET |
/items/{id} |
Get item by ID |
PUT |
/items/{id} |
Update item |
DELETE |
/items/{id} |
Delete item |
# Register
curl -X POST "http://localhost:8000/auth/register" \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "password123"}'
# Login
curl -X POST "http://localhost:8000/auth/login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=user@example.com&password=password123"
# Use token
curl -X GET "http://localhost:8000/items/" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"pip install -r requirements-dev.txt
ruff check . && ruff format --check .
pytest -vTests run against an isolated in-memory SQLite database. The same checks run on every push and pull request via GitHub Actions.
Ready for deployment on:
- Railway, Render, Fly.io — free tiers
- AWS, Google Cloud, Azure
- Docker — add a Dockerfile as needed
- Python 3.11 or higher
Wagner Lacerda — Senior Software Engineer | Python, Backend, AI Apps, Automation & Systems
📍 Rio Grande do Sul, Brazil
Distributed under the MIT license. See LICENSE for more details.