explaingit

tng/archunit

Analysis updated 2026-07-03

3,690JavaAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

ArchUnit is a Java library that lets you write automated tests to enforce architecture rules in your codebase, catching violations like illegal dependencies or circular imports as part of your normal test suite.

Mindmap

mindmap
  root((ArchUnit))
    What it does
      Tests architecture rules
      Scans Java bytecode
      Fails build on violations
    Use Cases
      Enforce layer separation
      Prevent circular deps
      Check naming conventions
    Tech Stack
      Java
      JUnit
      Maven or Gradle
    Audience
      Java developers
      Tech leads
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Write a test that fails if any controller class directly calls a repository, enforcing a strict service-layer separation.

USE CASE 2

Catch circular package dependencies automatically on every CI build before they become a long-term problem.

USE CASE 3

Enforce naming conventions across a Java project, such as requiring all Spring service classes to end in 'Service'.

What is it built with?

JavaJUnitMavenGradle

How does it compare?

tng/archunitmojang/brigadieroasisfeng/island
Stars3,6903,6883,685
LanguageJavaJavaJava
Setup difficultyeasyeasyhard
Complexity2/52/54/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Just add ArchUnit as a test dependency in Maven or Gradle, no external infra or API keys needed.

Apache License 2.0, use freely for any purpose, including commercial projects, as long as you keep the copyright notice.

In plain English

ArchUnit is a Java library that lets you write automated tests for your code's architecture. In software projects, architecture refers to rules about how code is organized: which parts of the codebase are allowed to talk to each other, how layers are separated, whether there are circular dependencies, and so on. Without a tool like this, those rules typically live only in documentation or team memory and violations accumulate silently over time. ArchUnit lets you express the rules as regular unit tests that run in your existing test suite. The library works by scanning your compiled Java bytecode, loading all the classes into an in-memory structure, and then checking them against rules you define in Java code. The rules are written using a fluent API that reads roughly like English: you state that certain classes should only depend on certain other classes, that packages should follow a specific layering pattern, or that there should be no cyclic dependencies between a given set of packages. If any class violates a rule, the test fails and reports exactly which violation occurred. Adding ArchUnit to a project takes two steps: add it as a test dependency via Maven or Gradle, then write a test class with one or more rule checks. The library integrates with standard Java test frameworks like JUnit, so no special tooling is required beyond what most Java projects already have. Common use cases include enforcing a layered architecture (controllers only call services, services only call repositories, repositories only touch the database), preventing circular package dependencies, and ensuring naming conventions are followed across a codebase. The library is free, open-source, and published under the Apache License 2.0.

Copy-paste prompts

Prompt 1
Using ArchUnit with JUnit 5, write a test that enforces a three-layer architecture where controllers may only call services, and services may only call repositories.
Prompt 2
Show me how to add ArchUnit to a Gradle project and write a rule that prevents any class in the 'internal' package from being imported outside of it.
Prompt 3
Write an ArchUnit test that checks there are no cyclic dependencies between packages in a Java project.

Frequently asked questions

What is archunit?

ArchUnit is a Java library that lets you write automated tests to enforce architecture rules in your codebase, catching violations like illegal dependencies or circular imports as part of your normal test suite.

What language is archunit written in?

Mainly Java. The stack also includes Java, JUnit, Maven.

What license does archunit use?

Apache License 2.0, use freely for any purpose, including commercial projects, as long as you keep the copyright notice.

How hard is archunit to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is archunit for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub tng on gitmyhub

Verify against the repo before relying on details.