4.4 KiB
4.4 KiB
Default to using Bun instead of Node.js.
- Use
bun <file>instead ofnode <file>orts-node <file> - Use
bun testinstead ofjestorvitest - Use
bun build <file.html|file.ts|file.css>instead ofwebpackoresbuild - Use
bun installinstead ofnpm installoryarn installorpnpm install - Use
bun run <script>instead ofnpm run <script>oryarn run <script>orpnpm run <script> - Use
bunx <package> <command>instead ofnpx <package> <command> - Bun automatically loads .env, so don't use dotenv.
APIs
Bun.serve()supports WebSockets, HTTPS, and routes. Don't useexpress.bun:sqlitefor SQLite. Don't usebetter-sqlite3.Bun.redisfor Redis. Don't useioredis.Bun.sqlfor Postgres. Don't usepgorpostgres.js.WebSocketis built-in. Don't usews.- Prefer
Bun.fileovernode:fs's readFile/writeFile - Bun.$
lsinstead 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.serveroutes and WebSockets,bun:sqliteorBun.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>(defaultsqlite://./data/stcourses.db) orpostgres://.... 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.jsonhas"license": "AGPL-3.0-only". - Never write into
/home/user/functional-programming-courseor/home/user/systemic-design-course; their manifests are overlays inoverlays/. - 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.