No-Code Data Contract — Dashboard API Endpoints
Summary (3–6 bullets)
- Defines read-only dashboard API contracts for no-code consumers.
- Documents endpoint schemas, field meanings, and source tables/views.
- Establishes rounding and precision expectations for money, percentages, and counts.
- Enforces a strict no-recomputation rule for commission/business logic outside Repo B.
- Captures planned visibility improvements (dataset routing + schema introspection).
When to use this (3–6 bullets)
- When wiring no-code tools to dashboard endpoints.
- When validating endpoint payload shape and data types.
- When reviewing whether a requested derived field is allowed or prohibited.
- When troubleshooting mismatches between frontend displays and backend data contracts.
What you’ll walk away with (2–5 bullets)
- A clear list of approved read-only endpoints and expected response fields.
- A practical boundary between safe no-code usage and forbidden logic duplication.
- A quick checklist for data precision and source-of-truth expectations.
Status: Planning Document (Read-Only Only)
Purpose
This document defines the data contract for no-code tools consuming dashboard API endpoints. All endpoints are read-only. No-code tools must NOT recompute commission math or create calculated fields that duplicate Repo B logic.1. Endpoint Schemas
/api/v1/ceo-metrics
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01format (e.g.,2025-07-01)
total_businesses: Integer count of distinct businessestotal_employees: Integer count of distinct employeesgross_payout: Financial amount (rounded to cents)chargebacks: Financial amount (rounded to cents)net_payout: Financial amount (rounded to cents)business_owner_commission: Financial amount (rounded to cents)total_policies: Integer count (same as total_employees)total_lives: Integer count (same as total_employees)
analytics.ceo_snapshot view
/api/v1/top-businesses
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01formatlimit(optional): Integer, default 10
business_name: String, normalized business nametotal_revenue: Financial amount (rounded to cents)employee_count: Integer countrank: Integer ranking (1-based)
analytics.top_businesses view
/api/v1/top-agents
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01formatlimit(optional): Integer, default 10
agent_name: String, agent nametotal_commission: Financial amount (rounded to cents)employee_count: Integer countbusiness_count: Integer countrank: Integer ranking (1-based)
analytics.top_agents view
/api/v1/growth-loss
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01format
gained_employees: Integer countlost_employees: Integer countnet_employee_change: Integer count (gained - lost)businesses_count: Integer count
analytics.business_growth_loss view
/api/v1/growth-loss-details
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01formatlimit(optional): Integer, default 10
business_name: String, normalized business namenet_employee_change: Integer count (can be negative)employee_change_pct: Float percentage (rounded to 2 decimal places)change_category: String enum (“Growth”, “Loss”, “Stable”)
analytics.business_growth_loss view
/api/v1/new-lost-businesses
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01format
new: Array of new businesses (present in current period, absent in previous)lost: Array of lost businesses (present in previous period, absent in current)summary.new_count: Integer countsummary.new_employees: Integer countsummary.lost_count: Integer countsummary.lost_employees: Integer count
raw.stage1_snapshots (FULL OUTER JOIN logic)
/api/v1/business-health
Method: GETQuery Parameters:
period_label(required): Date inYYYY-MM-01format
category: String enum (“Healthy”, “At Risk”, “Critical”)count: Integer countpercentage: Float percentage (rounded to 2 decimal places)
analytics.business_growth_loss view
2. Rounding Rules
Financial Fields
- Rounding: To cents ($0.01)
- Precision: 2 decimal places
- Examples:
19187.77,1608.49,17579.28
Percent Fields
- Rounding: To basis points (0.01%)
- Precision: 2 decimal places
- Examples:
25.50,-15.00,54.35
Count Fields
- Rounding: None (integers)
- Precision: Whole numbers only
- Examples:
92,1943,55
3. Source Tables/Views
| Endpoint | Primary Source | Secondary Source | Notes |
|---|---|---|---|
/api/v1/ceo-metrics | analytics.ceo_snapshot | processed.stage3_snapshots (for agent commissions) | View aggregates Stage 1 data |
/api/v1/top-businesses | analytics.top_businesses | None | Pre-aggregated view |
/api/v1/top-agents | analytics.top_agents | None | Pre-aggregated view |
/api/v1/growth-loss | analytics.business_growth_loss | None | View with LAG() window functions |
/api/v1/growth-loss-details | analytics.business_growth_loss | None | Same view, filtered and sorted |
/api/v1/new-lost-businesses | raw.stage1_snapshots | None | FULL OUTER JOIN logic |
/api/v1/business-health | analytics.business_growth_loss | None | View with categorization |
period_label (DATE) and tenant_id (STRING)
Dataset Routing: Controlled via environment variables:
BQ_DATASET_ANALYTICS(default:payroll_analytics)BQ_DATASET_RAW(default:payroll_raw)BQ_DATASET_PROCESSED(default:payroll_processed)
4. “No Recomputation Allowed” Warnings
⚠️ CRITICAL: No-Code Tools Must NOT Recompute Commission Math
Explicit Rules:- Read-Only Only: All endpoints are read-only. No write-back functionality exists or is planned.
- No Calculated Fields: No-code tools must NOT create calculated fields that duplicate Repo B logic (e.g.,
net_payout = gross_payout - chargebacks). - Authoritative Source: Repo B outputs are the single source of truth for all financial calculations.
- No AI Logic Changes: No-code tools must NOT modify commission calculation logic.
What No-Code Tools CAN Do:
- ✅ Read data from endpoints
- ✅ Filter and sort data
- ✅ Format data for display
- ✅ Aggregate data for visualization (e.g., sum totals, count items)
- ✅ Create derived metrics for display (e.g., “Total Revenue per Employee” =
total_revenue / employee_count)
What No-Code Tools CANNOT Do:
- ❌ Recompute commission splits (agent vs owner)
- ❌ Modify financial calculations
- ❌ Create calculated fields that duplicate Repo B business logic
- ❌ Write data back to BigQuery
- ❌ Modify source data
Rationale
Repo B implements authoritative commission calculation logic with:- Decimal-safe financial calculations
- Multi-stage data processing (Stage 1 → Stage 3 → Analytics)
- Business rule enforcement (e.g., agent commission allocation)
- Audit trail and reconciliation
- Create duplicate, potentially inconsistent calculations
- Bypass business rule enforcement
- Break audit trail
- Risk financial discrepancies
5. Dataset Routing Visibility (PLANNED)
Status: Planning phase (not implemented)Proposed Implementation
Option A: Response Header- Add header:
X-Dataset-Routing: analytics=payroll_analytics_shadow,raw=payroll_raw_shadow,processed=payroll_processed_shadow - Purpose: Enable no-code tools to verify which datasets are active
- Implementation: Add to all API responses
- Endpoint:
/api/v1/system-info - Returns:
{"datasets": {"analytics": "payroll_analytics_shadow", "raw": "payroll_raw_shadow", "processed": "payroll_processed_shadow"}} - Purpose: Enable no-code tools to query active dataset routing
- Implementation: New read-only endpoint
6. Schema Introspection (PLANNED)
Status: Planning phase (not implemented)Proposed Implementation
Endpoint:/api/v1/schema/{endpoint_name}
Example: /api/v1/schema/ceo-metrics
Response:
7. Explicitly EXCLUDED
The following features are explicitly excluded from this data contract:- ❌ Write-back functionality — No endpoints support writing data
- ❌ Calculated fields in no-code layer — No-code tools must not duplicate Repo B calculations
- ❌ AI logic changes — No AI-driven modifications to commission logic
- ❌ Commission math outside Repo B — All commission calculations must use Repo B outputs
- ❌ Any modification of financial calculations — Financial calculations are authoritative in Repo B
8. Versioning
Current Version: 1.0Last Updated: 2025-12-19 Version History:
- 1.0 (2025-12-19): Initial data contract document
9. Support
Questions or Issues:- Review
docs/DASHBOARD_WIRING_VALIDATION.mdfor wiring details - Review
docs/SHADOW_PREFLIGHT_RESULTS.mdfor data validation results - Contact development team for schema changes
Note: This is a planning document. Dataset routing visibility and schema introspection features are planned but not yet implemented.