MCPcopy Index your code
hub / github.com/TNG/ArchUnit

github.com/TNG/ArchUnit @v1.4.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.4.2 ↗ · + Follow
13,113 symbols 61,121 edges 1,318 files 945 documented · 7% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CI Maven Central License

ArchUnit

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between packages and classes, layers and slices, check for cyclic dependencies and more. It does so by analyzing given Java bytecode, importing all classes into a Java code structure. ArchUnit's main focus is to automatically test architecture and coding rules, using any plain Java unit testing framework.

An Example

Add the Maven Central dependency to your project

Gradle
testImplementation 'com.tngtech.archunit:archunit:1.4.2'
Maven
<dependency>
    <groupId>com.tngtech.archunit</groupId>
    <artifactId>archunit</artifactId>
    <version>1.4.2</version>
    <scope>test</scope>
</dependency>

Create a test

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;

public class MyArchitectureTest {
    @Test
    public void some_architecture_rule() {
        JavaClasses importedClasses = new ClassFileImporter().importPackages("com.myapp");

        ArchRule rule = classes()... // see next section

        rule.check(importedClasses);
    }
}

Let the API guide you

ArchUnit Fluent API

Where to look next

For further information, check out the user guide at http://archunit.org or test examples for the current release at ArchUnit Examples.

License

ArchUnit is published under the Apache License 2.0, see http://www.apache.org/licenses/LICENSE-2.0 for details.

It redistributes some third party libraries:

  • ASM (http://asm.ow2.org), under BSD Licence
  • Google Guava (https://github.com/google/guava), under Apache License 2.0

All licenses for ArchUnit and redistributed libraries can be found within the licenses folder.

Extension points exported contracts — how you extend this code

LocationProvider (Interface)
Allows to provide a custom implementation, that supplies Location Locations to be imported by the JUnit test inf [65 implementers]
archunit-junit/src/api/java/com/tngtech/archunit/junit/LocationProvider.java
DescriptorCreator (Interface)
A generic interface to be extended by users for providing custom implementations of ArchModule.Descriptor that c [34 implementers]
archunit/src/main/java/com/tngtech/archunit/library/modules/ArchModules.java
Link (Interface)
(no doc) [4 implementers]
archunit-integration-test/src/test/java/com/tngtech/archunit/testutils/MessageAssertionChain.java
ShoppingCartRepository (Interface)
(no doc) [3 implementers]
archunit-example/example-plain/src/main/java/com/tngtech/archunit/example/onionarchitecture/adapter/persistence/ShoppingCartRepository.java
InternalRunner (Interface)
(no doc) [2 implementers]
archunit-junit/junit4/src/main/java/com/tngtech/archunit/junit/ArchUnitRunner.java
Example (Interface)
This Category @Category marks tests that are supposed to fail and illustrate use cases of ArchUnit. They should
archunit-example/example-junit4/src/test/java/com/tngtech/archunit/exampletest/junit4/Example.java
RootClassDescriptorCreator (Interface)
A more convenient DescriptorCreator tailored to the case that we {@link #defineByRootClasses(Predicate) define o [34 implementers]
archunit/src/main/java/com/tngtech/archunit/library/modules/ArchModules.java
ExpectedRelation (Interface)
(no doc) [3 implementers]
archunit-integration-test/src/test/java/com/tngtech/archunit/testutils/ExpectedRelation.java

Core symbols most depended-on inside this repo

getName
called by 1966
archunit/src/main/java/com/tngtech/archunit/library/modules/ArchModule.java
should
called by 1273
archunit/src/main/java/com/tngtech/archunit/lang/syntax/elements/GivenClass.java
get
called by 1095
archunit/src/test/java/com/tngtech/archunit/testutil/TestUtils.java
as
called by 1014
archunit/src/main/java/com/tngtech/archunit/lang/ClassesTransformer.java
getSimpleName
called by 634
archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java
that
called by 586
archunit/src/main/java/com/tngtech/archunit/lang/ClassesTransformer.java
getClass
called by 542
archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java
format
called by 523
archunit/src/main/java/com/tngtech/archunit/core/domain/Formatters.java

Shape

Method 10,192
Class 2,485
Interface 307
Function 94
Enum 35

Languages

Java99%
TypeScript1%

Modules by API surface

archunit/src/test/java/com/tngtech/archunit/core/domain/JavaClassTest.java270 symbols
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/ShouldClassesThatTest.java246 symbols
archunit/src/main/java/com/tngtech/archunit/core/importer/DomainBuilders.java224 symbols
archunit/src/main/java/com/tngtech/archunit/core/domain/JavaClass.java223 symbols
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldTest.java200 symbols
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/ShouldOnlyByClassesThatTest.java177 symbols
archunit/src/main/java/com/tngtech/archunit/lang/conditions/ArchConditions.java140 symbols
archunit/src/jdk16test/java/com/tngtech/archunit/core/importer/testexamples/methodresolution/DeterminesMethodAnalogouslyToReflectionApi.java137 symbols
archunit/src/main/java/com/tngtech/archunit/core/importer/JavaClassProcessor.java122 symbols
archunit/src/test/java/com/tngtech/archunit/lang/syntax/elements/GivenClassesThatTest.java120 symbols
archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterAutomaticResolutionTest.java119 symbols
archunit-junit/junit5/engine/src/test/java/com/tngtech/archunit/junit/internal/ArchUnitTestEngineTest.java117 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add ArchUnit \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact