Hexagonal Architecture rules for ArchUnit.
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)
}
The following package structures are supported:
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.
domain
api
x
model
logic
spi
y
infrastructure
, the driven/secondary/right sidey
(for implementingdomain.spi.y
)- e.g.
memory
- e.g.
postgres
- e.g.
redis
- ...
- e.g.
Alternatively, you can merge application
and infrastructure
into adapters
:
adapters
x
- e.g.
grpc
- e.g.
http
- e.g.
management
- ...
- e.g.
y
- e.g.
memory
- e.g.
postgres
- e.g.
redis
- ...
- e.g.
domain
api
x
model
logic
spi
y
You can also use both approaches at the same time. That gives you a hybrid mix of the Default and Unified Adapters approaches.
adapters
z
(for exposingdomain.api.z
and implementingdomain.spi.z
)- e.g.
prometheus
- ...
- e.g.
application
x
- e.g.
grpc
- e.g.
http
- e.g.
management
- ...
- e.g.
domain
api
x
z
model
logic
spi
y
z
infrastructure
y
- e.g.
memory
- e.g.
postgres
- e.g.
redis
- ...
- e.g.