You want to enforce that the domain layer does not depend on infrastructure. How do you make it stick?
Show the full answer Hide the answer
What the interviewer is testing
Whether you convert an architectural rule into a mechanism rather than a convention.
Why conventions fail
A rule enforced by code review holds while the reviewer is paying attention and remembers it. It is violated once by a reasonable person under deadline, and then again because there is now precedent. Architectural intent decays this way in every codebase.
The mechanism
An architecture test in the build that inspects dependency direction and fails when the domain package imports from infrastructure. It is a unit test, it runs on every commit, and it holds always — including at 2 AM on a Friday.
Making it stick
Introduce it for new violations only. Record the existing violations as a baseline and fail only on additions. Turning it on against an existing codebase blocks everyone on day one and the test gets deleted — this is the single most important adoption detail.
Write an explanatory failure message. "Module X must not import Y; use the published interface Z" teaches and gives a route forward. "Architecture test failed" invites a workaround.
Reduce the baseline deliberately on a plan, so the exceptions shrink rather than becoming permanent.
Review it periodically. A fitness function encoding a decision the team has since changed is an obstacle rather than a guardrail.
The wider family worth building
Dependency direction between layers and modules. No cross-module access except through published interfaces. Package cycles. Forbidden imports of a deprecated library. Every public endpoint carrying authentication. p95 latency not regressing beyond a threshold. Bundle size within budget.
Static checks run in CI and block a merge; runtime checks evaluate deployed behaviour continuously. Both are fitness functions.
What a strong answer adds
The broader point: this is what makes evolutionary architecture possible. Guided incremental change requires a guide, and an automated one is the only kind that is always present. It also changes what governance means — from a meeting into a mechanism, which is the highest-leverage move available to an architecture function losing ground to delivery pressure.
Common weak answers
Documenting the rule in a standards page. Relying on review discipline.