Home / Insights / Architecture and Modernization
Architecture and Modernization
Architecture Fitness Functions: Automated Checks That Keep a Codebase Healthy
Most architectures do not fail in one bad decision. They erode, one convenient shortcut at a time, until nobody can say where the boundaries are. Fitness functions turn your architectural intentions into automated checks so erosion is caught in the pull request rather than in the post-mortem.
TopicsArchitecture and ModernizationQA and Software TestingWeb and SaaS Development
Key takeaways
- A fitness function is an objective, repeatable check that a system still has an architectural characteristic you care about, such as layering, performance, security posture or deployability.
- Start from the three or four characteristics that matter most to the business, not from whatever a tool can measure.
- Most fitness functions are cheap: dependency rules, performance budgets and security checks that run in the CI pipeline you already have.
- Introduce them with a baseline and a ratchet: record today’s state, block anything that makes it worse, and tighten over time.
- Treat fitness functions as living governance: give each an owner and a documented reason, and retire checks that no longer protect anything important.
On this page
- What a fitness function is, and what it is not
- Deciding what to protect
- Where fitness functions run: from commit to production
- Tools that make fitness functions cheap
- How to introduce fitness functions without stopping delivery
- Costs, risks and common pitfalls
- A fitness function checklist
- Frequently asked questions
- Sources and methodology
Every codebase begins with good intentions: a clean separation between the user interface, business logic and data access; services that do not reach into each other’s databases; pages that load quickly; dependencies that are kept up to date. Two years and several deadlines later, those intentions are often just slides. The code says something different, and the only way to find out is a painful review.
Architecture fitness functions are a practical answer. The idea, popularised by the book Building Evolutionary Architectures, is to express important architectural characteristics as automated checks that run continuously, so the architecture is tested in the same way as the features. This article is for CTOs, engineering managers and architects who want to keep a growing system healthy without relying on heroic reviews. It explains what fitness functions are, what to protect, which tools to use, how to introduce them and what they cost.
Our software architecture consulting work, from architecture reviews to modernisation strategies, regularly ends with the same recommendation: turn the most important findings into checks that run on every change, so the improvements survive after the review is over.
What a fitness function is, and what it is not
Thoughtworks’ Technology Radar, which placed architectural fitness functions in its ‘Trial’ ring, describes the concept as borrowed from evolutionary computing, where a fitness function measures how close a design is to its goals. In software, an architectural fitness function provides an objective assessment of a specific architectural characteristic, and it can be built from familiar mechanisms such as unit tests, metrics and monitors.
The second edition of Building Evolutionary Architectures by Neal Ford, Rebecca Parsons, Patrick Kua and Pramod Sadalage, published by O’Reilly in November 2022, devotes chapters to fitness functions and to automating architectural governance. It categorises them along several dimensions, including scope (atomic or holistic), cadence (triggered, continual or temporal), result (static or dynamic), invocation (automated or manual) and proactivity (intentional or emergent).
Examples in plain terms
- ‘The user interface layer must not import the database layer directly.’ Checked on every build.
- ‘No module may have a circular dependency on another.’ Checked on every build.
- ‘The product page must stay under an agreed JavaScript size and load-time budget.’ Checked on every pull request.
- ‘No dependency with a known critical vulnerability may be deployed.’ Checked on every build and nightly.
- ‘The service must recover automatically when one instance is terminated.’ Checked periodically in a test environment.
What they are not
Fitness functions are not a replacement for design thinking or for architecture reviews. They protect decisions that have already been made; they do not make good decisions for you. They are also not code style linting, although they often use similar tooling. A rule about indentation protects readability; a rule about which modules may depend on which protects the architecture.
Action: write down three architectural rules your team currently relies on people remembering. Those are your first candidates.
Deciding what to protect
The most common mistake is to start with tools and measure whatever they report. Start instead with the characteristics that matter for your business and your stage of growth, then ask how each could be checked.
| Characteristic | Why it matters to the business | Example fitness function | Typical cadence |
|---|---|---|---|
| Modularity and layering | Teams can change one area without breaking another; onboarding is faster | Dependency rules between packages or modules; no cycles | Every build |
| Performance | Conversion, retention and user satisfaction | Bundle size and load-time budgets; API latency thresholds under load tests | Every pull request; nightly load test |
| Security posture | Customer trust, contractual and compliance requirements | Vulnerable dependency scanning; required security headers present | Every build; nightly |
| Deployability | Speed of delivering fixes and features | Build and test pipeline duration under an agreed limit; services deployable independently | Every build |
| Resilience | Uptime and recovery from failure | Automated failover or instance-termination tests | Scheduled in staging |
| Data ownership | Services can evolve without coordinated releases | No service queries another service’s database tables | Every build |
How to prioritise
- Look at recent incidents and slowdowns. Which architectural erosion caused real pain in the last year?
- Look at your roadmap. If you plan to split a monolith, modularity checks matter now. If you are entering enterprise sales, security posture matters.
- Pick three or four characteristics. A small set of checks that are respected beats a large set that is ignored.
For example, a 30-person SaaS company preparing to extract its billing module into a separate service might start with three checks: no new dependencies from other modules into billing internals, no direct queries to billing tables from outside the module, and a bundle-size budget on its customer dashboard. This is an illustrative starting set, not a template.
Action: run a one-hour session with your senior engineers to agree the three or four characteristics to protect this quarter, and record why each matters.
Where fitness functions run: from commit to production
Different checks belong at different points in the delivery pipeline. Placing them well keeps feedback fast without missing problems that only appear at scale.
| Stage | Good fit for | Trade-off |
|---|---|---|
| Local and pre-commit | Fast static rules such as dependency direction | Developers can skip them; repeat in CI |
| Pull request CI | Dependency rules, cycles, bundle-size budgets, vulnerability scans, contract tests | Must stay fast or teams will resent them |
| Nightly or scheduled | Load tests, full dependency audits, broader holistic checks | Feedback arrives a day later |
| Staging environment | Resilience and failover tests, end-to-end performance | Needs a realistic environment |
| Production monitoring | Latency and error-rate objectives, real-user performance | Detects problems after users see them |
Atomic and holistic checks
An atomic fitness function checks one characteristic in isolation, such as ‘no cycles between modules’. A holistic one checks how characteristics interact, such as whether a new caching layer improves latency without breaking data freshness under load. Atomic checks are easy to automate and should form the bulk of your set; holistic checks are fewer, more expensive and usually scheduled.
Static and dynamic results
Some checks have a fixed pass or fail threshold. Others compare against a moving baseline, for example ‘no more than a set percentage slower than last week’. Moving baselines are useful for performance, where absolute numbers depend heavily on environment.
Action: map each of your chosen checks to a pipeline stage, and set a time limit for the pull request stage so it stays fast.
Tools that make fitness functions cheap
You rarely need specialist platforms. Most fitness functions can be written with open-source tools and run in the CI system you already use.
Structure and dependencies
- Java and JVM languages: ArchUnit is a free, extensible library that checks package and class dependencies, layers, slices and cyclic dependencies by analysing bytecode. Rules are written as ordinary unit tests, so they run wherever your tests run. This is especially valuable during upgrades, as described in our guide to upgrading to Java 21 and Spring Boot 3.
- JavaScript and TypeScript: dependency-cruiser validates dependencies against rules you define and reports violations for use in builds. Its starter configuration includes rules for circular dependencies, dependencies missing from the package manifest, orphan modules and production code that relies on development dependencies.
- Other stacks: similar rule engines exist for most ecosystems, and simple scripts that parse import statements can go a long way.
Performance
Google’s web.dev guidance on performance budgets describes limits on metrics that affect speed, grouped as quantity-based (such as script size or request count), milestone timings (such as First Contentful Paint) and rule-based scores (such as Lighthouse). It recommends enforcing budgets in the build with tools such as Lighthouse CI and bundle-size checks, and tracking real-user data after launch. For back-end services, scheduled load tests with latency thresholds play the same role; our guide to performance testing for mobile backends explains how to make that load realistic.
Security
- Dependency vulnerability scanning in CI, failing builds on new critical findings.
- Automated checks that required HTTP security headers are present in responses, as covered in our security headers and CSP baseline.
- Secret scanning on every commit.
Choosing a tool
| Need | Simple option | When to go further |
|---|---|---|
| Layer and dependency rules | ArchUnit, dependency-cruiser or equivalent | Multi-repository systems need cross-repo dependency analysis |
| Front-end performance | Bundle-size check plus Lighthouse CI | Real-user monitoring for production budgets |
| Service contracts | Contract tests in each consumer and provider | Shared contract broker for many services |
| Security posture | Dependency and secret scanning in CI | Policy-as-code across infrastructure |
Action: for each chosen characteristic, identify the simplest tool in your stack that can check it, and prototype one rule in a branch this week.
How to introduce fitness functions without stopping delivery
Switching on strict rules in a mature codebase usually produces hundreds of violations and an immediate revolt. A gradual approach works far better.
- Baseline. Run the check and record today’s violations. Do not try to fix them yet.
- Freeze. Configure the check to fail only on new violations. Most tools support an allow-list or baseline file for existing ones.
- Make failures understandable. Every failing rule should say what was violated, why the rule exists and where to read more. A rule nobody understands will be bypassed.
- Ratchet. As teams touch old code, they remove entries from the baseline. Track the count and celebrate when it falls.
- Tighten. Once the baseline is small, convert warnings to hard failures and lower thresholds where appropriate.
- Review quarterly. Add checks for new priorities and retire those that no longer protect anything important.
Governance without bureaucracy
- Give each fitness function a named owner who can explain it and approve exceptions.
- Record the reason for each rule alongside the code, so future engineers understand the decision behind it.
- Allow exceptions through a visible, reviewed mechanism, never by silently disabling the check.
- Report trends, such as baseline counts and budget headroom, in engineering reviews.
Working with AI-assisted code
Teams adopting AI coding assistants generate more code, faster. Fitness functions give a consistent, automatic check that generated code respects the same boundaries as hand-written code, which complements the governance practices described in our guide to rolling out AI coding assistants.
Action: introduce your first check in ‘fail on new violations only’ mode, and add its baseline count to your next engineering review.
Costs, risks and common pitfalls
Fitness functions are inexpensive compared with the erosion they prevent, but they are not free, and badly designed checks can do harm.
Costs
- Initial setup: usually days rather than weeks for a first set of static checks in one codebase.
- Pipeline time: every check adds seconds or minutes; slow pipelines reduce delivery speed.
- Maintenance: rules need updating as the architecture deliberately changes.
- Environments: load and resilience tests need realistic staging infrastructure, which has a running cost.
Pitfalls
- Measuring the measurable: checks that are easy to write but protect nothing important. Every rule should trace back to a characteristic the business cares about.
- Flaky checks: performance thresholds that fail randomly teach teams to ignore failures. Use stable environments, repeated runs or moving baselines.
- Brittle rules: rules tied to exact file paths break during legitimate refactoring. Express rules in terms of modules and layers.
- False confidence: passing checks show that specific rules hold, not that the architecture is good. Keep periodic human reviews.
- Gaming: if a metric becomes a target, people find ways around it. Review exceptions and trends, not just pass rates.
When fitness functions are not worth it yet
For a short-lived prototype or a very small codebase with one or two developers, the overhead may outweigh the benefit. The tipping point usually comes when several people or teams change the same codebase, or when a planned migration depends on boundaries holding.
Action: for each proposed check, write one sentence on the business risk it reduces. Drop any check where that sentence is hard to write.
A fitness function checklist
Use this checklist when introducing fitness functions or reviewing an existing set.
- Three or four priority architectural characteristics agreed and documented with reasons.
- Each characteristic has at least one automated check, or a documented reason why it cannot yet be automated.
- Each check is placed at an appropriate pipeline stage, and the pull request stage stays within an agreed time limit.
- Existing violations are baselined; checks fail on new violations.
- Failure messages explain what was violated, why the rule exists and where to learn more.
- Each check has a named owner and a visible exception process.
- Performance checks use stable environments or moving baselines to avoid flakiness.
- Baseline counts and budget headroom are reported in regular engineering reviews.
- Checks are reviewed quarterly; obsolete ones are retired.
- Human architecture reviews continue for decisions that automated checks cannot assess.
Action: score your current pipeline against this list and pick the two lowest-scoring items to address in the next sprint.
Frequently asked questions
Are fitness functions just another name for tests?
They often use the same mechanisms, but they test architectural characteristics rather than features. A unit test checks that a calculation is correct; a fitness function checks, for example, that the user interface never depends directly on the database layer.
How many fitness functions should we start with?
Three or four, tied to the characteristics that matter most right now. A small set that the team understands and respects is more effective than a large set that is routinely ignored.
Will fitness functions slow down our pipeline?
Static dependency and security checks typically add little time. Load and resilience tests are slower and are better scheduled nightly or in staging rather than on every pull request.
What if our codebase already violates the rules everywhere?
Baseline the existing violations and fail only on new ones. Teams then reduce the baseline gradually as they work on older code, so improvement happens without a disruptive clean-up project.
Do we need an architect to maintain them?
Someone needs to own each check and understand why it exists, but that can be a senior engineer. An external architecture review can help choose the first set and design the rules.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- Thoughtworks Technology Radar: Architectural fitness function — accessed 9 November 2026. Definition of architectural fitness functions as objective checks built from tests, metrics and monitors, and their Trial ring placement.
- O’Reilly: Building Evolutionary Architectures, 2nd Edition (November 2022) — accessed 9 November 2026. Authors, publication date and the categories of fitness functions (scope, cadence, result, invocation, proactivity).
- ArchUnit — accessed 9 November 2026. Java library for checking package and class dependencies, layers and cycles as plain unit tests.
- dependency-cruiser (GitHub) — accessed 9 November 2026. Rule-based dependency validation for JavaScript and TypeScript, including cycles and orphan modules, for use in builds.
- web.dev: Performance budgets 101 — accessed 9 November 2026. Types of performance budgets and enforcing them in the build with tools such as Lighthouse CI.
Related reading
Continue your research
Which architectural rules in your codebase should be checked on every change?
We can review your architecture, identify the characteristics worth protecting and help your team implement the first fitness functions in your pipeline.
