From 524ea31389b73dfed86a488251b06009852a3a02 Mon Sep 17 00:00:00 2001 From: Johannes Horn Date: Sun, 22 Nov 2026 12:50:10 +0100 Subject: [PATCH 1/6] docs: add AGENTS.md, CLAUDE.md and shared Claude Code settings and skills --- .claude/settings.json | 47 ++++++++++++++ .claude/skills/docs-check/SKILL.md | 37 +++++++++++ .claude/skills/pre-pr-check/SKILL.md | 59 ++++++++++++++++++ .gitignore | 4 ++ AGENTS.md | 93 ++++++++++++++++++++++++++++ CLAUDE.md | 11 ++++ CONTRIBUTING.md | 15 +++++ README.md | 2 + docs/ai-documentation.md | 29 ++++++--- 9 files changed, 289 insertions(+), 8 deletions(-) create mode 100644 .claude/settings.json create mode 100644 .claude/skills/docs-check/SKILL.md create mode 100644 .claude/skills/pre-pr-check/SKILL.md create mode 100644 AGENTS.md create mode 100644 CLAUDE.md diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 00000000..db23d14b --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://json.schemastore.org/claude-code-settings.json", + "permissions": { + "allow": [ + "Bash(pnpm lint)", + "Bash(pnpm typecheck)", + "Bash(pnpm test *)", + "Bash(pnpm build)", + "Bash(pnpm format)", + "Bash(pnpm format:check)", + "Bash(pnpm codegen)" + ], + "ask": [ + "Bash(pnpm db:setup *)", + "Bash(pnpm db:delete *)", + "Bash(pnpm db:push *)", + "Bash(pnpm db:migrate *)", + "Bash(pnpm db:generate *)", + "Bash(pnpm db:seed *)", + "Bash(pnpm db:psql *)" + ], + "deny": [ + "Read(.env)", + "Read(.env.*)", + "Read(!.env.example)", + "Bash(git add *)", + "Bash(git commit *)", + "Bash(git push *)", + "Bash(git pull *)", + "Bash(git merge *)", + "Bash(git rebase *)", + "Bash(git reset *)", + "Bash(git restore *)", + "Bash(git checkout *)", + "Bash(git switch *)", + "Bash(git stash *)", + "Bash(git cherry-pick *)", + "Bash(git revert *)", + "Bash(git tag *)", + "Bash(git rm *)", + "Bash(git mv *)", + "Bash(git clean *)", + "Bash(ssh *)", + "Bash(scp *)" + ] + } +} diff --git a/.claude/skills/docs-check/SKILL.md b/.claude/skills/docs-check/SKILL.md new file mode 100644 index 00000000..0e81bd93 --- /dev/null +++ b/.claude/skills/docs-check/SKILL.md @@ -0,0 +1,37 @@ +--- +name: docs-check +description: Check the current code changes against the project documentation in both directions - that the code follows what the docs require, and that the docs still describe the code. Use after implementing a change and before a pull request. +--- + +Our documentation is delivered and graded together with the code, so a statement in it that is no longer true is a bug. Check the current changes (`git diff main...HEAD` plus uncommitted changes) against the documentation in both directions. + +## 1. Does the code follow the documentation? + +Read the files that apply to the change. Read them now, also if you read them earlier in the session. + +| The change touches... | Check against | +| ---------------------------------- | ----------------------------------------------------- | +| any code | `CONTRIBUTING.md` | +| markup, components, styling | `docs/accessibility.md` | +| queries, requests, caching, assets | `docs/sustainability.md` | +| search, filters, sorting, paging | `docs/choices-and-reasoning.md` | +| frontend tests or mocks | `frontend/README.md` ("What is tested" and "Mocking") | +| the API, the database or API tests | `backend/README.md` | +| anything done by an AI agent | `docs/ai-documentation.md` | + +## 2. Does the documentation still describe the code? + +For every behavior that changed, search the documentation for statements about it. Search for the names of the things that changed (components, hooks, queries, commands) and for the concept itself, in `docs/`, the three READMEs and `CONTRIBUTING.md`. + +Look especially for: + +- sentences that say something is fetched once, cached, never done or always done +- lists of what is tested, which filters exist, which fields are fetched +- the "Limitations/Future work" tables in `docs/accessibility.md` and `docs/sustainability.md` +- `docs/specifications.md` together with "Changes/not implemented yet from our specification" in `docs/choices-and-reasoning.md` + +A new choice that someone could question (why this and not the obvious alternative) gets a short section in `docs/choices-and-reasoning.md`: what we chose, why, and what we considered instead. + +## 3. Report + +List each mismatch with the file, the sentence and what is wrong. Fix clear mismatches in the documentation, in the same plain style as the text around them, and say what you changed. Ask before changing code to fit the documentation when the fix is not obvious. End by saying which files you read, so the team member knows what the check covered. diff --git a/.claude/skills/pre-pr-check/SKILL.md b/.claude/skills/pre-pr-check/SKILL.md new file mode 100644 index 00000000..f42d2966 --- /dev/null +++ b/.claude/skills/pre-pr-check/SKILL.md @@ -0,0 +1,59 @@ +--- +name: pre-pr-check +description: Run the pull request checklist from CONTRIBUTING.md in both projects and report what passed. Use before a team member commits or opens a pull request, or when asked whether the changes are ready. +--- + +Check that the current changes are ready for a pull request. Do not fix anything larger than formatting without asking, and do not run any git write commands. + +## 1. Run the automatic checks + +These are the commands from the checklist in CONTRIBUTING.md, which are the same ones CI runs. Run each command and note whether it passed. Keep going when one fails, so the report covers everything. + +In `frontend/`: + +```sh +pnpm lint +pnpm typecheck +pnpm format:check +pnpm test +pnpm build +``` + +In `backend/`: + +```sh +pnpm lint +pnpm typecheck +pnpm format:check +pnpm test +pnpm build +``` + +The backend tests need PostgreSQL on PATH (see `backend/README.md`). If they cannot run here, say so instead of skipping them silently. + +The Playwright tests (`pnpm e2e` in `frontend/`) are the only checks that CI does not run, so they must be run locally before every commit and pull request. They need the local database to be running with the book dataset, and take a few minutes. Run them if you can. Otherwise, remind the team member to run them, every time and for every kind of change, and ask for the result before you call the changes ready. + +## 2. Check what the tools cannot check + +Look at `git diff main...HEAD` and the uncommitted changes, and compare them with CONTRIBUTING.md: + +- Exports are at the end of the file (generated resolver files and route files are exceptions). +- Components and helper functions inside them use the `function` syntax. +- New components are in the right folder: `components/Name/Name.tsx`, or `components/pageName/Name/Name.tsx` when used on one page. +- No `*.generated.*` file was edited by hand. If a `schema.graphql` or a `gql` document changed, codegen was run in `backend/` and then `frontend/`. +- Raw SQL is in UPPERCASE. +- Every new `
` and `` in our own components has a comment that says why it is needed (docs/accessibility.md). +- No leftover `console.log`, commented-out code or placeholder comments from code generators. + +Then run the `docs-check` skill, or do the same check by hand. + +## 3. Report + +Answer with: + +- a table of the commands and whether each passed +- anything from step 2 that needs to be fixed +- whether the E2E tests were run, and by whom. If they were not, say that this must happen before the commit +- anything else that was not verified +- suggested commits that follow Conventional Commits, split by what they change (for example backend, frontend, docs) +- a reminder that the pull request needs a description, an assignee, the issue and milestone, and a note about what the AI wrote diff --git a/.gitignore b/.gitignore index f57182c4..9f4ec727 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,10 @@ dist-ssr .env +# Personal Claude Code settings and instructions +.claude/settings.local.json +CLAUDE.local.md + # React Router .react-router/ build/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..4370b0c8 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,93 @@ +# Readr - instructions for AI agents + +This file gives AI coding agents (Claude Code, Cursor, Codex and others) the context they need to work in this repository. It is deliberately short: it points to our documentation instead of repeating it. If this file and the documentation disagree, the documentation wins, and this file should be fixed. + +Readr is a web app for searching, filtering, saving and reviewing books, made by group 37 in IT2810 Web Development at NTNU. + +## Read these first + +| Before you... | Read | +| -------------------------------------------- | --------------------------------------------------------------------- | +| write or change any code | [CONTRIBUTING.md](./CONTRIBUTING.md) (code style, git, issues, PRs) | +| do anything at all as an AI agent | [docs/ai-documentation.md](./docs/ai-documentation.md) (our AI rules) | +| change markup, components or styling | [docs/accessibility.md](./docs/accessibility.md) | +| add a query, a request or an asset | [docs/sustainability.md](./docs/sustainability.md) | +| change how search, filters or sorting behave | [docs/choices-and-reasoning.md](./docs/choices-and-reasoning.md) | +| need to know how the parts fit together | [docs/infrastructure.md](./docs/infrastructure.md) | +| work in the frontend (setup, tests, mocking) | [frontend/README.md](./frontend/README.md) | +| work in the backend (database, API tests) | [backend/README.md](./backend/README.md) | + +CONTRIBUTING.md uses the RFC 2119 keywords (MUST, SHOULD, MAY). Treat every MUST as a hard requirement. + +## Rules for AI agents + +These come from [docs/ai-documentation.md](./docs/ai-documentation.md) and are not optional: + +- **No git write operations.** Do not commit, push, merge, rebase, stash, reset or switch branches. Read-only commands such as `git status`, `git diff` and `git log` are fine. A team member makes the branch and the commits. +- **Never read, print or copy `.env` files.** This also means not copying a folder that contains one. `.env.example` is fine. +- **Never touch our infrastructure:** the VM, the deployed app or its database. No `ssh`, no deployment commands. +- **Be careful with the local database.** `pnpm db:setup` and `pnpm db:delete` delete it. Ask before running them, and never run destructive SQL (`DROP`, `TRUNCATE`, `DELETE` without `WHERE`), also not as a security test. +- **Mark AI contributions.** Tell the team member what you wrote, so it can be stated in the pull request. +- **Do not over-engineer.** Solve the issue that was asked for, with the simplest solution that fits the existing code. Suggest larger changes instead of making them. +- **Always remind the team member to run the E2E tests** (`pnpm e2e` in `frontend/`) before they commit or open a pull request. They are the only checks that do not run in CI, so nothing else catches a failure there before it reaches `main`. Do this every time, also for changes that seem unrelated to the pages. +- **A human reviews everything.** Explain what you changed and why, and say plainly what you did not check. + +## Project layout + +Two separate pnpm projects. There is no root `package.json`, so run every command inside `frontend/` or `backend/`. + +- `frontend/`: React 19, React Router (SPA, no SSR, base path `/project2/`), Apollo Client, Tailwind CSS v4, shadcn/ui on Base UI. + - `app/routes/`: one file per page. + - `app/components/`: `ComponentName/ComponentName.tsx` for shared components, `pageName/ComponentName/ComponentName.tsx` for components used on one page. + - `app/components/ui/`: shadcn/ui components. Change them as little as possible. + - `app/hooks/`: data fetching (`useSearchBooks`, `useBookFacets`, ...) and URL state (`useBookSearchParams`). + - `app/test/`: shared test helpers (`renderRoutes`, `mocks`, fixtures). `e2e/`: Playwright tests. +- `backend/`: Apollo Server on Express, Drizzle ORM, PostgreSQL 18, better-auth. + - `src/schema//schema.graphql`: the GraphQL schema, with resolvers in `resolvers/` next to it. + - `src/db/schema/`: the Drizzle tables and indexes. `drizzle/`: migrations. + - `tests/`: API tests against a real, temporary Postgres database. +- `docs/`: the documentation that is delivered with the project. + +Local addresses: frontend `http://localhost:5173/project2/`, backend `http://localhost:3001/`, development database on port 5433, test database on port 5434. Use `localhost`, not `127.0.0.1`: the backend only accepts requests from `http://localhost:5173` (CORS). + +## Commands + +```sh +# In frontend/ +pnpm dev # codegen + dev server +pnpm lint +pnpm typecheck +pnpm test # Vitest, no backend needed +pnpm build +pnpm format:check # pnpm format to fix +pnpm e2e # Playwright, not run in CI. Needs the local database with the book dataset + +# In backend/ +pnpm db:start # start the local database +pnpm dev # codegen + server +pnpm lint +pnpm typecheck +pnpm test # needs PostgreSQL on PATH, uses its own database +pnpm build +pnpm format:check +``` + +## Things that are easy to get wrong + +- **Generated files.** Never edit `*.generated.*` by hand. After changing a `schema.graphql`, run `pnpm codegen` in `backend/` first, then in `frontend/` (the frontend types are generated from the backend schema and from the `gql` documents in `frontend/app`). Backend codegen also creates empty resolver files for new types and fields. +- **Exports go at the end of the file**, components and helper functions inside them use the `function` syntax, and raw SQL is written in UPPERCASE. See CONTRIBUTING.md for the exceptions. +- **`
` and ``** are only used where no semantic element fits, and each one in our own components has a comment that says why. Landmarks of the same kind (`