Prompt
Need a normalized accounting data model across vendors
Latest observation
A good normalized accounting data model across vendors should separate:
- Source/vendor-specific raw data
- Canonical accounting entities
- Posting/journal mechanics
- Reference/master data
- Mapping and reconciliation metadata
Below is a practical vendor-agnostic model you can use for QuickBooks, Xero, NetSuite, SAP, Stripe, Bill.com, etc.
1. Core design principles
- Keep raw source records immutable
Store vendor payloads as-is for auditability. - Normalize into canonical tables
Convert each vendor’s objects into a shared schema. - Use stable internal IDs
Every entity should have an internal UUID plus source references. - Separate header vs lines
Most accounting documents have a parent/header and child/line structure. - Model accounting entries as double-entry journals
This is the most portable universal layer. - Allow multi-currency and multi-entity
Essential for real-world accounting. - Support many-to-many mappings
For accounts, tax codes, customers, vendors, products, etc.
2. Canonical entities
A. Organization / tenant
Represents the company or legal entity.
organization
organization_id(PK)namelegal_namebase_currencycountrytimezonestatuscreated_atupdated_at
B. Source system
Tracks which vendor the data came from.
source_system
source_system_id(PK)organization_id(FK)vendor_name(e.g. quickbooks, xero, netsuite)external_account_idauth_connection_idcreated_atupdated_at
C. Raw ingested records
Store original objects exactly as received.
raw_record
raw_record_id(PK)organization_id(FK)source_system_id(FK)entity_type(e.g. invoice, bill, journal_entry)external_idpayload_jsonpayload_hashingested_atsource_updated_atdeleted_atnullable
3. Master data
A. Account / chart of accounts
account
account_id(PK)organization_id(FK)account_type
Examples: asset, liability, equity, revenue, expense, cogsaccount_subtypeaccount_codenameparent_account_idnullableis_activeis_systemcurrency_codenullablecreated_atupdated_at
account_mapping
account_mapping_id(PK)organization_idsource_system_idexternal_account_idaccount_id(FK)confidence_scoremapping_statuscreated_at
B. Counterparties
Customers, vendors, employees, contractors.
party
party_id(PK)organization_idparty_type
customer | vendor | employee | contractor | otherlegal_namedisplay_nametax_idemailphonestatuscreated_atupdated_at
party_mapping
party_mapping_idorganization_idsource_system_idexternal_party_idparty_idsource_party_typeconfidence_score
C. Products / services
item
item_id(PK)organization_iditem_type
inventory | service | non_inventory | expense | otherskunamedescriptionincome_account_idnullableexpense_account_idnullableasset_account_idnullableis_activecreated_atupdated_at
4. Accounting transactions
A. Universal document header
A common header for financial documents.
document
document_id(PK)organization_iddocument_type
invoice | bill | credit_note | vendor_credit | payment | receipt | journal_entry | deposit | transfer | estimate | purchase_orderdocument_numberstatus
draft | open | paid | void | posted | partialissue_datedue_dateposting_datecurrency_codeexchange_rateparty_idnullablereference_numbermemosource_system_idexternal_idcreated_atupdated_atvoided_atnullable
B. Universal document lines
document_line
document_line_id(PK)document_id(FK)line_numberline_type
item | account | tax | discount | shipping | fee | adjustment | descriptiondescriptionitem_idnullableaccount_idnullablequantitynullableunit_pricenullableamounttax_code_idnullabledepartment_idnullableclass_idnullablelocation_idnullableproject_idnullablecustomer_idnullablevendor_idnullablecreated_at
C. Payments / settlements
You can model payments as documents or separate payment entities. For portability, documents work well.
If separate:
payment
payment_id(PK)organization_idpayment_datepayment_methodcurrency_codeamountparty_idapplied_document_idnullablesource_system_idexternal_idstatuscreated_at
5. General ledger layer
This is the most important normalized layer.
A. Journal entry
journal_entry
journal_entry_id(PK)organization_identry_numberentry_dateposting_datesource_document_idnullablesource_system_idexternal_idmemostatus
draft | posted | reversed | voidcreated_atupdated_at
B. Journal lines
journal_line
journal_line_id(PK)journal_entry_id(FK)line_numberaccount_id(FK)party_idnullabledebit_amountcredit_amountcurrency_codeexchange_rateamount_base_currencydescriptiontax_code_idnullabledepartment_idnullableclass_idnullablelocation_idnullableproject_idnullabledocument_line_idnullablecreated_at
Notes
- Every journal entry should balance: sum(debit) = sum(credit)
- Store both transaction currency and base currency values
- Keep links back to source docs and source lines
6. Tax and dimensions
A. Tax codes
tax_code
tax_code_id(PK)organization_idnamecodetax_typerateis_activecreated_at
B. Tax lines
tax_line
tax_line_iddocument_iddocument_line_idnullabletax_code_idtaxable_amounttax_amountjurisdictioncreated_at
C. Analytical dimensions
Many vendors call these classes, departments, locations, segments, tracking categories, classes, tags.
dimension_type
dimension_type_idorganization_idname
department | class | location | customer | project | segment | tagis_active
dimension_value
dimension_value_idorganization_iddimension_type_idnamecodeparent_dimension_value_idnullableis_active
document_line_dimension
document_line_dimension_iddocument_line_iddimension_type_iddimension_value_id
journal_line_dimension
journal_line_dimension_idjournal_line_iddimension_type_iddimension_value_id
7. Reconciliation and mapping metadata
A. Entity mapping table
Use one generic mapping table instead of many if preferred.
entity_mapping
entity_mapping_idorganization_idsource_system_identity_typeexternal_idinternal_entity_typeinternal_idmapping_statusconfidence_scorematched_bycreated_atupdated_at
This can replace account_mapping, party_mapping, etc., if you want a single extensible table.
B. Sync tracking
sync_run
sync_run_idorganization_idsource_system_idstarted_atfinished_atstatusrecords_readrecords_writtenrecords_failederror_summary
sync_error
sync_error_idsync_run_identity_typeexternal_iderror_codeerror_messageraw_payload_jsoncreated_at
8. Common vendor variations and how to normalize them
QuickBooks
Invoice,Bill,JournalEntry,Payment,Deposit- Uses
Linearrays and references toAccountRef,CustomerRef,VendorRef
Xero
Invoice,Bill,CreditNote,Payment,ManualJournal- Uses
LineItems,AccountCode,Contact
NetSuite
- Has more complex transactions and segmentations
- Often requires more robust handling of subsidiaries, classes, departments, locations
- Keep parent-child relationships and dimension tables flexible
Stripe / payment processors
- Transactions are not always accounting documents
- Normalize into
payment,fee,refund,payout, then journalize - Often need settlement batches and fees split out separately
9. Recommended minimum viable schema
If you want the smallest useful normalized model, start with:
organizationsource_systemraw_recordaccountpartyitemdocumentdocument_linejournal_entryjournal_lineentity_mappingsync_runsync_error
That will cover most use cases.
10. Example normalized flow
Example: Vendor bill from Xero
- Ingest raw bill JSON into
raw_record - Map
Contacttoparty - Map
AccountCodetoaccount - Create
documentwith type = bill - Create
document_linerows for each line item - Generate
journal_entry - Create balanced
journal_linerows:- Dr Expense
- Dr Tax receivable if applicable
- Cr Accounts Payable
11. Important implementation details
- Use UUIDs for internal keys
- Keep external IDs and source system IDs
- Use soft deletes for accounting records where source systems support voiding/deletion
- Store effective dates and posting dates separately
- Support versioning if upstream objects can change
- Do not overwrite raw records
- Preserve line ordering with
line_number - Add audit columns:
created_atupdated_atcreated_byupdated_by
12. Best-practice ERD summary
Core relationships
- Organization 1—N SourceSystem
- Organization 1—N Accounts / Parties / Items / Documents / JournalEntries
- Document 1—N DocumentLines
- JournalEntry 1—N JournalLines
- SourceSystem N—N InternalEntity via EntityMapping
- DocumentLine N—N Dimensions
- JournalLine N—N Dimensions
If you want, I can also provide:
- a PostgreSQL DDL schema
- an ERD diagram in Mermaid
- a dbt-style dimensional model
- a canonical JSON schema for API ingestion