digital

Research · agentic SaaS systems

The zero-database harness for infinite agentic micro-SaaS.

Writing the core solver for a focused engineering tool takes days with AI agents. Wiring DNS, auth, password resets, Stripe catalog entries, API keys, webhooks, billing portals, and production secrets usually takes longer and leaves a bill for idle databases. We engineered a reusable zero-database harness inside Lyon Industries so any new paid subdomain can be configured and shipped from one file and one command. Preflight is our first live venture built on it.

01 / Core discovery
Wildcard DNS + Stripe metadata state + one-command deploy
02 / Idle infra cost
$0/month per dormant app (zero Postgres, zero Redis)
03 / Live proof #1
Preflight →

01

Why launching small SaaS products carries absurd fixed overhead

Agentic coding compressed the cost of building deterministic compilers, validators, and developer tools by an order of magnitude. The bottleneck moved from writing product logic to operating SaaS plumbing.

Every time a studio spins up a standalone SaaS tool the conventional way, it buys a fresh domain, configures DNS records, provisions a managed Postgres database, integrates an auth vendor, clicks through the Stripe Dashboard to create products and prices, copies webhook secrets into hosting dashboards, and pays monthly fixed fees whether that tool has zero customers or five hundred. That overhead kills experimentation before a single real user tests the idea.

Our hypothesis was simple: eliminate every per-app manual step and every per-app database. If DNS, Stripe billing, transactional email, session signing, API key issuance, and Vercel deployment are standardized once at the studio level, an engineer working with AI agents can spin up a theoretically unlimited catalog of focused micro-SaaS businesses whose idle cost is zero.

02

The three-layer zero-database harness

We split the harness into three strict layers: a shared studio control plane provisioned once, an agentically configurable subdomain layer where every venture lives inside web-apps/<app>.lyon-industries.no/, and a stateless zero-database runtime plane backed entirely by Stripe Customer metadata and cryptographic HMAC cookies.

Shared layerProvisioned contractWhy agents never redo it
Wildcard DNS*.lyon-industries.no -> cname.vercel-dns.comProvisioned once at Webhuset. Attaching any new subdomain via CLI issues HTTPS automatically with zero DNS edits.
Master Stripe AccountShared catalog isolated by metadata.appProducts, recurring prices, subscriptions, and customer API keys live under one account scoped cleanly by appId.
Transactional EmailVerified Resend domain (eu-west-1)DKIM and SPF already verified on noreply@lyon-industries.no for 15-minute magic links and onboarding emails.
Monorepo Build Isolationvercel.json ignoreCommand per appgit diff HEAD^ HEAD --quiet -- . ensures pushing to one venture never burns build minutes on unrelated apps.
Shared Dev EnvironmentRoot .env.local inheritance in next.config.tsLocal dev inherits unset Stripe test, Resend, and session keys automatically; ignored whenever VERCEL=1.

03

One 48-line config file per business

Every backend API route, Stripe bootstrapper, cookie signer, magic-link sender, and deployment script reads from a single declarative TypeScript file: saas.config.ts. Because every Stripe product, subscription, cookie, and customer metadata key is namespaced by appId, hundreds of independent businesses can share one Stripe account and one verified sending domain with zero cross-contamination.

web-apps/preflight.lyon-industries.no/saas.config.ts
SINGLE DECLARATIVE BUSINESS CONTRACTTypeScript
// web-apps/preflight.lyon-industries.no/saas.config.ts
// Changing this single 48-line contract re-skins billing, cookies, API key
// prefixes, and email sender identity for a brand-new subdomain venture.
export const SAAS_CONFIG = {
  appId: "preflight",
  name: "Preflight",
  domain: "preflight.lyon-industries.no",
  fromEmail: "Preflight <noreply@lyon-industries.no>",
  cookieName: "lyon_preflight_session",
  apiKeyPrefix: "pf",
  freeDailyLimit: 2,
  publicImagePath: "/stripe-icon.png",
  plans: [
    {
      id: "solo",
      envVar: "STRIPE_PRICE_SOLO",
      name: "Preflight Solo Pro",
      priceUsd: 39,
      interval: "month",
      monthlyApiLimit: 500,
      description: "Automated HTML email compiler & dark-mode auto-fixer.",
    },
    {
      id: "agency",
      envVar: "STRIPE_PRICE_AGENCY",
      name: "Preflight Team & Agency",
      priceUsd: 99,
      interval: "month",
      monthlyApiLimit: 5000,
      description: "Unlimited seats and 5,000 monthly API compiles for CI gates.",
    },
  ] satisfies PlanSpec[],
} as const;

