Guarding Architecture

riekelt/principal-engineer/plugins/principal-engineer/skills/guarding-architecture

作者 riekelte67b7af9ac74無授權條款5 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫3 週前更新

Use when a change crosses module boundaries, adds a dependency direction between modules, touches a critical path, or conflicts with a stated principle - and when writing or updating architecture principles themselves. Encodes structural invariants as named, enforced contracts: statement, rationale, guard. Use whenever "we'll just import it from there for now" appears, which is how boundaries die.

AI 產生的概覽

將結構性不變量編碼為具名且受強制執行的契約,包含陳述、理由與機械式守衛。

功能
定義一套模式,把架構不變量轉化為具名、可引用的契約,每項包含陳述、具體的失敗理由與影響。它把穩定的原則文件與隨程式碼變動的實現文件分開,要求可強制的不變量由會使建置失敗的架構測試支撐,並把違規視為需要重新設計而非辯解。它也說明如何以修正案或有期限的豁免提出例外,以及如何處理守衛排除項。
適用情境
適用於變更跨越模組邊界、在模組之間新增依賴方向、觸及關鍵路徑,或與既定原則衝突時。也適用於撰寫或更新架構原則本身,或當有人打算先臨時加一個匯入時。它面向希望由建置而非僅靠審查來守住邊界的團隊。
執行需求
不需要腳本或工具,僅為說明性內容。它要求以 principal-engineering 技能作為必備背景,並提及 keeping-one-source-of-truth、handling-failures、recording-decisions 等相關技能。

Guarding architecture

REQUIRED BACKGROUND: the principal-engineering skill.

Overview

Structural invariants are load-bearing contracts: violating one surfaces as a class of bugs, not a single defect. An invariant that matters gets a name, a written rationale, and a mechanical guard; an invariant without a guard is a wish.

The pattern

  1. Name the invariants. Numbered and citable ("Law 3"), each with a Statement (technology-neutral, meant to outlast any framework), a Rationale, and Implications. The Rationale is a concrete failure narrative: the class of bugs that appears when the invariant is violated, told from an incident, not an abstraction.
  2. Split the stable from the volatile. The principles document changes rarely and names no classes; its current realization (the canonical owners, the guards, the reference designs) lives in a companion that changes with the code. When the two disagree, the invariant governs and the realization document gets corrected.
  3. Enforce mechanically. Every enforceable invariant gets an architecture test that fails the build: dependency directions, package boundaries, layering rules, forbidden imports. What cannot be build-enforced becomes a named review check with the invariant cited.
  4. Violations mean redesign, never justification. A design that violates a named invariant is wrong by construction: redesign it, do not argue the exception into the spec. Watering the contract down to match nonconforming code is the banned move; the violation gets recorded and the code gets fixed (the same rule the technical-writer plugin applies to normative documents).
  5. Specs show conformance. A design that touches guarded ground names the invariants it touches and shows, per invariant, how it upholds each; the reviewer checks claims against named invariants instead of debating taste.
  6. Exceptions are amendments. A genuine exception proposes an amendment, naming the invariant it bends and the boundary of the bend; silent exceptions are how an invariant becomes a suggestion. This is the only legal form of exception, and point 4 bans every other; an unreachable owner does not create one, so the change waits or lands conforming. A genuinely temporary exception is a dated waiver with an expiry condition and the owner's sign-off, recorded in the volatile realization document, not by amending the stable invariant for a passing condition.
  7. An unexplained guard exclusion is a violation hidden from the build. Whoever finds one surfaces it to the invariant's owner. An exclusion is never precedent for the next one; extending an exclusion list "like the others did" ratifies erosion instead of following a pattern.

Common invariant classes

Worth guarding in most systems, as examples rather than mandates:

  • One canonical owner per concern (see keeping-one-source-of-truth).
  • Dependency direction: the domain never imports the delivery mechanism.
  • Critical-path isolation: no I/O and no slow or optional dependency on the hot path.
  • Fail-closed boundaries: a gate that cannot evaluate must deny (see handling-failures).
  • Migration immutability (see the hard rules in principal-engineering).

Common mistakes

  • A principles document full of class names: the realization document wearing the wrong title; split them.
  • Adding the import "for now". Boundaries die by single convenient imports; the guard exists because each violation is locally reasonable.
  • An invariant asserted in review but absent from the build: enforced exactly as often as the right reviewer is present.
  • Justifying a violation by the cost of conforming. The cost argument may be right, but its correct form is an amendment to the invariant, decided by the owner, recorded (via recording-decisions where installed), never a quiet exception in one spec.
  • Principles written as taste ("prefer small modules") instead of contracts ("module X never imports module Y"). A contract can fail a build; taste can only fail a mood.

來源與署名

來源:riekelt/principal-engineer位於plugins/principal-engineer/skills/guarding-architecture提交e67b7af

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架