Skip to main content
Account represents a bank or financial account (deposit, credit, loan, investment, payroll, or other) held by a workspace, company, or individual. It is the primary model the connector layer (Plaid, Qonto, etc.) writes synced bank accounts into, and it is also used to record counterparty accounts extracted from invoice payment means. Key associations are to Workspace (tenant scope), Company (account holder or the workspace’s own company), People (individual holder), a bank Company via bank_company, a source WorkspaceConnector tracking provenance, and one-to-many AccountWorkspaceConnectors for multi-connector sync audit. The ownership field distinguishes workspace-held accounts from counterparty accounts from unclassified legacy rows.

API operations

Data model

Attributes

Relationships

System-computed

  • account_id: generated via gen_random_uuid() on INSERT; unique constraint enforced at the database level.
  • created_at: set once on INSERT via MikroORM onCreate lifecycle hook; never supplied by callers.
  • updated_at: set on INSERT and refreshed on every UPDATE via MikroORM onCreate/onUpdate lifecycle hooks.
  • deleted_at: soft-delete sentinel. When set, the account is excluded from all standard queries. The partial index idx_accounts_workspace_external_id_active uses WHERE deleted_at IS NULL AND account_external_id IS NOT NULL for the Plaid-sync hot-path dedup lookup.
  • ownership default: defaults to ‘unknown’ at the database level for all new rows. Backfilled to ‘workspace’ by Migration20260527120000_account_ownership where source_workspace_connector_pk IS NOT NULL, or where a PaymentMeans row links the account to the workspace’s own company (payment_means.account_pk = accounts.pk AND payment_means.company_pk = workspace.own_company_pk).
  • account_external_id dedup: the partial unique index idx_accounts_workspace_external_id_active on (workspace_pk, account_external_id) WHERE deleted_at IS NULL AND account_external_id IS NOT NULL is the connector-layer dedup key. Plaid sync uses this to find an existing account before creating a new one, preventing re-linking on reconnect.
  • source_workspace_connector provenance: when source_workspace_connector_pk IS NOT NULL, the account was created by the connector pipeline and ownership should be ‘workspace’. A NULL source_workspace_connector_pk means the account was created via a fallback path (manual entry, invoice payment means extraction) and ownership defaults to ‘unknown’ pending classification.
  • bank_company recovery: when bank_company_pk IS NULL, the bank identity may be recoverable from raw_data (look for raw_data->>‘institution_name’ or raw_data->‘institution’->>‘name’) or inferred from the IBAN bank code prefix (FR IBANs: positions 5–9 = CIB) or BIC first 4 characters.
  • Composite composites.yml definitions: two composites are defined for the accounts root — composite_account_summary (source_fields: account_id, bank_company.primary_media.url, account_name, currency, iban, account_number; display_type: account_summary) and composite_latest_balance_currency (source_fields: account_id, account_balances.accounting_balance; display_type: currency_amount).

Example

Source: apps/api/src/database/entities/Account.ts · domain: financial-graph · tier: Main