skills/api-design/SKILL.md
# API Design Skill You are an expert FastAPI backend architect specializing in RESTful API design, Pydantic data validation, and scalable backend systems. ## When to Use This Skill Use this skill when: - Designing new REST APIs or endpoints - Creating Pydantic models and schemas - Implementing authentication (JWT, OAuth) - Setting up error handling and validation - Structuring FastAPI applications - Working with OpenAPI/Swagger documentation ## Core Principles ### 1. RESTful Design - Use HT
npx skillsauth add ainative-studio/ainativestudio-ide skills/api-designInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are an expert FastAPI backend architect specializing in RESTful API design, Pydantic data validation, and scalable backend systems.
Use this skill when:
/api/v1/users/{user_id})/api/v1/)from fastapi import FastAPI, APIRouter
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI(
title="My API",
description="API description",
version="1.0.0"
)
# CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Router
router = APIRouter(prefix="/api/v1", tags=["v1"])
app.include_router(router)
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
class UserBase(BaseModel):
email: str = Field(..., pattern=r"^[\w\.-]+@[\w\.-]+\.\w+$")
name: str = Field(..., min_length=1, max_length=100)
class UserCreate(UserBase):
password: str = Field(..., min_length=8)
class UserUpdate(BaseModel):
name: Optional[str] = Field(None, min_length=1, max_length=100)
email: Optional[str] = Field(None, pattern=r"^[\w\.-]+@[\w\.-]+\.\w+$")
class UserResponse(UserBase):
id: str
created_at: datetime
class Config:
from_attributes = True
from fastapi import APIRouter, HTTPException, Depends
router = APIRouter(prefix="/api/v1/users", tags=["users"])
@router.post("/", status_code=201, response_model=UserResponse)
async def create_user(user: UserCreate):
"""Create a new user"""
# Validate business logic
if await user_exists(user.email):
raise HTTPException(status_code=400, detail="Email already registered")
# Create user
new_user = await create_user_db(user)
return new_user
@router.get("/{user_id}", response_model=UserResponse)
async def get_user(user_id: str, current_user=Depends(get_current_user)):
"""Get user by ID"""
user = await find_user(user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user
from fastapi import HTTPException, Request
from fastapi.responses import JSONResponse
class APIError(Exception):
def __init__(self, status_code: int, detail: str):
self.status_code = status_code
self.detail = detail
@app.exception_handler(APIError)
async def api_error_handler(request: Request, exc: APIError):
return JSONResponse(
status_code=exc.status_code,
content={"error": exc.detail}
)
from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
import jwt
security = HTTPBearer()
async def get_current_user(
credentials: HTTPAuthorizationCredentials = Depends(security)
):
token = credentials.credentials
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
user_id = payload.get("sub")
if not user_id:
raise HTTPException(status_code=401, detail="Invalid token")
return await get_user_by_id(user_id)
except jwt.ExpiredSignatureError:
raise HTTPException(status_code=401, detail="Token expired")
except jwt.InvalidTokenError:
raise HTTPException(status_code=401, detail="Invalid token")
Detailed examples in references/:
endpoint-patterns.md - Complete CRUD patternspydantic-models.md - Model validation techniqueserror-handling.md - Comprehensive error handlingauth-patterns.md - JWT and OAuth implementations/api/v1/ prefixfrom typing import List
@router.get("/", response_model=List[UserResponse])
async def list_users(skip: int = 0, limit: int = 100):
return await get_users(skip=skip, limit=limit)
@router.get("/", response_model=List[UserResponse])
async def list_users(
status: Optional[str] = None,
role: Optional[str] = None
):
filters = {}
if status:
filters["status"] = status
if role:
filters["role"] = role
return await get_users(**filters)
@router.post("/bulk", status_code=201)
async def create_users_bulk(users: List[UserCreate]):
results = []
for user in users:
results.append(await create_user_db(user))
return results
When implementing APIs, provide:
Always structure code for:
development
ZeroDB vector database best practices, semantic search patterns, RLHF workflows, and memory management. Use when working with ZeroDB APIs, vector search, or AI memory systems.
development
TDD/BDD workflows for FastAPI + React stack with pytest, vitest, and integration testing. Use when writing tests, configuring test runners, or implementing test-driven development.
devops
Railway deployment workflows, nixpacks configuration, environment management, and production troubleshooting
tools
MCP server development patterns extending Anthropic's mcp-builder with AINative-specific conventions. Use when creating MCP servers, integrating ZeroDB, or building tool-based AI systems.