agentleFS
subhash-arabhisubhash-arabhi/saas-playbook/skills/api-and-interface-design/SKILL.md

api-and-interface-design

Skill1 starsChanged 30 days agoMITView on GitHub

Guides stable API and interface design. Use when designing or changing API endpoints, contracts between the website and the API, module boundaries, or any public interface.

72 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use constraint-driven-development, deprecation-and-migration and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 17 projects that use this

  • HK-hubSkill

    deprecation-and-migration

    Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.

    Also in 40 projects that use this

  • seikaikyoSkill

    doubt-driven-development

    對非平凡決策啟動新鮮 context 對抗審查(找碴不背書),在修正還便宜的時候抓出錯誤方向。適用:高風險改動(production、資安敏感邏輯、不可逆操作)、不熟的程式碼、要宣稱「這樣是安全的 / 可行的」之前。機械性操作與一行修改不適用。

    Also in 47 projects that use this

  • HK-hubSkill

    source-driven-development

    Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.

    Also in 42 projects that use this

  • skytiger6724Skill

    brainstorm-experiments-existing

    Design experiments to test assumptions for an existing product — prototypes, A/B tests, spikes, and other low-effort validation methods. Use when validating assumptions, testing feature ideas cheaply, or planning product experiments.

    Also in 4 projects that use this

  • skytiger6724Skill

    prioritize-assumptions

    Prioritize assumptions using an Impact × Risk matrix and suggest experiments for each. Use when triaging a list of assumptions, deciding what to test first, or applying the assumption prioritization canvas.

    Also in 4 projects that use this

  • +2 more from skytiger6724

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 5 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 67 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

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

    Project rules first: If the project has .agents/rules/ (installed with the SaaS playbook), read .agents/rules/backend.md and …

    line 8
  2. Distinctive:

    When database, API and website deploy one after another, the live website briefly talks to the new API.

    line 30
  3. Distinctive:

    Every API change must keep working with the website that's live now.

    line 31
  4. Distinctive:

    Remove or rename in two deploys: (1) add the new thing and switch the website to it.

    line 32
  5. Distinctive:

    Contract first: Write the request/response schemas before the logic, so the spec and generated client exist first.

    line 39
  6. Very specific:

    One response shape per endpoint: Don't return different shapes depending on conditions.

    line 41
  7. Distinctive:

    Don't validate between internal functions that share types, in utilities called by validated code, or on data from your own database.

    line 60

“Common” is measured: kept by at least 6 in 10 of the 67 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
<!-- Adapted from addyosmani/agent-skills@1401c8b (MIT, see licenses/). Changes: default conventions (camelCase, <domain>/api/<resource>, no versioning, OpenAPI + generated client), deploy-window compatibility, auth/health rules, language-agnostic, trimmed; layered: general guidance here, playbook decisions in .agents/rules/. -->

Project rules first. If the project has .agents/rules/ (installed with the SaaS playbook), read .agents/rules/backend.md and .agents/rules/deployment.md and follow them: they override this skill where they differ. Without them, follow this skill as written.

API and Interface Design

Design interfaces that are stable and hard to misuse. Applies to the website's API, module boundaries, UI component inputs, and any surface where one piece of code calls another. Internal callers are still callers: give them a contract too.

Defaults (a project's rules override these)

TopicDefault
Base URLhttps://<domain>/api/<resource>, same address as the website (no subdomain, no CORS)
VersioningNone. One version, changed only by adding. /v1 only if outside customers call the API directly
CasingJSON fields and query params camelCase; enums and error codes UPPER_SNAKE; booleans is/has/can prefix
ContractOpenAPI spec generated from the code's request/response schemas, committed
Website clientTypes and client generated from the spec, never hand-written. Regenerate on every API change
AuthEvery endpoint declares who may call it. Default deny. Public endpoints explicitly marked public
HealthGET /api/health, no auth, OK when the API can serve requests. Deploy smoke checks use it
ErrorsOne shape: { "error": { "code", "message", "details?" } }
ListsPaginated from the start, pageSize capped

The deploy window

When database, API and website deploy one after another, the live website briefly talks to the new API.

  • Every API change must keep working with the website that's live now. Add fields and endpoints; never rename, remove or change the type of anything the live website uses in the same deploy.
  • Remove or rename in two deploys: (1) add the new thing and switch the website to it; (2) once live, check nothing still calls the old one (logs or code search), then remove it.
  • Migrations follow the same rule: the old API must still work with the migrated schema.

Principles

  • Every observable behaviour is a contract (Hyrum's Law): error text, ordering, timing, quirks. Expose only what you mean to; don't leak implementation details.
  • One version at a time. Extend, don't fork.
  • Contract first. Write the request/response schemas before the logic, so the spec and generated client exist first.
  • Addition over modification. New input fields are optional. Never remove a field or change its type in place.
  • One response shape per endpoint. Don't return different shapes depending on conditions. Don't mix throwing, returning null and returning { error }.

Errors

StatusMeaning
400Malformed request
401Not authenticated
403Authenticated but not allowed
404Not found, including a resource that belongs to someone else
409Conflict: duplicate, version mismatch, in-flight idempotent request
422Validation failed (code: "VALIDATION_ERROR", field errors in details)
429Rate limited
500Server error; never expose internal details

Validate at boundaries only

Validate at: API route handlers; website forms (for UX only, the API still validates); outside-service responses (always untrusted: check shape and content before using them in logic or rendering); config loading (fail fast on missing required settings).

Don't validate between internal functions that share types, in utilities called by validated code, or on data from your own database. After validation, internal code trusts the typed value.

REST patterns

  • Plural nouns, no verbs: GET/POST /api/tasks, GET/PATCH/DELETE /api/tasks/{id}, sub-resources as /api/tasks/{id}/comments.
  • Scope user-owned resources to the caller: someone else's {id} returns 404, lists return only the caller's data. Add a test that proves it.
  • Pagination: page-based by default (?page=1&pageSize=20&sortBy=createdAt&sortOrder=desc → { data, pagination: { page, pageSize, totalItems, totalPages } }). Use cursors (?cursor= → nextCursor) for very large or constantly changing lists.
  • Filters are query params: ?status=IN_PROGRESS&createdAfter=2025-01-01.
  • Updates use PATCH with partial objects: only provided fields change.
  • DELETE is idempotent: succeeds even if already deleted.

Types

  • Model distinct states as explicit variants (tagged union or a type field), not one shape full of optional fields. Code handling them must cover every variant; a compiler or test catches a missing case.
  • Separate input from output types. Never accept server-owned fields (id, createdAt, ownerId) from the caller.
  • Give each kind of ID its own type where the language allows, so a UserId can't pass as a TaskId.

Idempotency

State-changing endpoints either honour an idempotency key or are documented as unsafe to retry. Design for at-least-once delivery: no queue gives exactly-once across a consumer crash. When implementing an idempotency key (payments, external side effects, queue consumers), read references/idempotency.md.

Done when

  • OpenAPI spec regenerated and committed; website client regenerated from it.
  • Changes are additive; the live website still works with the new API.
  • GET /api/health still works.

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.