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
40 changes: 40 additions & 0 deletions ai/context/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# turso-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 Next.js + Turso starter — a todo list — on Cloudflare Workers +
Static Assets, with the todos in a D1 database Terraform provisions and a
migration creates, 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`: cloudflare-d1 →
db-migrate → web per environment), then records what went live (`02-docs`).

## Release

| | |
|---|---|
| Latest tag | `baseline-v2` (TU5, one landing); `baseline-v1` is TU4's four-phase build |
| On `main` since | TU6 — 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 migration lane against a stand-in D1 API and a todo round-tripped through the built Worker included; a live bootstrap from a tag is still to come (risk TU-E) |

## Where to read

| Question | Page |
|---|---|
| What shipped, and every departure from upstream | `specs/epics/turso-starter/IMPLEMENTATION-STATUS.md` |
| Why it is built this way | [decisions.md](decisions.md), then `specs/epics/turso-starter/design.md` |
| What could still go wrong | [open-risks.md](open-risks.md), then `specs/epics/turso-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/cloudflare-d1`, `tests/{web,db}` (generated; `python3 tooling/catalog/gen-component-docs.py`) |

## Next

1. Bootstrap one product from a tag against a workspace whose Cloudflare
token can mint D1 Edit as well as Workers Scripts (TU-F), and record its
timings (closes TU-E).
2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin TU6.
20 changes: 20 additions & 0 deletions ai/context/decisions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# turso-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 | `lib/turso.ts` keeps the libSQL client's `execute()` shape over the `DB` D1 binding; the template's SQL runs as written | D1 is SQLite, and so are the template's statements: one file changes | `specs/epics/turso-starter/README.md`, design.md |
| 2 | ~~The table is created on first use, as upstream does~~ — superseded by #3 in TU5 | — | risk TU-A |
| 3 | The schema is a migration (`packages/db`'s `010_todos`), applied by `infra/db-migrate` between the D1 apply and the Worker's deploy; the page never writes DDL | The template said to remove create-on-first-use in production; the convergence's order then includes the schema | risk TU-A, design.md §6 |
| 4 | `app/page.tsx` is `force-dynamic` | The Worker serves pre-rendered pages from a read-only cache, so ISR would never show a new todo | risk TU-D |
| 5 | `wrangler.jsonc` is rendered from the D1 root's wiring document per environment, and the fixture render is committed; dev renders the fixture | The deploy lane checks the config exists before the build; no root applies in dev | risks TU-G, TU-H |
| 6 | One landing (`01-product`) then the record (`02-docs`), replacing TU4's four phases; edges `mode: enforced` on main, advisory on a pull request | The plan, not a landing boundary, orders the database, its schema and the Worker (cirrus-baseline since baseline-v22) | design.md §6 |
| 7 | The D1 apply and the migrations use their own `d1-edit` key (`CLOUDFLARE_D1_TOKEN`) | The `workers-deploy` token cannot touch D1 | design.md §6, risk TU-F |
| 8 | The migrations package is named `@saas/db` | stack-tectonic's db-migrate composition builds `--filter=@saas/db` | risk TU-J |
| 9 | The smoke requires `data-todos="N"` on `/` | Only a Worker that read the migrated table renders it; read-only, so no deploy writes a todo | IMPLEMENTATION-STATUS (TU5) |
| 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0 links the install out of the job's tree, which Next 16's Turbopack refuses | `intent.yaml` (the pin's comment) |
| 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 (TU6) |
| 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` |
16 changes: 16 additions & 0 deletions ai/context/open-risks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# turso-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/turso-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 |
|---|---|---|---|
| TU-E | Not yet proven live: the `d1-edit` mint, the Terraform apply and its wiring publish, the migrations against the real D1 API, the deploy and the workers.dev probes | OPEN | One bootstrap from a tag against a workspace whose Cloudflare token can mint D1 Edit |

Accepted, and worth knowing before you change them: TU-B (D1's limits),
TU-F (a Cloudflare token without D1 Write stops the bootstrap before the
landing), TU-I (the bootstrap floor plans every edge enforced), TU-J (the
migrations package is named `@saas/db`), TU-K (a custom domain is the
owner's step).
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 |
| -------- | ------------- | ------------------------------------- |
| `DB` | D1 database | `d1_database_id` from `cloudflare-d1` |
| `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_D1_PROD`
- `WIRING_CLOUDFLARE_D1_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 todo list (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-d1** — Provisions the Cloudflare D1 todos database for stage and prod
- **db-migrate** — Applies the todos schema (packages/db's migrations) to the stage and prod Cloudflare D1 databases

## 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 -Eq 'data-todos="[0-9]+"'
```

## 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.
16 changes: 16 additions & 0 deletions infra/db-migrate/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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_todos`

## Resolved at run time (names only)

- `CLOUDFLARE_ACCOUNT_ID`
- `CLOUDFLARE_API_TOKEN`
- `WIRING_CLOUDFLARE_D1`
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 the todos schema (packages/db's migrations) to the stage and prod Cloudflare D1 databases

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 todos schema as migrations, and the runner that applies them to D1 (built by the db-migrate component before it plans or applies)
- **cloudflare-d1** — Provisions the Cloudflare D1 todos database for stage and prod

## Depended on by

- **web** — The todo list (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.
29 changes: 29 additions & 0 deletions infra/terraform/cloudflare-d1/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# cloudflare-d1 — architecture

A `terraform` root at `infra/terraform/cloudflare-d1/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_d1_database.platform`

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

## Resolved at run time (names only)

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

Provisions the Cloudflare D1 todos database for stage and prod

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

| | |
| ------------ | ---------------------------------------------------------------------------------------------------- |
| Type | `terraform` |
| Source | `infra/terraform/cloudflare-d1` |
| 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 the todos schema (packages/db's migrations) to the stage and prod Cloudflare D1 databases
- **web** — The todo list (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment)
20 changes: 20 additions & 0 deletions infra/terraform/cloudflare-d1/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cloudflare-d1 — 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 todos schema as migrations, and the runner that applies them to D1 (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` |

## Depends on

- (none)

## Depended on by

- **db-migrate** — Applies the todos schema (packages/db's migrations) to the stage and prod Cloudflare D1 databases
25 changes: 25 additions & 0 deletions packages/db/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# db — runbook

## How it runs

Its lane runs on every pull request that changes it; it has no deployed surface.
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 @saas/db build
pnpm --filter @saas/db typecheck
pnpm --filter @saas/db lint
```

## 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 dependent fails to build after a change here**: run `pnpm typecheck`
across the workspace before merging.
Loading
Loading