In lib/stripe.ts, if explicit STRIPE_PRICE_* environment variables are omitted during local development, resolvePriceIdForPlan() automatically queries Stripe for the active product tagged with metadata.app === SAAS_CONFIG.appId and matching recurring amount, caching the resolved Price ID in memory.

04

Using Stripe Customer metadata as the entire state plane

Stateless developer tools do not need a relational database to know whether a user has paid. Stripe already stores every customer's email address, active subscription status, invoices, and an arbitrary key-value metadata dictionary.

When a visitor completes Stripe Checkout and lands back on /?checkout=success&session_id=..., POST /api/auth/activate verifies payment directly with Stripe, mints an app-prefixed API key (pf_live_<36 hex>), stores both the key and its SHA-256 digest in Stripe Customer metadata under <appId>_api_key and <appId>_key_hash, sends a Welcome email via Resend, and sets a 30-day HMAC-SHA256 HttpOnly cookie checked with crypto.timingSafeEqual.

web-apps/preflight.lyon-industries.no/lib/auth.ts
TIMING-SAFE HMAC COOKIES + STRIPE METADATA API KEY VERIFICATIONTypeScript
// web-apps/preflight.lyon-industries.no/lib/auth.ts
// 1. Stateless HMAC-SHA256 tokens verified in constant time (no session table)
export function verifyToken<T extends { exp: number }>(
  token: string | null | undefined,
  secret = getSessionSecret(),
): T | null {
  if (!token) return null;
  const dot = token.indexOf(".");
  if (dot <= 0 || dot === token.length - 1) return null;
  const body = token.slice(0, dot);
  const sig = token.slice(dot + 1);
  const expected = crypto.createHmac("sha256", secret).update(body, "utf8").digest("base64url");
  const sigBuf = Buffer.from(sig, "utf8");
  const expBuf = Buffer.from(expected, "utf8");
  if (sigBuf.length !== expBuf.length || !crypto.timingSafeEqual(sigBuf, expBuf)) return null;
  const parsed = JSON.parse(Buffer.from(body, "base64url").toString("utf8")) as T;
  return Math.floor(Date.now() / 1000) > parsed.exp ? null : parsed;
}

// 2. Per-app API key lookup directly against Stripe Customer metadata
const API_KEY_HASH_META = `${SAAS_CONFIG.appId}_key_hash`;
const query = `metadata['${API_KEY_HASH_META}']:'${hashApiKey(trimmed)}'`;
const search = await stripeApiRequest<{ data: StripeCustomer[] }>(
  "GET", `/customers/search?query=${encodeURIComponent(query)}&limit=5`,
);

Passwordless re-entry on a new device uses the exact same HMAC signer with a 15-minute expiry emailed via Resend. A small detail caught in testing turned out to matter: getRequestOrigin(request) inspects x-forwarded-host and host headers before falling back to request.url so magic-link redirects never drop session cookies across reverse proxies, LAN testing, or custom subdomains.

05

One-command agentic rollout (pnpm launch)

Manual dashboard clicks break reproducibility and block agents from executing clean deployments. Both sandbox provisioning (scripts/setup-stripe.mjs) and live launch (scripts/launch-subdomain.mjs) run idempotently from the terminal. Running setup-stripe.mjs checks existing active Stripe products by metadata.app and metadata.plan, attaches each app's 512 x 512 icon at /stripe-icon.png, and creates missing recurring prices without duplicating catalog items on reruns.

web-apps/preflight.lyon-industries.no/scripts/launch-subdomain.mjs
FIVE-STAGE AUTOMATED PRODUCTION LAUNCHTypeScript
// web-apps/preflight.lyon-industries.no/scripts/launch-subdomain.mjs
// One command deploys a complete paid micro-SaaS with zero Dashboard clicks:
//   STRIPE_SECRET_KEY=rk_live_... pnpm launch

// 1. Sync live Stripe products + prices via API (attaches logo + metadata.app)
const setupOut = execFileSync("node", ["scripts/setup-stripe.mjs"], { cwd, encoding: "utf8" });

