Domain driven design for Splitwise

24 views Asked by At

I am Trying to do DDD for splitwise. Use cases are

  1. ability to add, remove, edit transaction with
  2. we should be able to create a group as well as one-one expenditures.
  3. We should be able to show simplified balance so that number of money exchanges are minimised.

Here is what i have come so farenter image description here User: Individual User

TransactionGroup: Group against which transaction can be added (1-1 transactions are also modelled as group with only 2 participants.)

GroupMemebers: Mapping of users in a group.

Transaction: Record of expenditure. example 1: User1 paid 200 split equally among User1, User2. example 2: User1 paid 100, User2 paid 200 split in 40:60. While adding a transaction I will create ledger entries as well.

Ledger: Every transaction is broken into multiple ledger entries telling the effective money lending has happened in a transaction. This table is mainly to calculate Group Account balance. instead of iterating through all the Transactions, I can just use sql queries on ledger table.

But I am unsure of how to model simplified view.

Option A: First add transaction, ledger entries then calculate simplified view using ledger entries? This will make simplified view eventually consistent.

Option B: Get existing ledger entries merge it with new transaction and update TransactionGroup, Transaction, Ledger by a lock on TransactionGroup.

Are there other ways to model this?

0

There are 0 answers