Skip to main content

Data Flows

Three critical data flows power HostMetrics.

1. CSV Import Flow

Data enters the system via CSV file upload or Chrome extension sync. Key details:
  • Trip records are deduplicated by (user_id, reservation_id)
  • Earnings records are deduplicated by (user_id, composite_key)
  • Previous imports of the same type are marked “superseded”
  • Vehicle records are auto-created from trip data if they don’t exist

2. KPI Calculation Pipeline

Dashboard metrics are computed from raw data using pure functions. Key files:
  • src/lib/kpi/queries.ts — Parallel data fetching
  • src/lib/kpi/calculations.ts — Pure calculation functions (869 lines)
  • src/hooks/useKPIs.ts — React hook wrapper

3. Investor Payment Flow

Revenue sharing between host and investor. Key files:
  • src/lib/calculations/investorEarnings.ts — Three-pool expense model
  • src/lib/calculations/vehicleRevenue.ts — Revenue adjustment with inclusion toggles
  • src/lib/db/investors.ts — Payment CRUD + calculations