- All Implemented Interfaces and Traits:
- com.tngtech.archunit.lang.ArchRule
@SuppressWarnings(value: CodeNarc.MethodCount)
@CompileStatic
class HexagonalCqrsEsArchitecture
extends Object
implements com.tngtech.archunit.lang.ArchRule
Implementation of ArchUnit's ArchRule
for asserting CQRS/ES flavored hexagonal architecture used in klokwrk
.
It supports 4 variants of CQRS/ES flavored hexagonal architecture: general (without specific architecture subtype), commandSide, querySide and projection. It is inspired by ArchUnit's
implementation for asserting onion architecture and follows very similar usages patterns.
Usage example for asserting commandSide subtype of CQRS/ES flavored hexagonal architecture (from klokwrk's code):
ArchRule rule = HexagonalCqrsEsArchitecture
.architecture(HexagonalCqrsEsArchitecture.ArchitectureSubType.COMMANDSIDE)
.domainValues("..cargotracking.domain.model.value..")
.domainEvents("..cargotracking.domain.model.event..")
.domainCommands("..cargotracking.domain.model.command..")
.domainAggregates("..cargotracking.domain.model.aggregate..")
.applicationInboundPorts("..cargotracking.booking.app.commandside.feature.*.application.port.in..")
.applicationOutboundPorts("..cargotracking.booking.app.commandside.feature.*.application.port.out..")
.applicationServices("..cargotracking.booking.app.commandside.feature.*.application.service..")
.adapterInbound("in.web", "..cargotracking.booking.app.commandside.feature.*.adapter.in.web..")
.adapterOutbound("out.remoting", "..cargotracking.booking.app.commandside.feature.*.adapter.out.remoting..")
.withOptionalLayers(false)
rule.check(importedClasses)
Usage example for asserting projection subtype of CQRS/ES flavored hexagonal architecture (from klokwrk's code):
ArchRule rule = HexagonalCqrsEsArchitecture
.architecture(HexagonalCqrsEsArchitecture.ArchitectureSubType.PROJECTION)
.domainModelValues("..cargotracking.domain.model.value..")
.domainEvents("..cargotracking.domain.model.event..")
.adapterProjection("out.persistence", "..cargotracking.booking.app.queryside.projection.rdbms.feature.*.adapter.out..")
// We are ignoring dependencies originating from command classes. Command classes should not be used in projections. Only events can be used. Since command and events are not split it their
// own modules, we need to ignore commands here. Illegal access to commands is verified in other test.
.ignoreDependency(JavaClass.Predicates.resideInAPackage("org.klokwrk.cargotracking.domain.model.command.."), JavaClass.Predicates.resideInAPackage("org.klokwrk.cargotracking.."))
.withOptionalLayers(false)
rule.check(importedClasses)
Usage example for asserting querySide subtype of CQRS/ES flavored hexagonal architecture (from klokwrk's code):
ArchRule rule = HexagonalCqrsEsArchitecture
.architecture(HexagonalCqrsEsArchitecture.ArchitectureSubType.QUERYSIDE)
.domainModelValues("..cargotracking.domain.model.value..")
.applicationInboundPorts("..cargotracking.booking.app.queryside.view.feature.*.application.port.in..")
.applicationOutboundPorts("..cargotracking.booking.app.queryside.view.feature.*.application.port.out..")
.applicationServices("..cargotracking.booking.app.queryside.view.feature.*.application.service..")
.adapterInbound("in.web", "..cargotracking.booking.app.queryside.view.feature.*.adapter.in.web..")
.adapterOutbound("out.persistence", "..cargotracking.booking.app.queryside.view.feature.*.adapter.out.persistence..")
.withOptionalLayers(false)
rule.check(importedClasses)