- packages/metadata: {variable} templates, Photo Mechanic code replacement, IPTC fields of the current pad (title = persons shown), IIM/XMP mapping, delivery folder and file-name templates (FPA, Liga)
- API: events with agenda and IPTC template, FTP logins, ingest worker (hash, dedupe, EXIF in Lisbon time, routing by agenda + capture time, previews), library culling, IPTC preview, code list, signed file URLs
- Realtime: Socket.io with Postgres LISTEN/NOTIFY fan-out
- Delivery: queue with fixed sequence numbers, 4000 px JPEG 100 with IPTC via ExifTool, WebDAV upload with retries, OCS share links, encrypted app passwords
- Web app: approved type and Lightroom-style workspace, grid/loupe with keyboard culling, players, IPTC panel, delivery queue, code list editor
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
9.2 KiB
Architecture
Living plan (Portuguese, editable): https://claude.ai/code/artifact/f64515d2-9d1f-47d5-ade1-743511fb3da2 This file is the in-repo summary agents work from. Decisions dated 2026-10-11.
Decisions
- One monorepo, one API, one PostgreSQL database, one account system, one UI for web and desktop.
- Built greenfield on new containers and the
nextenvironment; old projects keep running until cutover. Final domain:app.photoreport.pt. Data (accounts, galleries, sales, squads) is imported, not restarted. - Desktop = Tauri around the same React SPA (replaces the Flutter Studio).
- Develop engine = LightCraft crates (
lightcraft-develop,lightcraft-pipeline,lightcraft-raw,lightcraft-codecs,lightcraft-faces), pinned, behindengine/core. Notlightcraft-engine/catalog: our catalog is the API. - Faces:
lightcraft-faces(YuNet detection + SFace recognition, pure Rust) inworkers/render. Enabled for FPA (own photos, internal federation use for news and galleries); off by default elsewhere. - Jersey numbers: PaddleOCR in
workers/ml, matched against the squad. OpenAI fallback off by default. - CPU: no practical limit; workers scale to whatever cores are needed. Speed first.
- Priority cameras: Canon EOS R1 and R3, then pro Canon, Sony and Nikon bodies used by photojournalists.
Stack
Node 22 + TypeScript + Fastify · PostgreSQL 17 + pgvector · Prisma · queues as PostgreSQL tables
(FOR UPDATE SKIP LOCKED) · Socket.io fanned out with LISTEN/NOTIFY · sharp + ExifTool · local storage now,
Garage (S3-compatible) later · SFTPGo (tusd later) · React + Vite + Tailwind (apps/app) · Next.js
(apps/site) · Tauri 2 (apps/desktop) · Rust (engine, workers/render) · Python (workers/ml).
Realtime edits
Client sends EditEnvelope -> API validates permissions, assigns per-photo seq, stores in op log,
broadcasts EditBroadcast to user:<id> and event:<id>. Clients render locally with their own engine.
Reconnect = "everything since seq X". Offline queue: IndexedDB (web), SQLite (desktop). Conflict rule:
last writer wins per control. Slider drags are coalesced (about one command per 50 ms, one undo step per drag).
Uploads and ingest
Camera -> SFTPGo (FTP/SFTP) into <INGEST_ROOT>/<ftp login>/. Each login is tied to one member of one
organization (ftp_accounts, managed by admins). The worker (apps/api/src/worker.ts) picks a file up once
its size and time stop changing, hashes it (duplicates are dropped), reads EXIF (capture time in Lisbon time
unless the camera wrote an offset; a per-login clock offset fixes drifting bodies), routes it to the event the
photographer is assigned to whose ingest window (default: 2 h before to 4 h after the start) holds the capture
time, or to the inbox, moves it into storage and makes a 480 px thumb and a 2048 px preview. Unreadable files
are kept and marked failed; non-JPEG and unknown logins are set aside in _unsupported/ and _unclaimed/.
Measured locally: a dropped JPEG shows up in an open browser in about 2 s.
Still to come: browser/desktop uploads (tus, preview first), OCR and faces at ingest, and the final export
replaying the edit op log (phase 2). Files live on local disk behind LocalStorage (originals and
derivatives per organization); the API and the worker share that folder (Proxmox bind mount). Garage replaces
it when files must be served from more than one host.
Library realtime
Socket.io on the API (/v1/realtime, WebSocket only, access token in the handshake, one room per
organization). Every message goes through PostgreSQL LISTEN/NOTIFY (photoreport_realtime): the worker and
every API process publish, every API process delivers to its own sockets. No Redis/Valkey and no sticky
sessions needed. Messages: photo.added, photo.updated (culling, players), delivery.updated.
Client delivery (Nextcloud)
PhotoReport storage is the source of truth; Nextcloud receives organised copies. Any client organization can have one or
more destinations on any Nextcloud instance, each with its own folder and file-name templates (variables
from packages/metadata). Default delivery: final edited JPEG, 4000 px long edge, maximum quality.
Implemented (apps/api/src/delivery): editors send picks to a target; each photo becomes a queue item with
its {n} fixed at that moment (capture order, never reused). The worker renders it (oriented, 4000 px,
JPEG 100 4:4:4, camera EXIF and ICC kept, IPTC written to IIM and XMP with ExifTool), creates the folders
(WebDAV MKCOL) and uploads (PUT), up to 4 at a time, retrying network and server errors with back-off
(5 attempts); authentication and template errors fail at once. App passwords are stored encrypted
(AES-256-GCM, DELIVERY_SECRET_KEY). Editors can create a read-only public link to an event folder (OCS).
Large files may later need WebDAV chunked upload.
| Instance | Client | Folders today | Files |
|---|---|---|---|
| cloud.photoreport.pt | FPA | /FPA/Fotos/2026_2027/Competições Nacionais/PO01 - Campeonato Betclic/20260923 - VSC x AAAS/ |
PS_<Home> x <Away>_<n>.jpg |
| liga.photoreport.pt | Liga Portugal | /LPBetclic 25-26/Jornada 1/1. Casa Pia x Sporting/; institutional events at root |
camera name (JMA27728.jpg) |
Archive import: folder names changed across seasons (LPbwin - 22-23, LPBetclic 2023-24,
LPBetclic - 24-25, LPBetclic 25-26), so the importer proposes a folder -> competition/match mapping that
an editor confirms before import.
Editor scope
JPEG first: most event and match photographers shoot JPEG for speed, so JPEG must be perfect before RAW. Default editor modules: Crop (with straighten and aspect presets) and Basic (white balance, exposure, contrast, highlights, shadows, whites, blacks, texture, clarity, dehaze, vibrance, saturation). Every other LightCraft module (curves, colour mixer, grading, masks, detail, optics...) is available but off by default; each user chooses which panels to show, and the choice syncs across their devices.
RAW support (secondary; LightCraft rev pinned in Cargo.toml, checked 2026-10-11)
- Canon EOS R1, R3 (CR3): unverified; lossless and single-tile C-RAW decode, other CRX variants fall back to the embedded preview. No measured Canon colour calibration yet.
- Nikon Z 9, Z 8: NEF decodes except High Efficiency (HE / HE*), which is preview-only.
- Sony A9 / A9 II / A9 III: verified. Action (low priority): collect real files from each body, add them to our reference set, contribute samples upstream.
Status
Phase 0 code is in place and verified: accounts, organizations and roles, web login (httpOnly refresh cookie,
rotation with reuse detection), desktop login through the browser (device authorization) with the keychain,
synced editor-panel preferences, deploy receiver and script. Remaining for phase 0: create the next
containers and webhooks (docs/DEPLOY.md), and macOS/Windows runners for desktop installers.
Phase 1 so far (verified end to end locally: FTP drop -> live grid -> keyboard culling -> players by code ->
IPTC preview -> delivery into the FPA folder layout): events with agenda and IPTC template, FTP ingest and
routing, previews, the library (Lightroom-style grid and loupe, P/X/U, stars, colour labels, filters, live
updates), code replacements, IPTC with the fields of the current Photo Mechanic pad (packages/metadata),
Nextcloud delivery queue and share links. Still open in phase 1: IPTC template editor per event in the UI,
delivery-target and FTP-login admin screens (API exists), SFTPGo provisioning, tus uploads, and a real match
run on the next containers (the phase gate).
Phases (gate to pass)
- Foundation: monorepo, CI,
nextcontainers, accounts, organizations, tokens (login on web and desktop). - Ingest + library: SFTPGo/tus, routing, previews, IPTC, code replacements, culling, Nextcloud delivery (a real match arrives captioned and delivered with no manual step).
- Synced editor: native + WASM engine, op log, Socket.io, offline, render worker (PoC demo: same photo edited on web and desktop).
- Galleries and sales: PhotoReport and ShootYourMove storefronts, private galleries, Stripe, VAT/VIES, payouts, affiliates, press accounts, data import dry runs (end-to-end test purchase with invoice and payout).
- Events and printing: QR guest flow, templates, print jobs, Print Agent (a real event printed).
- Player identification: jersey OCR, faces, global search (parity with old projects validated).
- Cutover: final import, redirects, old projects read-only, then switched off.
Deploy
Push to main -> Gitea webhook per container -> pull, build, migrate, reload, health check, auto-rollback.
Details: docs/DEPLOY.md.
Infrastructure (next)
| Container | Services | Domain |
|---|---|---|
| pr-api | apps/api + Socket.io (2 instances) |
api.next.photoreport.pt |
| pr-ingest | SFTPGo + photoreport-worker (ingest + delivery) |
ftp.next.photoreport.pt (DNS-only) |
| pr-app | apps/app static |
app.next.photoreport.pt |
| pr-site | apps/site |
next.photoreport.pt + brand domains |
| pr-db | PostgreSQL 17 + pgvector, pgBackRest | internal |
| pr-storage | /srv/photoreport-data bind mount shared by pr-api and pr-ingest (Garage later) |
internal |
| pr-workers | workers/media + workers/render |
internal |
| pr-ml | workers/ml |
internal |