Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -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 *)"
]
}
}
37 changes: 37 additions & 0 deletions .claude/skills/docs-check/SKILL.md
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 37 additions & 0 deletions .claude/skills/pre-pr-check/SKILL.md
Original file line number Diff line number Diff line change
@@ -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 `<div>` and `<span>` 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
54 changes: 54 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading