Production-ready FastAPI scaffold with Docker, PostgreSQL, and CI/CD — deploy in minutes.
- FastAPI async REST API with Pydantic v2 validation
- PostgreSQL persistence via SQLAlchemy 2.0 async engine
- Multi-stage Docker build — final image < 120 MB
- docker-compose one-command local stack (app + db)
- GitHub Actions CI — lint (ruff), test (pytest), container build
- Health endpoint with DB connectivity check
- 12-Factor config via environment variables
┌─────────────┐ ┌─────────────┐
│ Client │─────▶│ FastAPI │
└─────────────┘ │ (uvicorn) │
└──────┬──────┘
│ async
┌──────▼──────┐
│ PostgreSQL │
│ (pg 16) │
└─────────────┘
git clone https://github.com/gridguard-ai/fastapi-deploy-template.git
cd fastapi-deploy-template
docker compose up --build
# API available at http://localhost:8000
# Docs at http://localhost:8000/docspython -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/app"
uvicorn app.main:app --reload| Method | Path | Description |
|---|---|---|
GET |
/health |
Liveness + DB check |
POST |
/tasks |
Create a task |
GET |
/tasks |
List all tasks |
GET |
/tasks/{id} |
Get task by ID |
PUT |
/tasks/{id} |
Update a task |
DELETE |
/tasks/{id} |
Delete a task |
| Variable | Default | Description |
|---|---|---|
DATABASE_URL |
postgresql+asyncpg://postgres:postgres@db:5432/app |
Async DB connection string |
APP_ENV |
production |
Environment name |
MIT
If this helped you, consider supporting GridGuard's open-source work:
Every tip fuels more free tools and templates.