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 從公開儲存庫中收錄這些內容。

檢舉或申請下架