Skip to content

SA5: saas-starter becomes an Orun baseline - #6

Merged
ruehowl merged 2 commits into
mainfrom
claude/blissful-ptolemy-c5ajf8
Oct 15, 2026
Merged

ruehowl merged 2 commits into
mainfrom
claude/blissful-ptolemy-c5ajf8

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

The repository becomes an Orun baseline on the Cloudflare + Supabase (Lumen) conventions, built the way cirrus-baseline v22 builds a product: one landing. It is the reference conversion for the Supabase group. Milestone SA5, task SA-6.

What was added

The card (blueprint.yaml)

  • requires.integrations: [github, cloudflare, supabase].
  • spec.secrets previews the five brokered keys. Each is transcribed from a reconcile hook, and each is a key the product's plan actually resolves:
    • CLOUDFLARE_API_TOKEN (workers-deploy)
    • CLOUDFLARE_HYPERDRIVE_TOKEN (hyperdrive-edit)
    • CLOUDFLARE_ACCOUNT_ID (account-id)
    • SUPABASE_ACCESS_TOKEN (management-access)
    • SUPABASE_ORG_ID (org-id)
  • The programme is 01-product, 02-docs; expectedMinutes: 20.
  • There is no Stripe key, because no platform brokers one.

The build document (repo-blueprint.yaml): two phases

  • 01-product places every module (25 of them).
    • Post hooks, in the brief's order: retouch, git-init, stage → rebrand, orun-workspace → work-tree --strip, promotion --defer, dev-lanes --defer → restage, rebrand-verify → pnpm lockfile → orun.repo/ensure@v1, then link → five orun.integrations/reconcile@v1 hooks, one key each → orun.pr/land@v1.
    • Await hooks:
      • orun.run/watch@v1 on the merge sha;
      • orun.secrets/exists@v1 for SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL and WIRING_CLOUDFLARE_HYPERDRIVE, on stage and prod;
      • orun.http/probe@v1 on / and /api/health, on stage and prod.
  • 02-docs is hook-only: restore promotion and dev-lanes, render the record, land, probe.

Deploy order on github-push-main

  • Per environment, the order is supabase → cloudflare-hyperdrive → db-migrate → web. Every edge is dependsOn + mode: enforced, with a modeRules entry that makes it advisory on github-pull-request (the cirrus shape).
  • db-migrate also waits on cloudflare-hyperdrive. Migrations are the one step a re-run cannot undo, so they run last before the app.

Product changes

  • Stripe (brief rule 8). The Stripe client is built lazily. Without a key:

    • /pricing renders the template's plans, with checkout disabled and "Connect Stripe to enable checkout.";
    • the checkout and portal actions and the checkout callback redirect to /pricing;
    • the webhook answers 503.

    How the owner adds STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET is documented in the product README ("Connect Stripe"), ai/context/operations.md and BOOTSTRAP.md.

  • The session key. If AUTH_SECRET is unset, the session key is one the database generates for itself (migration 020_app_secrets, app_private.secrets). A fresh build therefore signs users up with no secret set by hand.

  • Row-level security on every table in public (migration 030_row_level_security; .enableRLS() in schema.ts), with no policies.

    • Supabase's Data API serves public to the anon key, and the template's tables, password hashes included, had no RLS. Now anon and authenticated read and write nothing through it.
    • The app connects through Hyperdrive as postgres, which owns the tables, so RLS doesn't apply to it.
    • The migration checks first: if postgres neither owns every table nor has SUPERUSER/BYPASSRLS, it raises before enabling anything.
    • Resolves risk SA-L.
  • /api/health (new) checks that Hyperdrive reaches the database and the schema is migrated. The deploy smoke checks it.

  • apps/web/wrangler.jsonc is now committed as the fixture render (lesson 4). Stage and prod re-render it from their wiring before the build, and dev verifies with the fixture.

  • The supabase root publishes only Lumen's three outputs, and both Terraform roots carry Lumen's lock files.

  • Pipeline: stack-tectonic pinned at 0.19.0, checks.yml runs on pull requests only, ci.yml uses the linked gate and runs its lanes on v2.78.4.

Baseline machinery

  • From portfolio baseline-v2, adapted: .baseline/, the rebrand engine with the product-name seam apps/web/lib/site.ts, the bootstrap helpers, hooks/render-deployment-docs.sh, ai/context/, docs/phases/, BOOTSTRAP.md, baseline.yml and tag.yml.
  • The rebrand protects the upstream template's links and the migrations, whose checksums the manifest records.

How it was verified (locally)

Repository checks

  • All green: pnpm install --frozen-lockfile, wire:fixture, typecheck, lint, test, build.
  • Lint: 0 errors, 4 warnings in upstream code. Tests: 27 in tests/web and 10 in tests/db.
  • tests/db runs every migration in PGlite (Postgres compiled to WASM, pinned 0.5.8). It fails if a table in public lacks RLS, if a policy or FORCE appears, or if a role with the Data API's grants can read or write a row. It also exercises the guard's refusal.

