# CLAUDE.md
## Project
Benthrow Boulder: booking and membership site for a bouldering gym in Brno. Members buy 10-entry passes or monthly memberships and book course slots; staff check people in at the desk on a tablet.
Django 5.1, Python 3.12, Postgres 16, HTMX + Alpine.js, Tailwind (standalone CLI), GoPay, Celery + Redis. Czech (default) and English. Deployed with Docker Compose on one Hetzner VPS.
## Commands
- Start Postgres and Redis: `docker compose up -d db redis`
- Dev server (port 8000): `uv run python manage.py runserver`
- Celery worker: `uv run celery -A config worker -l info`
- Celery beat (runs the nightly membership-expiry job): `uv run celery -A config beat -l info`
- All tests: `uv run pytest`
- Single test: `uv run pytest apps/bookings/tests/test_slots.py::test_overbooking`
- Lint and format: `uv run ruff check . && uv run ruff format .`
- Migrations: `uv run python manage.py makemigrations`, then `uv run python manage.py migrate`
- Translations: `uv run python manage.py makemessages -l cs`, then `uv run python manage.py compilemessages`
- Tailwind while developing: `./bin/tailwindcss -i static/src/input.css -o static/css/app.css --watch`
- Tailwind build before committing or deploying: `./bin/tailwindcss -i static/src/input.css -o static/css/app.css --minify`
- Add a dependency: `uv add <package>`
- Deploy: `./deploy.sh` (pulls on the VPS, rebuilds, runs migrate and collectstatic)
## Layout
- `config/`: Django settings and the Celery app.
- `apps/bookings/`: slots and course bookings.
- `apps/billing/`: invoices and the `InvoiceSequence` model.
- `apps/notifications/tasks.py`: every outgoing email, as Celery tasks.
- `apps/legacy_import/`: one-off importer from the old Excel member sheet. Leave it unchanged.
- GoPay integration: [add path]
- Templates: [add path]
- `static/src/input.css` is the Tailwind source; `static/css/app.css` is generated output, so edit the source.
- Secrets live in `.env` on the VPS and load through django-environ. `.env.example` is the template; add new keys there.
## Rules
- Build interactivity with HTMX attributes and small Alpine components. The project has no Node on purpose and the VPS has none, so do not add `package.json`, npm, Vite or webpack.
- Wrap every user-facing string in `{% translate %}` / `{% blocktranslate %}` in templates or `gettext` / `gettext_lazy` in Python. Czech is the default language, so a hardcoded English string is a bug for most users. This includes form labels, validation errors and email bodies.
- Take invoice numbers from `InvoiceSequence` in `apps/billing/models.py`, locked with `select_for_update` inside a transaction. Czech VAT law requires gapless sequential numbers per calendar year; primary keys and counters outside the lock produce gaps or duplicates.
- Store and calculate money as integers in haléře; floats lose precision on amounts that end up on legal documents.
- Calculate VAT (21%) once per invoice on the total, not per line, rounded half-up to whole haléře. Per-line rounding makes invoice totals differ from what the law expects.
- Send email only by calling a Celery task from `apps/notifications/tasks.py`, never from a view. Sending inline blocks the request and loses the email if SMTP fails.
- Add or upgrade packages with `uv add`, never `pip install`; pip bypasses the lockfile, so the VPS build will not match.
- Read new settings and secrets from the environment via django-environ and document them in `.env.example`. Never commit `.env`.
- Store datetimes as timezone-aware UTC and convert to Europe/Prague only for display and for interpreting staff/member input. Naive datetimes break slot booking around the DST change.
## Workflow
- Before changing billing, bookings or memberships, read the existing models and tests in that app and say which invariants (invoice sequence, slot capacity, expiry) the change touches.
- Write or update a test for the behaviour first, run it as a single test, then run the full suite.
- If you change models, run `makemigrations` and commit the migration with the change, since `./deploy.sh` runs `migrate`.
- If you add or change strings, run `makemessages -l cs` and leave the new Czech entries for review rather than inventing translations, unless asked.
- If you change templates or CSS classes, run the minified Tailwind build so `static/css/app.css` is current.
- Finish with `uv run ruff check . && uv run ruff format .` and `uv run pytest`.
## Gotchas
- Python's `round()` rounds half to even, not half-up. For VAT use integer arithmetic or `Decimal.quantize(..., rounding=ROUND_HALF_UP)`.
- Generate slot times in Europe/Prague local time and then convert to UTC; adding `timedelta`s to UTC values shifts slots by an hour across DST.
- Queue Celery tasks with `transaction.on_commit` when they depend on rows written in the same transaction, or the worker may read data that does not exist yet.
- The membership-expiry job only runs when Celery beat is running, so start beat locally when testing expiry.
- The check-in screen is used on a desk tablet, so test touch-sized targets and that HTMX swaps work without a keyboard.
- Whether compiled `.mo` files are committed: [add whether they are committed or built in the Docker image]
Why these rules
- No Node/npm/Vite rule: prevents suggesting a
package.json and a Vite or webpack setup. - Translate every string rule: prevents hardcoded English strings in templates.
InvoiceSequence with select_for_update rule: prevents generating invoice numbers from the primary key.- Email only through Celery tasks rule: prevents sending emails directly in views.
uv add rule: prevents using pip install.
To fill in
GoPay integration: [add path]: the app or module that holds GoPay calls and webhook handling, so Claude edits payments in the right place.Templates: [add path]: whether templates live in a project-level templates/ folder or per app..mo files: [add whether they are committed or built in the Docker image]: ./deploy.sh doesn't run compilemessages, so Claude needs to know whether compiled translations must be committed.- I couldn't access the repository from this session, so the commands and paths come from your notes only and haven't been checked against the code.