Skip to content

V2: Data Model, in memory

Anatoliy Yastreb edited this page Jan 6, 2019 · 2 revisions

An in-memory (app state) data model of MoneyTracker V2.

Data Model

Session

Session model holds data related to current device session, such as CouchDB credentials if user is signed in, type of session (Demo/Live) etc.

Settings

General app settings are stored in Settings model and synchronized across devices.

Symbol

Symbol is a general model for Currency (USD, EUR, JPY etc), Cryptocurrency (BTC, ETH etc) or Stock (AAPL, MSFT, VOO etc). Symbol's exponent determines its smallest unit (e.g. 2 for USD cents, 0 for JPY since Japanese yen is already the smallest unit). All monetary values are stored in smallest units (e.g. in cents) as whole integers to avoid floating point rounding error. The value is converted to human readable format for UI display only, all arithmetic operations are performed with smallest units.

Transaction

Transaction records are stored in Transaction model. Transaction kind is represented by enum (Expense = 1, Transfer = 2, Income = 4). Transfer transactions have additional fields for linkedAccountId, linkedAmount and linkedSymbol representing transfer target values. E.g. transfer of 100.00 USD from account A001 to 10,800 JPY on account A002 would look like this:

{
   'kind': 2,                 // 2 is Transfer
   'accountId': 'A001',       // "From" account
   'symbol': 'USD',           // "From" symbol
   'amount': 10000,           // Amount in cents
   'linkedAccountId': 'A002', // "To" account
   'linkedSymbol': 'JPY'      // "To" symbol
   'linkedAmount': 10800,     // Japanese yen does not have cents
}

Category

Categories are divided by Expense and Income type. Each expense transaction must have one Expense category and each income transaction must have one Income transaction.

User can change category name, visibility, icon, label color and rearrange categories order relative to each other.

Account & AccountGroup

By default 5 account groups are provided (Cash, Bank Account, Deposit, Credit and Asset), but users can edit and add new ones, as well as rearrange groups order. Group order is used for display of accounts list on Dashboard and drop-down selectors.

User's accounts are stored in Account model. Each account has base symbol, which will be used as default symbol for transactions on that account and for displaying account total value, if account contains multiple symbols. Current account balance is stored in balance map. User can change account's visible symbols stored in symbols list. Accounts order can be rearranged within its group.

Clone this wiki locally