Quality Attributes

Fitness Function

Also known as: architectural fitness function

Definition

An architectural fitness function is an automated, objective test of a non-functional requirement — coupling, latency, security posture, cost — run continuously in CI. It turns an architectural intention into something that can fail a build, which is the only mechanism that reliably prevents slow erosion.

Last reviewed · Part of the Architecture Glossary

In practice

Every fitness function needs three things, and a rule missing any of them is a wish:

  1. A metric — cyclomatic complexity, p99 latency, count of forbidden imports, bundle size in KB.
  2. A threshold — the value at which the build fails, chosen from today's number so it ratchets rather than blocks.
  3. A place it runs — pre-merge CI, nightly, or continuously in production.

Concrete examples:

AttributeFunctionThreshold
ModularityArchUnit: no domain to infrastructure imports0 violations
Performancek6 smoke test p95 on the checkout path< 400 ms
Securitynpm audit / Trivy on the built image0 critical
CostInfracost delta on the Terraform plan< $50/month
ResilienceChaos experiment: kill one AZSLO holds

When it matters

Any architectural characteristic you have written down and expect to still be true in a year. Coupling rules in particular decay within two sprints of being agreed verbally.

Common mistake

Setting the threshold at the aspirational value, so the build is red on day one and someone adds continue-on-error. Set it at the current measurement, fail on regression, and tighten it deliberately.

See also

Go deeper