Migration reference · Sources checked November 24, 2026
Keep the intent across languages
Choose the check from the constraint and the evidence it needs.
What ArchUnit sees
TNG's ArchUnit analyzes JVM class files. It can protect Java packages, annotation conventions, and dependencies in code that calls a Rust service, including restricting which Java classes may use a generated client. It does not import ordinary Rust source or native Rust binaries, inspect the Rust implementation, or prove that an external service behaves correctly. ArchUnit's input model.
For example, "controllers must reach pricing through an application service" can become a Java dependency rule. "The Rust pricing API must keep returning amounts in minor currency units" needs an API or behavioral contract test. A shared architectural statement can lead to several concrete tests.
Rust tools and the exercises they support
| Tool | What it checks; planned practice |
|---|---|
| Rust compiler visibility | Restrict access to items using private modules and
pub(crate), pub(super), or pub(in ...). Exercise: expose a small
service API while keeping storage details inaccessible; prove a forbidden access fails compilation.
Reference. |
| cargo-deny | Apply dependency bans, allowed consumers, and other package policies. The first exercise is ready. Follow-up: allow one legacy adapter to depend on a banned library and reject another direct consumer. It does not inspect every source-level use within an allowed package. Configuration. |
| cargo-modules | Inspect module/item structure and dependency graphs. Its
cargo modules dependencies --lib --acyclic mode fails on a detected cycle.
Exercise: introduce an internal module cycle and inspect the reported graph. Choose the target and
features explicitly; this is not a general arbitrary package-policy DSL.
Acyclic mode. |
| cargo-semver-checks | Find public Rust API changes that violate the intended semantic
version compatibility. Exercise: remove a public function and compare with a saved earlier library
version using --baseline-root. That baseline is an earlier API, not a list of accepted
architecture violations. It does not check HTTP/JSON compatibility or all runtime behavior.
Project documentation. |
| Cargo metadata | Export machine-readable package and resolved dependency information
using cargo metadata --format-version 1. Use this if a precise graph policy cannot be
expressed by an existing tool; account for dependency kinds and selected features/targets.
It supplies evidence rather than enforcing a policy itself.
Cargo Book. |
A Rust library with a similar rule style
The independent archunit crate, branded ArchUnitRust, documents file-dependency,
layer, and cycle rules that run through Cargo tests. Its documentation currently identifies version
0.0.2 and active development. It is a separate project from TNG's Java ArchUnit; compatible naming
does not imply a shared implementation or freeze store.
Crate documentation.
Its documented extraction is based on source syntax: it does not expand macros or inspect build-script-generated code, combines conditional-compilation branches conservatively, and uses files as dependency nodes. Treat it as an optional trial: compare what it detects against small fixtures containing a direct path, a re-export, a macro, and mutually exclusive feature branches. Do not adopt it for a particular rule until those examples establish useful coverage for that rule.
No directly equivalent automatic shrinking violation store was verified among the Rust tools in this reference. Scoped exceptions, graph snapshots, and previous-API comparisons have different semantics. If a Rust policy needs grandfathered debt, evaluate the tool's actual exception behavior before designing custom baseline machinery.
Checks shared by Java and Rust
A contract test checks an agreement between a consumer and a provider, such as the requests a client sends and the responses it requires. Pact has JVM and Rust implementations. It can carry consumer expectations across a service rewrite; verify the provider against those expectations and check that both implementations support the chosen Pact specification and features. Pact JVM · Pact Rust.
The planned exercise keeps a Java client's expected interaction and verifies it against a Rust provider, including a deliberate response change that must fail. Contract tests cover the interactions you specify; keep integration and behavior tests for other migration risks.
If the interface uses Protobuf, buf breaking checks schema compatibility against a
chosen baseline. Pick the compatibility category for the clients and wire format you support.
For HTTP/JSON, choose checks for your actual OpenAPI or JSON contract instead. Schema compatibility
does not establish business semantics, such as currency units.
Buf breaking-change detection.
If Java invokes Rust through a native interface, add tests for calling conventions, data layout, resource ownership, and error handling at that interface. Neither Java bytecode rules nor Rust API compatibility checks establish those properties.