- Home
- Skills
- Mjunaidca
- Mjs Agent Skills
- Scaffolding Fastapi Dapr
scaffolding-fastapi-dapr_skill
- Python
19
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill mjunaidca/mjs-agent-skills --skill scaffolding-fastapi-dapr- SKILL.md8.7 KB
Overview
This skill builds production-grade FastAPI backends using SQLModel for typed schemas, Dapr for event-driven microservices, and JWT/JWKS for secure authentication. It provides reusable patterns for async database access, CRUD endpoints, pub/sub integration, scheduled jobs, structured logging, and testing. Use it to scaffold robust REST APIs and Dapr-enabled services ready for deployment.
How this skill works
The skill supplies concise, ready-to-adopt patterns: SQLModel schemas and async engine/session setup for Neon/Postgres; FastAPI routes wired to dependency-injected async sessions; JWT/JWKS middleware examples for token validation. It also includes Dapr patterns to discover subscriptions, handle CloudEvents, publish events, and register scheduled jobs, plus production practices like repository/service separation, structured logging, and async tests.
When to use it
- Building REST APIs that need typed models, async DB access, and JWT-protected endpoints
- Implementing event-driven microservices with Dapr pub/sub and scheduled jobs
- Creating CRUD services backed by Neon PostgreSQL using SQLModel and asyncpg
- Scaffolding a production-ready FastAPI app with logging, DI, and test patterns
- Not suitable for simple scripts or monolithic apps without microservice/event needs
Best practices
- Use SQLModel for single-source-of-truth schemas and separate Create/Read DTOs
- Replace DATABASE_URL prefix to enable asyncpg and use AsyncSession dependency injection
- Keep business logic in services and data access in repositories for testability
- Validate and decode JWTs against JWKS on each protected route, caching keys when appropriate
- Treat Dapr request bodies as CloudEvents (data nested) and handle both wrapped/unwrapped payloads
- Use structured logging and contextvars to correlate events across services
Example use cases
- CRUD task service: async endpoints, SQLModel schemas, repository/service layers
- Event-driven workflows: publish task-created events and handle them via Dapr subscriptions
- Scheduled background jobs: register schedules with Dapr Jobs API and process callbacks
- Protected admin endpoints: enforce JWT/JWKS verification to expose sensitive APIs
- Integration tests: override DB session dependency and run async HTTP tests against the app
FAQ
Yes for pub/sub, state, and jobs examples; you can run the app standalone but Dapr features need the sidecar.
How do I enable async Postgres connections?
Set DATABASE_URL to your Postgres URL and replace the driver prefix to postgresql+asyncpg:// before creating the async engine.