| name | developing-fastapi |
| description | FastAPI project structure, Router organization, Dependency injection, Use when this capability is needed. |
| metadata | {"author":"gitwalter"} |
Fastapi Development
FastAPI project structure, Router organization, Dependency injection, Pydantic v2 models, Background tasks, WebSocket endpoints, Middleware, CORS, OpenAPI customization
Build production FastAPI applications with proper structure, dependency injection, Pydantic validation, and async patterns.
Process
- Scaffold – Run
python scripts/scaffold.py --name myapp --output-dir . or create structure manually.
- App Entry – FastAPI instance with CORS middleware, routers, health endpoint at
/health.
- Routers – APIRouter per domain with prefix (e.g.
/api/v1/users), thin handlers delegating to services.
- Dependencies –
get_db, get_current_user in core/dependencies.py; inject via Depends().
- Schemas – Pydantic v2 models in
domains/*/schemas.py; separate Create/Update/Response; use ConfigDict(from_attributes=True) for ORM.
- Background Tasks – Use
BackgroundTasks.add_task() for non-blocking work (emails, cleanup).
- WebSockets – ConnectionManager pattern;
accept(), receive_text(), send_text(), handle WebSocketDisconnect.
- Middleware – Add logging, timing, rate limiting via
BaseHTTPMiddleware.
- OpenAPI – Customize via
app.openapi override or get_openapi().
Best Practices
- Domain-driven structure (organize by feature, not layer)
- Keep routers thin; delegate to service layer
- Use dependency injection for all external resources
- Separate Pydantic schemas from SQLAlchemy models
- Use async for all I/O
- Implement exception handlers; use
response_model to limit exposed data
- Add type hints throughout; use Pydantic validators for complex validation
- Add health check at
/health; configure CORS from settings
- Use structured logging; HTTPS in production
Anti-Patterns
| Anti-Pattern | Fix |
|---|
| Business logic in routers | Move to service layer |
| Synchronous database calls | Use async database drivers |
| Missing validation | Use Pydantic models |
| Global state | Use dependency injection |
| Missing error handling | Add exception handlers |
| No response models | Use response_model parameter |
Bundled Resources
- QUICKSTART.md – 5-minute getting started guide
- scripts/scaffold.py – Generate FastAPI project structure (
--name, --output-dir)
- scripts/verify.py – Check project follows skill patterns (
--project-dir)
- examples/basic_app/ – Minimal working FastAPI app (health endpoint, CRUD resource, Pydantic models)
When to Use
This skill should be used when strict adherence to the defined process is required.
Prerequisites
- Basic understanding of the agent factory context.
- Access to the necessary tools and resources.
Source: gitwalter/antigravity-agent-factory — distributed by TomeVault.