diff --git a/.claude/settings.json b/.claude/settings.json
new file mode 100644
index 0000000..db23d14
--- /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 0000000..11b38b1
--- /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 larger choice that someone could question (why this and not the obvious alternative) can get a short section in `docs/choices-and-reasoning.md`: what we chose, why, and what we considered instead. Not every change belongs there. For a small or obvious change, a comment in the code is enough, so suggest the section and let the team member decide instead of writing it.
+
+## 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 0000000..5a92b3b
--- /dev/null
+++ b/.claude/skills/pre-pr-check/SKILL.md
@@ -0,0 +1,37 @@
+---
+name: pre-pr-check
+description: Run the pull request checklist from CONTRIBUTING.md for the frontend and the backend, 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 checklist
+
+Run every command under "Checklist beforehand" in `CONTRIBUTING.md`, for both the frontend and the backend. Read the list from the file, since it is the one place where it is kept up to date. Note whether each command passed, and keep going when one fails, so the report covers everything.
+
+Two of them may not be possible to run here:
+
+- The backend tests need PostgreSQL on PATH (see `backend/README.md`). If they cannot run, say so instead of skipping them silently.
+- The E2E tests need the local database with the book dataset and take a few minutes. They are the only checks that CI does not run. 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:
+
+- "Code style" and "Components" in `CONTRIBUTING.md`
+- the rule about `
` and `` in `docs/accessibility.md`
+
+Also check that there is no leftover `console.log`, commented-out code or placeholder comment from a code generator.
+
+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 f57182c..9f4ec72 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 0000000..4b64bda
--- /dev/null
+++ b/AGENTS.md
@@ -0,0 +1,54 @@
+# 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, so each rule is written in one place. Only what is specific to AI agents is written here. 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) |
+| change the GraphQL schema or a query | "Generated files" in [CONTRIBUTING.md](./CONTRIBUTING.md) |
+| change the database schema | "After changing the database schema" in the backend README |
+
+Read the file before you start, not when something fails. 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
+
+The frontend and the backend are separate, each with its own `package.json`. There is no `package.json` in the root, so run every command inside `frontend/` or `backend/`.
+
+- `frontend/`: React, React Router (SPA, no SSR, base path `/project2/`), Apollo Client, Tailwind CSS, shadcn/ui on Base UI. Pages are in `app/routes/`, components in `app/components/`, data fetching and URL state in `app/hooks/`, shared test helpers in `app/test/` and Playwright tests in `e2e/`.
+- `backend/`: Apollo Server on Express, Drizzle ORM, PostgreSQL, better-auth. The GraphQL schema and resolvers are in `src/schema/`, the tables in `src/db/schema/`, migrations in `drizzle/` and API tests in `tests/`.
+- `docs/`: the documentation that is delivered with the project.
+
+How to install, run and test the frontend and the backend is described in their READMEs, and the commands to run before a pull request are in the checklist in CONTRIBUTING.md. Use `http://localhost:5173/project2/` and not `127.0.0.1` when you open the app: the backend only accepts requests from `localhost` (CORS).
+
+## Definition of done
+
+1. Every command in the checklist under "Pull requests" in CONTRIBUTING.md passes, for both the frontend and the backend.
+2. New behavior has tests: API tests for the backend, component or page tests for the frontend.
+3. The documentation still describes what the code does. A change in behavior usually means an update in `docs/` or a README. A larger choice that someone could question belongs in `docs/choices-and-reasoning.md`. A small or obvious change does not: a comment in the code is enough, so ask before adding a section there.
+4. You have told the team member what to commit, what you could not verify (often the E2E tests), and that the pull request must mention the AI contribution.
+
+Suggest commits that follow Conventional Commits and a branch name like `feat/short-name`, but let the team member create them.
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000..4717c0b
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,12 @@
+@AGENTS.md
+@CONTRIBUTING.md
+
+## Claude Code
+
+Claude Code reads this file, not `AGENTS.md`, so the lines above import our shared instructions for agents and our contribution guidelines. That way the rules are loaded in every session without being written twice. Put instructions that apply to every agent in `AGENTS.md`, rules for everyone in `CONTRIBUTING.md`, and only Claude Code specifics here.
+
+- **Permissions.** [.claude/settings.json](./.claude/settings.json) denies reading `.env` files, git write operations and `ssh`, and asks before the commands that delete or change the local database. Do not try to work around a denied command. Ask the team member to run it instead.
+- **Skills.** Our shared skills are in [.claude/skills](./.claude/skills/):
+ - `/pre-pr-check`: run the pull request checklist from CONTRIBUTING.md and report the result.
+ - `/docs-check`: check the current changes against our documentation, in both directions.
+- **Personal preferences** go in `CLAUDE.local.md` or `.claude/settings.local.json`, which are not committed.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a2cbd6b..bba548b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -131,6 +131,9 @@ Exceptions:
Files that are generated by Apollo Codegen or other tools, i.e. all `*.generated.*` files, MUST NOT be edited manually.
Any manual changes in these files will be overwritten the next time `pnpm codegen` is run.
+After changing a `schema.graphql` file in the backend, or a GraphQL query in the frontend, run `pnpm codegen` in `backend/` first and then in `frontend/`.
+The frontend types are generated from the backend schema, so the order matters. In the backend, it also creates empty resolver files for new types and fields.
+
### Lucide icons
Icons from [Lucide](https://lucide.dev/) are great, and we use them actively in the project.
@@ -237,15 +240,30 @@ Before opening a pull request, these commands MUST NOT report any issues:
cd frontend
pnpm lint
pnpm typecheck
+pnpm format:check
pnpm test
pnpm build
# And the backend:
cd ../backend
+pnpm lint
pnpm typecheck
+pnpm format:check
+pnpm test
pnpm build
```
+These are the same checks that CI (GitHub Actions) runs on every pull request, so running them locally first saves a round of waiting.
+
+The end-to-end tests are the only tests that do not run in CI, so they MUST be run locally before opening a pull request:
+
+```sh
+cd frontend
+pnpm e2e
+```
+
+They need the local database to be running with the book dataset, see the [frontend README](./frontend/README.md#playwright-end-to-end-tests).
+
### Creating a pull request
All pull requests (PRs):
diff --git a/README.md b/README.md
index d56775a..cfb270e 100644
--- a/README.md
+++ b/README.md
@@ -57,3 +57,5 @@ Check out [CONTRIBUTING.md](./CONTRIBUTING.md) for further details regarding cod
- What steps we've taken to make the app accessible to everyone
- [AI documentation](/docs/ai-documentation.md)
- How AI was used during development
+- [AGENTS.md](./AGENTS.md)
+ - Instructions for AI agents working in this repository, with [CLAUDE.md](./CLAUDE.md) and [.claude](./.claude/) for Claude Code
diff --git a/docs/ai-documentation.md b/docs/ai-documentation.md
index 15e2091..39a41e5 100644
--- a/docs/ai-documentation.md
+++ b/docs/ai-documentation.md
@@ -6,6 +6,7 @@ We have used Claude (through Claude Code) as a tool during development. In short
- **Test setup.** Setting up Vitest and React Testing Library and writing the initial tests. We then removed the tests that did not add value and wrote new ones ourselves.
- **Understanding.** Explaining technologies that were new to some of the team members, such as Drizzle and GraphQL. Team members less experienced with React and TypeScript also found AI useful as a resource for asking questions about concepts while learning and working on the project.
- **Documentation.** Drafting parts of the documentation, such as the sustainability document and the project choices, which we then edited and checked against the code.
+- **Implementing features.** In the final deliverable, Claude implemented some issues from start to finish, such as the relevant filter options (#158), under the direction of a team member who reviewed, tested and committed the result.
## How we keep humans in the loop
@@ -13,13 +14,27 @@ We have used Claude (through Claude Code) as a tool during development. In short
- **All AI-generated code is reviewed.** Every piece of AI-generated code has been reviewed by a team member, and in most cases rewritten or adjusted. We experienced that AI sometimes overdoes a task, so we simplify its suggestions to avoid over-engineering.
- **AI is a tool, not a replacement.** Our use of GitHub issues, pull requests and reviews of each other's work shows that there is always a human in the loop, and that AI supports our development work rather than replacing it.
+## Shared context for AI agents
+
+- **[AGENTS.md](../AGENTS.md)**: the instructions every AI agent gets. It is short on purpose. It contains the rules from this document, a short overview of the project, a definition of done, and a table that says which documentation to read before which kind of change. It points to [CONTRIBUTING.md](../CONTRIBUTING.md), the READMEs and the files in `docs/` instead of repeating them, so each rule is written in one place.
+- **[CLAUDE.md](../CLAUDE.md)**: Claude Code reads this file and not `AGENTS.md`, so it imports `AGENTS.md` and `CONTRIBUTING.md`, which loads both in every session, and adds the few things that only apply to Claude Code. Other tools, such as Cursor and Codex, read `AGENTS.md` directly.
+- **[.claude/settings.json](../.claude/settings.json)**: turns the restrictions described [below](#llms-are-unpredictable---and-their-access-is-restricted-based-on-that) into configuration that is the same for all of us. Claude Code is denied reading `.env` files, running git commands that write, and using `ssh`. It has to ask before commands that delete or change the local database, and may run lint, typecheck, tests and build without asking.
+- **Skills** in [.claude/skills](../.claude/skills/): written-down procedures for work we do again and again, which the agent loads when they are needed:
+ - `pre-pr-check` runs the pull request checklist from CONTRIBUTING.md and reports what passed and what was not verified.
+ - `docs-check` compares a change with our documentation in both directions: that the code follows the documentation, and that the documentation still describes the code.
+- **A reminder to run the E2E tests.** The Playwright tests are the only checks that do not run in CI, so a failure there is not caught by a pull request (see #167). `AGENTS.md` and the `pre-pr-check` skill therefore tell the agent to remind us to run `pnpm e2e` before every commit and pull request.
+
+The instructions are context, not a guarantee. An agent can still miss a rule, and the deny rules match the command the agent writes, so they are a guard against mistakes and not a security boundary. This is why the automatic checks, the human review and the restrictions below still apply to everything an agent produces.
+
+Some team members may have used external skills in addition to the ones we have in common here. Examples include [Ponytail](https://github.com/dietrichgebert/ponytail), which aims to guide the AI agent to only change as little code as possible to make efficient edits, and [Superpowers](https://github.com/obra/superpowers), which is a set of multiple skills that can be used in order to plan, execute and review a coding task.
+
## Learning and AI
There is a strong correlation between using AI and how much you learn and remember. There are multiple studies regarding this, with many reporting somewhat negative results when students (and people in general) are overly reliant on AI.
-For example, [Walker, et al. (2026)](https://scale.stanford.edu/ai/evidence-base-review/evidence-base-ai-k12-november-review) reviewed the AI usage in K-12 education and reported that *"AI appears more likely to support learning when students use it to understand new material than when they use it to produce work for them, although neither type of use consistently improves learning."*
+For example, [Walker, et al. (2026)](https://scale.stanford.edu/ai/evidence-base-review/evidence-base-ai-k12-november-review) reviewed the AI usage in K-12 education and reported that _"AI appears more likely to support learning when students use it to understand new material than when they use it to produce work for them, although neither type of use consistently improves learning."_
-[Liu, et al. (2026)](https://arxiv.org/pdf/2604.04721) find that *"Across a variety of tasks, including mathematical reasoning and reading comprehension, we find that although AI assistance improves performance in the short-term, people perform significantly worse without AI and are more likely to give up."*
+[Liu, et al. (2026)](https://arxiv.org/pdf/2604.04721) find that _"Across a variety of tasks, including mathematical reasoning and reading comprehension, we find that although AI assistance improves performance in the short-term, people perform significantly worse without AI and are more likely to give up."_
These studies make it clear that if AI shall be helpful for learning, it must be used correctly. Otherwise, it is likely to cause more harm than good.
@@ -42,7 +57,7 @@ Some things cannot be checked automatically, such as some of the practices descr
The LLMs used by our group do not have access to run any write operations using git. This means no automatic committing, pushing or otherwise adding code that has not been quality checked.
Furthermore, the LLMs only have access to the fewest tools they need to get the job done. That means reading and editing only the files they need, and performing only the terminal commands that are needed.
This is important to avoid situations where LLMs do something very stupid, such as modifying git history, deleting important files or otherwise attempting to "escape the box".
-Using configuration files, Claude or other LLMs also do not have access to read `.env` or other files containing secrets which shall not be shared.
+Using configuration files, Claude or other LLMs also do not have access to read `.env` or other files containing secrets which shall not be shared. For Claude Code, these restrictions are in the shared [.claude/settings.json](../.claude/settings.json).
Last, but definitively not least:
@@ -57,10 +72,10 @@ While LLMs often have good ideas, they may not always fit what we're trying to a
Some examples include:
- Claude suggested using an undocumented Goodreads API to load image covers of different sizes for books.
-While this may be a good idea on paper, this API can change at any time, which would mean we have to rewrite our own code, or it could lead to unintended side effects.
-This idea was rejected, and the decision is documented in our [sustainability documentation](./sustainability.md).
+ While this may be a good idea on paper, this API can change at any time, which would mean we have to rewrite our own code, or it could lead to unintended side effects.
+ This idea was rejected, and the decision is documented in our [sustainability documentation](./sustainability.md).
- LLMs sometimes weren't following our code style and guidelines. In order to document how we should write code and what checks need to run before one can commit new code to the project, we have added the [CONTRIBUTING.md](../CONTRIBUTING.md) file.
-This file is mainly intended for human readers, but LLMs can also use it as input.
+ This file is mainly intended for human readers, and [AGENTS.md](../AGENTS.md) tells AI agents to read it before writing code.
- An LLM attempted to use the `DROP TABLE books` SQL command when testing for SQL injection in our app.
-This did not lead to any data loss, because the app wasn't vulnerable and the only database it had access to was the local development database, which does not contain any important data.
-However, this prompted us to write extra guidelines regarding how the app is security-tested to avoid running potentially dangerous commands. These rules are saved locally for team members using AI like Claude.
+ This did not lead to any data loss, because the app wasn't vulnerable and the only database it had access to was the local development database, which does not contain any important data.
+ However, this prompted us to write extra guidelines regarding how the app is security-tested to avoid running potentially dangerous commands. These rules are now part of [AGENTS.md](../AGENTS.md), so every team member's agent gets them.