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.
1---2name: developing-fastapi3description: FastAPI project structure, Router organization, Dependency injection, Use when this capability is needed.4---5# Fastapi Development67FastAPI project structure, Router organization, Dependency injection, Pydantic v2 models, Background tasks, WebSocket endpoints, Middleware, CORS, OpenAPI customization89Build production FastAPI applications with proper structure, dependency injection, Pydantic validation, and async patterns.1011## Process12131. **Scaffold** – Run `python scripts/scaffold.py --name myapp --output-dir .` or create structure manually.142. **App Entry** – FastAPI instance with CORS middleware, routers, health endpoint at `/health`.153. **Routers** – APIRouter per domain with prefix (e.g. `/api/v1/users`), thin handlers delegating to services.164. **Dependencies** – `get_db`, `get_current_user` in `core/dependencies.py`; inject via `Depends()`.175. **Schemas** – Pydantic v2 models in `domains/*/schemas.py`; separate Create/Update/Response; use `ConfigDict(from_attributes=True)` for ORM.186. **Background Tasks** – Use `BackgroundTasks.add_task()` for non-blocking work (emails, cleanup).197. **WebSockets** – ConnectionManager pattern; `accept()`, `receive_text()`, `send_text()`, handle `WebSocketDisconnect`.208. **Middleware** – Add logging, timing, rate limiting via `BaseHTTPMiddleware`.219. **OpenAPI** – Customize via `app.openapi` override or `get_openapi()`.2223## Best Practices2425- Domain-driven structure (organize by feature, not layer)26- Keep routers thin; delegate to service layer27- Use dependency injection for all external resources28- Separate Pydantic schemas from SQLAlchemy models29- Use async for all I/O30- Implement exception handlers; use `response_model` to limit exposed data31- Add type hints throughout; use Pydantic validators for complex validation32- Add health check at `/health`; configure CORS from settings33- Use structured logging; HTTPS in production3435## Anti-Patterns3637| Anti-Pattern | Fix |38|--|--|39| Business logic in routers | Move to service layer |40| Synchronous database calls | Use async database drivers |41| Missing validation | Use Pydantic models |42| Global state | Use dependency injection |43| Missing error handling | Add exception handlers |44| No response models | Use `response_model` parameter |4546## Bundled Resources4748- **QUICKSTART.md** – 5-minute getting started guide49- **scripts/scaffold.py** – Generate FastAPI project structure (`--name`, `--output-dir`)50- **scripts/verify.py** – Check project follows skill patterns (`--project-dir`)51- **examples/basic_app/** – Minimal working FastAPI app (health endpoint, CRUD resource, Pydantic models)5253## When to Use54This skill should be used when strict adherence to the defined process is required.5556## Prerequisites57- Basic understanding of the agent factory context.58- Access to the necessary tools and resources.5960---61> Source: [gitwalter/antigravity-agent-factory](https://github.com/gitwalter/antigravity-agent-factory) — distributed by [TomeVault](https://tomevault.io).62<!-- tomevault:4.0:skill_md:2026-06-16 -->