fastapi-router-creator
FastAPI Router Creator
This skill guides the creation of modular, organized FastAPI routers, emphasizing maintainability and scalability.
Routing Strategies
1. Modular Router Pattern (Standard)
The most common and recommended approach for FastAPI.
Structure:
src/api/v1/endpoints/
├── users.py
├── items.py
└── auth.py
Implementation:
src/api/v1/endpoints/users.py:
from fastapi import APIRouter
router = APIRouter()
@router.get("/")
async def get_users():
...
src/api/v1/api.py (Aggregator):
from fastapi import APIRouter
from src.api.v1.endpoints import users, items
api_router = APIRouter()
api_router.include_router(users.router, prefix="/users", tags=["users"])
api_router.include_router(items.router, prefix="/items", tags=["items"])
2. File-Based Routing (fastapi-router)
For a Next.js-like experience where file structure dictates URLs. (Requires fastapi-router library or custom walker).
Structure:
src/app/
├── api/
│ ├── users/
│ │ ├── route.py # Handles /api/users
│ │ └── [id]/
│ │ └── route.py # Handles /api/users/{id}
Best Practices
- Prefixing: Use prefixes at the router include level, not inside every endpoint decorator.
- Tags: Use tags to group endpoints in OpenAPI docs.
- Dependencies: Apply dependencies (like auth) at the router level if they apply to all endpoints in that router.
router = APIRouter(dependencies=[Depends(get_current_active_user)]) - Version: Namespace routers by API version (
v1,v2).
More from first-fluke/fullstack-starter
component-refactoring
Refactor high-complexity React components. Use when complexity metrics are high or to split monolithic UI.
33ui-ux-pro-max
Advanced design intelligence for professional UI/UX. Use for implementing modern design patterns (Glassmorphism, Bento Grid), ensuring accessibility, and generating tailored design systems for web and mobile.
26frontend-code-review
Standardized checklist and process for reviewing frontend code (.tsx, .ts, .js).
23frontend-engineer
Develop production-grade frontend code using shadcn/ui, best practices, and strict design alignment.
17skill-lookup
Discover, retrieve, and learn about available Agent Skills. key capability for finding tools to solve specific problems.
16fastapi-templates
Production-ready FastAPI project templates and patterns. Use when starting new FastAPI projects, services, or adding standard components like auth, DB connection, or middleware.
15