obsidian/wiki/tech-patterns/fastapi-python-docker.md
2026-04-15 10:48:47 +01:00

3.7 KiB

title aliases tags sources created updated
FastAPI + Python + Docker Stack
fastapi-docker
python-api
fastapi
python
docker
backend
01 Projects/gmal-scope-builder
01 Projects/modcomms
01 Projects/video-accessibility
01 Projects/pdf-accessibility
01 Projects/olivas
01 Projects/pimco-charts
01 Projects/solventum-image-metadata
2026-04-15 2026-04-15

FastAPI + Python + Docker Stack

The dominant backend pattern at Oliver — Python FastAPI served via Docker Compose, typically paired with React/Vite frontend.

Key Takeaways

  • Default backend choice for all new Oliver AI tools
  • Uvicorn is the ASGI server; standard port is 8000 or 8001
  • Always use asyncpg + SQLAlchemy async when touching PostgreSQL
  • Docker Compose is the standard deploy — backend + frontend + DB in one compose.yml
  • alembic for database migrations (PostgreSQL projects)
  • uv emerging as the package manager of choice (Sandbox NotebookLM uses Python 3.13 + uv)

When to Use

Any new Oliver internal tool needing a REST API backend, especially when AI integration is required.

Key Details

  • ASGI server: Uvicorn (uvicorn app.main:app --reload --host 0.0.0.0 --port 8000)
  • Async DB: SQLAlchemy async + asyncpg (PostgreSQL) or PyMongo (MongoDB)
  • Migrations: Alembic (30+ revisions in Enterprise Nexus)
  • Package manager: pip / venv standard; uv for newer projects
  • Port conventions: Backend 8000 or 8001; Frontend 3000, 3010, or 5173

Projects Using This Pattern

Standard Docker Compose Structure

services:
  backend:
    build: ./backend
    ports: ["8000:8000"]
    env_file: .env
    depends_on: [db, redis]
  frontend:
    build: ./frontend
    ports: ["3000:3000"]
  db:
    image: postgres:16
    ports: ["5432:5432"]
  redis:
    image: redis:7

Gotchas & Lessons

  • GCP Load Balancer has a 30s timeout — long AI calls must use HTTP polling, not WebSocket streaming (learned from Mod Comms + Semblance)
  • Vite proxy timeout must be increased for long AI operations: proxy timeout: 300000 (5 min) — learned from GMAL
  • DEV_AUTH_BYPASS env var pattern for skipping Azure AD auth locally
  • For PostgreSQL, always pin port to non-default (e.g., 5433) to avoid conflicts with local installs
  • When using Alembic: run alembic upgrade head inside the container after first start