From mattpocock-skills
Provides shared vocabulary and principles for designing deep modules: small interfaces with rich implementations. Useful when designing or refactoring module interfaces, finding deepening opportunities, placing seams, or improving testability.
How this skill is triggered — by the user, by Claude, or both
Slash command
/mattpocock-skills:codebase-designThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
设计 **deep modules**:把大量行为放在小 interface 之后,把 interface 放在清晰 seam 上,并通过该 interface 测试。凡是在设计或重构代码时,都使用这套语言和原则。目标是给 callers 带来 leverage,给 maintainers 带来 locality,并让每个人都更容易测试。
设计 deep modules:把大量行为放在小 interface 之后,把 interface 放在清晰 seam 上,并通过该 interface 测试。凡是在设计或重构代码时,都使用这套语言和原则。目标是给 callers 带来 leverage,给 maintainers 带来 locality,并让每个人都更容易测试。
准确使用这些术语,不要替换成 "component"、"service"、"API" 或 "boundary"。一致语言就是重点。
Module - 任何拥有 interface 和 implementation 的东西。它故意不限定尺度:function、class、package,或跨层 slice 都可以。Avoid: unit, component, service.
Interface - caller 为了正确使用 module 必须知道的一切:type signature,以及 invariants、ordering constraints、error modes、required configuration 和 performance characteristics。Avoid: API, signature(太窄,只指 type-level surface)。
Implementation - module 内部的代码体。它不同于 Adapter:一个东西可以是小 adapter 但有大 implementation(Postgres repo),也可以是大 adapter 但 implementation 很小(in-memory fake)。讨论 seam 时说 adapter;其他时候说 implementation。
Depth - interface 上的 leverage:caller(或 test)每学习一单位 interface,就能触达多少行为。大量行为藏在小 interface 后面时,module 是 deep;interface 几乎和 implementation 一样复杂时,module 是 shallow。
Seam(Michael Feathers)- 你可以在不编辑当前位置的情况下改变行为的地方;也就是 module 的 interface 所在的 location。seam 放在哪里是独立设计决策,不同于 seam 后面放什么。Avoid: boundary(它和 DDD bounded context 过载)。
Adapter - 在 seam 上满足某个 interface 的具体东西。描述的是 role(填哪个槽位),不是 substance(内部是什么)。
Leverage - callers 从 depth 获得的收益:每学习一单位 interface,就得到更多能力。一个 implementation 会在 N 个 call sites 和 M 个 tests 中回本。
Locality - maintainers 从 depth 获得的收益:change、bugs、knowledge 和 verification 集中在一个地方,而不是散到 callers 里。修一次,到处都修好。
Deep module = small interface + lots of implementation:
+------------------+
| Small Interface | -> few methods, simple params
+------------------+
| |
| Deep | -> complex logic hidden
| Implementation |
| |
+------------------+
Shallow module = large interface + little implementation(避免):
+-------------------------------+
| Large Interface | -> many methods, complex params
+-------------------------------+
| Thin Implementation | -> mostly pass-through
+-------------------------------+
设计 interface 时问:
好的 interfaces 让测试自然发生:
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. 更少 methods = 需要更少 tests。更少 params = 更简单的 test setup。
interface keyword 或 class public methods:太窄;这里的 interface 包括 caller 必须知道的所有事实。npx claudepluginhub vinvcn/mattpocock-skills-zh-cnProvides a shared vocabulary and principles for designing deep modules with small interfaces, high leverage, and testability. Use when designing or refactoring module interfaces, deciding seam placement, or making code more testable.
Provides a shared vocabulary and principles for designing deep modules—small interfaces with lots of implementation behind clean seams—to increase leverage, locality, and testability.
Provides a shared vocabulary for designing deep modules with small interfaces and rich behavior. Useful when structuring or refactoring code into testable, maintainable seams.