POST /rowing in the Go backend no longer calls the Anthropic SDK. It keeps the admin gate, EXIF date, duplicate check, sanity bounds and insert, and sends the image to a new internal Python route, POST /internal/rowing/read, which makes the Claude call and returns the three numbers it read. The route spends a paid call and has no auth of its own, so nginx 404s /py/internal/ and the route refuses anything carrying the proxy headers nginx adds. The python container now receives CLAUDE_API_KEY. Co-Authored-By: Claude Opus 5.5 <[email protected]>
100 lines
6.2 KiB
Markdown
100 lines
6.2 KiB
Markdown
# CLAUDE.md
|
|
|
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
|
|
## Build & Run Commands
|
|
|
|
### Full stack (dev mode, HTTP only)
|
|
|
|
```
|
|
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
|
|
```
|
|
|
|
Dev mode seeds the database with test data (`SEED_DB=true`) and disables certbot/SSL. Visit `http://localhost`.
|
|
|
|
### Full stack (production, HTTPS)
|
|
|
|
```
|
|
docker compose up --build
|
|
```
|
|
|
|
### Frontend only (hot reload)
|
|
|
|
```
|
|
cd vue && npm run dev
|
|
```
|
|
|
|
Vite dev server proxies `/api` to `localhost:8080`, `/gitea` to `localhost:3000`, `/radio` to `localhost:8000`.
|
|
|
|
### Frontend build
|
|
|
|
```
|
|
cd vue && npm run build
|
|
```
|
|
|
|
### Regenerate GraphQL (after editing schema files)
|
|
|
|
```
|
|
cd backend && go run github.com/99designs/gqlgen generate
|
|
```
|
|
|
|
This regenerates `graph/generated.go` and `graph/model/models_gen.go`. Resolver implementations in `*.resolvers.go` files are preserved.
|
|
|
|
## Architecture
|
|
|
|
Dockerized multi-service personal website self-hosted on a Raspberry Pi.
|
|
|
|
**Backend** (`backend/`): Go with Gin router. GraphQL API via gqlgen at `POST /api/graphql`. REST endpoints for auth, file uploads, Spotify OAuth, and WebSockets. GORM for PostgreSQL with auto-migrations (no separate migration files). JWT auth stored in HTTP-only cookies.
|
|
|
|
**Frontend** (`vue/`): Vue 3 SPA with Vite, Tailwind CSS v4, Pinia stores, Vue Router. Built in a separate container; assets served through Nginx (production) or proxied to Vite dev server (dev mode).
|
|
|
|
**Python API** (`python/`): FastAPI app served by uvicorn on port 8000. Nginx proxies `/py/` to it and strips the prefix, so routes in `python/app/main.py` are written relative to `/`. Swagger UI at `/py/docs`. Dev mode mounts `python/app` and runs uvicorn with `--reload`. One route, `/internal/rowing/read` (the Claude call behind `POST /api/rowing`), is internal: the Go backend calls it directly over the Docker network and nginx 404s `/py/internal/`.
|
|
|
|
**Nginx** (`nginx/`): Reverse proxy + SPA server. Config is templated (`nginx.conf.template`) and selected at runtime by `entrypoint.sh` based on `DEV_MODE` and certificate presence. Rate limiting on login (5/min), API (30/sec), uploads (5/min).
|
|
|
|
## Backend Structure
|
|
|
|
- `main.go` — entry point: wires up DB, services, router
|
|
- `handlers/store.go` — `Store` struct holds DB, SpotifyAuth, Auth, EmailSync, etc. Passed to all handlers
|
|
- `handlers/handle_*.go` — REST handlers grouped by domain
|
|
- `graph/schema/*.graphql` — GraphQL schema files (source of truth)
|
|
- `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout)
|
|
- `graph/generated.go` — auto-generated by gqlgen, do not edit
|
|
- `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit
|
|
- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing)
|
|
- `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, Claude client, DB seeding
|
|
|
|
## Frontend Structure
|
|
|
|
- `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`)
|
|
- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData
|
|
- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines)
|
|
- `src/components/` — reusable UI components
|
|
- `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`.
|
|
|
|
## Key Patterns
|
|
|
|
- **GraphQL models vs GORM models**: `gqlgen.yml` maps GraphQL types directly to GORM models in `backend/models`. The `graph/model/` package has only generated input/payload types.
|
|
- **Auth flow**: Login sets `access_token` (7 days) and `refresh_token` (365 days) as HTTP-only cookies (`backend/main.go:96`). `AuthMiddleware` validates tokens and injects user into Gin context. `AuthContextMiddleware` passes Gin context into GraphQL resolver context. There is no token revocation — logout only clears cookies.
|
|
- **GraphQL resolvers authorise themselves.** The `/api/graphql` endpoint has no guarding middleware; `AuthContextMiddleware` only makes the user *available*. Every resolver that needs auth must check it itself. See `backend/graph/doc.go`.
|
|
- **Spotify tokens**: Persisted to `/backend/token/spotify_token.json` inside the container, surviving restarts.
|
|
- **Gitea feed**: Backend proxies and caches (1 min TTL) the Gitea activity feed API.
|
|
- **All GORM models use soft delete** (`gorm.DeletedAt` field) — except `ProcessedEmail`, whose dedup must see history. Note that a `uniqueIndex` still collides with soft-deleted rows.
|
|
|
|
## Further documentation
|
|
|
|
Each area has its own README with the detail that doesn't belong here:
|
|
|
|
- `backend/README.md` — request lifecycle, auth model, GraphQL-vs-REST split and why each REST endpoint isn't GraphQL, service rundown, gotchas.
|
|
- `vue/README.md` — app structure, routing, store/GraphQL data flow, the design-token styling system, and a live-vs-legacy map of the views.
|
|
- `python/README.md` — endpoints, the NDJSON streaming contract, the hotel pricing method, and the scraper's fragility points.
|
|
- `DEPLOYMENT.md` — service topology and ports, dev vs prod boot paths, TLS first-run and renewal, what persists, env vars, and an ops runbook.
|
|
- `.env.example` — every environment variable the stack reads, documented, with blank values.
|
|
|
|
## Conventions
|
|
|
|
- **Comments explain *why*, not *what*.** The codebase is deliberately heavily commented at the points where behaviour is non-obvious (concurrency, caching, auth, scraping, nginx templating). Preserve these when editing; if you change the behaviour they describe, update them.
|
|
- **Resolver commentary lives inside function bodies**, because gqlgen relocates or strips anything above the signature when regenerating.
|
|
- **Schema files use `#` comments**, not triple-quoted description blocks — descriptions would change GraphQL introspection output.
|
|
- **Legacy views are kept, not deleted.** `vue/src/views/unused/`, `Intro.vue`, `Gym.vue`, the unlisted CV templates and similar carry a `STATUS:` header comment saying whether they are live. They are tree-shaken out of the build. Check the header before assuming a file is dead — e.g. `views/unused/CoverLetters.vue` is actually live on `/cv`.
|