Account Type Architecture#
Sure models financial accounts using Rails' delegated_type pattern. The Account record is the single shared table for all accounts; it delegates to one of 9 accountable types, each backed by its own model and database table .
The canonical list of types is defined in the Accountable concern:
Depository | Investment | Crypto | Property | Vehicle | OtherAsset
CreditCard | Loan | OtherLiability
Classification: Assets vs. Liabilities#
Account carries a classification enum (asset / liability) , with corresponding assets and liabilities scopes . The value is determined by each accountable model's classification class method — a required contract enforced by the Accountable concern.
| Classification | Types |
|---|---|
| Asset | Depository, Investment, Crypto, Property, Vehicle, OtherAsset |
| Liability | CreditCard, Loan, OtherLiability |
The favorable_direction helper derives from classification: assets trend "up", liabilities trend "down".
The Accountable Concern#
app/models/concerns/accountable.rb is the shared interface all 9 types must implement:
- Required class methods:
classification,icon,color SUBTYPESconstant: defaults to{}; overridden per type to declare valid subtypes withshort/longdisplay labelssubtype_label_for(subtype, format:): resolves a subtype key to its display label via I18n, falling back to theSUBTYPEShashbalance_money(family): sums all active accounts of a given type, converting foreign currencies usingExchangeRate
The Account model delegates subtype to the accountable , with special handling for the case where subtype is assigned before the accountable record is built .
Accountable Types and Their Subtypes#
Depository — Asset#
app/models/depository.rb: Subtypes: checking (default), savings, hsa, cd, money_market .
CD/FD as term deposits: cd (Certificate of Deposit) is a Depository subtype. The Indian equivalent, FD (Fixed Deposit), is an Investment subtype (fd) with region: "in" — both model term deposits but are routed to different primary types based on how Plaid categorizes them.
HSA receives tax_treatment: :tax_advantaged via TAX_ADVANTAGED_SUBTYPES without touching the shared TaxTreatable concern.
Investment — Asset#
app/models/investment.rb: The most subtypes of any accountable — 50+ entries organized by region :
| Region | Example subtypes |
|---|---|
| US | brokerage, 401k, roth_ira, 529_plan, hsa |
| UK | isa, lisa, sipp, workplace_pension_uk |
| Canada | tfsa, rrsp, fhsa, resp |
| Australia | super, smsf |
| Europe | assurance_vie, pea, pillar_3a, riester |
| India | nps, ppf, fd, rd, sgb, and more |
| Generic | pension, retirement, mutual_fund, gold, other |
Each subtype carries a tax_treatment value (:taxable, :tax_deferred, :tax_exempt, :tax_advantaged) . The subtypes_grouped_for_select helper uses the family's currency to surface the user's likely region first.
Loan — Liability#
app/models/loan.rb: Subtypes: mortgage, student, auto, home_equity, line_of_credit, business, other . Also calculates monthly_payment from term_months and interest_rate for fixed-rate loans .
Crypto — Asset#
app/models/crypto.rb: Subtypes: wallet and exchange .
Property — Asset#
app/models/property.rb: Subtypes include single_family_home, multi_family_home, condominium, townhouse, investment_property, second_home, apartment, plot, commercial, agri_land .
CreditCard — Liability#
app/models/credit_card.rb: Single subtype: credit_card .
Vehicle, OtherAsset, OtherLiability#
Vehicle (asset), OtherAsset (asset), OtherLiability (liability) — no SUBTYPES defined; they use the default empty hash from the Accountable concern .
Key Source Files#
| File | Purpose |
|---|---|
app/models/account.rb | Core Account model; delegated_type wiring |
app/models/concerns/accountable.rb | Shared interface + TYPES registry |
app/models/depository.rb | Cash/savings/CD/HSA subtypes |
app/models/investment.rb | Multi-region investment subtypes with tax treatment |
app/models/loan.rb | Loan subtypes + payment calculations |
app/controllers/concerns/accountable_resource.rb | Shared CRUD controller concern for all account types |