# Accounting Portal + QuickBooks Synchronization Architecture

## Purpose
This architecture track defines an operator-friendly Accounting Portal inside Dispatch Spot for the accounting data Dispatch Spot already understands, while QuickBooks remains the broader accounting system of record.

## Core product goal
Dispatch Spot should help new operators clearly manage the money side of dispatch work without forcing them to become bookkeepers, while keeping key accounting events in sync with QuickBooks.

## Scope
- workspace accounting mode
- operational accounting portal
- customer, invoice, payment, payable, dispatch-fee, and expense-linked sync events
- QuickBooks connection and mapping layer
- sync center
- conflict and retry handling

## Workspace accounting modes

### 1. Dispatch company mode
Focus on:
- dispatch fees
- service revenue
- customer balances
- collections follow-up
- fee payment status

### 2. Transportation company mode
Focus on:
- freight revenue
- load-level margin
- carrier pay
- owner-operator pay
- trip-linked expenses
- truck profitability

## Portal sections

### Money overview
- revenue
- paid vs unpaid
- direct operating expenses
- dispatch fees
- net operating margin
- aging pressure

### Receivables
- customer invoices
- invoice status
- collections follow-up
- paid date and receipt history

### Payables
- carrier pay
- owner-operator pay
- dispatch-fee payouts
- expense reimbursements tied to loads

### Profitability
- by load
- by truck
- by driver
- by owner-operator
- by broker/customer
- by week/month

### Sync center
- QuickBooks connection status
- last sync time
- pending sync jobs
- failed sync jobs
- record mapping visibility
- retry / review actions

## Recommended architecture layers

### 1. Accounting domain model
- accounting profile
- customer
- vendor/payee
- invoice
- invoice payment
- payable
- dispatch fee
- expense link
- sync job
- sync error
- external mapping

### 2. QuickBooks integration layer
- QuickBooks company connection
- OAuth / auth posture
- company selection
- customer/vendor mapping
- invoice export/update
- payment export/update
- payable/dispatch-fee sync
- sync logs and retries

### 3. Mapping layer
- Dispatch Spot customer ↔ QuickBooks customer id
- Dispatch Spot vendor/payee ↔ QuickBooks vendor id
- Dispatch Spot invoice ↔ QuickBooks invoice id
- Dispatch Spot payment ↔ QuickBooks payment id
- Dispatch Spot payable/fee ↔ QuickBooks bill/expense id

### 4. Sync policy layer
Use event-driven sync rules for:
- new customer created
- invoice created
- invoice marked paid
- dispatch fee marked paid
- payable created or paid
- sync retry after failure

## Recommended sync rules
- create or map customer when needed
- create invoice from load-linked billing event
- sync payment when invoice is marked paid
- sync dispatch-fee and payable events based on workspace accounting mode
- never silently overwrite conflicts
- surface sync review items when QuickBooks and Dispatch Spot disagree

## Design rules
- Dispatch Spot should not try to replace full bookkeeping
- QuickBooks remains the wider accounting system of record
- Dispatch Spot should stay focused on operations-linked accounting visibility
- accounting UI must use simple language and visual clarity for new operators
- sync failures must be visible and recoverable

## Future build sequence
1. accounting portal architecture and accounting domain model
2. workspace accounting mode
3. QuickBooks connection and mapping architecture
4. customer and invoice sync
5. payment sync when invoices are marked paid
6. payable / dispatch-fee sync
7. sync center and conflict review
8. expanded profitability and accounting dashboards
