Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

j5ik2o/akka-ddd-cqrs-es-example

Repository files navigation

Bank API CQRS Event Sourcing System on Akka-Cluster (Concept Model)

!!!Notice!!!: This project is now considered outdated as it is based on the old Akka (untyped) API. For a more up-to-date example using the new Akka Typed API, please refer to j5ik2o/akka-cqrs-es-example-typed. We strongly recommend checking out the updated version for a better understanding and implementation of the CQRS/ES pattern.

Features

  • DDD, CQRS + Event Sourcing based design
  • Implement using Akka(-actor, -stream, -cluster-sharding, -persistence, -persistence-query, -http, ...)
  • Scala 2.12.4
  • REST API Application

Target domain

  • Bank Account to deposit/withdraw

Target Use cases

  • Deposit money to a Bank Account
  • Withdraw money from a Bank Account
  • Refer to deposits and withdraws in a Bank Account

Layered structure

In this project, the layered structure is based on 'Clean Architecture'.

Domain layer

  • Domain objects are represented by case class.
  • Domain types
    • BankAccountId
    • BankAccount
    • BankAccountEventId
    • BankAccountEvent
      • BankAccountOpened is the account opening event
      • BankAccountUpdateared is the account information updating event
      • BankAccountDeposited is the deposit event
      • BankAccountWithdrawn is the withdarw event
      • BankAccountClosed is the account closed event

Use case layer

Interface layer

Aggregate

Controller

Persistence

The DAOs and Records are generated by septeni-original/sbt-dao-generator

How to run unit tests

$ sbt clean test

How to run E2E tests

Terminal #1

$ sbt -DPORT=2551 -DHTTP_PORT=8080 'localMysql/run' 'api-server/run'

Terminal #2

$ sbt -DPORT=2552 -DHTTP_PORT=8081 'api-server/run'

Terminal #3

$ sbt -DPORT=2553 -DHTTP_PORT=8082 'api-server/run'

Terminal #4

$ sbt 'read-model-updater/run'

How to test

# open a bank account
$ curl -X POST \
  http://localhost:$PORT/bank-accounts \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{ "name": "test-1" }'
{"id":"XEe","errorMessage":null}%

# update the bank account
$ curl -X PUT \
  http://localhost:8080/bank-accounts/XEe \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
  "name": "test-2"
}'
{"id":"XEe","errorMessage":null}%

# deposit to the bank account
$ curl -X PUT \
  http://localhost:8080/bank-accounts/XEe/events \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"type": "deposit",
	"amount": 1000,
	"currencyCode": "JPY"
}'
{"id":"XEe","errorMessage":null}%

# withdraw from the bank account
$ curl -X PUT \
  http://localhost:8080/bank-accounts/XEe/events \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"type": "withdraw",
	"amount": 500,
	"currencyCode": "JPY"
}'
{"id":"XEe","errorMessage":null}%

# refer to events(deposits or withdraws) in the bank account
$ curl -X GET \
  http://localhost:8080/bank-accounts/XEe \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json'
{
    "id": "XEe",
    "values": [
        {
            "type": "deposit",
            "amount": 1000,
            "currencyCode": "JPY",
            "createAt": 1520219459
        }
    ],
    "errorMessage": null
}

# close the bank account
$ curl -X DELETE \
  http://localhost:8080/bank-accounts/XEe \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json'
{
    "id": "XEe",
    "errorMessage": null
}
{"id":"XEe","errorMessage":null}%

About

Bank API CQRS Event Sourcing System on Akka-Cluster (Concept Model)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published