guarding-architecture
riekelt/principal-engineer
Encode structural invariants as named, enforced contracts to prevent architectural decay.
What is guarding-architecture?
Guarding architecture establishes load-bearing structural contracts—named invariants with rationale and mechanical enforcement—to prevent boundary violations and architectural drift. Use when changes cross module boundaries, add dependency directions, touch critical paths, or conflict with stated principles.
- Name invariants with statement, rationale, and concrete failure narratives tied to incident classes
- Separate stable principles (rarely changing) from volatile realizations (canonical owners, guards, reference designs)
- Enforce invariants mechanically via architecture tests that fail the build for violations
- Require design conformance to named invariants rather than justifying exceptions
- Record genuine exceptions as amendments with owner sign-off and expiry conditions
- Surface unexplained guard exclusions as violations to the invariant owner
How to install guarding-architecture
npx skills add https://github.com/riekelt/principal-engineer --skill guarding-architecture- The principal-engineering skill must be installed first
How to use guarding-architecture
- 1.Name each structural invariant with a number, statement, rationale, and failure narrative
- 2.Create a stable principles document (changes rarely, names no classes) and a volatile realization document (canonical owners, guards, reference designs)
- 3.Write architecture tests that fail the build for each enforceable invariant (dependency directions, package boundaries, layering)
- 4.Require designs touching guarded ground to cite which invariants they touch and how they conform
- 5.Record any genuine exceptions as amendments with owner sign-off and expiry conditions in the realization document
- 6.Surface unexplained guard exclusions to the invariant owner instead of treating them as precedent
Use cases
- Preventing unauthorized cross-module imports by encoding dependency direction rules as build-enforced tests
- Protecting critical-path performance by guarding against I/O and slow dependencies in hot code
- Maintaining one canonical owner per concern through named, reviewable invariants
- Catching architectural drift early by failing builds on boundary violations instead of relying on code review
- Documenting design decisions that touch guarded ground by citing which invariants are upheld
- Principal engineers and architects defining structural contracts
- Teams managing large codebases with multiple modules and strict dependency rules
- Code reviewers enforcing architectural boundaries
- Development teams preventing incremental boundary erosion
guarding-architecture FAQ
The principles document contains stable, technology-neutral invariant statements and rationales that change rarely. The realization document contains the current implementation details: canonical owners, specific guards, reference designs, and exceptions—it changes with the code. When they disagree, the invariant governs and the realization document is corrected.
The code must be redesigned to conform; exceptions are never justified by cost or convenience. If the cost argument is valid, it becomes a formal amendment to the invariant, decided by the owner and recorded via decision-recording, never a silent exception.
A temporary exception is a dated waiver with an expiry condition and the owner's sign-off, recorded in the volatile realization document. Silent or undated exceptions are violations hidden from the build and must be surfaced to the invariant owner.
Common examples include: one canonical owner per concern, dependency direction (domain never imports delivery mechanism), critical-path isolation (no I/O on hot paths), fail-closed boundaries (gates that cannot evaluate must deny), and migration immutability.
Each individual violation may seem locally reasonable, but structural invariants are load-bearing contracts—violating one surfaces as a class of bugs, not a single defect. The guard prevents death-by-a-thousand-cuts boundary erosion.
Full instructions (SKILL.md)
Source of truth, from riekelt/principal-engineer.
name: guarding-architecture description: "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."
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
- 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.
- 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.
- 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.
- 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).
- 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.
- 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.
- 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-decisionswhere 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.
Related skills
More from riekelt/principal-engineer and the wider catalog.

handling-failures
Enforce loud, explicit failure handling—no silent swallows, typed errors, or undocumented degradation.

keeping-one-source-of-truth
Enforce single ownership of every fact in code and data to prevent drift and duplication.

operating-safely
Safety guards for destructive operations, secrets handling, and concurrent-session work on live systems.

principal-engineering
Evidence-based engineering discipline for safe, verifiable changes to code, data, and infrastructure.

scoping-changes
Right-size fixes to their trigger; decompose visibly instead of trimming quietly.

testing-changes
Determine what tests a behavior change requires and verify test coverage is sufficient.