Your wording pass on adminSchema.ts and fields.tsx: "Default: ..."
blank options, "eg." examples, "URL ID" for slugs, and relabelled
front page sections, stat sources and hero fields.
On top of it:
- Content block row titles end with an ellipsis when the paragraph
is cut. preview() in src/lib/text.ts does it for anything that
shortens text: it collapses whitespace, cuts on a word and adds
"..." only when it actually shortened.
- No em-dashes in the editor, front end or server: placeholders
("Internal note: ..."), the Organizations blurb, the URL ID help,
empty table cells (now "-"), the Award dropdown ("Torch Award
(NGU)" in OPTION_QUERIES), a boot error message, and every comment
in the admin files. Also cleared from the files added this branch
(QR page, directory route, embeds, hero, migration 024), and the
QR page's team labels read "Board (NGU)".
- A few comments where removing the dash had run two sentences
together get a comma, colon or parentheses back.
- docs/updating-data-in-code.md matches the new labels and gains a
"Writing text in the editor" section with these conventions;
CLAUDE.md lists them under Rules and gotchas.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6.7 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
NGU-Web
Website for NGU (Next Generation of Unity), a Unity movement organization with regional chapters in the US and internationally. Full-stack app with a public site and a role-based admin panel.
Stack
- Frontend: React, TypeScript, Tailwind CSS, React Router, Vite (in
src/) - Backend: Hono on Node.js, SQLite (WAL mode, STRICT tables) via better-sqlite3 / node:sqlite (in
server/) - Package manager: pnpm only (never npm or yarn)
Commands
Frontend (repo root):
pnpm dev/pnpm build/pnpm preview: Vitepnpm format: oxfmtpnpm exec tsc: type-check (noEmit; there is no separate lint or typecheck script)- There is no test suite.
Backend (server/, Node >= 22). The server reads HOST (default 127.0.0.1), PORT (default 3001) and DB_PATH (default ./ngu.db); locally, use DB_PATH=./dev.db:
DB_PATH=./dev.db pnpm dev: run withnode --watchDB_PATH=./dev.db pnpm migrate: apply migrations without starting the serverDB_PATH=./dev.db node src/admin-cli.js add|list|passwd|role|disable|enable ...: the only way accounts are created
In dev, Vite proxies /api to the target set in vite.config.ts, so the API must listen on that port.
Deployment (production)
- Ubuntu VPS, nginx reverse proxy, systemd service
ngu-api - App deployed to
/srv/ngu-api; database at/var/lib/ngu/ngu.db - Debugging: check
journalctl -u ngu-api -n 40 --no-pagerfirst. Make sure rsync ran from the repo (not the deployed copy) before restarting the service. - Never run commands against the production server or database unless explicitly asked.
Git workflow
- Remote is a self-hosted Forgejo server, not GitHub. Do not use
gh. - Open pull requests with
tea:tea pr create --base main --head <branch> --title "..." --description "..." - Never commit directly to main. Create a branch per change, push it, open a PR.
- Versions are marked with annotated tags (v1.0, v1.3...). Don't create or move tags unless asked.
server/dev.dband other*.dbfiles are local only and never committed.
How to work in this repo
- Read the relevant existing files before writing anything. Follow existing patterns exactly: descriptors, field syntax, extension shape, import conventions.
- Ask questions up front before implementing non-trivial features.
- Prefer targeted edits when surrounding code is stable; full rewrites only when a component is being substantially reworked.
- Fix root causes. No redirect shims or workarounds.
- Keep data logic in the database and presentation logic in code. Make things configurable via constants, not hardcoded in components.
- Name components for what they do, not what they currently filter.
Project layout
- All pages use
PageShell.tsxas the wrapper unless explicitly noted otherwise. - Pages live in
src/pages/; section-level components go insrc/pages/sections/. src/data/holds only hardcoded data shared across multiple section files (e.g.historyDecades.ts, map grid). Everything else comes from SQLite.navConfig.tsis the single source of truth for navigation, routes, and actions (header, footer, pages).api.tsis the shared caching client used by frontend data hooks.docs/updating-data-in-code.md: where content that isn't in the database lives (admin dropdown labels, fixed value lists, nav, banner, decades, map grid) and how to change it. Keep it current when adding a dropdown or code-owned content.- Logos: org logos in
public/org-logos/(served at/org-logos/), event logos inpublic/event-logos/. The<Logo>component hides itself on load error.
Rules and gotchas
- Role checks must use ladder comparisons, never equality. Roles rank viewer → editor → admin → superadmin. Use the minimum-rank helpers from
src/lib/roles.ts(canWrite,canDelete,isSuper,atLeast). Where a local variable shadows the name, import with an alias, e.g.canWrite as roleCanWrite.role === "admin"silently excludes higher roles and has caused repeated bugs. - Imports need explicit extensions (
.ts,.tsx,.js) everywhere. - Vite resolves
.jsbefore.ts, so a.jsand.tsfile with the same base name will import the wrong one. Give new hooks distinct names. - Don't use
fallback: EMPTYin api.ts hooks. It silently returns empty arrays and hides server errors; let the error state surface. - No em-dashes (U+2014) anywhere: UI text, help text, comments, docs, commit messages. Use a colon, comma or parentheses. An empty table cell shows
-. - Admin editor text: blank select options read
Default: …(what blank means), examples in help text start witheg., and record ids are called "URL ID". Cut-off preview text usespreview()fromsrc/lib/text.ts, which ends it with an ellipsis. Seedocs/updating-data-in-code.md.
Admin CRUD engine
Descriptor-driven: server/admin-crud.js and admin-schema.js (server) and adminSchema.ts (client) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code.
- Child collections are deleted and reinserted wholesale. Unsafe for entities referenced by foreign keys elsewhere.
reindex: falseprevents cross-entity sort order collisions.- The
OMITsentinel distinguishes unsent fields from deliberate clears. admin-schema-sync.jsruns at boot and throws if descriptors don't match livePRAGMA table_info. If boot fails after a schema change, update the descriptor or migration so they agree.admin-cli.jsimportsROLESanddestroyAllSessionsForfromauth.js. Keep it that way to prevent drift.
Migrations
server/src/migrations/023_schema.sqlis the baseline: the whole schema, consolidated from the old 001–023. It only runs on an empty database; the runner refuses a database between v1 and v22. It's the place to read the schema, not to change it: a database that already exists never re-runs it.- Changes go in new sequential files after it:
024_,025_, ... - The runner may drop statements after a
BEGIN...ENDtrigger body. Keep triggers last in a file, and put eachCREATE VIEWbefore any trigger or in its own file. - The runner turns foreign keys off around every migration (it can't be done inside the file's transaction) and runs
PRAGMA foreign_key_checkbefore committing, so a table rebuild needs noPRAGMA foreign_keysof its own. When views or triggers name the table being rebuilt, wrap the drop-and-rename inPRAGMA legacy_alter_table = ON...OFF, then recreate the rebuilt table's own indexes and triggers.
Integrations
- Church Center (ngu.churchcenteronline.com): Planning Center embeds for giving and the calendar.