Document codebase: comments, per-area READMEs, deployment guide

Readability pass across all four areas of the stack. Comments explain why
rather than what, concentrated at the points where behaviour is non-obvious:
concurrency, caching, auth, scraping and nginx templating.

Backend: doc comments on every exported declaration across handlers,
services, models and resolvers. Resolver commentary lives inside function
bodies so gqlgen does not strip it on regeneration; schema files use #
comments rather than description blocks so introspection output is
unchanged. Extracted the duplicated auth-cookie blocks into helpers.

Frontend: header comments on every component, store and view, including
STATUS: notes marking which of the parallel/legacy views are still live.
Documented the non-reactive animation-state pattern, the homeData hub and
the WebSocket stale-socket guard. Removed a few dead imports and named the
reconnect-backoff and poll-interval constants.

Python: module and function docstrings covering the Travelodge scraping
contract, the deadline threading, the two-executor concurrency and the
NDJSON streaming protocol.

Infra: header blocks on every compose file, nginx template, Dockerfile and
entrypoint, covering the config selection, envsubst allow-lists, rate-limit
semantics and volume persistence. Hoisted the duplicated envsubst variable
list in nginx/entrypoint.sh.

New: backend/README.md, python/README.md, DEPLOYMENT.md, .env.example,
backend/graph/doc.go. Refreshed vue/README.md. Corrected CLAUDE.md, which
stated a 24h access token where main.go sets 7 days.

No behaviour change. go build/vet, vite build, py_compile and docker
compose config all pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
2026-09-16 15:57:48 +01:00
co-authored by Claude Opus 5
parent a1102b4aa1
commit 64df70e5d2
183 changed files with 4691 additions and 204 deletions
+136
View File
@@ -18,6 +18,142 @@ The Vite dev server proxies API requests:
- `/api` -> `http://localhost:8080` (Go backend)
- `/gitea` -> `http://localhost:3000` (Gitea)
- `/radio` -> `http://localhost:8000` (Icecast2)
- `/py` -> `http://localhost:8000` (FastAPI; the `/py` prefix is stripped, as nginx does in production)
## Structure
```
src/
main.js entry point — awaits the wasm init, then mounts <App>
App.vue empty shell; all chrome lives in the layouts
router/index.js route table + the single admin route guard
graphql.js the entire GraphQL client (one axios POST)
layouts/ DefaultLayout (dark, navbar+footer) and CVLayout (light, print)
stores/ Pinia stores
components/ reusable UI — text/, input/, util/, borders/, elle/
views/ page components, one directory per area
assets/styles.css design tokens + base styles (see Styling)
js/ small shared helpers
wasm/ GENERATED by `npm run build:wasm`; gitignored, do not edit
crates/stp_wasm the Rust source for the above
```
## Routing
Two layout shells, defined in `src/router/index.js`:
| Path | Layout | Notes |
| --- | --- | --- |
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint) |
| `/stp` | DefaultLayout | The personal home page: the widget grid |
| `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` |
| `/automata`, `/hotels`, `/shrines/*` | DefaultLayout | |
| `/cv`, `/cv/jobs` | CVLayout | Light print theme; `/cv/jobs` is admin-only |
| `/stp2` | (none) | Bare full-bleed mock, deliberately outside both layouts |
| `:pathMatch(.*)*` | DefaultLayout | 404 |
Everything except the landing page is a dynamic `import()`, so Vite gives each
view its own chunk.
Route `name`s are contracts used by `RouterLink`/`router.push` — renaming one
breaks every link to it.
**The admin guard** (`router.beforeEach`) has one subtlety: the admin flag comes
from the `me` field of the home-data query, which arrives asynchronously.
Navigating straight to `/admin` on a cold load would otherwise read an empty
user and bounce a real admin to the login page, so the guard first awaits
`homeData.loaded` via a self-stopping watcher.
## Data flow
There is no GraphQL cache or codegen. `src/graphql.js` is a single function:
```js
const data = await gql(`query { ... }`, variables);
```
It POSTs to `/api/graphql` and throws on an error response with no data. Auth
rides along in **HTTP-only cookies** set by the Go backend, so nothing here
touches tokens — the request just has to be same-origin (nginx in production,
the Vite proxy in dev).
**`stores/homeData.js` is the hub.** It issues *one* query for everything the
`/stp` page needs (posts, favourites, activities, Spotify, rowing, bookmarks,
Gitea feed, Steam status, current user) instead of letting a dozen widgets each
fire their own request. That fetch is kicked off as a side effect of the first
`useHomeDataStore()` call, so no component has to start it.
The other stores are thin views over it:
| Store | Role |
| --- | --- |
| `homeData` | the one query; owns `loaded` / `error` |
| `auth` | current user; mirrors `homeData.me`, plus login/logout mutations |
| `posts`, `favorites`, `activity`, `songs`, `steam` | mirror one slice of `homeData` via an `immediate` watch, and keep a placeholder value until real data arrives |
| `places` | independent CRUD; sign-in only, so it is fetched lazily |
| `messages` | the chat WebSocket — not GraphQL at all |
| `models` | dormant; not imported anywhere |
The mirroring watches are `immediate` on purpose: a store created *after*
`homeData` has already loaded would never see the existing value otherwise.
## Component conventions
- Layout and one-off tweaks go in Tailwind utilities; reach for a scoped
`<style>` only for what utilities can't express (`grid-template-areas`,
keyframes, media-query-specific layouts).
- Never hard-code a colour — use a token. The one exception is `<canvas>`
drawing (`views/automata/MobileAutomata.vue`), which cannot read CSS
variables.
- Home widgets: title goes in `<Header>`; admin create forms use
`<CreateToggle v-model="showCreate">` in the header's `#action` slot and
render the form inside `<Modal v-model="showCreate">`.
- Admin create forms are loaded with `defineAsyncComponent`, so a visitor who
is not signed in never downloads them.
- Create forms emit `done` / `cancel` and never close themselves — the host
decides what to dismiss and refresh.
- Animation loops (`Headline`, `Intro2`, `Stamps`, `AutoScroll`, `Elle`) keep
their state in plain `let`s and write to the DOM directly. Putting per-frame
state in a `ref` would queue a Vue re-render 30–60 times a second. They also
cache measurements in a `ResizeObserver` rather than reading `offsetWidth` in
the rAF callback, which forces a synchronous layout every frame.
## Dev vs production
- **Dev** (`npm run dev`): Vite serves the SPA and proxies `/api`, `/gitea`,
`/radio` and `/py` (see the table above and `vite.config.js`). The `/py`
proxy strips the prefix, matching what nginx does in production.
- **Production** (`npm run build`): `dist/` is built into the nginx container
and served as static files, with nginx doing the same reverse-proxying.
Note `npm run build` runs `build:wasm` first, which needs **wasm-pack** on the
PATH. If you only want the Vue bundle and `src/wasm/` is already populated,
`npx vite build` skips that step.
## Live vs legacy views
Several files are kept around but not reachable. Each carries a `STATUS:` note
in its header comment; the summary:
| File | Status |
| --- | --- |
| `views/home/Home.vue` | live (`/stp`) — imports **Intro2** and **Gym2** |
| `views/home/Intro.vue` | superseded by `Intro2.vue`; not imported |
| `views/home/Gym.vue` | superseded by `Gym2.vue`; not imported |
| `views/home2/Home2.vue` | reachable at `/stp2`, but a static mock and unlinked |
| `views/home/BadApple.vue` | unfinished ASCII video player; not imported |
| `views/CV/CVProgramming.vue` | live — the only CV template listed in `CV.vue` |
| `views/CV/CV{General,Backend,Frontend,Security,Electrical,Hospitality,Analyst,Temp}.vue` | commented out of `CV.vue`'s list; unreachable |
| `views/unused/CoverLetters.vue` | **live** despite the directory — it is the "Cover Letter" tab on `/cv` |
| `views/unused/Notes.vue` | no route points at it; not imported |
| `components/util/wasm/AutoScroll.vue` | Rust port of the JS AutoScroll; not imported |
| `components/util/{MusicPlayer,ObjectTable}.vue` | not imported |
| `components/elle/Elle.vue`, `components/borders/UtenaFrame.vue` | decorative; not imported |
| `stores/models.js`, `js/mobile-automata.mjs` | not imported |
Nothing in this list is dead weight the build ships — unimported files are
tree-shaken out. They are kept deliberately; don't delete without asking.
## Styling