# vaughnvernon/iddd_samples architecture

> Architecture diagram of the GitHub repository vaughnvernon/iddd_samples, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vaughnvernon/iddd_samples
- Repository: https://github.com/vaughnvernon/iddd_samples

## Overview

##### Project type and purpose
- This repository is a set of sample “Bounded Context”‐level reference projects illustrating Domain-Driven Design patterns. It is not a single monolith, but four related Java modules:
- iddd_common – shared reusable DDD infrastructure
- iddd_agilepm – an Agile Project Management domain using a key-value store (LevelDB)
- iddd_collaboration – a Collaboration domain using Event Sourcing + CQRS (LevelDB write store + MySQL read store)
- iddd_identityaccess – an Identity & Access domain using Hibernate ORM, REST APIs, and Domain-Event notifications (RabbitMQ & REST)

##### File structure
- Top‐level modules: iddd_common, iddd_agilepm, iddd_collaboration, iddd_identityaccess
- Each module follows a layered architecture:
– application (ApplicationService classes / commands / queries / DTOs)
– domain (aggregate roots, entities, value objects, domain events, repositories)
– port.adapter
- persistence (LevelDB, Hibernate, Event Store, JDBC projections)
- messaging (RabbitMQ, SlothMQ listeners & publishers)
- REST resources (in identityaccess)
- Collaboration module adds a separate “read model” under port.adapter.persistence.view (MySQL projections)
- Build & orchestration: Gradle scripts, settings.gradle, Docker startup (startContainers.sh)

##### README for additional insights
- AgilePM: no container framework, pure Java + LevelDB
- Collaboration: intentionally demonstrates event sourcing + CQRS with two stores (LevelDB event journal, MySQL read model)
- IdentityAccess: uses Hibernate ORM, exposes RESTful resources, publishes domain events via RabbitMQ and REST logs
- Common: a library of domain-driven abstractions (entities, event sourcing, notification, messaging adapters)

A. Bounded Contexts (as separate “microservice” components)
1. AgilePM Context
– Application Layer
– Domain Layer (AgilePM aggregates)
– Persistence Adapter: LevelDB
– Messaging Adapters: RabbitMQ / SlothMQ listeners for inbound domain events
2. Collaboration Context
– Application Layer (Calendar, Forum services)
– Domain Layer (Event-sourced aggregates)
– Event Store Adapter: LevelDB journal
– CQRS Read-Model Adapter: MySQL
– Messaging Adapter: RabbitMQ event dispatcher
3. IdentityAccess Context
– REST Resources (JAX-RS controllers)
– Application Layer (Identity & Access services)
– Domain Layer (User, Tenant, Group aggregates)
– Persistence Adapter: Hibernate (MySQL)
– Notification Adapter: RabbitMQ + REST logging
B. Shared Common Module
– Domain-driven building blocks: Entity, ValueObject, DomainEventPublisher, EventStore interface, Messaging abstractions
C. External Services / Infrastructure
– LevelDB (embedded Java implementation)
– MySQL (read model for collaboration, identityaccess schema)
– RabbitMQ (message bus for events & notifications)
– SlothMQ (alternate lightweight message bus)
– Docker‐based container orchestration (MySQL + RabbitMQ)

##### Relationships & interactions
- ApplicationService → Domain aggregates → Repository → Persistence Adapter
- Domain publishes DomainEvents → DomainEventPublisher → Messaging or EventStore
- Collaboration: events appended to LevelDB → dispatched to MySQL projections → consumed by QueryServices
- IdentityAccess: commands via REST → ApplicationService → Domain → Hibernate → DomainEvents → RabbitMQ → other contexts
- AgilePM: inbound domain events (e.g., BacklogItemCommitted) arrive via RabbitMQ/SlothMQ → ApplicationService → Domain → LevelDB

##### Architectural patterns & design principles
- Layered architecture (Application → Domain → Port/Adapters)
- Hexagonal (Ports & Adapters)
- Event Sourcing (collaboration)
- CQRS (collaboration: separate read/write models)
- Domain-Driven Design: aggregates, bounded contexts, domain events
- Shared kernel pattern (iddd_common library across contexts)

##### Technologies & frameworks
- Java 7, Gradle
- LevelDB (pure Java)
- MySQL (JDBC + Hibernate)
- RabbitMQ, SlothMQ
- Spring XML contexts for wiring adapters (in collaboration & identityaccess)
- RESTful resources (JAX-RS or Spring MVC style in identityaccess)

