Engineering portfolioAI SAAS RELIABILITY
SYSTEMS HARDENING

Hardening an AI SaaS Revenue and Asset Pipeline

Reworked critical asset, generation, billing, and authentication paths so product behavior was backed by durable infrastructure rather than interface-only state.

Role

  • AI SaaS architecture
  • Next.js & Supabase engineering
  • Stripe revenue hardening
  • Atomic billing & RLS
  • Browser QA & Launch gates

Category

SaaS Reliability

Engineering discipline

SYSTEMS HARDENING

Asset Storage:Private Supabase + Signed URLs
Credit Mutations:Atomic SQL RPC Operations
Stripe Fulfillment:Idempotent Ledger Handling

Engineering objective

System challenge

Harden the product’s asset, generation, credit, payment, authentication, and administration paths into durable, server-owned infrastructure suitable for production operations.

Constraints

Working within real limits

  • Uploaded campaign references could remain in temporary browser state rather than private storage
  • Credit accounting required stronger server-side ownership and atomic SQL RPC operations
  • Stripe payment fulfillment required idempotent ledger handling to protect revenue
  • Generation entitlements required durable provider-backed results before credit settlement
  • Release gates required runtime, persistence, security, and billing evidence in addition to build success

Architecture

Durable Asset & Idempotent Revenue Pipelines

Diagram A: Durable Asset Storage & Delivery PipelineBrowser-Local Rejection vs. Durable Storage

1. Authenticated Upload

Validated reference image & campaign prompt

2. Private Supabase Storage

Persisted in private bucket with RLS policies

3. Signed Application Route

Authenticated access token delivery

4. Durable Campaign Output

Persisted in database & storage — no interface-only state

Diagram B: Idempotent Revenue & Atomic Billing PipelineStripe Event → Atomic Credit RPC

1. Stripe Checkout Event

Validated signature & server-side price lookup

2. Idempotent Webhook Ledger

Rejection of duplicate event IDs & bonus abuse protection

3. Atomic SQL Credit Mutation

Server-only SQL RPC operation — no non-atomic balance logic

Launch Readiness Sequence

Five Evidence-Based Deployment Gates

Evidence-Based Launch Gate SequenceEngineering Judgment over Build-Only Claims
01✓ PASSED

Code Quality

37 tests passed across 9 test files · Lint clean · TypeScript build passed

Status:VERIFIED LOCAL
02✓ PASSED

Local Browser Behavior

Protected route redirects · Invalid login rejection · Authenticated upload flow

Status:VERIFIED LOCAL
03✓ PASSED

Durable Backend

Private Supabase storage · Signed asset URLs · Atomic SQL credit RPCs

Status:VERIFIED LOCAL
04✓ PASSED

Payment Integrity

Idempotent Stripe ledger · Server-side price validation · Prebuild env check

Status:VERIFIED LOCAL
05⊘ GATE BOUNDARY

Live Domain & Webhook

Recorded snapshot boundary: Unconfirmed live DB migration & inaccessible live host

Status:EXTERNAL BOUNDARY
Engineering Honest Boundary: The system was intentionally not declared production-ready merely because local tests and builds passed. External gates were documented separately at the snapshot time.

Approach

How it was built

  1. 01

    Durable asset architecture: Moved campaign assets into private Supabase-backed storage, delivered assets through signed application routes, persisted generated images rather than relying on temporary browser state, passed reference images into generation workflows, and used durable asset URLs across generation paths.

  2. 02

    Revenue integrity: Shifted credit deductions and additions to server-only SQL RPC operations, replaced non-atomic application-level balance changes with database-owned mutations, implemented idempotent Stripe webhook ledger handling, validated price lookup keys and server-side pricing inputs, protected first-purchase launch bonuses from repeated fulfillment, and added a prebuild environment check to fail missing production config before deployment.

  3. 03

    Security and access: Mandated explicit grants on public database tables, tightened Row-Level Security (RLS) around authenticated and anonymous roles, enforced signed access for private asset delivery, browser-tested portal access, protected redirects, invalid credentials, and authenticated flows, and shifted the administration view away from static demo data toward live application metrics.

  4. 04

    Verification: Completed 37 readiness tests across 9 test files, verified clean lint, passed TypeScript compilation, completed production build, confirmed zero moderate vulnerabilities in npm audit, verified protected-route redirection and invalid-login rejection in browser tests, and confirmed an authenticated reference upload reached private campaign asset flow while loading the 430-model catalog during the browser smoke path.

  5. 05

    Release engineering: Separated application verification from external deployment configuration so database migrations, domain routing, and webhook delivery could be managed as explicit release gates.

Technical validation

Implementation evidence

Observable engineering evidence. Discipline: SYSTEMS HARDENING

Asset Storage

Private Supabase + Signed URLs

Credit Mutations

Atomic SQL RPC Operations

Stripe Fulfillment

Idempotent Ledger Handling

Readiness Suite

37 tests passed across 9 files

TypeScript & Lint

Passed cleanly

npm Audit

Zero moderate vulnerabilities

Production Build

Completed successfully

Browser QA

Auth & Upload Flow Verified

Browser Smoke Path

430-model catalog loaded

Release Gates

Database, domain, webhook

Outcome

What was delivered

  • Reworked critical asset, generation, billing, and authentication paths so product behavior was backed by durable infrastructure rather than interface-only state

  • Private Supabase-backed campaign assets delivered via signed application routes

  • Atomic SQL credit mutations and idempotent Stripe payment fulfillment protecting revenue integrity

  • 37 tests passed across 9 test files, lint passed, TypeScript passed, production build completed, zero moderate vulnerabilities in npm audit

  • Browser-tested protected-route redirection, invalid credential rejection, reference upload persistence, and authenticated 430-model catalog smoke path

  • Defined explicit release gates for database migration, domain routing, and webhook delivery

Technologies

Stack and tools

AI SaaSNext.jsSupabaseStripeDurable storageAtomic billingWebhooksRLSBrowser QADeployment readiness

Next engineering system

AGENT ARCHITECTURE

A Two-Authority AI System

Have an ambitious AI system to build?

Let’s build something serious.

I work across AI architecture, product engineering, private inference, automation, SaaS infrastructure, and production hardening.