Core Engineering Patterns
The canonical source of architectural patterns and principles for consistent, high-quality code.
Iron Law
Never throw in business logic
Every operation that can fail must return a Result type. Exceptions are allowed
only at system boundaries (API handlers, database adapters). A
throwstatement
in business logic is a violation.
Philosophy
- Functional Core, Imperative Shell — Pure business logic, side effects at boundary
- Explicit Error Handling — Result types, no exceptions in business logic
- Immutability by Default — Return new objects, never mutate (copy before
.sort()) - Dependency Injection — All deps injected, nothing instantiated internally
- Make Illegal States Unrepresentable — Types enforce invariants at compile time; discriminated unions with exhaustive switches; each error variant carries its full context
- Parse, Don't Validate — Schema transforms at boundaries
- Compose with pipes, and clean up resources in
finally
references/patterns.md shows each pattern in code.
Consistency Rules
- Result types: if one method returns Result, all must
- DI: apply consistently throughout
- Async: single pattern (don't mix callbacks/promises)
Anti-Patterns
- Throwing in business logic — use Result
- Silent failures — swallowed catch blocks
- Mutable state — return new objects
- Service locator — inject instead
Workaround Labeling (Required)
HACK: MOCK: TODO: TEMPORARY: NOT-PRODUCTION: ARCHITECTURE EXCEPTION:
Unlabeled workarounds are violations. See references/code-smell-violations.md.
Extended References
references/sources.md— Full bibliography (25 sources with access links)references/violations.md— Violation patterns with citationsreferences/patterns.md— The core patterns and extended correct patterns, with citationsreferences/checklist.md— Pre-implementation and review checklistsreferences/code-smell-violations.md— Fake solutions, deceptive code, magic valuesreferences/detection.md— Grep patterns for automated detection