Git Product home page Git Product logo

akka-ddd-cqrs-es-example's Introduction

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

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}%

akka-ddd-cqrs-es-example's People

Contributors

j5ik2o avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.