Deep module design
Fixes a shared vocabulary for deep modules (interface, seam, adapter, depth, leverage), with the deletion test, dependency categories and a design-it-twice pattern on parallel subagents. Use when designing a module's interface or deciding where a seam goes.
codebase-design- Author
- Matt Pocock
- Source
- mattpocock/skills/skills/engineering/codebase-design @ abeeaf9
- License
- MIT · Copyright (c) 2026 Matt Pocock
About this skill
What it does
Codebase design is a vocabulary and a short set of rules for deep modules: a lot of behaviour behind a small interface, at a clean seam, tested through that interface. It fixes the terms — module, interface, depth, seam, adapter, leverage, locality — and keeps the agent from swapping them for "component", "service", "API" or "boundary". An interface means everything a caller must know: types, but also invariants, ordering, error modes and performance. The rules: depth belongs to the interface; the deletion test (delete the module — does complexity vanish or spread across callers?); the interface is the test surface; one adapter is a hypothetical seam, two make a real one.
DEEPENING.md sorts dependencies into four kinds — in-process, local stand-in such as PGLite, your own remote service behind a port, third-party service behind a mock — and says how to test each; old unit tests on shallow modules are deleted once the new interface has tests. DESIGN-IT-TWICE.md has three or more subagents each design a radically different interface (minimal, flexible, tuned for the common caller, ports and adapters); the agent compares them on depth, locality and seam placement and recommends one or a hybrid. agents/openai.yaml holds the Codex display name and description.
When to use it, and when not
Use it to shape a module's interface, decide where a seam goes, or make code testable and easier for an agent to navigate. Other skills load it for its terms.
It does not scan the codebase or pick what to refactor; that is improve-codebase-architecture. On REST endpoints or pagination it has nothing to say.
How to run it
The install command below puts the whole folder in place. The agent picks the skill up by its description when interface design comes up; to call it yourself:
- Claude Code:
/codebase-design, or ask for the skill by name. - Codex:
$codebase-design. - Cursor: type
/in the Agent chat and pickcodebase-design.
Example: /codebase-design Billing logic is spread over six small files. Design one billing module's interface three ways and recommend one.
improve-codebase-architecture and tdd call this skill, and design-it-twice briefs its subagents with the GLOSSARY.md that domain-modeling maintains. Install them together.
How it differs from similar skills
API and interface design covers public contracts: Hyrum's law, error semantics, validation at boundaries, REST and TypeScript patterns. Codebase design is about the depth of modules inside the code and where tests attach. Safe refactoring from our catalog carries out a restructure in small steps under characterization tests; this skill decides which shape to aim for, not how to get there safely. React composition patterns works on component interfaces in React only, with fixed rules such as compound components and explicit variants instead of boolean props.
Install
Run one command — it saves SKILL.md and the files it uses into your agent's skills folder. Claude Code and Codex pick up a new skill without a restart; if it does not show up, restart the agent.
curl -fsSL --create-dirs -o ~/.claude/skills/codebase-design/SKILL.md https://anymodel.org/en/skills/matt-pocock/codebase-design/SKILL.md -o ~/.claude/skills/codebase-design/DEEPENING.md https://anymodel.org/en/skills/matt-pocock/codebase-design/DEEPENING.md -o ~/.claude/skills/codebase-design/DESIGN-IT-TWICE.md https://anymodel.org/en/skills/matt-pocock/codebase-design/DESIGN-IT-TWICE.md -o ~/.claude/skills/codebase-design/LICENSE https://anymodel.org/en/skills/matt-pocock/codebase-design/LICENSE -o ~/.claude/skills/codebase-design/agents/openai.yaml https://anymodel.org/en/skills/matt-pocock/codebase-design/agents/openai.yaml
curl -fsSL --create-dirs -o ~/.agents/skills/codebase-design/SKILL.md https://anymodel.org/en/skills/matt-pocock/codebase-design/SKILL.md -o ~/.agents/skills/codebase-design/DEEPENING.md https://anymodel.org/en/skills/matt-pocock/codebase-design/DEEPENING.md -o ~/.agents/skills/codebase-design/DESIGN-IT-TWICE.md https://anymodel.org/en/skills/matt-pocock/codebase-design/DESIGN-IT-TWICE.md -o ~/.agents/skills/codebase-design/LICENSE https://anymodel.org/en/skills/matt-pocock/codebase-design/LICENSE -o ~/.agents/skills/codebase-design/agents/openai.yaml https://anymodel.org/en/skills/matt-pocock/codebase-design/agents/openai.yaml
foreach ($f in 'SKILL.md','DEEPENING.md','DESIGN-IT-TWICE.md','LICENSE','agents/openai.yaml') { $p = Join-Path "$HOME\.claude\skills\codebase-design" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/matt-pocock/codebase-design/$f" -UseBasicParsing -OutFile $p }foreach ($f in 'SKILL.md','DEEPENING.md','DESIGN-IT-TWICE.md','LICENSE','agents/openai.yaml') { $p = Join-Path "$HOME\.agents\skills\codebase-design" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/matt-pocock/codebase-design/$f" -UseBasicParsing -OutFile $p }Any other agent: save the file into its skills folder, or give it the link to the file: https://anymodel.org/en/skills/matt-pocock/codebase-design/SKILL.md
SKILL.md
Codebase Design
Design deep modules: a lot of behaviour behind a small interface, placed at a clean seam, testable through that interface. Use this language and these principles wherever code is being designed or restructured. The aim is leverage for callers, locality for maintainers, and testability for everyone.
Glossary
Use these terms exactly: don't substitute "component," "service," "API," or "boundary." Consistent language is the whole point.
Module: anything with an interface and an implementation. Deliberately scale-agnostic: a function, class, package, or tier-spanning slice. Avoid: unit, component, service.
Interface: everything a caller must know to use the module correctly: the type signature, but also invariants, ordering constraints, error modes, required configuration, and performance characteristics. Avoid: API, signature (too narrow, they refer only to the type-level surface).
Implementation: what's inside a module, its body of code. Distinct from Adapter: a thing can be a small adapter with a large implementation (a Postgres repo) or a large adapter with a small implementation (an in-memory fake). Reach for "adapter" when the seam is the topic; "implementation" otherwise.
Depth: leverage at the interface. The amount of behaviour a caller (or test) can exercise per unit of interface they have to learn. A module is deep when a large amount of behaviour sits behind a small interface, shallow when the interface is nearly as complex as the implementation.
Seam (Michael Feathers): a place where you can alter behaviour without editing in that place; the location at which a module's interface lives. Where to put the seam is its own design decision, distinct from what goes behind it. Avoid: boundary (overloaded with DDD's bounded context).
Adapter: a concrete thing that satisfies an interface at a seam. Describes role (what slot it fills), not substance (what's inside).
Leverage: what callers get from depth. More capability per unit of interface they learn. One implementation pays back across N call sites and M tests.
Locality: what maintainers get from depth. Change, bugs, knowledge, and verification concentrate in one place rather than spreading across callers. Fix once, fixed everywhere.
Deep vs shallow
Deep module = small interface + lots of implementation:
┌─────────────────────┐
│ Small Interface │ ← Few methods, simple params
├─────────────────────┤
│ │
│ Deep Implementation│ ← Complex logic hidden
│ │
└─────────────────────┘
Shallow module = large interface + little implementation (avoid):
┌─────────────────────────────────┐
│ Large Interface │ ← Many methods, complex params
├─────────────────────────────────┤
│ Thin Implementation │ ← Just passes through
└─────────────────────────────────┘
When designing an interface, ask:
- Can I reduce the number of methods?
- Can I simplify the parameters?
- Can I hide more complexity inside?
Principles
- Depth is a property of the interface, not the implementation. A deep module can be internally composed of small, mockable, swappable parts; they just aren't part of the interface. A module can have internal seams (private to its implementation, used by its own tests) as well as the external seam at its interface.
- The deletion test. Imagine deleting the module. If complexity vanishes, it was a pass-through. If complexity reappears across N callers, it was earning its keep.
- The interface is the test surface. Callers and tests cross the same seam. If you want to test past the interface, the module is probably the wrong shape.
- One adapter means a hypothetical seam. Two adapters means a real one. Don't introduce a seam unless something actually varies across it.
Designing for testability
Good interfaces make testing natural:
Accept dependencies, don't create them.
// Testable function processOrder(order, paymentGateway) {} // Hard to test function processOrder(order) { const gateway = new StripeGateway(); }Return results, don't produce side effects.
// Testable function calculateDiscount(cart): Discount {} // Hard to test function applyDiscount(cart): void { cart.total -= discount; }Small surface area. Fewer methods = fewer tests needed. Fewer params = simpler test setup.
Relationships
- A Module has exactly one Interface (the surface it presents to callers and tests).
- Depth is a property of a Module, measured against its Interface.
- A Seam is where a Module's Interface lives.
- An Adapter sits at a Seam and satisfies the Interface.
- Depth produces Leverage for callers and Locality for maintainers.
Rejected framings
- Depth as ratio of implementation-lines to interface-lines (Ousterhout): rewards padding the implementation. We use depth-as-leverage instead.
- "Interface" as the TypeScript
interfacekeyword or a class's public methods: too narrow: interface here includes every fact a caller must know. - "Boundary": overloaded with DDD's bounded context. Say seam or interface.
Going deeper
- Deepening a cluster given its dependencies, see DEEPENING.md: dependency categories, seam discipline, and replace-don't-layer testing.
- Exploring alternative interfaces, see DESIGN-IT-TWICE.md: spin up parallel sub-agents to design the interface several radically different ways, then compare on depth, locality, and seam placement.
Connect through AnyModel API
This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.
AnyModel