shennawardana23/skillme/api-and-interface-design
Claude Code and agent skill by shennawardana23/skillme
- community
Checking that the SKILL.md file is still in the repository.
Guides internal interface and module-boundary design — Go interfaces, package APIs, and cross-team contracts inside a codebase, as distinct from the wire-level REST/RPC contract shape covered by the api-design skill. Use when defining an interface between packages, deciding where an interface should live, choosing between accepting an interface or a concrete type, evolving a public function signature without breaking callers, or reviewing a Go package's exported API for coupling and future flexibility.
Install
npx vskill@latest install shennawardana23/skillme/api-and-interface-designSKILL.md
The same SKILL.md was published earlier as shennawardana23/skillme/api-and-interface-design.
API and Interface Design
This skill covers in-process boundaries: interfaces between packages, modules, or teams inside a single codebase or binary. For the shape of a wire-level contract (REST/RPC request/response bodies, error envelopes, pagination, versioning of an HTTP or RPC API), use the api-design skill instead — the two are complementary: a service's HTTP handler is itself a consumer of the internal interfaces this skill is about.
Core rule: define the interface where it's consumed, not where it's implemented
The single most common Go interface mistake is declaring an interface next to its implementation ("I built a Store, so I export a Store interface next to it"). This forces every consumer to depend on the producer's package just to get the interface type, and it tempts the producer into a single fat interface covering everything the type does.
The producer (store.SQLStore) never needs to declare an interface at all — it just needs to satisfy whatever its consumers declare, which Go's structural typing does implicitly. This is the direct analogue of Go's own guidance ("accept interfaces, return structs"): a constructor should return a concrete type so callers get full access to it, and take interfaces as parameters so the function only asks for what it uses.
Core rules
- Small interfaces, defined by consumers. One or two methods is the
norm (io.Reader, sort.Interface). A ten-method interface is a sign the consumer actually depends on a concrete implementation and should just take one, or the interface should be split per-consumer.
- Accept interfaces, return structs. Functions and constructors take
the narrowest interface they need as a parameter, and return a concrete type. Returning an interface hides the concrete type's own methods from every caller, including ones that could safely use them.
- **Extend via new, optional parameters — never widen an existing
signature's meaning.** Adding a field to a struct passed by value, or a new method to an interface nobody outside this package implements, is safe. Adding a required parameter to an exported function, or a method to an interface implemented by external packages, breaks every implementer — use the functional-options pattern instead: ```go type Option func(*clientConfig)
func WithTimeout(d time.Duration) Option { return func(c *clientConfig) { c.timeout = d } }
// NewClient(url) still works; new callers add options without // breaking anyone who already calls NewClient(url). func NewClient(url string, opts ...Option) *Client { ... } ```
- One error-handling contract per package boundary. Callers must be
able to use errors.Is/errors.As against sentinel or typed errors you export (var ErrNotFound = errors.New(...)), not string-match err.Error(). Wrap with %w, never %v, so the chain survives.
- The One-Version Rule. Don't make consumers choose between two
incompatible versions of the same interface at once (a v1.Store and a v2.Store implemented by different types with overlapping callers). Prefer extending the existing interface additively, or migrating all consumers to the new one in one coordinated change — see deprecation-and-migration for the process when the old interface must eventually go.
- Validate at the boundary where untrusted input enters (HTTP
handler, CLI flag parsing, config file load) — internal function calls receiving already-validated types should not re-validate; see api-design for the full boundary-validation rule at the wire level.
Discriminated unions without a language feature
Go has no sum types, but the same "make illegal states unrepresentable" goal is achievable with an interface plus a private marker method, giving consumers exhaustive-style handling via a type switch:
Because isReservationState is unexported, no package outside this one can add a new implementation — the switch above really is exhaustive against every case that exists today.
Gotchas
- A one-method interface named after the method (
Reader,Closer,
ReservationGetter) reads clearly at the call site; a interface named after the producer type (StoreInterface) is a sign it was designed producer-first and is probably too big.
interface{}(orany) as a parameter type isn't "flexible design," it
deletes the compiler's ability to catch a caller passing the wrong thing — prefer a small concrete interface or a generic type parameter.
- Adding a method to an interface you export and that external packages
implement is a breaking change even though nothing in your own repo fails to compile — search for var _ YourInterface = (*T)(nil) style assertions and any known external implementers before changing it.
- Table-driven tests that construct a fake by hand-implementing a small
interface are cheap; a fake implementing a twelve-method interface is itself a maintenance burden that argues for shrinking the interface.
- Returning an interface from a constructor (
func New() Reader) instead
of the concrete type blocks every caller from later using errors.As(err, &myConcreteErr) style type assertions or calling a method that isn't on the interface, even if they need to.
Real-world grounding
The Go 1 compatibility promise (in effect since Go 1.0, 2012) is the industry's most disciplined public demonstration of additive-only interface evolution: the standard library has added methods, types, and functions for over a decade while guaranteeing "existing programs will continue to run correctly, unchanged, over the lifetime of that version" — achieved specifically by never changing an existing exported signature's meaning and by growing interfaces only where it could prove no external implementer would break (an audit only the Go team could realistically do, which is why in your own code the safer default is to add a new interface or new options rather than widen an old one).
Verification
- [ ] Interfaces are declared in the consuming package, sized to what that consumer calls
- [ ] Constructors return concrete types; parameters accept the narrowest interface needed
- [ ] No exported function signature or externally-implemented interface changed in place — extension used functional options or a new type instead
- [ ] Errors are wrapped with
%wand exposed as sentinels/typed errors consumers canerrors.Is/errors.Asagainst - [ ] No two incompatible versions of the same interface are live across consumers at once (One-Version Rule)
- [ ] Wire-level contract concerns (HTTP shape, pagination, error envelope) are handled per the
api-designskill, not duplicated here
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
- Repository stars
- 2
- 7-day trend score
- 5
Stars and forks are for the whole GitHub repository, not this skill alone. 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/shennawardana23/skillme/api-and-interface-design)