# packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide architecture

> Architecture diagram of the GitHub repository packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide
- Repository: https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide

## Overview

##### Project type and purpose
- This is a multi-module Maven project that accompanies the book “Domain-Driven Design with Java – A Practitioner’s Guide.”

##### File structure
- Top-level modules:
- Chapter05, Chapter06, … Chapter09 – each with its own pom.xml, main/java, main/resources, test/java.
- Within each ChapterXX:
- src/main/java/com/premonition/lc/chXX/domain – aggregates, entities, commands, events, exceptions
- src/main/java/com/premonition/lc/chXX/domain/queries – read-side event handlers, repositories, view models
- src/main/java/com/premonition/lc/chXX/domain/sagas – long-running workflow orchestrators
- src/main/java/com/premonition/lc/chXX/ui – JavaFX UI code: views, viewmodels, services
- application.properties – Spring Boot / Axon / JavaFX configuration
- CI workflow: .github/workflows/pipeline.yaml; root pom.xml orchestrates modules.

##### README for additional insights
- Describes the book’s DDD focus, layering, event-storming, CQRS, EDA, sagas, microservices decomposition, and usage of Spring, Axon, JavaFX.

a. Main components
- Client Layer: JavaFX UI (Views, ViewModels, UIUtils)
- API Layer: BackendService (HTTP/WebSocket client)
- Application (Spring Boot / Axon) – Command Gateway, Event Bus
- Domain Layer: Aggregates (LCApplication), Commands, Domain Events, Domain Exceptions
- Saga Orchestrator: AutoApprovalSaga
- Query Side: Event Handlers, Read-model repositories (LCViewRepository, LCSummaryRepository), View projections (LCView, LCSummaryView)
- Persistence: Transactional store for write model; separate store/tables for read model
- External Systems: Inbound validation services (ApplicantCreditValidatedEvent, ProductValueValidatedEvent, ProductLegalityValidatedEvent); Outbound notifications (LCApplicationApprovedEvent, etc.)

b. Component relationships & data flows
1. UI triggers command via BackendService →
2. API Layer invokes Axon Command Gateway →
3. Domain Aggregate handles command → emits Domain Event →
4. Event Bus broadcasts event to:
- Saga (AutoApprovalSaga) to orchestrate long-running workflows
- Query Handlers to update read models (projections)
- Message publishers to external systems (outbound events)
5. External systems send inbound events → consumed by Domain Event Handlers → continue saga or update state
6. UI queries read model via BackendService → returns projected views

c. Architectural patterns & design principles
- Layered Architecture (Presentation, Application, Domain, Infrastructure)
- CQRS: separation of command (write) model and query (read) model
- Event-Driven Architecture: domain events as the source of truth, asynchronous message bus
- Saga Pattern: long-running business process orchestration
- Hexagonal / Ports & Adapters: UI and external systems connect via well-defined service interfaces

d. Key technologies & frameworks
- Java 14, Spring Boot
- Axon Framework (Command Gateway, Event Bus, Sagas)
- JavaFX for desktop UI
- Maven for build and module orchestration
- Asciidoctor + PlantUML/Graphviz for documentation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Views["JavaFX UI Views"]:::presentation
        ViewModels["JavaFX UI ViewModels"]:::presentation
        UIUtils["UIUtils"]:::presentation
        BackendService["BackendService (API Layer)"]:::presentation
        Views -->|uses| ViewModels
        ViewModels -->|uses| UIUtils
        ViewModels -->|calls| BackendService
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        App["App (Spring Boot / Axon)"]:::application
        CommandGateway["CommandGateway"]:::application
        EventBus["EventBus"]:::application
        App -->|initializes| CommandGateway
        CommandGateway -->|dispatches| EventBus
        BackendService -->|HTTP/WebSocket| App
    end

    %% Domain Module
    subgraph "Domain Module"
        direction TB
        Aggregate["LCApplication Aggregate"]:::domain
        Commands["Domain Commands"]:::domain
        InboundEvents["Inbound Domain Events"]:::domain
        OutboundEvents["Outbound Domain Events"]:::domain
        Exceptions["Domain Exceptions"]:::domain
        Saga["AutoApprovalSaga"]:::domain

        CommandGateway -->|sends| Commands
        Commands -->|handled by| Aggregate
        Aggregate -->|emits| OutboundEvents
        InboundEvents -->|handled by| Saga
        OutboundEvents -->|triggers| Saga
        Aggregate -->|throws| Exceptions
        OutboundEvents -->|published on| EventBus
    end

    EventBus -->|broadcasts| Saga
    EventBus -->|broadcasts| QueryHandlers
    EventBus -->|publishes| ExternalPublisher

    %% Query Side
    subgraph "Query Side"
        direction TB
        QueryHandlers["Event Handlers"]:::query
        Repositories["Repositories"]:::query
        Projections["View Projections"]:::query
        QueryModel["MyDraftLCsQuery"]:::query

        EventBus -->|subscribes| QueryHandlers
        QueryHandlers -->|updates| Repositories
        Repositories -->|stores| Projections
        BackendService -->|queries| QueryModel
        QueryModel -->|reads from| Repositories
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        WriteDB[(Write Model DB)]:::infra
        ReadDB[(Read Model DB)]:::infra
        Aggregate -->|persist| WriteDB
        Repositories -->|persist| ReadDB
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        ValidationServices["Validation Services"]:::external
        NotificationChannels["Notification Channels"]:::external

        ValidationServices -->|sends inbound events| InboundEvents
        OutboundEvents -->|sends outbound events| NotificationChannels
    end

    %% Click Events
    click Views "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/Chapter09/src/main/java/com/premonition/lc/ch09/ui/views"
    click ViewModels "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/Chapter09/src/main/java/com/premonition/lc/ch09/ui/viewmodels"
    click UIUtils "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/ui/utils/UIUtils.java"
    click BackendService "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/ui/services/BackendService.java"
    click App "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/App.java"
    click Aggregate "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/LCApplication.java"
    click Commands "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/commands"
    click InboundEvents "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/events/inbound"
    click OutboundEvents "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/events/outbound"
    click Exceptions "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/exceptions"
    click Saga "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/sagas/AutoApprovalSaga.java"
    click QueryHandlers "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/queries/LCApplicationStartedEventHandler.java"
    click Repositories "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/queries/LCViewRepository.java"
    click Projections "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/queries/LCView.java"
    click QueryModel "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/Chapter09/src/main/java/com/premonition/lc/ch09/domain/queries/MyDraftLCsQuery.java"
    click CI "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/.github/workflows/pipeline.yaml"
    click POM "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/blob/master/pom.xml"
    click Book "https://github.com/packtpublishing/domain-driven-design-with-java-a-practitioner-s-guide/tree/master/book/src/docs/asciidoc"

    %% Styling
    classDef presentation fill:#cee7ff,stroke:#2a56c6
    classDef application fill:#d4f4dd,stroke:#2f8f3e
    classDef domain fill:#e0ffe0,stroke:#27ae60
    classDef query fill:#fff4cc,stroke:#d4a017
    classDef infra fill:#ffe5cc,stroke:#d35400
    classDef external fill:#f0f0f0,stroke:#636e72,stroke-dasharray: 2 2
```