##### Detail without over‐complication
- Four modules and their dependencies
- Dual storage strategy in collaboration (LevelDB vs MySQL)
- How identityaccess bridges domain events to external notifications
- Don’t try to show every class—focus on layers, adapters, stores, and messaging endpoints

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% AgilePM Context
    subgraph "AgilePM Context" 
        direction TB
        APM_App["Application Layer"]:::app
        APM_Domain["Domain Layer"]:::domain
        APM_Persist["LevelDB Persistence Adapter"]:::adapter
        APM_RMQ["RabbitMQ Messaging Adapter"]:::adapter
        APM_SMQ["SlothMQ Messaging Adapter"]:::adapter
    end

    %% Collaboration Context
    subgraph "Collaboration Context"
        direction TB
        COL_App["Application Layer"]:::app
        COL_Domain["Domain Layer"]:::domain
        COL_ES["LevelDB Event Store Adapter"]:::adapter
        COL_CQRS["MySQL Read-Model Adapter"]:::adapter
        COL_Msg["RabbitMQ Messaging Adapter"]:::adapter
    end

    %% IdentityAccess Context
    subgraph "IdentityAccess Context"
        direction TB
        IA_REST["REST Resources"]:::adapter
        IA_App["Application Layer"]:::app
        IA_Domain["Domain Layer"]:::domain
        IA_Hib["Hibernate → MySQL Adapter"]:::adapter
        IA_Notify["Notification Adapter"]:::adapter
    end

    %% Shared Common Module
    subgraph "Shared Common Module" 
        direction TB
        CM_DDD["DDD Building Blocks"]:::common
        CM_ES_IF["Event Sourcing Interfaces"]:::common
        CM_Msg["Messaging Abstractions"]:::common
        CM_Persist["Persistence Adapters"]:::common
    end

    %% External Infrastructure
    LevelDB["LevelDB"]:::external
    MySQL["MySQL"]:::external
    RabbitMQ["RabbitMQ"]:::external
    SlothMQ["SlothMQ"]:::external
    Docker["Docker Orchestration"]:::external

    %% Flows AgilePM
    APM_App -->|"uses"| APM_Domain
    APM_Domain -->|"repository"| APM_Persist
    APM_Domain -.->|"publish events"| APM_RMQ
    APM_Domain -.->|"publish events"| APM_SMQ
    APM_RMQ -->|inbound| APM_App
    APM_SMQ -->|inbound| APM_App
    APM_Persist -->|stores| LevelDB
    APM_RMQ -->|connects to| RabbitMQ
    APM_SMQ -->|connects to| SlothMQ

    %% Flows Collaboration
    COL_App -->|"uses"| COL_Domain
    COL_Domain -->|"append events"| COL_ES
    COL_Domain -.->|"publish events"| COL_Msg
    COL_ES -->|stores| LevelDB
    COL_Msg -->|dispatch events| COL_CQRS
    COL_CQRS -->|projections| MySQL
    COL_CQRS -->|queried by| COL_App
    COL_Msg -->|connects to| RabbitMQ

    %% Flows IdentityAccess
    IA_REST -->|"commands"| IA_App
    IA_App -->|"uses"| IA_Domain
    IA_Domain -->|"repository"| IA_Hib
    IA_Domain -.->|"publish events"| IA_Notify
    IA_Hib -->|stores| MySQL
    IA_Notify -->|connects to| RabbitMQ
    IA_Notify -->|REST logging| Docker

    %% Shared Common dependencies
    CM_DDD -.-> APM_Domain
    CM_DDD -.-> COL_Domain
    CM_DDD -.-> IA_Domain
    CM_ES_IF -.-> COL_ES
    CM_Msg -.-> APM_RMQ
    CM_Msg -.-> COL_Msg
    CM_Msg -.-> IA_Notify
    CM_Persist -.-> APM_Persist
    CM_Persist -.-> IA_Hib

    %% Infrastructure orchestration
    Docker -->|starts| MySQL
    Docker -->|starts| RabbitMQ

    %% Click Events AgilePM
    click APM_App "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_agilepm/src/main/java/com/saasovation/agilepm/application"
    click APM_Domain "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_agilepm/src/main/java/com/saasovation/agilepm/domain/model"
    click APM_Persist "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_agilepm/src/main/java/com/saasovation/agilepm/port/adapter/persistence"
    click APM_RMQ "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_agilepm/src/main/java/com/saasovation/agilepm/port/adapter/messaging/rabbitmq"
    click APM_SMQ "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_agilepm/src/main/java/com/saasovation/agilepm/port/adapter/messaging/sloth"

    %% Click Events Collaboration
    click COL_App "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/collaboration/application"
    click COL_Domain "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/collaboration/domain/model"
    click COL_ES "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/collaboration/port/adapter/persistence/repository"
    click COL_CQRS "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/collaboration/port/adapter/persistence/view"
    click COL_Msg "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/collaboration/port/adapter/messaging"

    %% Click Events IdentityAccess
    click IA_REST "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/resource"
    click IA_App "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/application"
    click IA_Domain "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/domain/model"
    click IA_Hib "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/infrastructure/persistence"
    click IA_Notify "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/application/NotificationApplicationService"

    %% Click Events Common & Build
    click CM_DDD "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_common/src/main/java/com/saasovation/common/domain/model"
    click CM_ES_IF "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_common/src/main/java/com/saasovation/common/event/sourcing"
    click CM_Msg "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_common/src/main/java/com/saasovation/common/port/adapter/messaging"
    click CM_Persist "https://github.com/vaughnvernon/iddd_samples/tree/master/iddd_common/src/main/java/com/saasovation/common/port/adapter/persistence"
    click Docker "https://github.com/vaughnvernon/iddd_samples/blob/master/build.gradle"

    %% Styles
    classDef app fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef domain fill:#d4edda,stroke:#333,stroke-width:1px
    classDef adapter fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef common fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef external fill:#ffeeba,stroke:#333,stroke-width:1px
```
