This is the DDD reactive implementation of bank account example. The purpose of this demo is to demonstrate how to deal with data consistency in the reactive implementation using DDD (domain driven design) principles.
- DDD
- message driven architecture
- event sourcing
- CQRS
This demo is implemented using:
- Spring Boot
- Project Reactor (reactive streams implementation)
- Java 17
- Gradle for build management
- Jackson for JSON serialization
- Immutables for immutable domain objects
AccountTransaction
Those two aggregate roots representing two bounded contexts Account bounded context and Transaction bounded context.
account-domain-api module contains the definition of the contract provided by Account aggregate.
Here is the list of basic operations:
- create account
- deposit money
- withdraw money
The application exposes a RESTful HTTP API through the account-http-api module using Spring WebFlux.
Available endpoints include:
POST /accounts- Create a new accountGET /accounts/{id}- Get account by IDGET /accounts- Get all accountsPUT /accounts/moneys/deposit- Deposit money to accountPUT /accounts/moneys/withdraw- Withdraw money from account
An Insomnia HTTP collection (Insomnia_http_demo.json) is provided in the root directory for testing the API endpoints.
transaction-domain-api module contains the definition of the contract provided by Transaction aggregate
Here is the list of basic operations:
- create transaction
- cancel/rollback transaction
- finish transaction
- transfer money between two accounts
The implementation follows CQRS and event sourcing design pattern. Persistence API is provided by
common-persistence-api. This module provides in-memory storage for:
- events generated by particular aggregate
AggregateRepositoryImpl - storage for view model
ViewRepositoryImpl
Note: The persistence layer uses in-memory storage for demonstration purposes only. Data is not persisted between application restarts.
- Create two accounts
AandBwith a specific amount of money - Create a transaction for transferring a specific amount of money from account
Ato accountB - Transaction finishes: successfully or failed
- Transaction is closed and returns the result.
- Transaction is closed and returns the result.
- Transaction returns money to account
A - Transaction is closed and returns the result.
- If money was withdrawn from account
A, the money is returned to accountA - Transaction is closed and returns the cancellation result.