| 1 | --- |
| 2 | name: principle-boundary-discipline |
| 3 | description: "Apply when wiring validation, error handling, or framework adapters. Concentrate guards at system boundaries (CLI, config, network, external APIs); trust internal types and keep business logic in pure functions." |
| 4 | disable-model-invocation: true |
| 5 | --- |
| 6 | |
| 7 | # Boundary Discipline |
| 8 | |
| 9 | Place validation, type narrowing, and error handling at system boundaries. Trust internal code unconditionally. Business logic lives in pure functions. The shell is thin and mechanical. |
| 10 | |
| 11 | **Why:** Scattered validation is noisy, redundant, and gives a false sense of safety. Keep logic out of framework wiring so it can be tested without the framework. |
| 12 | |
| 13 | **The pattern:** |
| 14 | - **At boundaries** (CLI args, config files, external APIs, network protocols): validate, return errors, handle defensively. |
| 15 | - **Inside the system:** typed data, error propagation, no re-validation. Trust the types. |
| 16 | - **Across the boundary.** Expose domain concepts, not the boundary's private representation. Keep general-purpose mechanism inside and special-purpose policy at the edge. |
| 17 | |
| 18 | **Applications:** |
| 19 | |
| 20 | Validation and error handling: |
| 21 | - Validate config at parse time (the boundary), not inside business logic |
| 22 | - Parse raw data into domain types at the boundary |
| 23 | - Do not re-export transport, storage, framework, or wire types through the public surface |
| 24 | - No redundant nil checks deep in call chains if the boundary already validated |
| 25 | |
| 26 | Code organization: |
| 27 | - Business logic in pure functions with no framework dependencies |
| 28 | - Parse functions: pure transforms from raw bytes to typed state |
| 29 | - Prompt construction: structured state in, string out |
| 30 | - Scoring and assessment: pure transforms from state to results |
| 31 | |
| 32 | **The tests:** |
| 33 | - "Is this data crossing a system boundary right now?" If not, validation is redundant. |
| 34 | - "Can this be a pure function that the shell just calls?" If yes, extract it. |