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.

CodingPack: Matt Pocock's skills114 linescodebase-design
Author
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 pick codebase-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.

Claude Code — macOS, Linux
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
Codex, Cursor — macOS, Linux
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
Claude Code — Windows PowerShell
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 }
Codex, Cursor — Windows PowerShell
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

Raw

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:

  1. Accept dependencies, don't create them.

    // Testable
    function processOrder(order, paymentGateway) {}
    
    // Hard to test
    function processOrder(order) {
      const gateway = new StripeGateway();
    }
    
  2. Return results, don't produce side effects.

    // Testable
    function calculateDiscount(cart): Discount {}
    
    // Hard to test
    function applyDiscount(cart): void {
      cart.total -= discount;
    }
    
  3. 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 interface keyword 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.

More from the pack Matt Pocock's skills

Code review against standards and spec

Reviews the diff since a commit, branch or tag on two axes in parallel subagents: the repo's written standards plus a baseline of Fowler code smells, and the originating spec or issue. Use when a branch or PR needs checking against its spec.

Diagnosing hard bugs

Diagnoses hard bugs and slowdowns by first building a fast, deterministic command that reproduces the exact symptom, then minimising it, ranking falsifiable hypotheses and adding a regression test at a real seam. Use when something fails, throws or got slow.

Domain modeling

Sharpens a project's domain language during design: challenges fuzzy or conflicting terms, writes resolved ones to GLOSSARY.md at once and offers a short ADR only for hard-to-reverse trade-offs. Use when discussing terminology or recording an ADR.

Implement a spec

Implements a spec and its tickets on one integration branch: a fresh implementer subagent per ticket in its own worktree, run in parallel along the blocking graph, then a code review and one fix pass. Use when the tickets from to-tickets are ready.

Improve codebase architecture

Finds shallow modules worth deepening, starting from the code that changes most, shows the candidates in an HTML report with before/after diagrams and grills the chosen one with you. Use when a codebase has grown hard to test or navigate.

Throwaway prototype

Builds throwaway code to answer one design question: a single-file clickable HTML demo for a state model, or several structurally different UI variants on one route switched by a URL param. Use when checking whether logic holds or how a page should look.

Coding session retrospective

Reviews a finished coding session from its logs and proposes changes to the agent's environment: navigation pointers, lint rules, pre-commit and CI checks, reviewer standards, tool use. Use when an agent session went slowly or made avoidable mistakes.

TDD with integration tests

Drives test-first work through public interfaces: agrees the seams to test with the user, runs one red-green cycle per test, mocks only at system boundaries and leaves refactoring to review. Use when building a feature or fixing a bug test-first.

Conversation to spec

Turns the current conversation and codebase into a spec with user stories, implementation and testing decisions, and publishes it to the issue tracker as ready-for-agent, without interviewing the user. Use when a discussed feature needs writing up.

Spec to tickets

Splits a spec, plan or conversation into tracer-bullet tickets, vertical slices that each fit one agent session, with blocking edges, and publishes them as local files or tracker issues. Use when work is too big for one session and needs a task graph.

Issue and PR triage

Triages issues and external PRs on the tracker: gives each a category and a state, checks for existing code and past rejections, reproduces bugs and writes agent briefs for ready work. Use when a maintainer works through incoming issues and PRs.

Wayfinder for huge work

Charts work too big for one agent session as a map issue with child decision tickets on the tracker, then resolves one ticket per session until the route to the goal is clear. Use when a large effort has open questions that block a spec or plan.

Bash wizard for manual steps

Generates an interactive bash script that walks a person through manual steps such as dashboard setup, API keys and CI secrets, opening each URL and saving values to .env and GitHub secrets. Use when setup or a migration needs steps only a human can take.

Git guardrails for Claude Code

Installs a Claude Code PreToolUse hook that stops the usual forms of git push, reset --hard, clean -f, branch -D and checkout or restore of the whole tree, for one project or all, then tests it. Use when you want a safety net against an agent pushing or discarding work on its own.

Migrate tests to shoehorn

Replaces as and as unknown as casts in TypeScript tests with fromPartial and fromAny from @total-typescript/shoehorn, adds the imports and runs the type check. Use when tests fake whole objects or cast partial test data to satisfy the compiler.

Pre-commit hooks setup

Sets up Husky and lint-staged in a Node repo so each commit runs Prettier on staged files, then the typecheck and test scripts, matched to the lockfile, and makes the first commit through the hook. Use when a repo has no commit-time checks.

Grilling a plan

Questions the user about a plan or decision in rounds of numbered questions with recommended answers, looks facts up itself through subagents and stops only when no decision is left assumed. Use when a plan needs stress-testing before work starts.

Teach me a topic

Runs a multi-session course in the current folder: a mission, trusted sources, short HTML lessons with quizzes, reference sheets and learning records that set the next lesson. Use when the user wants to learn a topic over time, not get one answer.

Decision questionnaire

Writes a Markdown questionnaire for someone who holds knowledge the user lacks, after asking only who it goes to and what answers are needed, with the most important questions first. Use when a decision depends on facts from another person.

Writing for agents

Gives the rules for writing text agents read: skill descriptions as context pointers, what to keep inline and what to move to a separate file, completion criteria, leading words and pruning. Use when creating or editing a skill, AGENTS.md or CLAUDE.md.