Every team has an architecture diagram. Almost no team has an architecture that still matches it after eighteen months. The controller imports the repository directly, the “shared” module becomes a dependency of everything, and a package cycle quietly forms between order and billing. Code review does not catch it, because each individual pull request looks reasonable.
Two tools exist to turn that diagram into a build failure instead of a wiki page: ArchUnit and jQAssistant. They solve the same problem from opposite directions — one is a JUnit-style assertion library that inspects bytecode on the classpath, the other imports your entire codebase into a graph database and lets you query it with Cypher. In 2026 they are both actively maintained, and choosing between them comes down to how much infrastructure you want in your build.
TL;DR
- Pick ArchUnit 1.5.1 for 90% of teams. It is a JUnit dependency, it runs in the same test phase as your unit tests, and a rule is a fluent one-liner you can review in a pull request.
- Pick jQAssistant 2.10.0-RC1 when you need cross-artifact analysis: multiple modules, SQL migrations, Maven POMs, or queries that join code structure with things that are not code.
- Do not run both unless you have a specific reason. Two rule languages, two failure surfaces, and two sets of false positives is how architecture enforcement gets switched off in month three.
| Dimension | ArchUnit | jQAssistant |
|---|---|---|
| GitHub stars | 3,918 | 303 |
| Latest release | 1.5.1 (Sep 2026) | 2.10.0-RC1 (Nov 2026) |
| Last commit | Dec 2026 | Dec 2026 |
| Approach | Bytecode import + fluent Java rules | Bytecode import + graph database + Cypher |
| Rule language | Java DSL (ArchRuleDefinition) | Cypher queries or annotated Java concepts |
| Runtime | In-process, seconds | Scan + analyze phases, embedded Neo4j |
| Feedback | JUnit failure with a readable violation list | Build report / Neo4j browser |
| Freeze existing violations | FreezingArchRule | Baseline via stored rule results |
| Best fit | Single service, layered rules, CI gate | Multi-module estates, cross-domain queries |
Decision Matrix
| Situation | Choose | Why |
|---|---|---|
| One Spring Boot service, enforce layer boundaries | ArchUnit | layeredArchitecture() covers it in 15 lines |
| Enforce “no cycles between feature packages” | ArchUnit | SlicesRuleDefinition.slices() is purpose-built |
| Existing codebase with 400 violations you cannot fix this quarter | ArchUnit | FreezingArchRule stores the baseline in the repo |
| 40 Maven modules and you want one architecture report | jQAssistant | Single scan across the reactor, one graph |
| Rules that mix code with POM versions or SQL DDL | jQAssistant | Only it has those nodes in the graph |
| Ad-hoc exploration (“who calls this internal API?”) | jQAssistant | Cypher against the graph beats writing throwaway rules |
| Rules must block a pull request in under a minute | ArchUnit | No database, no separate build step |
| Team has no Java expertise beyond Spring | ArchUnit | The rule reads like English |
ArchUnit 1.5.1 — Architecture as a Unit Test
ArchUnit imports compiled classes into a metamodel and evaluates rules against it. That is the whole design. There is no server, no schema, no separate build phase — you add a test dependency, write a class annotated with @AnalyzeClasses, and the rules run whenever your test suite runs.
The fluent API is the reason it wins adoption. A layered architecture rule reads almost like the diagram:
| |
Inside a JUnit 5 suite the same rule becomes a static field, and a violation fails the build with the exact class and line that broke it:
| |
Dependency and the JUnit 5 integration:
| |
The feature that makes ArchUnit survivable on legacy code is FreezingArchRule. Instead of failing on all 400 existing violations, it records them in a text store and fails only on new ones. Fix a violation and the store shrinks; introduce one and CI goes red. That turns architecture enforcement from an all-or-nothing migration into a ratchet.
| |
Configure the store location in archunit.properties so the baseline is committed and reviewed like any other file:
| |
Where ArchUnit stops is at the edge of the bytecode. It cannot tell you that a service depends on a database table, that two modules share a POM dependency they should not, or that a REST endpoint is exposed without a matching security configuration. Those questions need data ArchUnit never sees.
jQAssistant 2.10.0-RC1 — Your Codebase as a Queryable Graph
jQAssistant takes the opposite approach. A Maven or Gradle plugin scans bytecode (and optionally POMs, SQL, XML, YAML), writes everything into an embedded Neo4j graph, and then evaluates rules written in Cypher. Every class, method, field, annotation, and dependency becomes a node with relationships.
Setup is a plugin in your build:
| |
A rule is a constraint expressed as a query. Everything the query returns is a violation:
| |
You can also declare concepts and constraints in Java, which keeps rules in the same language as the codebase:
| |
The payoff is the queries you cannot express anywhere else. Because POMs, SQL scripts, and bytecode live in the same graph, a single rule can answer “which services use a library version that is out of range” or “which entities have no matching table in the migration scripts”. Ad-hoc exploration in the Neo4j browser is genuinely pleasant — type a Cypher query, get a graph, click through it.

