Back to Public Spending Explorer

Technical Documentation

Normalized v2 data schema, deterministic ID generation, cents-level reconciliation, and search/CSV API reference.

Data schema & API (v2)

Every record is normalized in lib/transparency/schema.js and indexed in lib/transparency/search-engine.js.

Normalized Payment (Open FI$Cal)

v2

Individual expenditure or vendor transaction line from Open FI$Cal monthly CSVs (Spending_FY*P*.csv and Vendor_FY*P*.csv).

  • id (fiscal_{sp|vn}_fy{YYYY}p{PP}_{docId}_{sha256_12}[_dupN])
  • documentId (source document_id voucher reference)
  • agencyName, businessUnit, cabinetAgency
  • vendorName, isConfidentialVendor, isUnspecifiedVendor
  • amount, grossAmount, refundAmount, isRefundOrAdjustment
  • fiscalYearBegin, fiscalYearLabel (e.g., FY2025-26), fiscalPeriod (1..12), calendarYearMonth
  • category, subCategory, fundGroup, fundDescription
  • budgetAuthority (Budget Act / Non-Budget Act), budgetCategory (State Operations / Local Assistance)
  • sourceDataset, sourceFile, sourceUrl, sourceUpdatedAt, rowNumber, rowChecksum

Normalized Contract / Purchase Order (DGS CKAN)

v2

Historical purchase order line from the California DGS Open Data datastore (resource bb82edc5-9c78-44e2-8947-68ece26197c5, FY2012–13 to FY2014–15).

  • id (dgs_po_{ckan_id}_{po_number}_{sha256_10})
  • contractNumber (Purchase Order Number), lpaNumber (Leveraged Procurement Agreement)
  • agencyName (Department Name), vendorName (Supplier Name), supplierCode
  • totalValue, grossAmount, refundAmount, quantity, unitPrice
  • fiscalYearLabel, startDate, endDate, dateAnomalyNotice
  • acquisitionType, acquisitionMethod, category, calCard
  • sourceDataset, sourceFile, sourceUrl, rowNumber, rowChecksum

Ingest Run & Reconciliation Log

v2

Provenance and reconciliation manifest produced for every imported file or API batch.

  • runId, sourceFile, sourceUrl, sourceDataset, sourcePublishedAt
  • fileSha256 (cryptographic digest of raw input)
  • rowCount, validRowCount, skippedRowCount, duplicateContentLineCount
  • multiLineDocumentCount, refundRowCount, zeroAmountRowCount
  • grossPositiveTotal, refundAdjustmentTotal, netTotal, reconciledExactMatch

Search & Export API (/api/transparency/search)

v2

Complete indexed search, directory aggregation, and formula-safe CSV export endpoint.

  • GET /api/transparency/search?type=payments|contracts&keyword=...&agency=...&vendor=...
  • Filters: category, fundGroup, budgetAuthority, fiscalYear, fiscalPeriod, startDate, endDate, minAmount, maxAmount, includeRefunds
  • Pagination & Sort: page, pageSize (up to 200), sortBy (date|amount|agency|vendor), sortDir (asc|desc)
  • Directory mode: GET /api/transparency/search?mode=directories&type=payments|contracts
  • CSV export: GET /api/transparency/search?format=csv&type=payments|contracts (up to 5,000 matching rows with formula-injection protection)

Ingestion, reconciliation & security design

Pipelines are repeatable, resumable, and verified against raw source checksums.

Official Sources & Pointers

  • Open FI$Cal Spending Pointer: adwoutputfilesadlsstore.blob.core.windows.net/transparency/MonthlySpendingTransactionPointer/MonthlySpendingTransactionPointer.csv
  • Open FI$Cal Vendor Pointer: adwoutputfilesadlsstore.blob.core.windows.net/transparency/MonthlyVendorTransactionPointer/MonthlyVendorTransactionPointer.csv
  • DGS Purchase Order CKAN API: data.ca.gov/api/3/action/datastore_search?resource_id=bb82edc5-9c78-44e2-8947-68ece26197c5

Stable IDs & Duplicate/Refund Handling

  • Never key records by raw `document_id` alone: single FI$Cal vouchers regularly span multiple account distributions or reversal pairs.
  • Compute deterministic IDs combining dataset prefix, fiscal year/period, `document_id`, and a 12-char SHA-256 digest of the canonical accounting attributes.
  • If two lines in the same file have identical canonical attributes, tag with `_dup2` (or skip if configured) and record `duplicateContentLineCount`.
  • Preserve negative adjustments (`amount < 0`) and `$0` clearing lines; reconcile `grossPositiveCents + refundAdjustmentCents === netCents`.

Resumable CLI & Production Safety Gate

  • Run `node scripts/ingest-fiscal-data.js --build-snapshot` to rebuild `data/transparency/verified-ca-snapshot.json` and verify reconciliation locally.
  • Firestore batch writes require `CONFIRM_PRODUCTION_INGEST=true` or `FIRESTORE_EMULATOR_HOST` and checkpoint progress in `sync_cursors` and `ingest_runs`.

Security & CSV Export Hardening

  • All exported CSV cells beginning with `=`, `+`, `-`, `@`, tab, or CR are prefixed with a single quote to prevent spreadsheet formula injection.
  • DGS purchase order dates outside 1990–2035 (such as source typos `1911-10-01` or `6070-12-10`) are nulled for date-range indexing and flagged in `dateAnomalyNotice`.