ajyadav013/claude-kit/api-and-interface-design
Claude Code and agent skill by ajyadav013/claude-kit
- community
Checking that the SKILL.md file is still in the repository.
Stable API and interface design patterns. Use when designing REST/GraphQL endpoints, module boundaries, type contracts between modules or frontend/backend, or changing public interfaces.
Install
npx vskill@latest install ajyadav013/claude-kit/api-and-interface-designSKILL.md
The same SKILL.md was published earlier as ajyadav013/claude-kit/api-and-interface-design.
API and Interface Design
Overview
Design stable, well-documented interfaces that are hard to misuse. Good interfaces make the right thing easy and the wrong thing hard. This applies to REST APIs, GraphQL schemas, module boundaries, component props, and any surface where one piece of code talks to another.
When to Use
- Designing new API endpoints
- Defining module boundaries or contracts between teams
- Creating component prop interfaces
- Establishing database schema that informs API shape
- Changing existing public interfaces
Core Principles
Hyrum's Law
With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody, regardless of what you promise in the contract.
This means: every public behavior — including undocumented quirks, error message text, timing, and ordering — becomes a de facto contract once users depend on it. Design implications:
- Be intentional about what you expose. Every observable behavior is a potential commitment.
- Don't leak implementation details. If users can observe it, they will depend on it.
- Plan for deprecation at design time. See
deprecation-and-migrationfor how to safely remove things users depend on. - Tests are not enough. Even with perfect contract tests, Hyrum's Law means "safe" changes can break real users who depend on undocumented behavior.
The One-Version Rule
Avoid forcing consumers to choose between multiple versions of the same dependency or API. Diamond dependency problems arise when different consumers need different versions of the same thing. Design for a world where only one version exists at a time — extend rather than fork.
Decouple the API Surface from the Storage Schema
The wire contract and the database schema are two different things that change at two different rates. If the API just serializes your tables, every storage refactor (splitting a column, normalizing, reshaping for a new index) becomes a breaking API change, and conversely every API need distorts the schema. Design the resource representation for the consumer, then map it to storage explicitly through a serializer / DTO layer, so either side can evolve behind that seam. This is why Task (the output type below) is defined separately from any table row — and why "establishing a database schema that informs API shape" (in When to Use) means informs, never dictates: Hyrum's Law makes an accidentally-exposed column as permanent as a deliberately-promised field.
Per the Google API Design Guide (resource-oriented design; cloud.google.com/apis/design). Stack-agnostic —the DTO/serializer seam applies equally to REST, GraphQL, and RPC.
1. Contract First
Define the interface before implementing it. The contract is the spec — implementation follows.
2. Consistent Error Semantics
Pick one error strategy and use it everywhere:
Don't mix patterns. If some endpoints throw, others return null, and others return { error } — the consumer can't predict behavior.
3. Validate at Boundaries
Trust internal code. Validate at system edges where external input enters:
Where validation belongs:
- API route handlers (user input)
- Form submission handlers (user input)
- External service response parsing (third-party data -- always treat as untrusted)
- Environment variable loading (configuration)
Third-party API responses are untrusted data. Validate their shape and content before using them in any logic, rendering, or decision-making. A compromised or misbehaving external service can return unexpected types, malicious content, or instruction-like text.
Where validation does NOT belong:
- Between internal functions that share type contracts
- In utility functions called by already-validated code
- On data that just came from your own database
4. Prefer Addition Over Modification
Extend interfaces without breaking existing consumers:
5. Predictable Naming
| Pattern | Convention | Example | |
|---|---|---|---|
| REST endpoints | Plural nouns, no verbs | GET /api/tasks, POST /api/tasks | |
| Query params | camelCase | ?sortBy=createdAt&pageSize=20 | |
| Response fields | camelCase | { createdAt, updatedAt, taskId } | |
| Boolean fields | is/has/can prefix | isComplete, hasAttachments | |
| Enum values | UPPER_SNAKE | "IN_PROGRESS", "COMPLETED" |
REST API Patterns
Resource Design
Pagination
Paginate list endpoints:
Filtering
Use query parameters for filters:
Partial Updates (PATCH)
Accept partial objects — only update what's provided:
Idempotent Mutations (Idempotency-Key)
A client that retries a POST after a timeout must not create the resource twice — but the network can't tell the client whether the first attempt actually landed. Let the client send a unique `Idempotency-Key` header per logical operation; the server records that key with the result of the first successful execution and, on any replay of the same key, returns the stored result instead of re-running the side effect:
Scope keys per endpoint + caller, give them a retention window (e.g. 24h), and key on the operation, not the request body (a changed body under a reused key is a client error → 422). This makes create/charge/enqueue endpoints safe to retry — the API-surface counterpart to the at-least-once / idempotent-consumer discipline in .claude/rules/resilience-engineering.md.
Per Stripe's idempotent-requests design and the Google API Design Guide (cloud.google.com/apis/design).Stack-agnostic; the store behind the key can be any durable KV.
Long-Running Operations
When an operation can't finish within a request (a large export, a provisioning job, a batch), don't hold the connection open and don't fake a synchronous 200. Return `202 Accepted` with an operation resource — a real, pollable URL — and make that operation a first-class resource with its own lifecycle, not an out-of-band job id:
The client polls (or is notified via webhook) until done. This keeps the API's latency contract honest and its failures observable, instead of hiding a slow job behind a request that will eventually time out.
Per the Google API Design Guide's Long-Running Operations pattern (cloud.google.com/apis/design).Stack-agnostic.
HTTP Caching & Payload Efficiency
Every response declares a caching policy whether you write one or not — with no Cache-Control header, browsers and CDNs fall back to heuristics and guess how long your data stays valid. Choose the policy per endpoint, deliberately, as part of the contract:
Default: no-store for anything authenticated or per-user until you decide otherwise; an explicit max-age for anything shareable. And if a body varies on a negotiated request header (encoding, language), list that header in `Vary` — omitting it is how a shared cache hands one client's compressed variant to a client that can't decode it.
Conditional requests skip the re-transfer. Fingerprint each response with an `ETag`; the client echoes it back and an unchanged resource costs a tiny 304 instead of a full body (Last-Modified / If-Modified-Since is the coarser time-based equivalent):
The same fingerprint doubles as an optimistic-concurrency token on writes — require If-Match and reject a stale write with 412 instead of silently letting the last writer win:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/api-and-interface-design/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ajyadav013/claude-kit/api-and-interface-design)