Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ jobs:
echo "── $t"
bash "testing/$t.test.sh"
done
# Every component's docs/{overview,architecture,runbook}.md is generated
# from what the component declares (its manifest, Worker config,
# Terraform, migrations, package scripts). A pull request that changes
# one of those facts without regenerating the pages fails here.
- name: Component docs match their manifests
run: python3 tooling/catalog/gen-component-docs.py --check

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
Expand Down
43 changes: 43 additions & 0 deletions ai/context/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# subscription-payments — where this repository stands

The entry page for anyone (or any agent) picking this repository up. It is
this repository's own state and does not ship to a product built from it;
the two pages that do are [operations.md](operations.md) and
[deployment.md](deployment.md).

## What it is

Vercel's Next.js Subscription Payments Starter — Supabase Auth, a Postgres
schema behind row-level security, Stripe Checkout, the Customer Portal and
webhooks — on Cloudflare Workers + Static Assets (through
`@opennextjs/cloudflare`), with its Supabase project from Terraform and its
schema applied by db-migrate. It is packaged as an Orun baseline:
`orun new --blueprint repo-blueprint.yaml` builds a new product in its own
repository and takes it to live on stage and prod in one landing
(`01-product`: the Supabase project, then the migrations, then the app),
then records what went live (`02-docs`). Stripe is the owner's to connect
afterwards; the app deploys and serves without it.

## Release

