Reference · Model-invoked · Vocabulary layer

codebase-design 速查

Deep-module 词汇单一真源的口袋版。完整教学见 Lesson 0005; 原文见 SKILL.mdDEEPENING.mdDESIGN-IT-TWICE.md

一句话

设计 deep modules:大量行为 · 小 interface · 干净 seam · 经 interface 可测。 这是语言不是流程——不写架构 HTML、不代重构;给 leverage / locality / 可测性统一用词。

何时伸手

Glossary(禁替代词)

Module
有 interface + implementation 的任何尺度(函数/类/包/切片)。避免:unit、component、service。
Interface
调用者必须知道的一切:签名 + invariants、顺序、错误模式、配置、性能。避免:API、signature(过窄)。≠ TS interface 关键字全集。
Implementation
模块内部代码体。谈「里面是什么」用它;谈「填哪个槽」用 adapter。
Depth
Interface 上的 leverage。Deep = 小面后大行为;shallow = 面与实现几乎同复杂。用 leverage 量,不用行数比。
Seam(Feathers)
可不编辑该处即改变行为的位置;interface 的落点。避免:boundary(DDD 过载)。
Adapter
在 seam 上满足 interface 的具体物(角色,非物质)。
Leverage
调用者收益:每学一单位 interface 得到更多能力;一份实现服务 N 调用 + M 测试。
Locality
维护者收益:变更/缺陷/知识/验证集中一处。

关系(记骨架)

Module ──has one──► Interface ──lives at──► Seam ──filled by──► Adapter
Depth 属性在 Interface 上;Depth → Leverage(调用者)+ Locality(维护者)
Internal seams 可存在于实现内;勿为测试暴露到 external interface

四原则

  1. Depth 是 interface 的属性,不是 implementation 的属性
  2. Deletion test:删模块 → 复杂度消失=pass-through;散回 N 调用者=赚 keep
  3. Interface is the test surface:调用者与测试同 seam;想测穿 → 形状多半错
  4. One adapter = hypothetical;two = real:无变化轴不开 seam

Deep vs shallow

Deep:  小 interface + 深 implementation(藏复杂度)
Shallow: 大 interface + 薄 implementation(转发)— 避免
三问:少方法?简参数?多藏复杂度?

可测性三启发式

  1. Accept dependencies, don't create them
  2. Return results, don't produce side effects
  3. Small surface area

Rejected framings

DEEPENING · 依赖类别

#测法要点
1In-process合并;直接经 interface 测;无 adapter
2Local-substitutablePGLite 等 stand-in;内部 seam;对外不必 port
3Remote but ownedPort + HTTP/gRPC prod adapter + in-memory test
4True external注入 port;mock adapter

Replace, don't layer:新测在深 interface → 删旧浅 unit tests; 断言可观察结果;测试应扛住内部 refactor。

DESIGN-IT-TWICE · 流程卡

  1. Frame problem space(约束、依赖类别、非提案 sketch)→ 给用户后立刻并行
  2. 3+ sub-agents:极简面 / 最大灵活 / 最常见调用者 /(可选)ports&adapters;brief 含 SKILL 词 + CONTEXT 词
  3. 顺序展示 → 比 depth · locality · seam placement → 给推荐(可 hybrid)

消费者

副作用

单独使用:主要无持久副作用(词汇与设计讨论)。 Temp HTML 报告是 architecture 的事,不是本 skill。 真改代码形状 → 主 flow / tdd。

下一步