A handler that imports a framework’s transaction annotation makes the application core depend on that framework. The Architecture Kernel avoids that coupling: it is a small, framework-independent module of architectural types shared across domain, application, and adapter boundaries. section 4.1.1 section 4.4.3
The kernel is an architectural microframework, not a DDD Shared Kernel. It contains neutral building blocks, not shared domain concepts, business rules, or ubiquitous language. Its types include stereotypes such as @UseCase, Command and Query markers, and command and query bus contracts. section 4.1.1
Listing 4.11 Handler with technology-agnostic transactional boundary
@ApplicationService
@RequiredArgsConstructor
@Transactional #A
final class PublishArticleHandler implements PublishArticleUseCase {
private final ArticleRepository articleRepository;
@Override
public Either<Error, Void> handle(final PublishArticleCommand command) {
return this.articleRepository.readById(command.articleId())
.flatMap(article -> article.publish(command.authorId()))
.flatMap(article -> this.articleRepository.save(article));
}
}
The handler declares transactional intent with the kernel’s technology-agnostic annotation while orchestrating the use case through a repository abstraction. section 4.4.3
Place the transaction boundary on the handler, not on a repository or input adapter: the handler coordinates the full use case as one unit of work. At runtime, a custom transaction interceptor implements the kernel’s @Transactional intent and rolls back by returned value rather than by exception. section 6.3.4 section 6.6
Listing 4.13 CommandBus from the Architecture Kernel
public interface CommandBus {
<E, C extends Command> Either<E, Void>
execute(final C command); #A
}
The CommandBus contract gives adapters one entry point for executing commands. A use case can extend CommandHandler to participate in bus routing while remaining available through direct injection. section 4.5.2