| | |
|---|---|
| Latest tag | `baseline-v1` (SP5, [#6](https://github.com/sourceplane/subscription-payments/pull/6)) |
| On `main` since | SP6 — the cirrus standard (no kiox, generated component docs, this context pack) |
| Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier migrates a local Postgres under the real Supabase Auth and Data API with the product's own runner, builds in orun's staged job tree, and signs a user up and in with no Stripe key. No bootstrap from a tag has run against a workspace: the Supabase root's apply through the brokered token (SP-M), db-migrate against a real project, the service-role push, a real deploy and the card's twenty minutes (SP-N) are unproven |

## Where to read

| Question | Page |
|---|---|
| What shipped, and every departure from upstream | `specs/epics/subscription-payments/IMPLEMENTATION-STATUS.md` |
| Why it is built this way | [decisions.md](decisions.md), then `specs/epics/subscription-payments/design.md` |
| What could still go wrong | [open-risks.md](open-risks.md), then `specs/epics/subscription-payments/risks-and-open-questions.md` |
| How to instantiate it | `BOOTSTRAP.md`, `docs/phases/` |
| What each component is | `<component>/docs/` beside each `component.yaml` — `apps/web`, `packages/db`, `infra/db-migrate`, `infra/terraform/supabase`, `tests/{web,db}` (generated; `python3 tooling/catalog/gen-component-docs.py`) |

## Next

1. Bootstrap one product from a tag against a workspace with Cloudflare and
Supabase connected, and record its timings (closes SP-M and SP-N).
2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin SP6.
20 changes: 20 additions & 0 deletions ai/context/decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# subscription-payments — decisions

The choices that shape this repository, one line each, with where the full
reasoning lives. Superseded decisions stay listed, marked, so the history
reads in order.

| # | Decision | Why | Source |
|---|---|---|---|
| 1 | OpenNext on Workers + Static Assets (Next 16.3.8, React 19) | `@opennextjs/cloudflare` needs Next ≥ 15.5; only what Next 16 and Workers force changes in the template | epic README, IMPLEMENTATION-STATUS |
| 2 | One wiring document per environment, `WIRING_SUPABASE`: the URL and anon key are wrangler vars the build inlines; the service-role key is pushed as a Worker secret by every deploy (`wrangler secret bulk`). *Supersedes SP1–SP4's separate secrets* | The anon key is public (RLS protects the data); the service-role key bypasses RLS and never enters a wrangler file or a bundle | design.md §3, risks SP-B, SP-L |
| 3 | Stripe is optional: the app deploys and serves with no key (sample plans, checkout disabled, webhook 503); the owner adds the three Stripe secrets when ready | The platform brokers no Stripe connection, so a fresh product must come up without one | risk SP-I |
| 4 | `stripe` stays on v14, with `createFetchHttpClient` and SubtleCrypto webhook verification | v14 already has both Workers adapters; nothing else in the Stripe code changes | design.md §4, risk SP-E |
| 5 | The schema is applied by the `@saas/db` runner through Supabase's Management API, from the template's `init.sql` verbatim — not `supabase db push` in CI | The token is already brokered; no CLI binary, no direct Postgres connection on the runner | design.md §7, risk SP-A |
| 6 | Row-level security on every table in `public`, upstream's policies kept; migration `020` raises if any table lacks it | RLS is the app's access control over the Data API | risk SP-K |
| 7 | No Hyperdrive | The app speaks PostgREST over HTTPS, never a Postgres socket | epic README |
| 8 | `apps/web/wrangler.jsonc` is committed as the fixture render; stage and prod re-render it | The composition checks it exists before the build | risk SP-J |
| 9 | The supabase root points the project's Auth at the Worker (`supabase_settings`: Site URL and redirect allow-list) and autoconfirms sign-ups unless the component's `authEmailConfirmation` is `"true"` | Auth redirects must reach the product's own origin, and a project without its own SMTP emails only its organization's members | risk SP-C, `infra/terraform/supabase/terraform/main.tf` |
| 10 | One landing (`01-product`) then the record (`02-docs`); supabase → db-migrate → web enforced on main, advisory on a pull request; stack-tectonic 0.19.0 | A landing has a fixed cost; 0.20.0's lane-scoped install is refused by Turbopack | `repo-blueprint.yaml`, `intent.yaml`, IMPLEMENTATION-STATUS (SP5) |
| 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version (v2.15.0) nothing ran | IMPLEMENTATION-STATUS (SP6) |
| 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph and bindings drifts silently | `tooling/catalog/gen-component-docs.py` |
17 changes: 17 additions & 0 deletions ai/context/open-risks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# subscription-payments — open risks

What is not yet proven or not yet decided. The full write-up of every risk,
including the accepted and resolved ones, is
`specs/epics/subscription-payments/risks-and-open-questions.md`; this page
lists only what is still live, so it should be short.

| ID | Risk | State | What closes it |
|---|---|---|---|
| SP-M | The supabase root reads the project's API keys and writes its Auth config with the brokered `management-access` token; whether that token's scopes reach those endpoints is untested, and a refusal fails the first apply | OPEN | The first live bootstrap's supabase apply |
| SP-N | No bootstrap has been timed (the card's twenty minutes is summed from estimates); the root has not been applied and db-migrate has not run against a real project | OPEN | One bootstrap from a tag against a workspace |

Accepted, and worth knowing before you change them: SP-A (`init.sql` is not
idempotent), SP-F (the `supabase` CLI devDependency under pnpm 10), SP-H
(lucide-react 0.330.0 on React 19), SP-L (the service-role key's path), SP-O
(the bootstrap floor plans `modeRules` as enforced), SP-P (two Supabase
projects per product), SP-Q (the e2e downloads real Supabase binaries).
27 changes: 27 additions & 0 deletions apps/web/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# web — architecture

Built by the turbo pipeline from `apps/web` and deployed with wrangler.

| | |
| ------------------- | ----------------------------------------------- |
| Worker config | `apps/web/wrangler.template.jsonc` |
| Entry | `.open-next/worker.js` |
| Compatibility date | `2026-10-01` |
| Compatibility flags | `nodejs_compat`, `global_fetch_strictly_public` |

## Bindings

| Binding | Kind | Source |
| -------- | ------------- | ------------------- |
| `ASSETS` | Static assets | `.open-next/assets` |

## Variables

`NEXT_PUBLIC_SITE_URL`, `NEXT_PUBLIC_SUPABASE_ANON_KEY`, `NEXT_PUBLIC_SUPABASE_URL`.

## Wiring

Resolved at deploy time from secrets the infrastructure lanes publish (names only):

- `WIRING_SUPABASE_PROD`
- `WIRING_SUPABASE_STAGE`
21 changes: 21 additions & 0 deletions apps/web/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# web

The Next.js Subscription Payments Starter — Supabase Auth, Stripe Checkout, Customer Portal and webhooks (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)

A Cloudflare Worker with Static Assets (server rendering plus static files), deployed per environment by its CI lane.

| | |
| ------------ | ------------------------------------------------------------------------------------------------------------------ |
| Type | `cloudflare-workers-assets-turbo` |
| Source | `apps/web` |
| Package | `@app/web` |
| Environments | `dev`: `verify` · `stage`: `verify`, `deploy` on a push to `main` · `prod`: `verify`, `deploy` on a push to `main` |

## Depends on

- **supabase** — Provisions Supabase projects for stage and prod, points their Auth at the app, and wires the database credentials and the app's URL and keys into orun secrets
- **db-migrate** — Applies database migrations to stage and prod Supabase instances

## Depended on by

- (none)
40 changes: 40 additions & 0 deletions apps/web/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# web — runbook

## How it runs

Pull requests verify it; a merge to `main` deploys it to `stage`, `prod`.
CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;
the plan orders a component after everything it depends on.

## Local commands

```bash
pnpm --filter @app/web dev
pnpm --filter @app/web build
pnpm --filter @app/web typecheck
pnpm --filter @app/web lint
pnpm --filter @app/web preview
```

## Verify

After a deploy the lane runs this smoke against the environment it
deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL:

```bash
html=$(curl -sfL "${DEPLOYED_URL}/") && echo "${html}" | grep -q 'Pricing' && health=$(curl -sf "${DEPLOYED_URL}/api/health") && echo "${health}" | grep -q '"ok":true'
```

## Rollback

Revert the commit on `main`. The next convergence applies the previous desired
state; nothing was changed out of band, so there is nothing else to undo.

## Common failures

- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream
has not applied for this environment yet. Within one convergence the plan
runs it first; on its own, re-run that lane.
- **The smoke fails right after a first deploy**: a new workers.dev route can
answer 4xx for a few seconds and the lane retries. A failure that persists
is a regression in the deployed code.
18 changes: 18 additions & 0 deletions infra/db-migrate/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# db-migrate — architecture

Applies the migrations under `packages/db/src/migrations` in order, recording each one
it applies so a run only ever applies what is new. An already-applied migration
is never edited: a change is a new, later migration.

## Migrations

- `000_control`
- `010_subscriptions_init`
- `020_row_level_security`

## Resolved at run time (names only)

- `SUPABASE_ACCESS_TOKEN`
- `SUPABASE_DB_PASSWORD`
- `SUPABASE_DB_URL`
- `SUPABASE_PROJECT_REF`
20 changes: 20 additions & 0 deletions infra/db-migrate/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# db-migrate

Applies database migrations to stage and prod Supabase instances

Applies this repository's ordered database migrations per environment: plan on pull requests, apply on merge to `main`.

| | |
| ------------ | ------------------------------------------------------------------------------------------ |
| Type | `db-migrate` |
| Source | `infra/db-migrate` |
| Environments | `stage`: `plan`, `apply` on a push to `main` · `prod`: `plan`, `apply` on a push to `main` |

## Depends on

- **db** — The database migrations and their runner (built by the db-migrate component before it plans or applies)
- **supabase** — Provisions Supabase projects for stage and prod, points their Auth at the app, and wires the database credentials and the app's URL and keys into orun secrets

## Depended on by

- **web** — The Next.js Subscription Payments Starter — Supabase Auth, Stripe Checkout, Customer Portal and webhooks (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)
19 changes: 19 additions & 0 deletions infra/db-migrate/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# db-migrate — runbook

## How it runs

Pull requests plan it; a merge to `main` applies it to `stage`, `prod`.
CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;
the plan orders a component after everything it depends on.

## Rollback

Revert the commit on `main`. The next convergence applies the previous desired
state; nothing was changed out of band, so there is nothing else to undo.

## Common failures

- **An applied migration's file changed**: the run stops rather than guess.
Restore the file and write the change as a new migration.
- **The database is unreachable**: the infrastructure lane it depends on has
not applied for this environment; that lane runs first in a convergence.
34 changes: 34 additions & 0 deletions infra/terraform/supabase/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# supabase — architecture

A `terraform` root at `infra/terraform/supabase/terraform`.

- **State** lives in the Orun Cloud HTTP state backend — no local state and
no state bucket to manage.
- **Credentials are brokered per run** from the workspace's provider
connections and resolved by name; none is stored in this repository.
- **Adoption** (`adopt.tf`): when state is empty but the resource already
exists, plan-time import adopts it instead of failing.

## Resources

- `random_password.db_password`
- `supabase_project.this`
- `terraform_data.project_ready`
- `supabase_settings.this`

## Published outputs

Written as job-output secrets on each environment after an apply; deploy
lanes downstream resolve them by name.

| Secret | Terraform output |
| ---------------------- | ------------------- |
| `SUPABASE_PROJECT_REF` | `project_ref` |
| `SUPABASE_DB_PASSWORD` | `database_password` |
| `SUPABASE_DB_URL` | `connection_uri` |
| `WIRING_SUPABASE` | `wiring` |

## Resolved at run time (names only)

- `SUPABASE_ACCESS_TOKEN`
- `TF_VAR_supabaseOrgId`
20 changes: 20 additions & 0 deletions infra/terraform/supabase/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# supabase

Provisions Supabase projects for stage and prod, points their Auth at the app, and wires the database credentials and the app's URL and keys into orun secrets

Terraform-managed infrastructure, planned and applied per environment by its CI lane.

| | |
| ------------ | ---------------------------------------------------------------------------------------------------- |
| Type | `terraform` |
| Source | `infra/terraform/supabase` |
| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` |

## Depends on

- (none)

## Depended on by

- **db-migrate** — Applies database migrations to stage and prod Supabase instances
- **web** — The Next.js Subscription Payments Starter — Supabase Auth, Stripe Checkout, Customer Portal and webhooks (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)
20 changes: 20 additions & 0 deletions infra/terraform/supabase/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# supabase — runbook

## How it runs

Pull requests plan it; a merge to `main` applies it to `stage`, `prod`.
CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;
the plan orders a component after everything it depends on.

## Rollback

Revert the commit on `main`. The next convergence applies the previous desired
state; nothing was changed out of band, so there is nothing else to undo.

## Common failures

- **Provider authentication fails**: the workspace's provider connection is
missing or revoked. Reconnect it in the console; credentials are brokered
from it per run.
- **"Already exists" on a first apply**: state is empty but the resource is
not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform.
11 changes: 0 additions & 11 deletions kiox.lock

This file was deleted.

6 changes: 0 additions & 6 deletions kiox.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions packages/db/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# db — architecture

A workspace package at `packages/db`, consumed by the components that depend
on it. It has no deployed surface of its own.

## Exports

- `.`
- `./manifest`
- `./runner`
- `./types`
20 changes: 20 additions & 0 deletions packages/db/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# db

The database migrations and their runner (built by the db-migrate component before it plans or applies)

A workspace package built by the turbo pipeline. It deploys nothing itself: its lane type-checks, lints, tests and builds it.

| | |
| ------------ | --------------------------------------------------------------------- |
| Type | `turbo-package` |
| Source | `packages/db` |
| Package | `@saas/db` |
| Environments | `dev`: `quick-check` · `stage`: `quick-check` · `prod`: `quick-check` |

## Depends on

- (none)

## Depended on by

- **db-migrate** — Applies database migrations to stage and prod Supabase instances
Loading
Loading