Personal cycling-training app https://trainer.kreidl.org
  • TypeScript 81.8%
  • JavaScript 15%
  • HTML 2.2%
  • Batchfile 0.4%
  • Shell 0.3%
  • Other 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
chris-kreidl 2955238bb6
Merge pull request #330 from chris-kreidl/chore/self-host
Self-host on Coolify (Vultr VPS)
2026-12-04 00:50:40 -05:00
.claude Vendor Impeccable 4.9.0 into .claude instead of installing it from the marketplace 2026-11-20 10:59:09 -05:00
.github/workflows Postgres 18 in production, CI and local 2026-12-04 00:27:33 -05:00
.impeccable Log out, History in: no Log page, History a destination 2026-11-10 22:19:40 -05:00
docs Architecture: Coolify stop grace period covers the shutdown drain 2026-12-04 00:46:58 -05:00
e2e Review fixes for #323: archived bikes on their own loader, shared row action, bikes e2e flow 2026-11-20 23:43:45 -05:00
evals update recording fixtures 2026-11-18 10:32:19 -05:00
fixtures Map: bun run map:refresh brings stored tiles to the latest build 2026-11-07 17:41:17 -05:00
prisma Hide a set distance from each end of a ride's route (default plus per-ride override) 2026-11-20 21:12:42 +00:00
prompts Ignore claude-code-action's .claude-pr/; review checklist checks AI request settings across calls 2026-11-21 00:20:52 -05:00
public Review fixes: offline page links to Today, refused-writes sheet survives a retry, retired Log pages leave the cache 2026-11-10 22:27:43 -05:00
scripts Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
src Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
.dockerignore Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
.env.example Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
.gitattributes Keep ride fixtures byte-for-byte 2026-09-30 22:29:17 -04:00
.gitignore Ignore claude-code-action's .claude-pr/; review checklist checks AI request settings across calls 2026-11-21 00:20:52 -05:00
.prettierignore Vendor Impeccable 4.9.0 into .claude instead of installing it from the marketplace 2026-11-20 10:59:09 -05:00
.prettierrc.json Scaffold TanStack Start on Bun with StyleX and Base UI 2026-09-29 23:26:17 -04:00
.vercelignore Configure Vercel: Node 22 runtime, build-time migrations, preview-aware auth URL 2026-09-30 20:59:18 -04:00
bun.lock Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
CLAUDE.md Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
compose.yaml Postgres 18 in production, CI and local 2026-12-04 00:27:33 -05:00
DESIGN.md A real dark mode, and a night route map 2026-11-11 01:13:28 -05:00
Dockerfile Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
eslint.config.js Ignore claude-code-action's .claude-pr/; review checklist checks AI request settings across calls 2026-11-21 00:20:52 -05:00
package.json Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00
playwright.config.ts Maps 2/4: cache each outdoor ride's base-map tiles 2026-11-07 08:41:13 -05:00
prisma.config.ts Cycling only: take strength out of the app 2026-11-08 19:26:39 -05:00
PRODUCT.md Docs for the roadbook redesign; theme-color, manifest and map greys follow it 2026-11-08 09:09:49 -05:00
README.md README: note the development bot 2026-11-20 15:15:00 +00:00
tsconfig.json Ride planned sessions and free rides in ERG over Web Bluetooth, saved as rides 2026-10-18 10:31:53 -04:00
vite.config.ts Self-host on Coolify: Docker image, background work drained on shutdown, tiles on disk 2026-12-04 00:23:26 -05:00

Trainer

Personal cycling-training app with strength work alongside the bike. An AI coach builds a periodised plan, every ride gets a TSS, and the plan re-plans itself after each session. Single user, sign-up closed.

Spec: docs/requirements.md. Working rules: CLAUDE.md. Session state: docs/PROGRESS.md.

Local setup

Needs Bun 1.4.x and Docker: the local database is Postgres 17 in a container (compose.yaml).

bun install                 # also runs `prisma generate`
cp .env.example .env        # then set BETTER_AUTH_SECRET (openssl rand -base64 32)
bun run db:dev              # start the local Postgres (restarts with Docker; data in a volume)
bun run db:migrate          # apply migrations, regenerate the client
bun run db:seed             # 45-exercise strength library
bun run user:create         # the one owner account (name, email, password)
bun dev                     # http://localhost:3000

Sign in with your password, then register a passkey under Settings.

Everyday commands

Command What it does
bun dev Vite dev server on port 3000
bun test Unit tests; DB-backed tests skip without DATABASE_URL
bun run typecheck / lint / format Bun check, ESLint, Bun fmt
bun run format:check / audit Bun format check, dependency advisories (both run in CI)
bun run test:e2e Playwright flows on a production build (needs bun run db:dev)
bun run build then bun run start Production build, served locally with Bun
bun run db:migrate New migration from schema changes, then regenerate the client
bun run db:reset Wipe the local database, re-migrate and re-seed
bun run db:studio Prisma Studio

Environment variables

Variable Local (.env) Vercel Preview Vercel Production
DATABASE_URL localhost:5432 (.env.example) Preview database (Prisma Console, direct postgres:// URL) Its own database, not shared with Preview
BETTER_AUTH_SECRET random, 32+ bytes random, set as Sensitive random, different from Preview
BETTER_AUTH_URL http://localhost:3000 not set: derived from VERCEL_BRANCH_URL / VERCEL_URL the production URL
ANTHROPIC_API_KEY, AI_* from session 11 from session 11 from session 11

Keep DATABASE_URL out of Vercel's Development environment. vercel env pull writes it to .env.local, which Bun loads ahead of .env, so local work would quietly hit the cloud database.

Passkeys are tied to one hostname. On previews they work on the URL the app derives (the branch URL when there is one, else the deployment URL). Password sign-in works on any of the deployment's URLs.

Deploy

The code is on a private GitHub repo (chris-kreidl/trainer). .github/workflows/ci.yml runs typecheck, lint, format check, the dependency audit and bun test (DB tests against Postgres 17) on every pull request and on main.

Production deploys from Git. The Vercel project is connected to the repo with main as its production branch, so merging a pull request deploys it to production (https://trainer.kreidl.org). vercel.json git.deploymentEnabled builds main only: session branches and PRs get no automatic preview, since every preview build would run its migrations against the one shared preview database. Roll back with vercel rollback or Instant Rollback in the dashboard; a rollback doesn't undo migrations, which is one reason they stay additive.

For a preview, deploy from the CLI:

vercel deploy --target preview --yes

Always pass --target. Vercel's docs say a bare vercel deploy makes a preview, but in session 05, before the project was connected to Git, a bare deploy here made a production deployment.

A Vercel build runs bun run build:vercel:

  1. prisma generate, because Bun can skip postinstall on a cached install.
  2. prisma migrate deploy against that environment's own DATABASE_URL (Preview and Production have separate databases).
  3. vite build, where Nitro's Vercel preset writes .vercel/output.
  4. scripts/check-vercel-runtime.ts, which fails the build unless the function runtime is bun1.4.x.

To create the owner on a cloud database, run this from your own terminal so the URL and password stay local:

DATABASE_URL='<direct postgres:// URL>' bun run db:seed
DATABASE_URL='<direct postgres:// URL>' bun run user:create

Previews sit behind Vercel's Deployment Protection. For scripted requests, use vercel curl <path> --deployment <url>.

Development bot

Label an issue ready and roboziggy, the owner's GitHub bot, picks it up: it asks questions on the issue or opens a pull request. The bot:* labels show where it is; see CLAUDE.md for what they mean.

Why the server runs on Bun

The requirements started on Node 22 with a Bun spike (session 05, branch spike/bun-vercel). Measured on the same preview from iad1:

Node 22 Bun 1.4.1
Cold /login, first request on a fresh deployment 0.98 s, 1.02 s 0.90 s, 1.30 s
Warm /login, median of 10 0.32 s 0.27 s
Warm server function, median of 10 0.25 s 0.26 s

A static file took 0.20–0.25 s, so most of each request is network. Auth, cookies, passkeys, the Prisma pg adapter and password hashing all worked on Bun. With no speed difference either way, the owner chose Bun: this is a personal app, and running it on Bun end to end is the point.

The catch is configuration. "bunVersion": "1.4.x" alone gives Bun 1.3.14, because Nitro writes runtime: "bun1.x" into the function config. engines.node in package.json overrides bunVersion entirely. So vite.config.ts pins Nitro's Vercel runtime to bun1.4.x, package.json has no engines, and the build check above catches any regression. To go back to Node, set the Nitro runtime to nodejs22.x, remove bunVersion, and drop the check.