This starter aims to be productive, clear, and robust:
- FastAPI as the HTTP server
- Auth middleware based on Bridge Validation (Flowless)
- SQLAlchemy 2.x (async) for multi-dialect databases
- Hybrid cache: in-memory LRU + optional Redis
- Configuration via Pydantic Settings
app/main.py: app creation, CORS, startup/shutdown eventsapp/routes/: API and health routes with examplesapp/lib/auth/: session validation (Flowless), middleware, validation modesapp/lib/database/: connection and async session helpersapp/models/: SQLAlchemy models (e.g.,User)
- Client sends
X-Session-Idwith requests. - Middleware validates against Flowless
/auth/bridge/validateusingX-Bridge-Secret. - If valid,
SessionDatais injected into your endpoint viaDepends(). - Results are cached to accelerate subsequent requests.
- PostgreSQL and CockroachDB (asyncpg)
- MySQL (aiomysql)
- SQLite/LibSQL (aiosqlite)
Dialect detection is automatic based on
DATABASE_URL.
- Incoming request → CORS → middleware parses headers → (optional) session validation → route handler → DB access via
AsyncSession→ response serialization
- Add new routes in
app/routes/and protect them withrequire_authorrequire_user_type. - Define new models in
app/models/and create migrations with Alembic. - Introduce caching by using the hybrid cache instances in
app/lib/cache/.