All Projects → akhansari → EsBankAccount

akhansari / EsBankAccount

Licence: MIT License
Bank Account kata and Functional Event Sourcing in F#

Programming Languages

F#
602 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to EsBankAccount

Frp Eventsourcing
Functional Reactive Programming in Event Sourcing Systems
Stars: ✭ 117 (+85.71%)
Mutual labels:  event-sourcing, eventsourcing
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (+157.14%)
Mutual labels:  event-sourcing, eventsourcing
Pipedream
Connect APIs, remarkably fast. Free for developers.
Stars: ✭ 2,068 (+3182.54%)
Mutual labels:  event-sourcing, eventsourcing
Event Store Client
PHP 7.4 Event Store Client Implementation
Stars: ✭ 93 (+47.62%)
Mutual labels:  event-sourcing, eventsourcing
eventuous
Minimalistic Event Sourcing library for .NET
Stars: ✭ 236 (+274.6%)
Mutual labels:  event-sourcing, eventsourcing
Bifrost
This is the stable release of Dolittle till its out of alpha->beta stages
Stars: ✭ 111 (+76.19%)
Mutual labels:  event-sourcing, eventsourcing
Goes
Go Event Sourcing made easy
Stars: ✭ 144 (+128.57%)
Mutual labels:  event-sourcing, eventsourcing
Eventstore
The stream database optimised for event sourcing
Stars: ✭ 4,395 (+6876.19%)
Mutual labels:  event-sourcing, eventsourcing
tardis
Event sourcing toolkit
Stars: ✭ 35 (-44.44%)
Mutual labels:  event-sourcing, eventsourcing
Totem
Knowledge work at play
Stars: ✭ 56 (-11.11%)
Mutual labels:  event-sourcing, eventsourcing
Go Cqrs All
All-in-one collection for Go CQRS / ES / DDD examples
Stars: ✭ 39 (-38.1%)
Mutual labels:  event-sourcing, eventsourcing
micro
Functional prooph for microservices
Stars: ✭ 53 (-15.87%)
Mutual labels:  event-sourcing, eventsourcing
Eventhorizon
CQRS/ES toolkit for Go
Stars: ✭ 961 (+1425.4%)
Mutual labels:  event-sourcing, eventsourcing
Marten
.NET Transactional Document DB and Event Store on PostgreSQL
Stars: ✭ 1,654 (+2525.4%)
Mutual labels:  event-sourcing, eventsourcing
Eventsourcing
A library for event sourcing in Python.
Stars: ✭ 760 (+1106.35%)
Mutual labels:  event-sourcing, eventsourcing
Eventflow.example
DDD+CQRS+Event-sourcing examples using EventFlow following CQRS-ES architecture. It is configured with RabbitMQ, MongoDB(Snapshot store), PostgreSQL(Read store), EventStore(GES). It's targeted to .Net Core 2.2 and include docker compose file.
Stars: ✭ 131 (+107.94%)
Mutual labels:  event-sourcing, eventsourcing
Netcoremicroservicessample
Sample using micro services in .NET Core 3.1 Focusing on clean code
Stars: ✭ 403 (+539.68%)
Mutual labels:  event-sourcing, eventsourcing
workflow
Functional CQRS Eventsourcing Engine
Stars: ✭ 22 (-65.08%)
Mutual labels:  event-sourcing, eventsourcing
fmodel-ts
Functional Domain Modeling with Typescript
Stars: ✭ 41 (-34.92%)
Mutual labels:  event-sourcing, eventsourcing
delta
DDD-centric event-sourcing library for the JVM
Stars: ✭ 15 (-76.19%)
Mutual labels:  event-sourcing, eventsourcing

Bank account kata and Functional Event Sourcing

F# template/POC about Functional Event Sourcing, Onion Architecture and WebAssembly.

Wanna file an issue? a suggestion? Please feel free to create a new issue and / or a pull request.
Or start a new discussion for questions, ideas, etc.

Why?

