agentleFS
vaultysvaultys/VaultysClaw/.github/skills/add-api-route/SKILL.md

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

  • Other versions4 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 4

    1. suxrobGM/jobpilot★ 110same name
    2. bmarshall511/forexflow★ 14same name
    3. linjiejim/greenhouse★ 3same name
    4. 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.

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
  1. Very specific:

    If sub-resource (e.g. workspaces/members): app/api/workspaces/[id]/members/route.ts.

    line 24
  2. Very specific:

    Use ./assets/route-template.ts as starting point.

    line 28
  3. Very specific:

    Always call getAuthContext(request) first (pass request for API key auth).

    line 30
  4. Very specific:

    Use forbidden() for permission failures (e.g.

    line 31
  5. Very specific:

    Add helper functions to packages/control-plane/lib/db.ts:

    line 38
  6. Very specific:

    Use getDb() singleton and raw better-sqlite3 prepared statements

    line 40
  7. Very specific:

    Add indexes with CREATE INDEX IF NOT EXISTS idx_<table>_<col> inside createTables()

    line 42
  8. Very specific:

    Add an entry to packages/control-plane/lib/route-registry.ts (ROUTE_REGISTRY):

    line 53
  9. Very specific:

    Use ./assets/test-template.ts.

    line 87
  10. Very specific:

    Import handlers directly: import { GET, POST } from "@/app/api/<resource>/route"

    line 91

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 (pass request for API key auth); return unauthorized() if null
  • Use forbidden() for permission failures (e.g. !auth.isGlobalAdmin, !auth.canAccessWorkspace(id))
  • Wrap all handlers in try/catch; log with console.error("METHOD /api/<resource> error:", err)
  • For list endpoints, apply pagination — see template for the pattern
  • Parse [id] from dynamic segments with const { id } = await params

3. Add DB Query Functions (if needed)

Add helper functions to packages/control-plane/lib/db.ts:

  • Use getDb() singleton and raw better-sqlite3 prepared 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> inside createTables()

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 getAuthContext from @/lib/auth-utils with vi.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/catch with 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.ts if new resource
  • Entry added to lib/route-registry.ts (ROUTE_REGISTRY)
  • @openapi JSDoc annotation on each handler
  • Test file created with at least auth coverage

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.