THIRI logo
build.thiri.ai
Solana · Seeker · Cadenza
Week 06 · Devlog

Week 6 — Stripe Billing Architecture & Theory 3.0

June 10, 2026 on-track

We’re shifting focus to commercial readiness and next-generation harmonic processing. This week, we finalized the design for our direct Stripe billing logic and began architecting Theory 3.0 to support serious developer applications.

Stripe Billing Integration Logic

To maintain an ultra-low latency profile for the Worker-based API, we designed a zero-dependency Stripe integration using native Web Crypto APIs:

graph TD
    Stripe[Stripe Webhook Event] --> Webhook[handleStripeWebhook]
    Webhook --> Verify{Verify Signature Header}
    Verify -- Invalid --> Error[Return 400 Bad Request]
    Verify -- Valid --> Match{Match event.type}
    
    Match -- checkout.session.completed --> Promote[Promote owner to builder tier]
    Match -- customer.subscription.updated --> UpdateStatus{Check sub.status}
    Match -- customer.subscription.deleted --> Demote[Gracefully demote to free tier]
    
    UpdateStatus -- active / trialing --> Maintain[Maintain builder tier]
    UpdateStatus -- past_due / unpaid --> Grace[Maintain tier during dunning]
    UpdateStatus -- canceled --> Demote
    
    Promote --> DB[(Update D1: api_keys & billing_customers)]
    Demote --> DB
    Maintain --> DB

Core Architecture & Verification Steps:

  1. Direct HMAC-SHA256 Signature Verification: Verified natively via Web Crypto APIs using worker secrets to prevent signature spoofing, keeping memory and CPU footprint minimal.
  2. Graceful Dunning & Degradation: Cancelled or failed subscriptions never hard-lock a developer’s key. Instead, the D1 database gracefully demotes the key back to the free tier (1,000 calls/mo), preventing system breakages in customer code.
  3. Case-Insensitive Resolution: Normalizes email lookups when matching Stripe webhook customer details to the api_keys.owner column, preventing activation failures due to capital letters.

🎷 Prepping Theory 3.0: Coming Soon for Serious Developers

The next major leap for THIRI is Theory 3.0, designed to power advanced autonomous composition agents. We are moving beyond simple chord queries into deep contextual music orchestration:

  • Voice-Leading Constraint Solvers: Real-time checking of parallel fifths, octaves, and voice crossing in multi-voice arrangements.
  • Secondary Dominant & Modal Interchange Networks: Dynamic graph-traversal queries that suggest substitute progressions based on path distances across key-centers.
  • Microtonal & Extended Just-Intonation: Support for non-equal temperament scaling models for experimental synthesis.

This update will roll out in the coming weeks with annotations and helper bindings specifically optimized for MCP servers.

— Dennison