Quick revision
The short answer
Publish the rules as a versioned test library containing shared ArchRule definitions, and have each service add one small test class that applies them to its own packages. Wrap the rules in FreezingArchRule so existing violations are recorded and only new ones fail. Teams may add local rules but may not disable shared ones without review, and violation counts are reported centrally so we can see where the architecture is eroding.
What to remember
In this answer, we packaged the rules as a versioned test library of shared ArchRule constants, applied them in each service with one small test class using ArchTests.in(), and wrapped them in FreezingArchRule so that existing violations are recorded and only new ones fail. Teams can add local rules but cannot quietly disable shared ones, and counting the frozen violations centrally shows where erosion is happening and when a rule can be made strict.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Publish the rules as a versioned test library containing shared ArchRule definitions, and have each service add one small test class that applies them to its own packages. Wrap the rules in FreezingArchRule so existing violations are recorded and only new ones fail. Teams may add local rules but may not disable shared ones without review, and violation counts are reported centrally so we can see where the architecture is eroding.
Why this question is asked
Writing an ArchUnit rule for one service is easy. Keeping the same rules consistent in 80 services, owned by a dozen teams with different histories, is a design problem: the rules must be easy to adopt, impossible to quietly weaken, and possible to change without editing 80 repositories. Interviewers ask this to see whether we can design a small platform rather than just a test. In this answer, we will design the shared library, show the test class each service adds, plan the rollout with frozen rules, decide on governance for local and disabled rules, and finish with central reporting.
1The Rules We Want to Share
The question names three rules. No web-to-repository access means controllers must go through services. No cycles between modules means that the top-level packages of a service, such as orders and billing, depend on each other in one direction only. No use of deprecated internal APIs means services must stop using classes from our internal platform libraries that are marked for removal.
For these to work in every service, the rules must rely on conventions rather than service-specific names: web classes live in packages with a web segment, modules are the direct sub-packages of the service's base package, internal platform APIs live under com.acme.platform. Agreeing these conventions is part of the design, and the library documents them.
2A Versioned Library of Shared Rules
We create a small Maven or Gradle artifact, for example com.acme.arch:arch-rules, owned by the platform or architecture group. It contains ArchRule constants and depends only on ArchUnit. Services add it in test scope, and its version is managed in the company's BOM, the bill of materials that pins dependency versions, so most services get updates with their regular dependency upgrades.
Notice three details. Every rule carries a short identifier in its because() text, so a failure message links to a wiki page explaining it. Every rule is frozen, which is what makes rollout possible. And the slice pattern uses the second package segment as the module name, which only works because all services follow the com.acme.<service>.<module> convention; check that the pattern matches your naming before publishing.
3The Test Class in Each Service
Each service then adds a single test class. ArchUnit's ArchTests.in() pulls in every @ArchTest field from the shared class, so a new rule in the library reaches all services as soon as they upgrade.
The service controls only which packages are analysed. The frozen-violation store is a set of text files committed with the service, so reviewers can see when a violation is added or removed. For the first run the store has to be created; ArchUnit has a property, freeze.store.default.allowStoreCreation, that controls whether this is allowed, and we typically allow it only for the initial adoption commit so that CI cannot silently create a new store; check the documentation for your version.
4Rolling Out Across Teams
With frozen rules, adoption is a ten-minute change for each service: add the dependency, add the test class, run the tests once to record existing violations, commit the store. Nothing has to be fixed on day one, and from that day nothing can get worse. A platform team can open these 80 pull requests with a script or an automated refactoring tool, and teams only need to review and merge them.
New rules follow the same path. They are added to the library frozen, so upgrading the library records the current state rather than breaking the build. When we later want a rule to be strict everywhere, for example once the deprecated API is fully removed, we announce it, give teams a date, and then remove freeze() from that rule in a new major version of the library.
- Publish arch-rules 1.xfrozen rules, versioned in the BOM
- Open one adoption PR per servicedependency, test class, initial store
- Upgrades bring new rulesnew rules start frozen
- Report store sizes centrallyviolations per rule per service
- Violations near zero?YesMake the rule strict in the next majorNoHelp the teams with most violations
5 steps in order. Play them, or step through them one at a time.
Frozen rules make adoption cheap; reporting shows where to help.
5Governance: Local Rules and Exceptions
Teams should be free to add their own rules, because they know their service best, and the test class above shows how. Disabling a shared rule is a different matter. If each team could drop a rule from its test, the shared rules would mean nothing within a year. So we make the shared rules come as a single ArchTests.in() line, ask CODEOWNERS, the file that names required reviewers for paths in a repository, to include the architecture group for ArchitectureTest.java and the store, and handle exceptions by a reviewed entry in the store or a documented exemption list in the library rather than by deleting the line. A small CI check can also verify that every service's test class still includes AcmeRules.
6Reporting Violation Counts Centrally
The store files are the data we need. A CI step can count entries per rule in each service's store and send the counts, with the service name and library version, to a dashboard. Over time this shows the trend for each rule across the company: whether the 340 recorded cycle violations are going down, which services are adding new frozen entries during upgrades, and which teams might need help. It also gives us evidence when deciding whether a rule is worth keeping: a rule whose violations never fall may be unrealistic.
7Follow-up questions
Why a library instead of copying the rules into each service?
Copies drift. After a year there would be 80 slightly different versions with different bugs and exceptions. A library gives one definition, one place to fix a rule, and a version number that tells us which rules each service actually runs.
What if a service does not follow the package conventions?
The shared rules will either not match anything or produce wrong results. During adoption we check that each service's packages match the conventions; for outliers we either move packages, which frozen rules make safe, or let the service pass its own package patterns to rule factory methods in the library instead of using constants.
Could Spring Modulith replace part of this?
For the no-cycles rule within each service, yes: Spring Modulith's verification covers module cycles and internal access with a convention. A company could standardise on Modulith for module structure and keep the shared ArchUnit library for company-specific rules such as banned platform APIs.
8Conclusion
In this answer, we packaged the rules as a versioned test library of shared ArchRule constants, applied them in each service with one small test class using ArchTests.in(), and wrapped them in FreezingArchRule so that existing violations are recorded and only new ones fail. Teams can add local rules but cannot quietly disable shared ones, and counting the frozen violations centrally shows where erosion is happening and when a rule can be made strict.
Open with
I would treat the rules as a small internal product. First, a versioned library, say arch-rules, with the shared ArchRule constants: no web-to-repository access, no cycles between module slices, and no dependency on deprecated classes in our platform packages, each with a because clause carrying a rule id that links to a page explaining it.
Then, if they want more
The version is managed in our BOM so services pick up updates with normal upgrades. Each service adds one test class with AnalyzeClasses on its own base package and an ArchTest field that pulls in all the shared rules with ArchTests in.
Every rule is wrapped in FreezingArchRule, so adoption is cheap: the first run records existing violations in a store committed with the service, nothing must be fixed on day one, and nothing can get worse afterwards. New rules start frozen too.
Teams can add their own local rules, but removing a shared one goes through review, enforced with CODEOWNERS and a simple CI check. Finally, CI reports the number of frozen violations per rule and service to a dashboard, so we can see where erosion happens, help the teams with the most violations, and decide when a rule can become strict.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Maven guides, Gradle user manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "You want the same architecture rules (no web-to-repository access, no cycles between...": https://scrivio-interview-library.netlify.app/java/code-quality-tools/64b9b211b1/