add-api-route
Skill84 starsChanged 6 months agoMITView on GitHub
Add a new REST API route to the control-plane. Use when creating a new resource endpoint, adding GET/POST/PUT/DELETE handlers, building paginated list APIs, or extending the REST API surface. Covers file creation, auth guard, DB queries, response shape, api-types.ts registration, and test scaffolding.
- Reads credentials
4 other projects use a version of this.
Adopted by
Most recently taken up by
- suxrobGM/jobpilottheir own version, first seen Nov 7, 2026
- skillist-io/skillisttheir own version, first seen Oct 11, 2026
- linjiejim/greenhousetheir own version, first seen Oct 11, 2026
- bmarshall511/forexflowtheir own version, first seen Apr 17, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- suxrobGM/jobpilot★ 110same name
- bmarshall511/forexflow★ 14same name
- linjiejim/greenhouse★ 3same name
- skillist-io/skillist★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- add-ws-messageSkill
The file
We split this skill into the rules it gives an agent
10 rules. 0 are common, 0 are distinctive, and 10 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
If sub-resource (e.g. workspaces/members): app/api/workspaces/[id]/members/route.ts.
- Very specific: line 28
Use ./assets/route-template.ts as starting point.
- Very specific: line 30
Always call getAuthContext(request) first (pass request for API key auth).
- Very specific: line 31
Use forbidden() for permission failures (e.g.
- Very specific: line 38
Add helper functions to packages/control-plane/lib/db.ts:
- Very specific: line 40
Use getDb() singleton and raw better-sqlite3 prepared statements
- Very specific: line 42
Add indexes with CREATE INDEX IF NOT EXISTS idx_<table>_<col> inside createTables()
- Very specific: line 53
Add an entry to packages/control-plane/lib/route-registry.ts (ROUTE_REGISTRY):
- Very specific: line 87
Use ./assets/test-template.ts.
- Very specific: line 91
Import handlers directly: import { GET, POST } from "@/app/api/<resource>/route"
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Add API Route — Control Plane
When to Use
- Creating a new resource endpoint under
packages/control-plane/app/api/ - Adding handlers to an existing route file
- Ensuring consistent auth, error handling, pagination, and response shapes
Procedure
1. Determine Route Path & Handlers
From the argument (e.g. invitations):
- Collection:
app/api/invitations/route.ts—GET(list) +POST(create) - Item:
app/api/invitations/[id]/route.ts—GET(detail) +PUT/PATCH(update) +DELETE
If sub-resource (e.g. workspaces/members): app/api/workspaces/[id]/members/route.ts.
2. Create the Route File
Use ./assets/route-template.ts as starting point. Key rules:
- Always call
getAuthContext(request)first (passrequestfor API key auth); returnunauthorized()if null - Use
forbidden()for permission failures (e.g.!auth.isGlobalAdmin,!auth.canAccessWorkspace(id)) - Wrap all handlers in
try/catch; log withconsole.error("METHOD /api/<resource> error:", err) - For list endpoints, apply pagination — see template for the pattern
- Parse
[id]from dynamic segments withconst { id } = await params
3. Add DB Query Functions (if needed)
Add helper functions to packages/control-plane/lib/db.ts:
- Use
getDb()singleton and rawbetter-sqlite3prepared statements - Name convention:
getXxx(id),listXxx(filters),createXxx(data),updateXxx(id, data),deleteXxx(id) - Add indexes with
CREATE INDEX IF NOT EXISTS idx_<table>_<col>insidecreateTables()
4. Register Response Types (if new resource)
Add to packages/control-plane/lib/api-types.ts:
- Summary type for list items (e.g.
InvitationSummary) - Full type for detail response if different from summary
5. Register in Route Registry
Add an entry to packages/control-plane/lib/route-registry.ts (ROUTE_REGISTRY):
{ path: "/api/my-resource", methods: ["GET", "POST"], group: "MyGroup", description: "List / create my resources" },
{ path: "/api/my-resource/[id]", methods: ["GET", "PUT", "DELETE"], group: "MyGroup", description: "Get / update / delete a my resource" },This drives the API key permission tree in the admin UI and the check-api-coverage.ts script.
6. Add Swagger JSDoc
Annotate each handler with an @openapi JSDoc block:
/**
* @openapi
* /api/my-resource:
* get:
* summary: List my resources
* tags: [MyGroup]
* security:
* - sessionCookie: []
* - apiKey: []
* responses:
* 200:
* description: OK
*/
export async function GET(request: NextRequest) {Or let the AI generator add it: pnpm tsx scripts/generate-swagger-docs.ts (requires OPENAI_API_KEY in packages/control-plane/.env).
7. Scaffold the Test
Use ./assets/test-template.ts. Key rules:
- Place in
__tests__/<resource>-routes.test.ts - Mock
getAuthContextfrom@/lib/auth-utilswithvi.mock - Import handlers directly:
import { GET, POST } from "@/app/api/<resource>/route" - Provide one happy-path test and one unauthenticated test per handler
6. Checklist Before Done
- Auth guard with
getAuthContext(request)at the top of every handler try/catchwith console.error in every handler- Paginated GET list returns
{ items, total, page, pageSize, totalPages } - POST returns 201 on creation (
{ status: 201 }) - No hardcoded strings for error messages — keep them descriptive
- Types added to
api-types.tsif new resource - Entry added to
lib/route-registry.ts(ROUTE_REGISTRY) @openapiJSDoc annotation on each handler- Test file created with at least auth coverage
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

