You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merges domain vocabulary from CONTEXT.md into CLAUDE.md
CONTEXT.md was always-read only if explicitly fetched; CLAUDE.md is
automatically loaded into every agent context, so the vocabulary is
more reliably available there.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**, **seam**, **adapter**.
3
+
How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in
When assessing a candidate for deepening, classify its dependencies. The category determines how the deepened module is tested across its seam.
8
+
When assessing a candidate for deepening, classify its dependencies. The category determines how the
9
+
deepened module is tested across its seam.
8
10
9
11
### 1. In-process
10
12
11
-
Pure computation, in-memory state, no I/O. Always deepenable — merge the modules and test through the new interface directly. No adapter needed.
13
+
Pure computation, in-memory state, no I/O. Always deepenable — merge the modules and test through
14
+
the new interface directly. No adapter needed.
12
15
13
16
### 2. Local-substitutable
14
17
15
-
Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable if the stand-in exists. The deepened module is tested with the stand-in running in the test suite. The seam is internal; no port at the module's external interface.
18
+
Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable
19
+
if the stand-in exists. The deepened module is tested with the stand-in running in the test suite.
20
+
The seam is internal; no port at the module's external interface.
16
21
17
22
### 3. Remote but owned (Ports & Adapters)
18
23
19
-
Your own services across a network boundary (microservices, internal APIs). Define a **port** (interface) at the seam. The deep module owns the logic; the transport is injected as an **adapter**. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.
24
+
Your own services across a network boundary (microservices, internal APIs). Define a **port**
25
+
(interface) at the seam. The deep module owns the logic; the transport is injected as an
26
+
**adapter**. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.
20
27
21
-
Recommendation shape: *"Define a port at the seam, implement an HTTP adapter for production and an in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across a network."*
28
+
Recommendation shape: _"Define a port at the seam, implement an HTTP adapter for production and an
29
+
in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across
30
+
a network."_
22
31
23
32
### 4. True external (Mock)
24
33
25
-
Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the external dependency as an injected port; tests provide a mock adapter.
34
+
Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the
35
+
external dependency as an injected port; tests provide a mock adapter.
26
36
27
37
## Seam discipline
28
38
29
-
-**One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a port unless at least two adapters are justified (typically production + test). A single-adapter seam is just indirection.
30
-
-**Internal seams vs external seams.** A deep module can have internal seams (private to its implementation, used by its own tests) as well as the external seam at its interface. Don't expose internal seams through the interface just because tests use them.
39
+
-**One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a port
40
+
unless at least two adapters are justified (typically production + test). A single-adapter seam is
41
+
just indirection.
42
+
-**Internal seams vs external seams.** A deep module can have internal seams (private to its
43
+
implementation, used by its own tests) as well as the external seam at its interface. Don't expose
44
+
internal seams through the interface just because tests use them.
31
45
32
46
## Testing strategy: replace, don't layer
33
47
34
-
- Old unit tests on shallow modules become waste once tests at the deepened module's interface exist — delete them.
48
+
- Old unit tests on shallow modules become waste once tests at the deepened module's interface exist
49
+
— delete them.
35
50
- Write new tests at the deepened module's interface. The **interface is the test surface**.
36
51
- Tests assert on observable outcomes through the interface, not internal state.
37
-
- Tests should survive internal refactors — they describe behaviour, not implementation. If a test has to change when the implementation changes, it's testing past the interface.
52
+
- Tests should survive internal refactors — they describe behaviour, not implementation. If a test
53
+
has to change when the implementation changes, it's testing past the interface.
When the user wants to explore alternative interfaces for a chosen deepening candidate, use this parallel sub-agent pattern. Based on "Design It Twice" (Ousterhout) — your first idea is unlikely to be the best.
3
+
When the user wants to explore alternative interfaces for a chosen deepening candidate, use this
4
+
parallel sub-agent pattern. Based on "Design It Twice" (Ousterhout) — your first idea is unlikely to
5
+
be the best.
4
6
5
-
Uses the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**, **seam**, **adapter**, **leverage**.
7
+
Uses the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**, **seam**, **adapter**,
8
+
**leverage**.
6
9
7
10
## Process
8
11
9
12
### 1. Frame the problem space
10
13
11
-
Before spawning sub-agents, write a user-facing explanation of the problem space for the chosen candidate:
14
+
Before spawning sub-agents, write a user-facing explanation of the problem space for the chosen
15
+
candidate:
12
16
13
17
- The constraints any new interface would need to satisfy
14
-
- The dependencies it would rely on, and which category they fall into (see [DEEPENING.md](DEEPENING.md))
15
-
- A rough illustrative code sketch to ground the constraints — not a proposal, just a way to make the constraints concrete
18
+
- The dependencies it would rely on, and which category they fall into (see
19
+
[DEEPENING.md](DEEPENING.md))
20
+
- A rough illustrative code sketch to ground the constraints — not a proposal, just a way to make
21
+
the constraints concrete
16
22
17
-
Show this to the user, then immediately proceed to Step 2. The user reads and thinks while the sub-agents work in parallel.
23
+
Show this to the user, then immediately proceed to Step 2. The user reads and thinks while the
24
+
sub-agents work in parallel.
18
25
19
26
### 2. Spawn sub-agents
20
27
21
-
Spawn 3+ sub-agents in parallel using the Agent tool. Each must produce a **radically different** interface for the deepened module.
28
+
Spawn 3+ sub-agents in parallel using the Agent tool. Each must produce a **radically different**
29
+
interface for the deepened module.
22
30
23
-
Prompt each sub-agent with a separate technical brief (file paths, coupling details, dependency category from [DEEPENING.md](DEEPENING.md), what sits behind the seam). The brief is independent of the user-facing problem-space explanation in Step 1. Give each agent a different design constraint:
31
+
Prompt each sub-agent with a separate technical brief (file paths, coupling details, dependency
32
+
category from [DEEPENING.md](DEEPENING.md), what sits behind the seam). The brief is independent of
33
+
the user-facing problem-space explanation in Step 1. Give each agent a different design constraint:
24
34
25
-
- Agent 1: "Minimize the interface — aim for 1–3 entry points max. Maximise leverage per entry point."
35
+
- Agent 1: "Minimize the interface — aim for 1–3 entry points max. Maximise leverage per entry
36
+
point."
26
37
- Agent 2: "Maximise flexibility — support many use cases and extension."
27
38
- Agent 3: "Optimise for the most common caller — make the default case trivial."
28
39
- Agent 4 (if applicable): "Design around ports & adapters for cross-seam dependencies."
29
40
30
-
Include both [SKILL.md](SKILL.md) vocabulary and CONTEXT.md vocabulary in the brief so each sub-agent names things consistently with the architecture language and the project's domain language.
41
+
Include both [SKILL.md](SKILL.md) vocabulary and CONTEXT.md vocabulary in the brief so each
42
+
sub-agent names things consistently with the architecture language and the project's domain
43
+
language.
31
44
32
45
Each sub-agent outputs:
33
46
@@ -39,6 +52,10 @@ Each sub-agent outputs:
39
52
40
53
### 3. Present and compare
41
54
42
-
Present designs sequentially so the user can absorb each one, then compare them in prose. Contrast by **depth** (leverage at the interface), **locality** (where change concentrates), and **seam placement**.
55
+
Present designs sequentially so the user can absorb each one, then compare them in prose. Contrast
56
+
by **depth** (leverage at the interface), **locality** (where change concentrates), and **seam
57
+
placement**.
43
58
44
-
After comparing, give your own recommendation: which design you think is strongest and why. If elements from different designs would combine well, propose a hybrid. Be opinionated — the user wants a strong read, not a menu.
59
+
After comparing, give your own recommendation: which design you think is strongest and why. If
60
+
elements from different designs would combine well, propose a hybrid. Be opinionated — the user
Copy file name to clipboardExpand all lines: .agents/skills/codebase-design/SKILL.md
+53-21Lines changed: 53 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,52 @@
1
1
---
2
2
name: codebase-design
3
-
description: Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
3
+
description:
4
+
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a
5
+
module's interface, find deepening opportunities, decide where a seam goes, make code more
6
+
testable or AI-navigable, or when another skill needs the deep-module vocabulary.
4
7
---
5
8
6
9
# Codebase Design
7
10
8
-
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.
11
+
Design **deep modules**: a lot of behaviour behind a small interface, placed at a clean seam,
12
+
testable through that interface. Use this language and these principles wherever code is being
13
+
designed or restructured. The aim is leverage for callers, locality for maintainers, and testability
14
+
for everyone.
9
15
10
16
## Glossary
11
17
12
-
Use these terms exactly — don't substitute "component," "service," "API," or "boundary." Consistent language is the whole point.
18
+
Use these terms exactly — don't substitute "component," "service," "API," or "boundary." Consistent
19
+
language is the whole point.
13
20
14
-
**Module** — anything with an interface and an implementation. Deliberately scale-agnostic: a function, class, package, or tier-spanning slice. _Avoid_: unit, component, service.
21
+
**Module** — anything with an interface and an implementation. Deliberately scale-agnostic: a
22
+
function, class, package, or tier-spanning slice. _Avoid_: unit, component, service.
15
23
16
-
**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).
24
+
**Interface** — everything a caller must know to use the module correctly: the type signature, but
25
+
also invariants, ordering constraints, error modes, required configuration, and performance
26
+
characteristics. _Avoid_: API, signature (too narrow — they refer only to the type-level surface).
17
27
18
-
**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.
28
+
**Implementation** — what's inside a module, its body of code. Distinct from **Adapter**: a thing
29
+
can be a small adapter with a large implementation (a Postgres repo) or a large adapter with a small
30
+
implementation (an in-memory fake). Reach for "adapter" when the seam is the topic; "implementation"
31
+
otherwise.
19
32
20
-
**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.
33
+
**Depth** — leverage at the interface: the amount of behaviour a caller (or test) can exercise per
34
+
unit of interface they have to learn. A module is **deep** when a large amount of behaviour sits
35
+
behind a small interface, **shallow** when the interface is nearly as complex as the implementation.
21
36
22
-
**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).
37
+
**Seam**_(Michael Feathers)_ — a place where you can alter behaviour without editing in that place;
38
+
the _location_ at which a module's interface lives. Where to put the seam is its own design
39
+
decision, distinct from what goes behind it. _Avoid_: boundary (overloaded with DDD's bounded
40
+
context).
23
41
24
-
**Adapter** — a concrete thing that satisfies an interface at a seam. Describes *role* (what slot it fills), not substance (what's inside).
42
+
**Adapter** — a concrete thing that satisfies an interface at a seam. Describes _role_ (what slot it
43
+
fills), not substance (what's inside).
25
44
26
-
**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.
45
+
**Leverage** — what callers get from depth: more capability per unit of interface they learn. One
46
+
implementation pays back across N call sites and M tests.
27
47
28
-
**Locality** — what maintainers get from depth: change, bugs, knowledge, and verification concentrate in one place rather than spreading across callers. Fix once, fixed everywhere.
48
+
**Locality** — what maintainers get from depth: change, bugs, knowledge, and verification
49
+
concentrate in one place rather than spreading across callers. Fix once, fixed everywhere.
29
50
30
51
## Deep vs shallow
31
52
@@ -59,10 +80,16 @@ When designing an interface, ask:
59
80
60
81
## Principles
61
82
62
-
-**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.
63
-
-**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.
64
-
-**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.
65
-
-**One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a seam unless something actually varies across it.
83
+
-**Depth is a property of the interface, not the implementation.** A deep module can be internally
84
+
composed of small, mockable, swappable parts — they just aren't part of the interface. A module
85
+
can have **internal seams** (private to its implementation, used by its own tests) as well as the
86
+
**external seam** at its interface.
87
+
-**The deletion test.** Imagine deleting the module. If complexity vanishes, it was a pass-through.
88
+
If complexity reappears across N callers, it was earning its keep.
89
+
-**The interface is the test surface.** Callers and tests cross the same seam. If you want to test
90
+
_past_ the interface, the module is probably the wrong shape.
91
+
-**One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a seam
92
+
unless something actually varies across it.
66
93
67
94
## Designing for testability
68
95
@@ -76,7 +103,7 @@ Good interfaces make testing natural:
76
103
77
104
// Hard to test
78
105
function processOrder(order) {
79
-
const gateway =newStripeGateway();
106
+
const gateway =newStripeGateway()
80
107
}
81
108
```
82
109
@@ -88,7 +115,7 @@ Good interfaces make testing natural:
88
115
89
116
// Hard to test
90
117
function applyDiscount(cart):void {
91
-
cart.total-=discount;
118
+
cart.total-=discount
92
119
}
93
120
```
94
121
@@ -104,11 +131,16 @@ Good interfaces make testing natural:
104
131
105
132
## Rejected framings
106
133
107
-
-**Depth as ratio of implementation-lines to interface-lines** (Ousterhout): rewards padding the implementation. We use depth-as-leverage instead.
108
-
-**"Interface" as the TypeScript `interface` keyword or a class's public methods**: too narrow — interface here includes every fact a caller must know.
134
+
-**Depth as ratio of implementation-lines to interface-lines** (Ousterhout): rewards padding the
135
+
implementation. We use depth-as-leverage instead.
136
+
-**"Interface" as the TypeScript `interface` keyword or a class's public methods**: too narrow —
137
+
interface here includes every fact a caller must know.
109
138
-**"Boundary"**: overloaded with DDD's bounded context. Say **seam** or **interface**.
110
139
111
140
## Going deeper
112
141
113
-
-**Deepening a cluster given its dependencies** — see [DEEPENING.md](DEEPENING.md): dependency categories, seam discipline, and replace-don't-layer testing.
114
-
-**Exploring alternative interfaces** — see [DESIGN-IT-TWICE.md](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.
142
+
-**Deepening a cluster given its dependencies** — see [DEEPENING.md](DEEPENING.md): dependency
143
+
categories, seam discipline, and replace-don't-layer testing.
144
+
-**Exploring alternative interfaces** — see [DESIGN-IT-TWICE.md](DESIGN-IT-TWICE.md): spin up
145
+
parallel sub-agents to design the interface several radically different ways, then compare on
0 commit comments