sdk-api-design
Skill1 starsChanged 3 months agoMITView on GitHub
Design, implement, review, or refactor language-agnostic SDK and client-library public APIs using the durable principles from Joshua Bloch's talk "How to Design a Good API and Why It Matters." Use this skill whenever a user asks to create or critique an SDK surface, API client, service wrapper, reusable library interface, public package contract, plugin API, or SPI—even when they ask only to "make this client easier to use," "clean up these methods," or implement a service integration. Apply it across programming languages and transports. Do not use it for a purely internal refactor that cannot affect a reused boundary.
In this repository8 other files it gives its agents.
- codexSkill
- diataxis-docs-writerSkill
- dsl-designSkill
- google-adk-agent-builderSkill
- google-adk-architectureSkill
- hexagonal-architectureSkill
- open-source-vendoring-best-practicesSkill
- python-sdk-designSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
26 rules. About 0 are common, 25 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈25
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Treat an SDK as a small language its users must learn.
- Distinctive: line 24
Do not import rules from other SDK guidelines.
- Distinctive: line 31
Implementation mode: create or change working SDK code.
- Very specific: line 38
Always read references/bloch-principles.md before making public-surface decisions.
- Distinctive: line 58
Write a small set of concrete client tasks that will judge the design.
- Distinctive: line 70
Keep the first draft to roughly one page: exported types and operations, signatures, and one-line contracts.
- Distinctive: line 80
Read the client code as a language:
- Distinctive: line 90
Do not implement a new public surface until these trials show it supports the use cases coherently [B04-B05].
- Distinctive: line 106
Keep replaceable choices—storage, transport, internal algorithm, serialization, or framework vocabulary—out of the public contract unless …
- Distinctive: line 115
Use inheritance only for honest substitutability.
- Distinctive: line 124
Avoid same-name variants whose resolution can silently select meaningfully different behavior [B23].
- Distinctive: line 128
Keep parameter order consistent and parameter lists short enough to use correctly, especially around same-shaped values [B25].
- Distinctive: line 130
Prefer ordinary value-shaped results to rare sentinels that every caller must remember [B26].
- Distinctive: line 139
Use disagreement to uncover missed use cases and hidden assumptions.
- Distinctive: line 149
Use the target language's customary mechanisms rather than copying another language's SDK shape [B15].
- Distinctive: line 156
If implementation exposes a design flaw, return to the sketch and client trials.
- Distinctive: line 162
Document every exported element.
- Distinctive: line 168
Keep the exemplary use-case programs current as samples and tests whenever the surface changes [B05].
- Distinctive: line 191
Use this order when the heuristics conflict:
- Distinctive: line 198
Prefer target-platform customs over cross-language sameness [B15].
- Distinctive: line 200
Consider lasting performance consequences without warping the contract [B14].
- Distinctive: line 203
Treat this as informed judgment, not scoring.
- Distinctive: line 222
Keep the surface sketch compact.
- Distinctive: line 247
Do not label an internal preference an API defect.
- Distinctive: line 252
Before finalizing work claimed to follow this skill:
- Distinctive: line 256
Remove, relabel, or justify any recommendation that lacks a mapping.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SDK API Design
Treat an SDK as a small language its users must learn. Shape that language from their use cases before implementation makes the public surface expensive to change.
This skill is derived solely from Joshua Bloch's talk How to Design a Good API
and Why It Matters. references/bloch-principles.md is the source map: every
normative API-design instruction below cites a Bxx identifier defined there.
Do not import rules from other SDK guidelines. Use target-ecosystem conventions
only to translate Bloch's principles into a native form [B15, B28].
Start by choosing the mode
- Design mode: propose a new public SDK surface. Follow the full workflow and deliver the design brief.
- Implementation mode: create or change working SDK code. Follow the design workflow before implementation; compress it only when concrete use cases, client trials, and an approved surface already exist [B03-B05].
- Review mode: audit an existing or proposed surface. Read
references/review-checklist.md, report evidence-backed findings, and do not edit unless the user requested changes.
Always read references/bloch-principles.md before making public-surface
decisions. It contains the reasoning needed when rules pull against one another.
Workflow: use before implementation
1. Identify the commitment and audience [B01-B02]
State:
- who will call, implement, or maintain the API;
- what vocabulary and platform knowledge they already have;
- how public and long-lived the boundary is;
- what existing client code or compatibility constraints already depend on it.
Spend more scrutiny on surfaces with more users, implementations, or expected longevity. Treat an established public behavior as costly to remove [B01, B08].
2. Recover requirements as use cases [B03]
Separate each requested outcome from the mechanism a stakeholder proposed. Write a small set of concrete client tasks that will judge the design. Include:
- the ordinary simple path;
- legitimate complex paths;
- likely mistakes the surface should make difficult.
Reject capability that has no demonstrated use case. Generalize only when the general form solves the underlying problem more simply or coherently [B03, B10].
3. Sketch the whole public surface [B04]
Keep the first draft to roughly one page: exported types and operations, signatures, and one-line contracts. Do not bury unresolved design choices under implementation detail. Restructure freely while the sketch is cheap to change.
4. Write client code against the unimplemented surface [B05]
For every use case, write realistic client code as if the SDK already existed. Show setup, the main operation, result use, and relevant failure behavior. Also write at least one plausible misuse when misuse resistance matters.
Read the client code as a language:
- Can an intended user guess it and later read it without constant lookup? [B02, B09]
- Does it expose plumbing rather than client intent? [B19]
- Can names, types, parameter order, or surprising side effects invite a likely mistake? [B20-B25]
- Does ordinary behavior require rare sentinels or exception-driven control flow? [B26-B27]
Do not implement a new public surface until these trials show it supports the use cases coherently [B04-B05]. Preserve the trials as samples and tests, and hold them to an unusually high standard because users will copy them [B05].
5. Reduce the surface's conceptual weight [B09-B12]
For every exported capability, type, method, and parameter, ask which use case requires it. Remove uncertain commitments; addition is easier than removal [B01, B10]. Count concepts users must learn, not declarations. Reuse an appropriate, familiar platform abstraction when that adds power without a new concept [B10, B15].
Let naming push back on the design. If clear, consistent names do not emerge, split unrelated purposes, merge internal steps, or find the coherent containing abstraction [B09]. Expose only elements clients actually need [B12].
Keep replaceable choices—storage, transport, internal algorithm, serialization, or framework vocabulary—out of the public contract unless interoperability or a use case requires the commitment [B11]. Avoid implementation-convenience size limits [B16].
6. Make correct use natural [B17-B27]
- Minimize mutability and keep any necessary state machine small and explicit [B17].
- Use inheritance only for honest substitutability; either specify the interaction of overridable operations or prohibit subclassing [B18].
- Move necessary repeatable plumbing into the SDK when the SDK can do it correctly without hiding a meaningful client choice [B19].
- Make names describe primary effects and important side effects [B20].
- Prevent invalid states when the platform can express the constraint; otherwise reject invalid input at the earliest operation that can recognize it [B21].
- Expose structured access to every datum also rendered in a display string [B22].
- Avoid same-name variants whose resolution can silently select meaningfully different behavior [B23].
- Choose types that express the actual domain and precision, neither so broad that common inputs fail later nor tied to one implementation [B24].
- Keep parameter order consistent and parameter lists short enough to use correctly, especially around same-shaped values [B25].
- Prefer ordinary value-shaped results to rare sentinels that every caller must remember [B26].
- Reserve exceptions for exceptional conditions; force explicit recovery only where the platform supports that distinction and callers can realistically recover [B27].
7. Seek feedback without designing by accretion [B07-B08]
Show the short surface and client trials to relevant users and implementers. Use disagreement to uncover missed use cases and hidden assumptions. Balance important constituencies, but keep one coherent vocabulary and design voice. Expect imagination to fail and preserve room for compatible additions.
For an SPI or plugin boundary, write multiple genuinely different providers before publishing it: two expose single-provider assumptions; a third gives stronger confidence that the abstraction can stretch [B06].
8. Implement behind the validated boundary [B11, B14-B16]
Use the target language's customary mechanisms rather than copying another language's SDK shape [B15]. Keep implementation types and errors behind the boundary [B11]. Consider whether the contract prevents an efficient implementation, but do not distort a long-lived surface to work around a temporary performance problem [B14]. Do not introduce a fixed ceiling merely because the first implementation is simpler with one [B16].
If implementation exposes a design flaw, return to the sketch and client trials. Do not patch over a bad surface with more internal machinery [B04-B05, B09].
9. Specify, document, and preserve the contract [B05, B13]
Document every exported element. Cover what an instance represents; operation preconditions, postconditions, side effects, and failures; parameter units, formats, and ownership; and legal transitions of mutable state [B13]. Specify observable guarantees without freezing incidental implementation behavior [B11, B13].
Keep the exemplary use-case programs current as samples and tests whenever the surface changes [B05]. Run the review checklist before declaring the public API ready.
Translate mechanics; preserve judgments
Bloch's examples use Java-era mechanisms. For each target language [B15, B28]:
- Identify the user-facing failure or property in the mapped principle.
- Inspect the customary mechanisms already used by the target platform and repository.
- Choose the native mechanism that best realizes the principle.
- Explain the tradeoff in terms of use cases and client harm.
For example, B25 supports reducing a long, ambiguous parameter list. Depending on the language, the native answer might be named arguments, a helper value, several cohesive operations, or a builder. The builder is an illustration, not the rule. Apply the same translation to overloads, checked exceptions, static typing, inheritance controls, and any other language-bound mechanism [B15, B21, B23, B27-B28].
Resolve tensions explicitly [B28]
Use this order when the heuristics conflict:
- Serve the intended audience's demonstrated use cases [B02-B03].
- Make correct ordinary use natural and misuse difficult [B02].
- Minimize conceptual weight [B09-B10].
- Omit unsupported commitments [B10].
- Still absorb necessary repeated client work [B19].
- Prefer target-platform customs over cross-language sameness [B15].
- Preserve established client meaning while extending around mistakes [B08].
- Consider lasting performance consequences without warping the contract [B14].
Treat this as informed judgment, not scoring. If violating a heuristic, name the competing principle, the use-case evidence, and what would cause the choice to be revisited [B28].
Deliverables
Design brief
## Audience and underlying problem
## Use cases
## Public-surface sketch
## Client-code trials
## Misuse and failure trials
## Omissions
## Tradeoffs and evolvability
## Feedback still neededKeep the surface sketch compact. Put explanations after the client trials so the surface must first stand on its own [B02, B04-B05].
Implementation handoff
Summarize:
- the use cases and validated public surface [B03-B05];
- the implementation boundary and hidden choices [B11];
- samples, tests, and exported contract documentation added [B05, B13];
- deliberate heuristic violations and their evidence [B28].
Review report
Lead with findings, ordered by irreversible client impact [B01, B08]. For each:
### [Severity] Finding title
- Evidence: [specific signature, call sequence, behavior, or file location]
- Principle: [Bxx and name]
- Client harm: [misuse, conceptual load, coupling, delayed failure, or blocked evolution]
- Smallest correction: [minimum coherent change]
- Tradeoff: [reason the current design might remain, if real]Do not label an internal preference an API defect. Tie every finding to a public consequence and a mapped principle [B28].
Source-only audit
Before finalizing work claimed to follow this skill:
- List the normative API-design recommendations in the output.
- Map each to a
Bxxprinciple inreferences/bloch-principles.md. - Remove, relabel, or justify any recommendation that lacks a mapping. A user requirement or repository constraint may still apply, but do not attribute it to Bloch.
- Confirm platform conventions were used only as mechanisms for B15, not as an additional design doctrine.
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.