testing/*.test.sh

  • Contract suites, all green: manifest, phases, coverage, rebrand, retouch, bootstrap-defer.
  • leak, green.
  • placement, green at 2.58.11, 2.78.4 and 2.79.0:
    • the product's own push-to-main plan shows the enforced chain;
    • the PR plan shows the same edges as advisory (checked at versions at or above the lane pin);
    • the brokered keys the plan resolves are exactly the 5 minted;
    • --resume is a no-op.
  • e2e, green at v2.78.4. Its Postgres now has Supabase's roles: postgres without SUPERUSER or BYPASSRLS, owning what it migrates, and anon/authenticated with Supabase's default grants.
    • the db-migrate lane's own steps apply all four migrations, and a re-apply is a no-op;
    • the web lane builds in the staged job tree;
    • wrangler dev runs with no Stripe key and no AUTH_SECRET and passes the smoke, every route, sign-up, dashboard and sign-in;
    • then anon and authenticated see 0 of the users, cannot write one, and cannot read app_private.

orun and Terraform

  • orun new --status at v2.58.11, v2.78.4 and 2.79.0; orun validate; orun work check: clean.
  • terraform fmt, init -backend=false and validate pass on both roots.

Offline only, not live:

  • a Terraform plan or apply;
  • a real Supabase project or db-migrate against one (so which role the Management API runs as is not observed — the guard covers it);
  • a live deploy, a live bootstrap, a Stripe checkout.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk

The repository is now a baseline on the Cloudflare + Supabase (Lumen)
conventions, built the way cirrus-baseline v22 builds a product: in ONE
landing.

- blueprint.yaml (the card): requires [github, cloudflare, supabase]; the
  five brokered keys as a preview (CLOUDFLARE_API_TOKEN workers-deploy,
  CLOUDFLARE_HYPERDRIVE_TOKEN hyperdrive-edit, CLOUDFLARE_ACCOUNT_ID
  account-id, SUPABASE_ACCESS_TOKEN management-access, SUPABASE_ORG_ID
  org-id); programme 01-product, 02-docs. No Stripe key: no platform
  brokers it.
- repo-blueprint.yaml: 01-product places every module, retouches, brands,
  re-tenants, strips the work tree, defers promotion and dev's push lanes,
  links the repo, reconciles one key per hook and lands one PR; it awaits
  the convergence, SUPABASE_PROJECT_REF / _DB_PASSWORD / _DB_URL and
  WIRING_CLOUDFLARE_HYPERDRIVE on stage and prod, and / plus /api/health.
  02-docs is hook-only: restore, render the record, land, probe.
- One convergence keeps the order: supabase -> cloudflare-hyperdrive ->
  db-migrate -> web per environment, every edge `mode: enforced` on
  github-push-main with an advisory modeRule for pull requests.
- The product deploys and serves with no Stripe key: the Stripe client is
  lazy, pricing says "Connect Stripe to enable checkout", checkout and the
  portal redirect there, the webhook answers 503. The session key defaults
  to one the database generates (migration 020_app_secrets), so sign-up
  works with no AUTH_SECRET. /api/health proves the Hyperdrive path and the
  schema; the deploy smoke reads it.
- apps/web/wrangler.jsonc is committed (the fixture render): the
  composition's verify-app-structure checks it before the build. Stage and
  prod re-render it from their wiring; dev verifies with the fixture.
- The supabase root publishes Lumen's three outputs only; both roots carry
  Lumen's provider lock files. stack-tectonic 0.19.0; checks.yml on pull
  requests only; ci.yml's linked gate and lanes on v2.78.4.
- .baseline/, the rename engine (upstream links and migrations protected),
  the bootstrap helpers, the deployment-record hook, ai/context/, the phase
  pages, BOOTSTRAP.md, baseline.yml and tag.yml.
- testing/: manifest, phases, coverage, rebrand, retouch, bootstrap-defer,
  leak (every shipped file read for factory paths), placement (the
  offline bootstrap of both phases; the product's own push-to-main plan
  read for the order; the PR plan's advisory edges; a --resume no-op) and
  e2e (checks at the landing; the db-migrate lane's own steps applying to a
  local Postgres through a Management API stand-in; the web lane's steps
  in the staged job tree; wrangler dev with no Stripe key and no
  AUTH_SECRET, the smoke, every route, a sign-up, sign-in and dashboard).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
Supabase's Data API (PostgREST) serves `public` to anyone holding the
project's anon key. The template's tables — users with password hashes,
teams, invitations — had no row-level security, so every product built
from this baseline would have served them (risk SA-L, now resolved).

- Migration 030_row_level_security (drizzle-kit twin 0002, from
  `.enableRLS()` on every table in schema.ts) enables RLS with NO policy:
  anon and authenticated read and write nothing through the Data API.
- The app is unaffected: it connects through Hyperdrive as `postgres`
  (the cloudflare-hyperdrive root's database_user; the supabase root's
  connection_uri), which runs db-migrate and so owns the tables, and an
  owner is not subject to RLS without FORCE. Unverified live, so the
  migration first checks that `postgres` owns every table in public or has
  SUPERUSER/BYPASSRLS, and otherwise raises before enabling anything.
  The ledgers (_migrations, drizzle) and app_private are outside public.
- tests/db runs every migration in PGlite (Postgres in WASM; pinned 0.5.8
  with one workspace override) and fails if any table in public lacks RLS,
  if a policy or FORCE appears, or if a role with the Data API's grants
  reads or writes a row; it also drives the guard's refusal and its
  BYPASSRLS pass.
- The e2e's Postgres now has Supabase's roles: supabase_admin the
  superuser, `postgres` a login role WITHOUT superuser or BYPASSRLS that
  owns what it migrates, anon and authenticated with Supabase's default
  grants. After a real sign-up and sign-in through the Worker, anon and
  authenticated see 0 of the users, cannot write one, and cannot read
  app_private.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
@ruehowl
ruehowl marked this pull request as ready for review October 15, 2026 20:12
@ruehowl
ruehowl merged commit 1e843f6 into main Oct 15, 2026
6 checks passed
ruehowl added a commit to sourceplane/rag-chatbot that referenced this pull request Oct 15, 2026
* RG5: rag-chatbot becomes an Orun baseline

The repository becomes an Orun baseline on the Cloudflare + Supabase
(Lumen) conventions, built the way cirrus-baseline v22 builds a product:
ONE landing (01-product), then a hook-only deployment record (02-docs).
Copied closely from saas-starter's SA5 (sourceplane/saas-starter#6).

- blueprint.yaml (requires [github, cloudflare, supabase]; the five
  brokered keys; the two-Supabase-projects prerequisite) and
  repo-blueprint.yaml (every module in 01-product; the cirrus v22 hook
  chain; await: the convergence, SUPABASE_PROJECT_REF/_DB_PASSWORD/_DB_URL
  and WIRING_CLOUDFLARE_HYPERDRIVE on stage and prod, / and /api/health).
- Infra before app on main: supabase -> cloudflare-hyperdrive ->
  db-migrate -> web, every edge enforced on github-push-main and advisory
  on pull requests.
- Workers AI is the default model provider through an AI binding in the
  committed wrangler config: @cf/meta/llama-4-scout-17b-16e-instruct for
  the chat, @cf/baai/bge-base-en-v1.5 for the embeddings
  (workers-ai-provider 2.0.2, the AI SDK v5 release). AI_GATEWAY_API_KEY
  is optional and switches only the chat to upstream's gateway model.
- Migration 020_workers_ai_embeddings resizes embeddings.embedding to
  vector(768) (with a guard against foreign vectors); 030 enables
  row-level security, no policy, on every table in public. Both have
  drizzle-kit twins; tests/db runs every migration on PGlite with pgvector.
- The build needs no Cloudflare credential: the platform proxy starts only
  under next dev, and the static-assets cache is populated by a copy.
- /api/health, the committed wrangler.jsonc, the rebrand engine and
  name seam, the bootstrap helpers, the deployment-record hook,
  ai/context, docs/phases, BOOTSTRAP.md, testing/ (with a deterministic
  Workers AI stand-in for the e2e), baseline.yml and tag.yml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk

* RG5: the page's Open Graph origin is the product's own

Upstream's layout hard-coded its demo's origin as metadataBase, which Next
resolves the page's opengraph-image.png against: every product built from
this baseline would have advertised upstream's vercel.app image URL as its
og:image.

- app/(preview)/layout.tsx reads NEXT_PUBLIC_SITE_URL (default
  http://localhost:3000).
- apps/web/component.yaml's buildCommand sets it, as postgres-drizzle-starter
  and portfolio-starter-kit do: the environment's SITE_URL (intent.yaml
  env:, for a custom domain), else its workers.dev URL, the subdomain
  written out because the composition exports WORKERS_DEV_SUBDOMAIN to the
  smoke step only. The page is pre-rendered, so the build bakes it in.
- .env.example documents NEXT_PUBLIC_SITE_URL; intent.yaml, the product
  README, operations.md and BOOTSTRAP.md say how a custom domain sets it.
- rebrand.test.sh covers the line (worker name and subdomain rewritten);
  tests/web holds the layout and the build line; the e2e asserts the served
  page's og:image is on the product's own stage origin, not vercel.app, and
  that the image is served.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk

---------

Co-authored-by: pullely <pullely@sourceplane.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants