What problem does it solve?
This Skill provides production-ready FastAPI project structures, solving the challenge of setting up new API projects with best practices from scratch. It ensures your applications are built with async patterns, proper dependency injection, and comprehensive error handling, saving development time and reducing boilerplate.
Core Features & Use Cases
- Structured Project Layout: Get a clear, scalable directory structure for your FastAPI applications.
- Dependency Injection: Leverage FastAPI's powerful DI for database sessions, authentication, and services.
- Async Patterns: Implement high-performance I/O-bound operations with
async/await for databases and external APIs.
- CRUD Repository & Service Layers: Separate data access from business logic for maintainable code.
- Use Case: Quickly scaffold a new REST API for a mobile application, complete with user authentication, database integration, and a clean, testable codebase.
Quick Start
Example: main.py for FastAPI App
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
await database.connect()
yield
await database.disconnect()
app = FastAPI(title="API Template", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=[""], allow_credentials=True,
allow_methods=[""], allow_headers=["*"],
)
from app.api.v1.router import api_router
app.include_router(api_router, prefix="/api/v1")