Automated Coaching Sync & Square Billing Pipeline
As a solo AI consultant and 1-on-1 coach, administrative billing used to consume over 45 minutes of manual cross-referencing every week—manually opening calendar entries, matching client names, checking hourly rates, and typing line items into invoicing software. To eliminate this busywork forever, Elijah engineered a private, local-first Python + SQLite pipeline hosted on his Raspberry Pi 4. It parses completed coaching sessions, stages them behind an air-tight human-in-the-loop review gate, and publishes invoices via Square in under 60 seconds a week.
Executive ROI & Operational Gains
Measured outcomes from replacing manual spreadsheet reconciliation with a deterministic local-first state machine.
Interactive 4-Step Pipeline Architecture
Click through each stage to inspect the technical data contracts, idempotency checks, and safety controls.
OAuth Ingestion & Deterministic Regex Filtering
The service communicates with the Google Calendar API via OAuth 2.0 with automated headless token refresh (token.json). Every evening, a systemd timer polls the calendar for completed events within the past 14 days.
Extracts client name from calendar titles regardless of client formatting variations.
- Discards cancelled, declined, or unconfirmed calendar invitations.
- Automatically identifies
[Free Discovery]and intro calls to avoid billing consultations. - Computes duration from RFC 3339 timestamps for partial-hour fractional billing.
Transactional Deduplication & Custom Rate Matching
Incoming parsed events are written into a local SQLite database configured with Write-Ahead Logging (WAL). Sessions are deduplicated using calendar event IDs as strict unique constraints.
Re-running sync 10 times a day can never create duplicate meeting records or double-bill.
- Resolves client record by name or email alias against
clientstable. - Retrieves client-specific agreed rates (e.g., $150/hr vs. customized retainer packages).
- Generates staged line items in state
PENDING_REVIEW.
1-Click Local Review Before Financial Dispatch
Financial transactions should never execute fully autonomously without human oversight. Elijah hosts a private, secure FastAPI web dashboard on the local LAN (Raspberry Pi 4:8000).
- Toggle individual sessions on/off with responsive checkboxes.
- Adjust session rates inline for prorated meetings or credited sessions.
- Preview live invoice totals and line item descriptions before submission.
- Runs strictly on the local home network with zero public port exposure.
- Client names and billing figures never pass through third-party multi-tenant SaaS servers.
- Full audit log of who approved each invoice and at what exact timestamp.
Deterministic Order Creation & Invoicing Webhooks
Upon clicking "Approve Batch", the system talks directly to the official Square SDK. It creates a customer if new, generates an Order with calculated line items, and publishes the invoice.
Even in the event of network dropouts or timeouts, Square guarantees zero duplicate charges.
- Supports
DRAFTmode for extra inspection orPUBLISHEDfor automatic email dispatch. - Updates local SQLite record with
square_invoice_idand direct Square Dashboard deep links. - Webhooks track invoice payment status (
PAID,UNPAID,REFUNDED).
Try the Human-in-the-Loop Staging Review
Experience the exact workflow in a safe, client-side sandbox using fictional sample data. Zero real client information or external APIs are touched.
Why Custom Code Beats Fragile No-Code Zaps
Why professional automation engineering relies on idempotent code rather than brittle multi-step SaaS subscriptions.
| Architectural Dimension | Generic SaaS / Zapier / Make | Elijah's Local-First Pipeline |
|---|---|---|
| Deduplication & Idempotency | High Risk Triggers fire multiple times on rescheduled meetings; prone to double-charging clients. | Guaranteed
Database-level UNIQUE(calendar_event_id) + Square idempotency keys prevent duplicates.
|
| Human-in-the-Loop Oversight | Blind Push Sends emails automatically on trigger; calendar typos turn into embarrassing billing disputes. | Staging Gate FastAPI review dashboard allows Elijah to review, edit, or exclude sessions with 1 click before send. |
| Operating Cost & SaaS Lock-In | $360 – $840 / year Expensive tiered subscriptions that scale up as your meeting volume increases. | $0 / month Runs continuously on a 5-watt self-hosted Raspberry Pi 4 with zero software fees. |
| Client Data Privacy | Third-Party Cloud Client names, emails, and financial amounts pass through shared multi-tenant cloud servers. | 100% Private OAuth tokens, client lists, and rate tables remain strictly on local encrypted disk. |
| Reliability & Maintainability | Brittle Silent token expirations, unannounced UI changes, and limited error debugging. | Rock Solid
14 passing pytest unit tests, structured logs, and automatic systemd service restart.
|