F#

Empowers everyone to write succinct, robust and performant code.
It enables you to write backend (taking advantage of .Net ecosystem) as well as frontend (transpiled to JS or compiled to Wasm) applications.

Functional Event Sourcing

Fully embrace immutability and expressions, in addition to other more traditional ES perks.

Onion Architecture

Leads to more maintainable applications since it emphasizes separation of concerns throughout the system.
It's even quite natural with F#, i.e. compositions and higher-order functions.

WebAssembly

Facilitate the development of powerful UIs and back office apps with minimal effort.
Note that for the sake of simplicity in this demo, the view and the business logic have both been put in the same project in order to make this application "hostable" on GitHub.
When deployed to an actual real-world production environment, they are often located in separate projects with different lifecycles.

Setup

  • Install .Net SDK 6.0 (Linux / Windows / macOS)
  • To [B|T]DD: dotnet watch test --project EsBankAccount.sln
  • To watch: dotnet watch run --project EsBankAccount/EsBankAccount.fsproj

Editors: Vim / VSCode / VS Windows / VS macOS

Kata

You can simply clone the kata-start branch and start practicing.
Follow the instructions in BankAccountTests.fs and BankAccountTests.state.fs.

Decider

Deciders should have, at least, an initial state and two functions:

  • evolve: 'State -> 'Event -> 'State
    Given the current state and what happened, evolve to a new state.

    • From new events: fold evolve currentState newEvents
    • From the history: fold evolve initialState history
  • decide: 'Command -> 'State -> 'Outcome
    Given what has been requested and the current state, decide what should happen.

They are composable:

decider

Decider Tests

It's very convenient to create Given-When-Then tests.

[<Fact>]
let ``close the account and withdraw the remaining amount`` () =
    spec {
        Given // history
            [ Deposited { Amount = 100m; Date = DateTime.MinValue } ]
        When  // command
            ( Close DateTime.MinValue )
        // what should happen
        Then // assert scenario
            ( function Ok events -> Assert.NotEmpty events | _ -> () )
        Then // true or false scenario
            ( function Ok [ Withdrawn _; Closed _ ] -> true | _ -> false )
        Then // equality then structural diff scenario
            [ Withdrawn { Amount = 100m; Date = DateTime.MinValue }
              Closed DateTime.MinValue ]
    }

There are two kinds of them:

  1. Test what has been done (mandatory).
    • We don't mind how we come up with the outcome.
    • But, we do need to make sure that the outcome has to be correct under the given condition.
  2. Test how it has been done (optional).
    • We aren't too concerned about the outcome.
    • But, we need to build the state in a particular way.

It should be noted that the BDD DSL style brings more readability and neat helpers but it isn't mandatory.
In your test files you can have different kind of unit tests. For instance a test could be as simple as this.

Decider Structure

It's possible to organize the Decider into five sections:

  1. types
  2. state logic
  3. decision logic
  4. validation (optional)
  5. decision pipeline

Keep it in one file until it hurts and then decide the best split(s) at the last responsible moment.

Decision Outcome

There are usually, at least, two categories of Deciders:

  1. System -> 'Event list
    Silent, if nothing has happened, then it will return an empty list. No need for validation.
  2. Frontal -> Result<'Event list, 'Error>
    When validation is required. For instance called from an API.
    Could also be -> Validation<'Event list, 'Error list>.

Validations

We could have different types of validation in each layer:

  1. Domain: Enforce constraints on new events, business validation.
  2. Application: Anti-corruption, validate infrastructures data.
  3. Startup: Secure and validate data shape.

Onion Architecture

  • Inner layers "aren't aware" of outer layers.
  • Domain is pure (i.e. think functional programming 101).
  • App only has a reference to the domain.
  • Infra only has references to other infrastructures.
  • Startup has references to the App and the Infra. Infra are injected to the App.
  • We usually start to code from the inside to the right (i.e. output), then again from the inside to the left (i.e. input).

onion architecture

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].