// 2. Create or link Vercel project under team scope
execSync(`CI=1 vercel link --yes --project ${appId} --scope ${VERCEL_SCOPE}`, { cwd });

// 3. Inject production secrets + resolved STRIPE_PRICE_* IDs
vercelEnvSet(cwd, "STRIPE_SECRET_KEY", stripeKey);
vercelEnvSet(cwd, "SESSION_SECRET", sessionSecret);
if (resendKey) vercelEnvSet(cwd, "RESEND_API_KEY", resendKey);

// 4. Attach custom subdomain (wildcard *.lyon-industries.no DNS already live)
execSync(`CI=1 vercel domains add ${domain} ${appId}`, { cwd });

// 5. Build and ship production deployment
execSync("CI=1 vercel --prod --yes", { cwd });

06

Proof point #1: Preflight and the 7-flow paying-customer test

To validate the harness end-to-end against real money, real DNS, and a real engineering problem, we built Preflight on top of it. Preflight's domain core is a deterministic HTML email compiler (CIELAB dark-mode contrast solver + fluid-hybrid Outlook MSO table rewriter + Gmail 102 KB compactor). Every single SaaS feature around that compiler came straight out of the harness and passed our 7-flow paying-customer acceptance suite before production launch.

#Flow verifiedObservable assertion
01Unauthenticated API gatePOST /api/v1/compile without Bearer header returns HTTP 401.
02Stripe Checkout & tagCheckout attaches metadata[app] and metadata[plan] on session and subscription.
03Zero-DB activationPOST /api/auth/activate verifies payment, mints pf_live_<hex> + SHA-256 hash on Customer metadata, emails Welcome, and sets HttpOnly cookie.
04Workspace state swapAuthenticated browser hides marketing hero, pricing, and footer, loading a clean 100dvh full-viewport workspace.
05Dual re-entry authSigned-out subscriber re-enters via either 15-minute Resend magic link or raw API key.
06Self-serve billingBilling Portal link opens Stripe invoice history, card updates, and cancellation directly.
07CI Bearer compilePOST /api/v1/compile with Authorization: Bearer <key> resolves Customer hash and returns HTTP 200.
Side-by-side compiled HTML email output from Preflight shown in Outlook Windows, Apple Mail Dark, and Gmail iOS Dark at 390 pixels width
Proof point #1 output · preflight.lyon-industries.noClick image to zoom full screenLive compiled output from the first venture deployed on the harness: deterministic WCAG contrast solving and Outlook MSO compilation served through both the subscriber browser workspace and Bearer-authenticated CI API.

07

Failure modes and when to add a real database

Eliminating Postgres is an intentional architectural trade, not dogma. It works cleanly for stateless transformation, compilation, auditing, and developer-API tools. Here are the exact limits we hit and the escape hatches built into the harness.

ConstraintWhere it shows upMitigation or graduation threshold
Stripe Search indexing lagA freshly minted test or live customer may not appear in /customers/search for several seconds.verifyApiKey() falls back automatically to scanning the 30 most recent customers whenever Search returns empty.
API key verification latencyEvery authenticated API call hits Stripe over HTTPS to confirm both key hash and live subscription status.Acceptable for low-frequency CI and pre-send compiles (500 to 5,000/mo); high-QPS endpoints need a short-TTL edge cache.
Strict monthly quota enforcementStripe Customer metadata stores entitlement tier, not atomic per-request counters.Soft monitoring works at early scale; hard rate-capped usage billing requires Stripe Meters or an edge KV counter.
Multi-user persistent workspacesStateless tools (compilers, validators, converters) need no user table.Only provision Postgres when the core product genuinely stores collaborative user data, never out of habit.

08

Handoff to commercialization

Preflight is the first commercial venture running on this harness today. As Lyon Industries launches additional micro-SaaS products on *.lyon-industries.no, each one plugs into this exact billing, auth, and deployment stack and links back to this research record.

First live venture on this harness

Preflight (Venture)

See the commercial product, supported email clients, browser workspace, CI API plans, and live Before/After compiler demo.

Verified directly against docs/subdomain-saas-playbook.md and web-apps/preflight.lyon-industries.no · Published 30 November 2026.