The cost is operational. You now have a scan phase that writes a database, an analyze phase that runs queries, a report to read when a rule fails, and a graph store to manage in CI. A cold scan of a 40-module reactor takes minutes, not seconds. Cache the store between builds or the feedback loop becomes useless. The current release is also a release candidate (2.10.0-RC1), which tells you something about the project’s cadence — check the changelog before you pin it in a regulated environment.
Rule Quality Decides Everything
Both tools fail the same way: someone writes forty rules in a burst of enthusiasm, half of them flag legitimate code, and within a quarter the whole suite is excluded from the build with a comment that says “temporarily disabled”. Three practices prevent that.
Start with three rules, not thirty. Layer boundaries, no package cycles, and one naming rule (controllers end in Controller, repositories implement an interface) catch most real drift. Add a rule only after a specific incident that it would have prevented.
Write the violation message for the person who will see it. “Rule violated” is useless at 6 p.m. before a release. ArchUnit lets you override because(...) on every rule; use it to explain the intended design, not to restate the rule.
Ratchet, never big-bang. With ArchUnit that is FreezingArchRule. With jQAssistant, keep the analyze phase non-failing at first and publish the report, then promote individual constraints to build-breaking once the count reaches zero.
Performance and CI Considerations
ArchUnit’s import is the expensive part — a few seconds for a mid-sized service, cached across rules in the same JVM. That is compatible with a pre-commit hook and comfortable in a pull-request pipeline.
jQAssistant’s scan is proportional to the size of the reactor and the number of plugins enabled. For a monorepo it belongs in a nightly job or a separate pipeline stage, with the store cached so incremental scans are cheap. Do not put a cold full scan in a pull-request gate unless the reactor is small.
One shared trap: both tools analyze bytecode, so they see the compiled result, not your source intent. Generated code, Kotlin defaults, and Lombok output all appear as real dependencies. Filter generated packages explicitly or your first rule run will report violations in code nobody wrote.
Pitfalls Worth Knowing
- ArchUnit and Kotlin. Kotlin’s default-parameter synthetic methods and
@JvmStaticbridges produce dependencies your source does not show. Rules that look correct can fail for invisible reasons; inspect the reported class before assuming the rule is wrong. consideringAllDependencies()is stricter than it sounds. It includes dependencies from fields, method signatures, return types, and thrown exceptions. Some teams wantconsideringOnlyDependenciesInLayers()instead and are surprised by the difference.- jQAssistant’s graph is a snapshot. It does not track history. Trends over time require exporting results per build and diffing them yourself.
- Rule files are code. Put jQAssistant rule XML under version control, review it like Java, and give constraints stable IDs — renaming an ID silently disables the baseline.
- Do not enforce rules on test code. Both tools will happily analyze
src/test/javaand report that your tests depend on things tests are supposed to depend on. - A green build is not proof. If the analyze phase is bound to a profile nobody activates, your architecture has no gate at all. Verify by deliberately breaking a rule once and confirming CI fails.
FAQ
Is ArchUnit enough, or do I need jQAssistant too?
For a single deployable with clear package boundaries, ArchUnit is enough and adding jQAssistant doubles your maintenance for little gain. Consider jQAssistant when your questions cross artifact types — code plus POMs plus SQL — or when you need one report across a large multi-module reactor.
Can ArchUnit check that controllers do not call repositories directly?
Yes. Either express it as a layer rule with layeredArchitecture(), or write classes().that().resideInAPackage("..controller..").should().onlyDependOnClassesThat().resideInAnyPackage("..service..", "..dto..", "java.."). The layered form produces clearer violation messages.
How do I adopt architecture rules without breaking the build immediately?
Use FreezingArchRule.freeze(rule) in ArchUnit, which records current violations in a store file and fails only on new ones. With jQAssistant, run the analyze phase in report-only mode first and promote constraints to failing once the violation count reaches zero.
Does jQAssistant work with Gradle as well as Maven?
Yes, a Gradle plugin exists alongside the Maven plugin, plus a CLI for builds that use neither. The scan and analyze phases are the same; only the task names differ.
Is jQAssistant 2.10.0-RC1 safe for production CI?
It is a release candidate, so pin the exact version and read the changelog before upgrading. The 2.x line has been stable for years, but a release candidate in a build-critical path deserves a deliberate upgrade policy rather than automatic version bumps.
Can these tools detect circular dependencies between modules?
ArchUnit detects package cycles with slices().matching("com.example.(*)..").should().beFreeOfCycles(). Module-level cycles across Maven modules are better handled by jQAssistant, which models POM dependencies as graph relationships and can query cycles directly.
Related Reading
Architecture rules are one part of a build that stays honest. For the surrounding decisions, see JVM build tools — Gradle vs Maven vs sbt vs Bazel for where the scan and analyze phases fit, Java testing libraries — AssertJ vs Hamcrest vs Truth for the assertion style your rule tests will use, and Java web frameworks — Spring Boot vs Quarkus vs Micronaut for the layered structures these rules typically enforce.
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com