/ddd-structure-demo

A project shows standard structure of Domain Driven Design project with Spring Boot

Primary LanguageJava

Template DDD project structure

A project shows standard structure of Domain Driven Design project with Spring Boot.

Why DDD?

  • Business processes is a complex subject
  • Software development is complicated
  • Goal of DDD is to manage complexity

Domain Driven Design Architecture

Domain Driven Design

Domain Driven Design Layers - Onion Architecture

DDD Layers

Onion Architecture

Hexagonal (Ports & Adapters) Architecture with DDD

Hexagonal Architecture with DDD

Hexagon with Application and Infrastructure

Please consider to adopt Hexagonal Architecture for DDD application layer, example packages as following:

  • web package: Web application with templates
  • rest package: HTTP REST API
  • graphql package: GraphQL API
  • grpc package: gRPC API
  • rsocket package: RSocket API
  • facade package: Facade API for other domains
  • common package: Common API for other ports

Clean Architecture

Clean Architecture

CQRS(Command Query Responsibility Separation) Pattern - Write and Read Separation

CQRS Pattern

Please consider to adopt CQRS Pattern for DDD Repository design.

Database Scaling Patterns:

  • Scaling for reads: read replication
  • Scaling for writes: sharding

Use cases:

  • CMS: Content Management System
  • E-Commerce: Item detail

Specification Design Pattern

Specification design pattern allows us to check whether our objects meet certain requirements. Through this design pattern, we can reuse expression specifications and combine those specifications to easily question whether more complex requirements are satisfied or not.

Specification design pattern is very important for DDD to validate domain objects and some business rules.

Reactive DDD - communication between bounded contexts

Reactive DDD

  • Async vs Sync
  • Message Driven & Back Pressure
  • Reactive(RSocket) protocols: Request/Response, Request/Stream, Fire & Forget, Channel
  • Reactive Stream Frameworks: Reactor(Mono,Flux), RxJava, Akka Streams, Smallrye Mutiny, Kotlin Flow
  • RSocket prefer

DDD with CQRS, Hexagonal Architecture, Reactive

  • DDD Repository: CQRS
  • DDD Application and Infrastructure Layers: Hexagonal Architecture
  • DDD Event/Communication: Reactive
  • DDD Factory: Design Pattern

Features

  • Project directory/package structure
  • Validation with specification
  • Exception with error package: Spring 6 ProblemDetail integration
  • Annotations with jMolecules
  • DDD application layer with Hexagonal architecture
  • Event firing/listener with Spring Events - ApplicationEventPublisher, @EventListener and ApplicationListener.
  • ArchUnit integrated
  • Specification Design Pattern

Requirements

  • Java 17
  • Apache Maven 3.5+

Tips

References