ARC-87Recommended
Check each architecture decision with a fitness function
Turn each architecture decision that code can break into a test the build runs, called a fitness function. Module borders inside one app get one first.
How to do it
A decision record says what the system must keep true, but only a test keeps it true when people and agents change the code. Module borders inside one deployable app are the first case. Each module is reached only through its public entry point, as Split off a service only for a written reason needs. Use the dependency tools from Point dependencies inward for the rule. Other decisions get their own tests, such as a speed budget from a quality scenario. You may replace an old part piece by piece, as Rewrite behind the old interface says. Then a test counts the calls still going to the old part and fails when the count grows.
Examples
Java example
// ArchUnit: other modules reach orders only through its api package
@ArchTest
static final ArchRule ordersInternalsArePrivate = noClasses()
.that().resideOutsideOfPackage("com.example.shop.orders..")
.should().dependOnClassesThat().resideInAPackage("com.example.shop.orders.internal..");
TOML example
# import-linter in pyproject.toml: other modules may not import orders internals
[[tool.importlinter.contracts]]
name = "Orders internals are private"
type = "forbidden"
source_modules = ["shop.billing", "shop.shipping"]
forbidden_modules = ["shop.orders.internal"]
TypeScript example
// dependency-cruiser: only orders/index.ts may be imported from outside orders/
export default {
forbidden: [{
name: 'orders-internals-private',
severity: 'error',
from: { pathNot: '^src/orders/' },
to: { path: '^src/orders/', pathNot: '^src/orders/index\\.ts$' },
}],
};
How to check
Each accepted decision record names its fitness function or says why code cannot break it. A pull request that imports another module's internal file fails the build.
Sources
Related rules
- ARC-86 Write each quality goal as a scenario with a number in Clean code and architecture
- ARC-85 Split off a service only for a written reason in Clean code and architecture
- ARC-63 Point dependencies inward in Clean code and architecture
- TKO-14 Rewrite behind the old interface in Codebase takeover
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/system-architecture/fitness-functions">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.