Files
STCourses/CLAUDE.md
T
2026-10-30 02:47:42 +01:00

4.4 KiB

Default to using Bun instead of Node.js.

  • Use bun <file> instead of node <file> or ts-node <file>
  • Use bun test instead of jest or vitest
  • Use bun build <file.html|file.ts|file.css> instead of webpack or esbuild
  • Use bun install instead of npm install or yarn install or pnpm install
  • Use bun run <script> instead of npm run <script> or yarn run <script> or pnpm run <script>
  • Use bunx <package> <command> instead of npx <package> <command>
  • Bun automatically loads .env, so don't use dotenv.

APIs

  • Bun.serve() supports WebSockets, HTTPS, and routes. Don't use express.
  • bun:sqlite for SQLite. Don't use better-sqlite3.
  • Bun.redis for Redis. Don't use ioredis.
  • Bun.sql for Postgres. Don't use pg or postgres.js.
  • WebSocket is built-in. Don't use ws.
  • Prefer Bun.file over node:fs's readFile/writeFile
  • Bun.$ls instead of execa.

Testing

Use bun test to run tests.

import { test, expect } from "bun:test";

test("hello world", () => {
  expect(1).toBe(1);
});

Frontend

Use HTML imports with Bun.serve(). Don't use vite. HTML imports fully support React, CSS, Tailwind.

Server:

import index from "./index.html"

Bun.serve({
  routes: {
    "/": index,
    "/api/users/:id": {
      GET: (req) => {
        return new Response(JSON.stringify({ id: req.params.id }));
      },
    },
  },
  // optional websocket support
  websocket: {
    open: (ws) => {
      ws.send("Hello, world!");
    },
    message: (ws, message) => {
      ws.send(message);
    },
    close: (ws) => {
      // handle close
    }
  },
  development: {
    hmr: true,
    console: true,
  }
})

HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. <link> tags can point to stylesheets and Bun's CSS bundler will bundle.

<html>
  <body>
    <h1>Hello, world!</h1>
    <script type="module" src="./frontend.tsx"></script>
  </body>
</html>

With the following frontend.tsx:

import React from "react";
import { createRoot } from "react-dom/client";

// import .css files directly and it works
import './index.css';

const root = createRoot(document.body);

export default function Frontend() {
  return <h1>Hello, world!</h1>;
}

root.render(<Frontend />);

Then, run index.ts

bun --hot ./index.ts

For more information, read the Bun API docs in node_modules/bun-types/docs/**.mdx.

Project rules

Full design: docs/superpowers/specs/2026-10-30-stcourses-design.md. Plan: docs/superpowers/plans/2026-10-30-stcourses.md.

  • Bun only: Bun.serve routes and WebSockets, bun:sqlite or Bun.sql, Bun.file, Bun.$, bun test, bun install, bunx. Never express, vite, dotenv, pg, postgres.js, better-sqlite3, jest or vitest.
  • Frontend: a React SPA served via HTML imports. No Next.js. Plain CSS with custom properties; no Tailwind.
  • Course content is never stored in the database. Deleting the DB loses user data only.
  • Database URL is STC_DATABASE_URL: sqlite://<path> (default sqlite://./data/stcourses.db) or postgres://.... Every migration and query must run on both.
  • Idle memory: at most 2 GB for the deployment.
  • License: AGPL-3.0-only. Every package's package.json has "license": "AGPL-3.0-only".
  • Never write into /home/user/functional-programming-course or /home/user/systemic-design-course; their manifests are overlays in overlays/.
  • Never commit anything from /home/user/example_course_content (licensed material, local test runs only).
  • Design tokens (spec 4.1): ground #12141a, side #181b22, raised #232733, line #262a33, line2 #343947; text #d9dce3, reading text #d9d4c8, heading #f2efe8, muted #a4abb8, faint #8c93a0; accent #f1b44c, accent-dim #8c7440. Fonts: IBM Plex Sans (UI), Literata (lesson titles and reading text, 19px / 1.75 in a 660px column), IBM Plex Mono (code). Dark theme only in v1.
  • Keyboard: arrow keys in the slide viewer, Escape closes overlays, normal Tab focus. No other shortcuts.
  • Commits: use the machine's git identity; every message ends with Co-Authored-By: Claude Opus 5.5 <[email protected]>.
  • Paths with spaces and non-ASCII characters must load, serve and download correctly. A broken overlay or manifest yields diagnostics, never a crash. Media serving supports Range (206/416) and returns 404 for paths escaping the course root.