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
1 change: 1 addition & 0 deletions specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace.

| Epic | Cluster | Status | What it is |
|------|---------|--------|------------|
| [`admin-dashboard/`](./admin-dashboard/) | **AD** | In progress (AD0) | Vercel's Admin Dashboard — a products table, Auth.js with GitHub sign-in — on Cloudflare Workers with Supabase Postgres through Hyperdrive, and an Orun baseline that instantiates it in one landing (AD2) |

As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`.
11 changes: 11 additions & 0 deletions specs/epics/admin-dashboard/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# admin-dashboard — implementation status

| Milestone | State | Landed |
|---|---|---|
| AD0 — the spec | ✅ | AD-1 |
| AD1 — the dashboard on Workers and Supabase | planned | AD-2 |
| AD2 — a baseline | planned | AD-3 |

## Departures from the upstream template

Recorded as they land, from AD1 on.
33 changes: 33 additions & 0 deletions specs/epics/admin-dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# admin-dashboard — Vercel's Admin Dashboard on Cloudflare

**The template's dashboard as it is — the products table, search and paging,
the customers page, Auth.js with GitHub, shadcn/ui — on one Cloudflare
Worker, its Postgres a Supabase project behind Hyperdrive, the schema, the
seed and the session key applied before the Worker deploys; and the
baseline that makes a copy of it somebody else's product in one landing.**

| | |
|---|---|
| Status | In progress — AD0 on main |
| Upstream | [vercel/nextjs-postgres-nextauth-tailwindcss-template](https://github.com/vercel/nextjs-postgres-nextauth-tailwindcss-template) (MIT), Vercel's [Admin Dashboard](https://vercel.com/templates/next.js/admin-dashboard), at `fe02671` |
| Reference | [postgres-drizzle-starter](https://github.com/sourceplane/postgres-drizzle-starter) — Supabase through Hyperdrive, migrations, db-migrate, row-level security; [ai-chatbot](https://github.com/sourceplane/ai-chatbot) — Auth.js on Workers, the session key generated in the database |
| Key | `AD` |

## Read in this order

1. [design.md](design.md) — the template, how each Vercel piece maps to
Cloudflare and Supabase, the repository and the build, and the
alternatives rejected.
2. [implementation-plan.md](implementation-plan.md) — the milestones.
3. [risks-and-open-questions.md](risks-and-open-questions.md) — what is not
proven, and what was accepted.
4. [IMPLEMENTATION-STATUS.md](IMPLEMENTATION-STATUS.md) — what shipped, and
every departure from the upstream template.

## Milestones

| Milestone | What it lands | Task |
|---|---|---|
| AD0 — the spec | the repository, its intent, CI, tooling and spec index; this doc set | AD-1 |
| AD1 — the dashboard on Workers and Supabase | the template in `apps/web`, its schema, products and session key as migrations, the Supabase and Hyperdrive roots, the tests | AD-2 |
| AD2 — a baseline | the console card, the build document, the context pack and the baseline's tests | AD-3 |
92 changes: 92 additions & 0 deletions specs/epics/admin-dashboard/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# admin-dashboard — design

## The template

Vercel's Admin Dashboard ([vercel/nextjs-postgres-nextauth-tailwindcss-template](https://github.com/vercel/nextjs-postgres-nextauth-tailwindcss-template))
is a Next.js 15 App Router app: a dashboard layout (a sidebar, a mobile
sheet, breadcrumbs, a search box and a user menu) around a products page — a
`products` table with a `status` enum read through Drizzle, five rows a page
with the total, and a search by name over the whole table — and an empty
customers page, all in shadcn/ui and Tailwind CSS. Auth.js (`next-auth`
5.0.0-beta.25) signs visitors in with GitHub (JWT sessions, no database
adapter) and runs as the middleware on every page; the dashboard itself is
visible signed-out, the user menu offering Sign In or Sign Out. On Vercel it
uses Vercel Postgres through `@neondatabase/serverless`, a module-level
client; its owner creates the table by hand in the Postgres dashboard, then
uncomments `/api/seed` and requests it once for ten demo products, and sets
`AUTH_SECRET`, `AUTH_GITHUB_ID` and `AUTH_GITHUB_SECRET`. Vercel Analytics is
in both layouts.

## How it maps to Cloudflare and Supabase

| Vercel | Here | Why |
|---|---|---|
| Next.js hosting | One Worker (`.open-next/worker.js`) + Static Assets, built by `@opennextjs/cloudflare` | The reference's shape |
| Vercel Postgres, `drizzle(neon(POSTGRES_URL))` at module scope | A Supabase project's Postgres through the `HYPERDRIVE` binding: `getSql()` builds a `postgres` client per call, `getDb()` wraps it in Drizzle | The Workers runtime refuses to reuse a socket across requests (the reference's decision 1) |
| The table created by hand | `packages/db`'s `010_products` (drizzle-kit's output, idempotent), applied by `infra/db-migrate` before the Worker deploys, and `020_row_level_security` | One schema, applied in order, recorded in a ledger |
| `/api/seed`, uncommented and requested once | `030_seed_products`: the same ten rows, keyed on their ids, the `serial` sequence moved past them | Nobody has to request a route, and no route is left for anybody else to request |
| `AUTH_SECRET`, set by the owner | `040_app_secrets` generates 64 hex characters into `app_private.secrets` once per database; `lib/auth-secret.ts` reads it (once per isolate) unless `AUTH_SECRET` is a Worker secret | A product comes up with nothing typed; ai-chatbot's AC5 |
| `AUTH_GITHUB_ID`, `AUTH_GITHUB_SECRET` | Optional Orun secrets per environment, inlined into the server bundle at build (`next.config.mjs` `env`); unset, Auth.js has no provider and `/login` says how to connect GitHub | Only the owner can create an OAuth App, and the product must deploy before they do |
| `middleware.ts` (Auth.js on every page, edge runtime) | `proxy.ts`, on Next.js 16's Node.js runtime | The proxy must read the session key from Postgres, which the edge runtime cannot reach |
| Next.js 15 | Next.js 16.3.8 | The reference's pin and the one OpenNext proxies run on (ai-chatbot); see Alternatives |
| Vercel's image optimiser | `images.unoptimized`: the product photos (still on Vercel Blob, as the template hosts them) and GitHub avatars load from their hosts | No optimiser on Workers |
| Vercel Analytics | Removed | Vercel's |
| "Deploy with Vercel" | `orun new --blueprint repo-blueprint.yaml` | One landing to live |

Every table in `public` has row-level security and no policy, and the
session key is in `app_private`, so Supabase's Data API — which serves
`public` to the project's public anon key — reads nothing; the app connects
as the tables' owner and is not subject to it.

## The repository

postgres-drizzle-starter's shape: `infra/terraform/supabase` (one project
per deployed environment, its credentials lease-published),
`infra/terraform/cloudflare-hyperdrive` (one config over it, its id
published as `WIRING_CLOUDFLARE_HYPERDRIVE`), `packages/db` (`@saas/db`: the
migrations and Lumen's runner, through Supabase's Management API),
`infra/db-migrate`, `apps/web` (type `cloudflare-workers-assets-turbo`,
depending on Hyperdrive and db-migrate, enforced on main), `tests/web` and
`tests/db`. The product's name is one seam, `SITE_NAME` in
`apps/web/lib/site.ts`: the page title and the dashboard's home link (the
template's `Acme Inc` and `Vercel` labels). Vercel's page for the template
is `…/templates/next.js/admin-dashboard…`, this baseline's slug, so the
rename engine masks it (`UPSTREAM` in `tooling/rebrand/rebrand.mjs`).

## The build

`next build` (Turbopack), `opennextjs-cloudflare build`, then the
static-assets cache populated. `/login` is pre-rendered (the GitHub keys are
build-time values); every other page renders per request. The build takes
no origin: nothing the dashboard renders is an absolute URL, and Auth.js
reads the origin from each request (`trustHost`). The Worker is about
2.0 MiB gzipped — Workers Free.

`repo-blueprint.yaml` is postgres-drizzle-starter's: one landing
(`01-product`), one convergence that applies the Supabase project, the
Hyperdrive config and the migrations, and deploys stage and prod side by
side, then `02-docs`, the record, which also probes whether GitHub sign-in
is connected. The smoke checks the dashboard's products card and
`/api/health`.

## Alternatives rejected

- **Keep Next.js 15 and its edge middleware.** The middleware needs the
session key, which lives in Postgres; the edge runtime has no TCP socket
for `postgres`. Next.js 15.5's Node.js middleware on OpenNext is no better
proven than 16's proxy, and 16.3.8 is what the reference and ai-chatbot
already run.
- **A seed route kept for the owner.** Anyone could request it; a migration
runs once, before the Worker serves.
- **GitHub keys as Worker secrets.** The workers-assets composition does not
push runtime secrets, and a key set with `wrangler secret put` is outside
the repository's secrets; inlining at build is how the other SaaS-key
starters do it (cms-contentful).
- **Drop the proxy.** It only refreshes the session cookie, but it is the
template's, and keeping it costs one cached read per isolate.

## Out of scope

- Real product actions. Upstream's delete action is commented out and its
Add Product and Export buttons do nothing; they are kept as they are.
- A users table or an Auth.js database adapter: upstream has none.
30 changes: 30 additions & 0 deletions specs/epics/admin-dashboard/epic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# The epic's declaration. metadata.name equals the directory name; metadata.key
# is the task-key prefix this epic reserves (AD → AD-1, AD-2, …). Owner, target
# date and health are the platform's — never written here.
apiVersion: orun.io/v1
kind: Epic
metadata:
name: admin-dashboard
key: AD
spec:
title: "Vercel's Admin Dashboard on Cloudflare Workers and Supabase"
summary: "Vercel's Next.js Admin Dashboard — a products table with search and paging read through Drizzle, a customers page, Auth.js with GitHub sign-in, shadcn/ui and Tailwind — run on Cloudflare Workers + Static Assets through @opennextjs/cloudflare, its Postgres a Supabase project reached through Hyperdrive, both provisioned by Terraform; the schema, the template's products and the session key applied by db-migrate; GitHub sign-in connected by its owner after the build; and become an Orun baseline that takes a new product from nothing to live on stage and prod in one landing."
state: started
milestones:
- name: "AD0 — the spec"
exitCriteria:
- "the repository is born with its intent, CI, tooling and spec index, and this doc set and the task contracts are on main"
tasks: [AD-1]
- name: "AD1 — the dashboard on Workers and Supabase"
exitCriteria:
- "apps/web is the template on Next.js 16.3.8, built by OpenNext into one Worker, its Postgres the HYPERDRIVE binding with a client per request, Auth.js through the proxy"
- "the products table, the template's ten products and the session key are packages/db migrations, applied by db-migrate; the Supabase and Hyperdrive roots provision stage and prod"
- "with no GitHub OAuth App the dashboard builds, serves signed-out and its login page says how to connect one; with one it offers GitHub sign-in"
- "`pnpm typecheck`, `pnpm lint`, `pnpm test` and `pnpm build` are green"
tasks: [AD-2]
- name: "AD2 — a baseline"
exitCriteria:
- "blueprint.yaml (the console card) and repo-blueprint.yaml (the build) take a new product from nothing to live on stage and prod in one landing, then record it"
- "a product built from it carries the product only, renamed throughout to its own name, repository, Worker, Supabase project and Hyperdrive config"
- "Baseline CI is green: contract tests, generated component docs, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the end-to-end tier"
tasks: [AD-3]
47 changes: 47 additions & 0 deletions specs/epics/admin-dashboard/implementation-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# admin-dashboard — implementation plan

Three milestones, each one reviewed pull request (AD0 is the repository's
first commit and its spec), each green before it merges.

## AD0 — the spec (AD-1)

The repository is born: `intent.yaml` with the placeholder workspace
`ws_CHANGE_ME`, `ci.yml` (byte for byte turso-starter's, with the comment
lines postgres-drizzle-starter's own copy changes), the shared TypeScript
and ESLint configuration, the wiring renderer and migration helpers, the
spec index, this doc set and the task contracts.

## AD1 — the dashboard on Workers and Supabase (AD-2)

- The template in `apps/web` on Next.js 16.3.8: `lib/db.ts`'s queries over
`getDb()` (`lib/sql.ts`, a client per request through `HYPERDRIVE`), the
schema in `lib/schema.ts` with `.enableRLS()`, `middleware.ts` as
`proxy.ts`, Vercel Analytics removed, `images.unoptimized`, ESLint in
eslint-config-next 16's flat form.
- Auth.js resolved per request (`lib/auth.ts`): the session key from
`lib/auth-secret.ts`, GitHub from `lib/github.ts` only when its OAuth App
is set; `/login` says how to connect it until then.
- `lib/site.ts` (the name seam), `app/api/health/route.ts`.
- `wrangler.template.jsonc` + `wiring.fixture.json`, `component.yaml`
(the GitHub keys as optional secrets, the smoke).
- `packages/db`: `010_products`, `020_row_level_security`,
`030_seed_products`, `040_app_secrets`, and their drizzle-kit twins; the
Supabase and Hyperdrive roots; `infra/db-migrate`.
- `tests/web` (the client, the queries, the session key, Auth.js's sessions
and providers, the login page, the health check, the wrangler config) and
`tests/db` (the manifest, the twins, the seed and the key, row-level
security, on PGlite).

## AD2 — a baseline (AD-3)

postgres-drizzle-starter's machinery on this tree: `blueprint.yaml`,
`repo-blueprint.yaml` (five brokered keys), `.baseline/` (identity, the
product's README with "Connecting GitHub sign-in", task contracts), the
rename engine (the template's Vercel page masked), the bootstrap helpers,
the record renderer (probing `/`, `/api/health` and `/api/auth/providers`),
`docs/phases/`, the context pack, and `testing/` — the leak and placement
gates (the GitHub refs optional in the product's own plan), and the e2e tier
that migrates the stage database through a stand-in Supabase API, then
serves the built Worker over it: the seeded products, both pages and the
search, the login page with GitHub not connected, a session under the
database's key, and the Data API's roles refused.
13 changes: 13 additions & 0 deletions specs/epics/admin-dashboard/risks-and-open-questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# admin-dashboard — risks and open questions

| ID | Risk | State | Notes |
|---|---|---|---|
| AD-A | `baseline-v1` is not yet proven live | OPEN | Proven offline in Baseline CI: the offline bootstrap with the blueprint's own hooks, the lanes' own steps in staged job trees (the migrations applied through a stand-in Supabase Management API over a real Postgres with Supabase's roles), and the built Worker served by `wrangler dev` over it. A live bootstrap needs a workspace with Cloudflare and Supabase connected and room for two Supabase projects (AD-E) |
| AD-B | Node.js proxy on OpenNext | ACCEPTED | `opennextjs-cloudflare build` says Node.js middleware support is experimental and not maintained by OpenNext. ai-chatbot runs the same shape; the e2e tier serves every page through it, eight concurrent first requests included |
| AD-C | `next-auth` 5.0.0-beta.25 under Next.js 16 | ACCEPTED | The template's pin; its peer range stops at Next.js 15, and pnpm warns. `tests/web` drives its real handlers and the e2e serves its sessions; ai-chatbot runs the same pair. A later beta (≥ 5.0.0-beta.30) admits 16 and is a deliberate bump |
| AD-D | The GitHub OAuth App's secret is in the server bundle | ACCEPTED | `next build` inlines `AUTH_GITHUB_SECRET` into the Worker's script, so anyone who can read the account's Workers scripts can read it — the same boundary as the cms-contentful tokens. A composition that pushes runtime secrets would move it into a Worker secret |
| AD-E | Two Supabase projects per product | ACCEPTED | Stage and prod are a project each; the free plan allows two active projects per organization. BOOTSTRAP.md lists it as a prerequisite |
| AD-F | The product photos are on Vercel Blob | ACCEPTED | The seed keeps the template's image URLs, as the reference keeps its avatars on Contentful's CDN. If they go, the photos break and nothing else does; any product's own photos replace them |
| AD-G | Hyperdrive's read cache | ACCEPTED | A product changed in the SQL editor shows within about a minute. The dashboard writes nothing (upstream's delete is commented out), so it never reads back its own write |
| AD-H | The session key lives in the database | ACCEPTED | Generated by `040_app_secrets` in `app_private`; whoever can read the database can forge a session. An `AUTH_SECRET` Worker secret overrides it |
| AD-I | stack-tectonic 0.19.0, not 0.20.0 | ACCEPTED | 0.20.0's lane-shared install links `node_modules` out of the job's tree, which Turbopack refuses (`intent.yaml` says why) |
15 changes: 15 additions & 0 deletions tasks/AD-1.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: AD-1
title: "The spec"
spec:
goal: The admin-dashboard repository is born with its intent, CI, tooling and spec index, and the admin-dashboard epic — declaration, doc set and task contracts — is on main
affects:
- specs/epics/admin-dashboard
- specs/epics/README.md
- tasks
doneWhen:
- epic.yaml, README, design, implementation plan, risks and status are on main
- the three task contracts exist
gates: []
21 changes: 21 additions & 0 deletions tasks/AD-2.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: AD-2
title: "The dashboard on Workers and Supabase"
spec:
goal: The admin dashboard runs on Cloudflare Workers + Static Assets with its Postgres a Supabase project reached through Hyperdrive, its schema, products and session key as migrations applied by db-migrate, the Supabase and Hyperdrive roots provisioning stage and prod, and GitHub sign-in connected after the build
affects:
- apps/web
- packages/db
- infra
- tests
- tooling/migrations
- pnpm-lock.yaml
- pnpm-workspace.yaml
- README.md
- .gitignore
doneWhen:
- pnpm typecheck, lint, test and build are green
- the built Worker serves the dashboard over a migrated database, reads sessions under the key the database generated, and says GitHub sign-in is not connected until it is
gates: []
27 changes: 27 additions & 0 deletions tasks/AD-3.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: AD-3
title: "admin-dashboard becomes an Orun baseline"
spec:
goal: blueprint.yaml and repo-blueprint.yaml take a new admin dashboard from nothing to live on stage and prod in one landing, held by Baseline CI
affects:
- blueprint.yaml
- repo-blueprint.yaml
- BOOTSTRAP.md
- .baseline
- .github/workflows/baseline.yml
- .github/workflows/tag.yml
- ai/context
- docs/phases
- hooks
- testing
- tooling/rebrand
- tooling/bootstrap
- tooling/catalog
- specs/epics/admin-dashboard
- README.md
doneWhen:
- every Baseline CI tier is green
- a product placed from it carries the product only, branded
gates: []
Loading