Principle Model The Domain

作者 cursorccb5507cec15无许可证10K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Apply when writing stateful logic, or when code branches a lot or repeats a shape assumption across files. Encode the domain in a structure instead of scattered conditionals.

AI 生成的概览

指导开发者在编写有状态逻辑时,用数据结构表达领域规则,而不是分散的条件分支。

功能
该技能为编写有状态或分支繁多的代码提供指导,主张把领域建模为明确的结构。它建议采用状态机、类型化模型、映射表、注册表、reducer 和模块边界等结构,并提醒不要强行引入只增加间接层、却未减少分支或非法状态的抽象。它产出的是设计建议,而不是文件或代码产物。
适用场景
适用于编写有状态逻辑、代码分支很多,或同一形状假设在多个文件中重复出现的情况。当新功能会给现有 if/else 链再加一个分支,或再增加一个必须与前者保持同步的布尔值时,也适合使用。
运行要求
不需要任何工具、软件包、运行时、凭据或网络访问;它只是说明性指令,不附带脚本。

Model the Domain

Encode the real domain in a data structure instead of scattering it across conditionals.

Why: Scattered booleans, repeated shape assumptions, and branching spread across files are accidental complexity. A structure that matches the domain makes invalid states unrepresentable and deletes branches. Choosing it at write time is cheap. Recovering it later reads as a refactor and gets deferred.

Reach for structures like these:

  • A state machine instead of scattered booleans, phases, or lifecycle checks.
  • A typed object/model instead of loose parameters or repeated shape assumptions.
  • A map, registry, lookup table, or discriminated union instead of branching spread across files.
  • A reducer or command/event model instead of ad hoc state mutations.
  • A module organized around one body of domain knowledge instead of a sequence such as load, validate, transform, and save. Execution order is not ownership.
  • A small module boundary that gathers repeated behavior, ownership, or invariants.
  • A queue, cache, index, graph/tree, or normalized collection where the data access pattern calls for it.
  • Any other structure that fits. When none fits, work out what the code must never allow and how the data gets read, then find the structure that encodes exactly that.

Do not force an abstraction. Prefer boring code if the current shape is already clear, local, and unlikely to grow. Be skeptical of an abstraction that adds indirection without removing branches, duplicated rules, invalid states, or lifecycle risk.

The sign that you skipped this is a new feature that grows an existing if/else chain by one more branch, or a second boolean that must stay in sync with the first. Temporal decomposition is another sign. Phase-named modules repeat the same domain rules across steps.

来源与署名

来源:cursor/plugins位于pstack/skills/principle-model-the-domain提交ccb5507

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架