From 087b8cdce7c9680227989f316559f79b8981b765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gjermund=20H=C3=B8s=C3=B8ien=20Wiggen?= Date: Sun, 7 Jun 2026 23:31:28 +0200 Subject: [PATCH] Replace auto-generated CLAUDE.md with proper project documentation - Architecture overview (backend + frontend) - Stack details (Bun/Hono/Drizzle + Next.js/shadcn) - How to run locally (backend, frontend, migrations) - API endpoint reference - Key design decisions (sequential IDs, transaction-centric, scrip engine) - Git workflow and common issues --- CLAUDE.md | 184 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 96 insertions(+), 88 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 764c1dd..bbe76d0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,106 +1,114 @@ +# Tessera -Default to using Bun instead of Node.js. +Open-source ticketing system — Request Tracker's paradigm rebuilt in modern TypeScript. -- Use `bun ` instead of `node ` or `ts-node ` -- Use `bun test` instead of `jest` or `vitest` -- Use `bun build ` instead of `webpack` or `esbuild` -- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` -- Use `bun run - - +### Run migrations +```bash +bun run src/db/migrate.ts ``` -With the following `frontend.tsx`: - -```tsx#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

Hello, world!

; -} - -root.render(); +### Start frontend +```bash +cd web +npm install # Use npm, NOT bun (bun has compatibility issues with Next.js dev server) +npx next build # Production build +npx next start --port 5173 # Production server ``` -Then, run index.ts +**Note:** `bun run dev` (Turbopack) has WebSocket HMR issues in this environment. Use production mode only. -```sh -bun --hot ./index.ts +## API Endpoints + +All endpoints are served by the backend on port 9876. The frontend proxies `/api/*` to the backend via `next.config.ts`. + +| Method | Path | Description | +|--------|------|-------------| +| GET | /health | Health check | +| GET | /tickets | List tickets (?queue_id=&status=) | +| POST | /tickets | Create ticket | +| GET | /tickets/:id | Get ticket with custom fields | +| PATCH | /tickets/:id | Update ticket (validates lifecycle, runs scrips) | +| POST | /tickets/:id/preview | Dry-run scrips for status change | +| POST | /tickets/:id/comment | Add comment to ticket | +| GET | /tickets/:id/transactions | List ticket transactions | +| GET/POST | /queues | List/create queues | +| GET/POST/PATCH | /scrips | CRUD scrips | +| GET/POST | /custom-fields | List/create custom fields | +| GET/POST | /lifecycles | List/create lifecycles | + +## Key Design Decisions + +- **Ticket IDs are sequential integers** (1, 2, 3...), formatted as `TKT-0001` for display. No UUIDs. +- **Transaction-centric:** Every state change creates a transaction record. The scrip engine runs on transactions. +- **Two-phase scrip engine:** Prepare (no side effects) then Commit (execute actions). Supports dry-run mode. +- **Lifecycle state machines:** Per-queue configurable status transitions with wildcard support. +- **Light mode is default.** Dark mode available via theme toggle (next-themes). +- **No ORM for frontend:** Drizzle is only on the backend. Frontend uses a typed fetch wrapper (`web/src/lib/api.ts`). + +## Git Workflow + +Repo: `https://git.gjermund.xyz/gjermund/tessera` + +Push via HTTPS with token auth (SSH port 2222 is not configured on Gitea): +```bash +git remote set-url origin https://gjermund:TOKEN@git.gjermund.xyz/gjermund/tessera.git ``` -For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`. +## Development Workflow + +All code is written by **OpenCode** (AI coding agent). Hermes writes specs, OpenCode writes code, Gjermund reviews. + +OpenCode server: `opencode serve --port 4096` (Gjermund attaches with `opencode --attach http://127.0.0.1:4096`) + +After OpenCode makes changes: +1. `cd web && npx next build` — verify zero errors +2. `npx next start --port 5173` — restart production server +3. `git push` — push to origin + +## Common Issues + +- **Frontend shows skeleton/blank page:** The frontend dev server (Turbopack) has WebSocket HMR issues. Use production mode (`npx next build` + `npx next start`). +- **Backend not running on 9876:** Restart with `bun run src/index.ts`. Check port with `ss -tlnp | grep 9876`. +- **Database connection refused:** Docker container may be stopped. `docker start tessera-db`. +- **Build errors after migration:** Run `bun run src/db/migrate.ts` to apply new migrations.