Fastapi Boilerplate project
This is a boilerplate project for fastapi. It is based on the fastapi official tutorial. It aims to be a simple MVC project with a database connection. The example is a simple todo list.
It uses Jinja2 as a template engine and Prisma as an ORM.
For the frontend, it uses Bootstrap and HTMX.
Requirements
Quickstart
Running the project
cp docker-compose.override.yml.dist docker-compose.override.yml
docker compose up
# Service is running on http://localhost:8000
Development
To improve development experience, a devcontainer configuration is available. To setup a development environment, you can simply use Vscode Devcontainer. Once the devcontainer is up, just run the command uv run fastapi dev ./app/main.py to start the dev server that will be available on localhost:8000
Else, you can follow those steps to configure the development environment on your host:
# Install dependencies
uv sync --all-groups --frozen
# Install prisma client
uv run prisma migrate dev --schema database/schema.prisma
# Run the project
uv run fastapi dev ./app/main.py
Project quality
# Run linters
uv run ruff check . --fix
Application structure
Declare a new route
To declare a new route, you need to create a new file in the app/routes directory. The file must contain a router variable that is an instance of fastapi.APIRouter. It will be automaticaly binded to the fastapi application.
# app/routes/my_route.py
from fastapi import APIRouter
router = APIRouter(prefix="/my_route")
@router.get("/helloworld")
async def my_route():
return {"message": "Hello World"}