Skip to main content

Domain: accounts

Curated entry point for the accounts bounded context.

Owner

Founder + agents (Phase 1).

Mission

Owns the trader-account lifecycle: provisioning evaluation accounts and instant-funded accounts; the account state machine (eval -> funded -> live); per-account configuration including the rules profile applied; the cash-and-equity ledger; and end-of-day balance computation. Boundary: accounts owns the account record itself and its lifecycle; rule evaluation lives in risk-engine; money in / money out lives in billing (in) and payouts (out).

Code paths

  • Application code: apps/api/src/modules/accounts/
  • Domain logic (pure): packages/domain/account-state/
  • Contracts: packages/contracts/api/accounts.ts, packages/contracts/events/accounts.ts
  • Database schemas owned: accounts (Account, AccountConfig, AccountLedger, EodSnapshot, AccountStateTransition)

PRD chapters that touch this domain

TDD chapters

(Empty - will populate as TDDs arrive.)

ADRs that affected this domain

Service interfaces this domain exposes

export interface AccountsService {
// provisionAccount(userId, productId, paymentRef): Promise<Account>
// getAccount(accountId: string): Promise<Account>
// getAccountsByUser(userId: string): Promise<Account[]>
// applyStateTransition(accountId, transition: StateTransition): Promise<Account>
// getEodSnapshot(accountId, date): Promise<EodSnapshot>
// recordLedgerEntry(args): Promise<LedgerEntry>
// (full surface defined during accounts TDD)
}

Events this domain produces / consumes

DirectionTopicTriggered by
producesaccounts.account.createdNew account provisioned
producesaccounts.account.state_changedState machine transition (e.g., eval -> funded)
producesaccounts.account.eod_snapshot_takenDaily EOD snapshot computed
producesaccounts.ledger.entry_recordedCash or equity ledger entry
consumesbilling.payment.completedTriggers account provisioning
consumesrisk.evaluation.breach_detectedTriggers state transition to breached
consumespayouts.payout.completedTriggers ledger debit

External integrations

  • None directly; account state is internal.

Runbooks for this domain

(Empty - will populate when alerts are defined in Section 17.6.)

On-call

To be filled in Section 17.6.

Cross-domain dependencies

  • This domain calls: identity (actor lookup).
  • This domain emits events consumed by: risk-engine (rule profile per account), audit (every state change), notifications (state-transition emails), admin (account dashboards), payouts (eligibility check).