一键导入
fastapi-routes
// Create or modify FastAPI routes in the Oscilla codebase. Use when: adding new API endpoints, creating Pydantic request/response models, registering routers, designing REST APIs, or following route conventions for this project.
// Create or modify FastAPI routes in the Oscilla codebase. Use when: adding new API endpoints, creating Pydantic request/response models, registering routers, designing REST APIs, or following route conventions for this project.
| name | fastapi-routes |
| description | Create or modify FastAPI routes in the Oscilla codebase. Use when: adding new API endpoints, creating Pydantic request/response models, registering routers, designing REST APIs, or following route conventions for this project. |
context7: If the
mcp_context7tool is available, resolve and load the fullfastapidocumentation before proceeding:mcp_context7_resolve-library-id: "fastapi" mcp_context7_get-library-docs: <resolved-id>
Guidelines and patterns for writing FastAPI routes in the Oscilla codebase.
APIs must adhere as closely as possible to REST principles, including appropriate use of HTTP verbs:
| Verb | Usage |
|---|---|
GET | Read one or many resources |
POST | Create a new resource |
PUT | Replace / fully update a resource |
PATCH | Partial update (use sparingly) |
DELETE | Remove a resource |
dict or Any.PostCreate — user input for creating a resourcePostUpdate — user input for updating (optional fields)PostRead — response shape returned to the clientField() with validation constraints and a description.Field() unless you need aliases or serialization control.from uuid import UUID
from pydantic import BaseModel, Field
class PostCreate(BaseModel):
title: str = Field(min_length=1, max_length=200, description="Post title")
content: str = Field(min_length=1, description="Post content")
class PostRead(BaseModel):
id: UUID
title: str
content: str
created_at: str
class PostUpdate(BaseModel):
title: str | None = Field(default=None, max_length=200)
content: str | None = None
Use APIRouter for all routes. Register the router in oscilla/www.py under the /api prefix.
from uuid import UUID
from fastapi import APIRouter, status
router = APIRouter()
@router.post("/posts", response_model=PostRead, status_code=status.HTTP_201_CREATED)
async def create_post(post: PostCreate) -> PostRead:
...
@router.get("/posts/{post_id}", response_model=PostRead)
async def get_post(post_id: UUID) -> PostRead:
...
@router.put("/posts/{post_id}", response_model=PostRead)
async def update_post(post_id: UUID, post: PostUpdate) -> PostRead:
...
@router.delete("/posts/{post_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_post(post_id: UUID) -> None:
...
All application routes must be registered under the /api prefix in oscilla/www.py.
Exceptions (no /api prefix by convention):
/health — liveness probe/ready — readiness probe/static — static file serving# oscilla/www.py
app.include_router(posts_router, prefix="/api")
The OpenAPI documentation is served at these fixed paths — do not move them:
| URL | Interface |
|---|---|
/api/docs | Swagger UI |
/api/redoc | ReDoc |
/api/openapi.json | Raw schema |
Use HTTPException with appropriate status codes:
from fastapi import HTTPException, status
@router.get("/posts/{post_id}", response_model=PostRead)
async def get_post(post_id: UUID) -> PostRead:
post = await get_post_from_db(post_id)
if post is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Post not found")
return post
Before submitting a new route, verify:
Create, Update, and Read models definedField() with descriptionasync/api in oscilla/www.pyPOST create endpointsDELETE endpoints (no response body)/api/docs), ReDoc (/api/redoc), OpenAPI schema, middleware, authentication integration, and dependency injection patterns.Write or modify Oscilla game content YAML manifests for any game package. Use when: creating a new game package, writing adventures, enemies, items, quests, regions, locations, skills, buffs, archetypes, recipes, loot tables, or conditions; designing progression systems; configuring game.yaml or character_config.yaml; authoring template expressions; setting up cooldowns or passive effects; validating content with the CLI; or any task that touches files under a content/ game package directory.
Work with the Oscilla Docker Compose development environment. Use when: starting or stopping services, inspecting logs, opening a shell in a container, resetting the database, or understanding the service topology.
Work on the Oscilla frontend (SvelteKit/Vite). Use when: writing or modifying any Svelte components, routes, stores, styles, or frontend tests; adding new UI features or pages; fixing frontend bugs; running frontend tests or type checks; managing npm dependencies; working on accessibility or usability; building production assets; or any task that touches files under frontend/.
Complete reference for all make targets in the Oscilla project. Use when: looking up the right make command for any task — setup, testing, linting, formatting, database, frontend, packaging, or cleanup.
Use the Oscilla CLI to assist content authors writing YAML manifests. Use when: setting up JSON schema validation for YAML manifests, running validate or oscilla content test, inspecting manifest content with list/show, tracing adventure paths, graphing world structure, scaffolding new manifests with oscilla content create, debugging content errors, checking cross-references. Knows all oscilla content subcommands: schema, test, list, show, graph, trace, create. Also covers oscilla validate.
Add or modify application configuration settings in Oscilla. Use when: adding new environment variables, adding new settings fields, understanding settings conventions, working with secrets, or configuring optional vs required settings.