agentleFS
KevinArceKevinArce/create-bun-api/skills/add-endpoint/SKILL.md

add-endpoint

Skill11 starsChanged 22 days agoApache-2.0View on GitHub

Add an HTTP endpoint or a new resource (routes, validation, service, SQL, tests) to a Bun + Elysia project created with create-bun-api, following its conventions, then prove it with bun run verify. Use when asked to add a route, endpoint, API resource, CRUD feature, or handler in a project that contains create-bun-api.json.

10 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Baseline: run bun run verify. If it already fails, fix that first (verify-and-debug skill) or report it.

    line 8
  2. Very specific:

    Create returns status(201, value).

    line 28
  3. Very specific:

    Finish: run bun run format (fixes formatting and import order), then bun run verify.

    line 29
  4. Very specific:

    Use status(204, undefined) and 204: t.Void().

    line 36
  5. Distinctive:

    Never log request bodies, headers, or tokens.

    line 38

“Common” is measured: kept by at least 6 in 10 of the 10 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 an endpoint

  1. Baseline: run bun run verify. If it already fails, fix that first (verify-and-debug skill) or report it. Don't build on a red baseline.
  2. Decide where the code goes:
    • New resource: a new folder src/modules/<name>/. <name> is plural and lowercase, e.g. notes.
    • New route on an existing resource: that module's <name>.routes.ts, with logic in <name>.service.ts.
    • New table or column: follow the add-model skill first.
  3. Write the module. A complete, tested example is in references/notes-module.md; copy its shape.
    • <name>.schema.ts: t schemas for bodies, params, and responses, plus typeof X.static types.
    • <name>.repository.ts: prepared SQL. Scope rows by owner (user_id) for per-user data.
    • <name>.service.ts: business rules. Throw notFound(), conflict(), and the other helpers from src/lib/errors.ts.
    • <name>.routes.ts: new Elysia({ prefix: "/<name>", tags: ["<name>"] }). Add .use(authPlugin(deps.tokens)) when any route sets auth: true. Declare body, params, query, and response on every route.
    • <name>.test.ts: use createTestApp() and signUp() from test/helpers.ts.
  4. Mount it in src/app.ts: create the service from db, then .use(<name>Routes({ ... })).
  5. Prove these behaviors in tests:
    • Invalid input returns 400 with error.code VALIDATION (the declared schema handles this).
    • A missing or invalid token returns 401.
    • Another user's resource returns 404, not 403.
    • Create returns status(201, value). Delete returns status(204, undefined), with 204: t.Void() in response.
  6. Finish: run bun run format (fixes formatting and import order), then bun run verify. You're done only when it passes. New routes appear automatically at /docs.

Gotchas

  • Returning { status: 401, body } sends HTTP 200. Throw the error helpers instead.
  • status(204) without a body fails the typecheck once a response map is declared. Use status(204, undefined) and 204: t.Void().
  • Path params declared as t.Integer() are converted from the URL string, so /notes/abc returns 400.
  • Never log request bodies, headers, or tokens.

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.