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 @@ -51,6 +51,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
41 changes: 41 additions & 0 deletions ai/context/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# postgres-drizzle-starter β€” 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 Postgres + Drizzle Next.js Starter β€” one page that reads a
`profiles` table with Drizzle β€” on Cloudflare Workers + Static Assets, with
the database a Supabase Postgres project reached through Hyperdrive, 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`: supabase β†’ cloudflare-hyperdrive β†’ db-migrate β†’ web
per environment), then records what went live (`02-docs`).

## Release

| | |
|---|---|
| Latest tag | `baseline-v1` (PD4) |
| On `main` since | PD5 β€” 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, a migrated local Postgres served through the built Worker included; a live bootstrap from a tag is still to come (risk PD-J) |

## Where to read

| Question | Page |
|---|---|
| What shipped, and every departure from upstream | `specs/epics/postgres-drizzle-starter/IMPLEMENTATION-STATUS.md` |
| Why it is built this way | [decisions.md](decisions.md), then `specs/epics/postgres-drizzle-starter/design.md` |
| What could still go wrong | [open-risks.md](open-risks.md), then `specs/epics/postgres-drizzle-starter/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,cloudflare-hyperdrive}`, `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 connections and room for two Supabase projects (PD-F), and
record its timings (closes PD-J).
2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin PD5.
20 changes: 20 additions & 0 deletions ai/context/decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# postgres-drizzle-starter β€” 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 | A Postgres client per request (`getSql()`/`getDb()`), Hyperdrive's connection string first, `POSTGRES_URL` as the fallback without a Cloudflare context | The Workers runtime refuses to share a socket across requests; Hyperdrive pools on Cloudflare's side | `specs/epics/postgres-drizzle-starter/design.md` Β§2, risk PD-A |
| 2 | Drizzle over a socket to Supabase Postgres through Hyperdrive, not Supabase's PostgREST client | The template's point is Drizzle and its schema file; PostgREST would replace both | design.md Β§2 |
| 3 | The `profiles` table is `db-migrate`'s (`packages/db`), applied before the Worker deploys; the page seeds only rows, on an empty table β€” superseding PD0's "seed on first use, no migrations for one table" | `CREATE TABLE IF NOT EXISTS` is not safe under concurrent first requests (2 of 160 racing sessions failed) | risk PD-B, IMPLEMENTATION-STATUS (PD4) |
| 4 | Row-level security on every table in `public`, with no policy | Supabase's Data API serves `public` to the public anon key; the app connects as the table's owner | risk PD-E |
| 5 | `wrangler.jsonc` committed as the fixture render; stage and prod re-render it from their wiring document | The composition checks for it before the build | epic README (decision 3), design.md Β§4 |
| 6 | One landing (`01-product`) then the record (`02-docs`); every edge `mode: enforced` on main, advisory on a pull request | One convergence runs supabase β†’ cloudflare-hyperdrive β†’ db-migrate β†’ web per environment (cirrus-baseline v22's shape) | IMPLEMENTATION-STATUS (PD4), design.md Β§4 |
| 7 | The migrations package is named `@saas/db` | stack-tectonic's db-migrate composition builds `--filter=@saas/db` | risk PD-H |
| 8 | The read-back after a seed calls `NOW()` | Hyperdrive's read cache would otherwise serve the empty answer for up to a minute | risk PD-I |
| 9 | `ci.yml` plans nothing while `intent.yaml` names `ws_CHANGE_ME` (the `linked` step) | A bootstrap cannot set a repository variable (replaced the `ORUN_CI` gate) | IMPLEMENTATION-STATUS (PD4) |
| 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0's lane-scoped install is refused by Turbopack | IMPLEMENTATION-STATUS (PD4) |
| 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 (PD5) |
| 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph, bindings and migrations drifts silently | `tooling/catalog/gen-component-docs.py` |
14 changes: 14 additions & 0 deletions ai/context/open-risks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# postgres-drizzle-starter β€” 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/postgres-drizzle-starter/risks-and-open-questions.md`; this page
lists only what is still live, so it should be short.

| ID | Risk | State | What closes it |
|---|---|---|---|
| PD-J | No live bootstrap yet: the repository created and linked, the five keys minted, real Terraform applies of the Supabase projects and Hyperdrive configs, a `db-migrate` apply against a real Supabase project, a real `wrangler deploy`, Hyperdrive's read cache and the probes are all unproven | OPEN | One bootstrap from a tag against a workspace with Cloudflare and Supabase connections |

Accepted, and worth knowing before you change them: PD-A (a client per
request), PD-F (two Supabase projects per product β€” an owner prerequisite on
the free plan), PD-H (the migrations package is named `@saas/db`).
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 |
| ------------ | ---------------------------- | -------------------------------------------- |
| `HYPERDRIVE` | Hyperdrive (pooled Postgres) | `hyperdrive_id` from `cloudflare-hyperdrive` |
| `ASSETS` | Static assets | `.open-next/assets` |

Identifiers marked _from_ a component are filled in at deploy time from
that component's published outputs for the environment being deployed.

## Wiring

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

- `WIRING_CLOUDFLARE_HYPERDRIVE_PROD`
- `WIRING_CLOUDFLARE_HYPERDRIVE_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 profiles table demo (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

- **cloudflare-hyperdrive** β€” Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases
- **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 'Recent Users' && 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_profiles`
- `020_row_level_security`

## Resolved at run time (names only)

- `SUPABASE_ACCESS_TOKEN`
- `SUPABASE_DB_PASSWORD`
- `SUPABASE_DB_URL`
- `SUPABASE_PROJECT_REF`
21 changes: 21 additions & 0 deletions infra/db-migrate/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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 and wires credentials into orun secrets
- **cloudflare-hyperdrive** β€” Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases

## Depended on by

- **web** β€” The profiles table demo (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.
31 changes: 31 additions & 0 deletions infra/terraform/cloudflare-hyperdrive/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# cloudflare-hyperdrive β€” architecture

A `terraform` root at `infra/terraform/cloudflare-hyperdrive/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

- `cloudflare_hyperdrive_config.postgres`

## Published outputs

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

| Secret | Terraform output |
| ------------------------------ | ---------------- |
| `WIRING_CLOUDFLARE_HYPERDRIVE` | `wiring` |

## Resolved at run time (names only)

- `CLOUDFLARE_ACCOUNT_ID`
- `CLOUDFLARE_API_TOKEN`
- `TF_VAR_cloudflare_account_id`
- `TF_VAR_supabase_db_password`
- `TF_VAR_supabase_project_ref`
20 changes: 20 additions & 0 deletions infra/terraform/cloudflare-hyperdrive/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cloudflare-hyperdrive

Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases

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

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

## Depends on

- **supabase** β€” Provisions Supabase projects for stage and prod and wires credentials into orun secrets

## Depended on by

- **db-migrate** β€” Applies database migrations to stage and prod Supabase instances
- **web** β€” The profiles table demo (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)
20 changes: 20 additions & 0 deletions infra/terraform/cloudflare-hyperdrive/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cloudflare-hyperdrive β€” 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.
31 changes: 31 additions & 0 deletions infra/terraform/supabase/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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`

## 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` |

## 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 and wires credentials 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

- **cloudflare-hyperdrive** β€” Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases
- **db-migrate** β€” Applies database migrations to stage and prod Supabase instances
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.
Loading
Loading