Paintbox
A painting company ran its entire estimating operation from one Excel file with 14,000+ formulas. We moved it to the web without losing what made it work.
Executive Summary
A painting company ran its entire estimating operation from one Excel file with 14,683 formulas. We compiled that logic into a 4,916-line formula engine using decimal.js for financial precision, built as a Next.js 15 PWA with offline-first architecture. Salesforce CRM integration keeps estimates tied to opportunities. CompanyCam links job-site photos to estimates. Circuit breakers protect external API calls. Estimators use it on tablets at job sites with no signal.
The heartbeat of offline-first sync
Architecture
Next.js 15 PWA with formula engine, Salesforce CRM, CompanyCam integration, and offline-first sync
Next.js 15 PWA with formula engine, Salesforce CRM, CompanyCam integration, a...
The Problem
The estimating spreadsheet had been refined over years - 14,683 formulas across multiple sheets. Every formula, every conditional format, every hidden column existed because someone had been burned by a bad estimate once. The file worked. But it lived on one laptop, could not be used offline in the field, and broke whenever someone accidentally edited a formula.
Formula Fidelity
If the tool gave different numbers than the spreadsheet, it was wrong - even if mathematically correct. The spreadsheet was the source of truth because the business was built on its outputs.
Offline Field Use
Estimators work on job sites with no cell signal. The tool had to function fully offline on tablets and sync when connectivity returned.
Financial Precision
Floating-point math produces rounding errors that accumulate across 14,683 formulas. Every calculation needed decimal.js precision matching Excel behavior.
CRM Integration
Estimates needed to flow to Salesforce opportunities and back. CompanyCam photos needed to attach to estimates for context.
We matched the spreadsheet cell for cell. The owner could run both side by side and get identical numbers. That was the only acceptance criteria that mattered.
What We Built
We compiled the spreadsheet logic into a web application with offline-first architecture, backed by a 4,916-line formula engine that reproduces every Excel calculation with decimal precision.
Formula Engine
- 4,916-line TypeScript engine processing 14,683 formulas
- decimal.js with 15-digit precision and ROUND_HALF_UP
- Dependency resolver for formula evaluation order
- Web Worker offloading for background calculation
- Formula caching layer (Redis + in-memory)
Offline-First PWA
- IndexedDB storage via Dexie for local persistence
- Service Workers via Workbox for offline capability
- Progressive sync with backoff (1s, 5s, 15s, 60s)
- PWA manifest with app shortcuts and file handlers
CRM & Photo Integration
- Salesforce OAuth with full CRUD on contacts, accounts, opportunities
- CompanyCam API for job-site photo management
- Circuit breakers protecting both external APIs
- Offline photo sync with retry logic and priority queue
Real-time Infrastructure
- WebSocket server with Redis adapter
- Zustand state with localStorage persistence
- Sentry error tracking + OpenTelemetry
- Performance monitoring and memory management
The estimators use it on tablets at job sites with no signal. It syncs when they are back online. The spreadsheet is retired.
Execution
Formula Translation
Months 1-3Reverse-engineered 14,683 Excel formulas into TypeScript. Built the dependency resolver to evaluate formulas in the correct order. Validated every output against the original spreadsheet.
The hardest formulas were not the complex ones - they were the ones that relied on Excel-specific rounding behavior that no documentation mentions.
Offline Architecture
Months 3-4Implemented IndexedDB storage, service workers, and the progressive sync system. Built the PWA manifest with app shortcuts for field estimators.
Sync conflicts were rare but catastrophic when they happened. The progressive backoff strategy prevented data loss during spotty connectivity.
Integration Layer
Months 5-6Built Salesforce OAuth integration with full CRUD, CompanyCam photo attachment, and circuit breakers for both. Added Redis caching for API response performance.
Circuit breakers were essential - Salesforce rate limits and CompanyCam outages would have cascaded into estimate calculation failures without them.
Production Hardening
Months 7-presentAdded Sentry monitoring, OpenTelemetry instrumentation, performance benchmarks, and memory management. The system now runs in production serving field estimators daily.
172K total lines of code. The formula engine alone (4,916 LOC) represents the core business logic that took years to build in Excel.
Related writing
Interested in this kind of work?
Start a conversation →