archunit-hexagonal
archunit-hexagonal copied to clipboard
Hexagonal Architecture rules for ArchUnit
archunit-hexagonal
Hexagonal Architecture rules for ArchUnit.
Usage
To run the architecture tests in your repository do something along the following
package my.package
import com.tngtech.archunit.core.importer.ImportOption
import com.tngtech.archunit.junit.AnalyzeClasses
import com.tngtech.archunit.junit.ArchTest
import com.tngtech.archunit.junit.ArchTests
import io.github.whiskeysierra.archunit.hexagonal.HexagonalArchitecture
import com.tngtech.archunit.junit.ArchTests.`in` as from
// Standard archunit scope identifier.
// See https://www.archunit.org/userguide/html/000_Index.html#_using_junit_support_with_kotlin
@AnalyzeClasses(
packagesOf = [Application::class],
importOptions = [ImportOption.DoNotIncludeTests::class]
)
object ArchitectureTest {
@ArchTest
val tests: ArchTests = from(HexagonalArchitecture::class.java)
}
Modes
The following package structures are supported:
Default
In the default setup, you are expected to have:
application, the driver/primary/left sidex(for exposingdomain.api.x)- e.g.
grpc - e.g.
http - e.g.
management - ...
- e.g.
domainapix
modellogicspiy
infrastructure, the driven/secondary/right sidey(for implementingdomain.spi.y)- e.g.
memory - e.g.
postgres - e.g.
redis - ...
- e.g.
Unified Adapters
Alternatively, you can merge application and infrastructure into adapters:
adaptersx- e.g.
grpc - e.g.
http - e.g.
management - ...
- e.g.
y- e.g.
memory - e.g.
postgres - e.g.
redis - ...
- e.g.
domainapix
modellogicspiy
Hybrid
You can also use both approaches at the same time. That gives you a hybrid mix of the Default and Unified Adapters approaches.
adaptersz(for exposingdomain.api.zand implementingdomain.spi.z)- e.g.
prometheus - ...
- e.g.
applicationx- e.g.
grpc - e.g.
http - e.g.
management - ...
- e.g.
domainapixz
modellogicspiyz
infrastructurey- e.g.
memory - e.g.
postgres - e.g.
redis - ...
- e.g.