Practices
Habits and tooling that make the principles and architectures stick.
Enforce boundaries with tooling
Use crate or project references, dependency-rule linters and architecture tests; documentation alone is not enough.
- Serves
- Evolutionary architecture with fitness functions
- Pairs with
- Prose may name, only code may claim (A boundary asserted in prose is a wish. Assert it in a test.)
Architecture decision records
Record each significant decision together with its context.
- Pairs with
- The why needs a carrier that cannot drift (An ADR records a decision at a date and does not claim to describe the present. Claims about the present belong to tests.)
Test at the seams
Fast core tests with in-memory adapters, contract tests per port, and few end-to-end tests.
- Pairs with
- Hexagonal architecture (ports and adapters) (In-memory adapters make core tests fast.), Capture the output, refactor, compare (The same idea from the outside: the program’s whole observable surface is the seam.)
- Served by
- Facts about the foreign world as tests (The adapter’s tests are the documentation of the foreign world.)
Twelve-factor discipline
Keep configuration, logging and process handling disciplined and environment-independent.
Observability as a port
Structured logs, traces and metrics are a first-class outbound port, not an afterthought.
CI as the gatekeeper
Format, lint, type-check and test on every change.
- Pairs with
- Ratchets for debt you cannot pay yet
Ratchets for debt you cannot pay yet
Write the existing violations of a rule down with their size. Fail if any grows or a new one appears, and also fail when one shrinks until its entry is lowered or removed, so that progress is locked in and the list can only get shorter. The same helper serves every rule: file length (a smell that two levels share a file), printing outside the presenter, tool words in names.
- Serves
- Evolutionary architecture with fitness functions (A fitness function you can adopt over code that already breaks it.)
- Pairs with
- CI as the gatekeeper, Capture the output, refactor, compare (A ratchet keeps a rule from getting worse. This keeps a change from altering behaviour.)
- Sources
- Ratchets in software development, How we evolve code: Notion’s ratcheting system using custom ESLint rules, ADR 20: Every module is a small language, and the outline is generated (measured baseline and ratchets)
Generate the outline from the code
Produce the table of contents of the program (each module and the sentence it gives for what it is for) from the modules themselves, and fail the build if the committed copy differs. Likewise generate the command list, the completions and the manual from the declared contract. Prose written by no one cannot drift.
- Serves
- Derive, don’t verify (The outline is computed, never written.)
- Pairs with
- Prose may name, only code may claim (The outline is only as true as the sentences it is built from, so they may only name.)
- Sources
- Living Documentation by design, with Domain-Driven Design, OUTLINE.md: the generated outline of a whole program, from what each module says it is for
Write stories in a grammar
A function at a high layer reads as a sequence of verbs on nouns: ask, do, record, say. Hide lifetimes, format strings, Option and Result plumbing, bare booleans and None arguments behind verbs named for what they mean, and cap how often a story branches and how many closures it spells out. Whatever language-level syntax remains marks a concept the layer has not named yet (a Stop, an Approved, a Said): name it. In practice, reading one handler for what it still spelled out found a missing noun, a story ended early by an answer that is not a yes. Naming it (a Stopped) replaced the same three lines in eight stories and let the program end with the right exit code. The next noun found this way was an Approved: a value that only asking can produce, taken by the function that begins a change, so that a change cannot be made unasked.
- Serves
- Stratified design: every layer a small language
- Pairs with
- Typestate (The missing noun is often a type: an Approved that only the answer to a question can produce.)
- Sources
- Every module is a small language (the rule, its procedure and its worked example)
The cold read
Give someone, or an agent, only the generated outline and the front files, and ask what the program does and what happens on one important action. Where they cannot say, a name is missing. It is the test of whether the code teaches. It is a procedure today and not yet an automated test.
- Enforces
- Stratified design: every layer a small language (Tests whether the layers actually teach.)
- Sources
- Every module is a small language (the rule, its procedure and its worked example)
Facts about the foreign world as tests
Record what is known about tools, systems and libraries as tests named as sentences, such as removing_an_area_deletes_every_snapshot_and_leaves_its_files, that run against the real thing in CI. They document the boundary and cannot drift: if the tool changes, the build says so.
- Serves
- Test at the seams (The adapter’s tests are the documentation of the foreign world.)
- Pairs with
- Hexagonal architecture (ports and adapters)
- Sources
- Every module is a small language (the rule, its procedure and its worked example)
Every layer is the top of the layers beneath it
The same shape repeats at every level. A module says what it is for and offers a vocabulary (nouns and verbs) to the layer above, and its body is written only in the vocabulary of the layers beneath it, each of which is in turn the top of its own. Reading one module alone tells you its purpose and its words, and going down is always optional. Top is relative: the command line and the window are the top of the whole program, and a small adapter is the top of the tool it wraps. Layers form a graph and not a tree, since a lower layer is used by many above it, and the only structural rule is that dependencies point downward. A module that needs two languages, which means two levels, is two modules, whatever its length. Length, such as a file past a screen, is only a smell that a level is hiding. It is never the rule.
- Serves
- Stratified design: every layer a small language
- Pairs with
- Screaming architecture (Module and directory names that read as the program’s purposes.)
- Sources
- Screaming Architecture, Every module is a small language (the rule, its procedure and its worked example)
Capture the output, refactor, compare
Before a wide change that is meant to preserve behaviour, capture what the program actually does for a set of commands that covers everything a user or a script can see: text, machine-readable output, error messages and exit codes, with what varies from run to run (times, ids) made stable. After the change capture again and compare byte for byte. This characterizes what the program does and not what it should do, so it needs no judgement of correctness, and it covers what unit tests of the code cannot: the whole observable surface. Pair it with a change that cannot alter output by construction, such as renaming code identifiers and never string literals, and use the comparison to check that it held.
- Pairs with
- Test at the seams (The same idea from the outside: the program’s whole observable surface is the seam.), Ratchets for debt you cannot pay yet (A ratchet keeps a rule from getting worse. This keeps a change from altering behaviour.)
- Sources
- Definition Of Refactoring, How We Work Efficiently with Legacy Code (characterization tests), snapall pull request 74: the core speaks of areas and locations (output of 24 commands compared byte for byte)
Declare the invocation surface
Declare a program’s arguments and the environment variables it reads once, as a typed, machine-readable contract (argenv); the parser, the accessors, completions for every shell, the man page and lint all come from that one declaration, so the surface cannot drift from the code and a wrong invocation is reported instead of silently ignored.