diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..16ffcc3 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,32 @@ +name: ci +on: + push: + branches: [main] + pull_request: + +jobs: + typescript: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + # pnpm-lock.yaml is committed from the first dev checkout; switch back to --frozen-lockfile then. + - run: pnpm install + - run: pnpm -r build + - run: pnpm -r typecheck + - run: pnpm -r test + + rust: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + - run: cargo fmt --all --check + - run: cargo clippy --workspace --all-targets -- -D warnings + - run: cargo test --workspace diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8735fb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules/ +dist/ +target/ +coverage/ +.env +.env.* +!.env.example +.DS_Store +*.log diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..2bd5a0a --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..47566bb --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,27 @@ +# Rules for agents (Paperclip, Claude Code, Cursor) + +Read `docs/ARCHITECTURE.md` before any task. One task id per branch/PR (`task/BIT--short-slug`). + +## Non-negotiables + +1. **LightCraft is consumed, never forked.** Only `engine/core` imports `lightcraft-*` crates. Pin by `rev` in + the root `Cargo.toml`. A bump is its own PR and must pass the reference-image tests. Missing engine features + go upstream as PRs to storytold/lightcraft. +2. **Edits are commands, not pixels.** Every edit is an `EditCommand` (`packages/contracts`, mirrored in + `engine/core`). The server assigns a per-photo `seq`; clients replay from a `seq`. +3. **Files and edits travel separately.** Uploads go through the queue (tus / SFTPGo); edits through Socket.io. +4. **Organizations from day one.** Every row that belongs to someone carries `organization_id`. Agency mode and + independent-photographer mode are an organization setting, not separate code paths. +5. **No Adobe assets or names in the UI.** Same workflow as Lightroom, original icons, labels and presets. +6. **Biometrics are opt-in per organization** and the legal basis is stored with the setting. +7. **No third-party AI by default.** Faces and OCR run locally; external fallbacks are opt-in per organization. +8. **Language:** code, comments, identifiers and commit messages in English. User-facing copy via i18n (pt-PT first). +9. **Never commit** secrets, `.env`, generated status/summary markdown files, or build output. +10. **Green CI before merge:** `pnpm -r build && pnpm -r typecheck && pnpm -r test` and `cargo fmt --check`, + `cargo clippy -D warnings`, `cargo test`. + +## Porting from the old projects + +Port logic and tests, not UI. Sources: `BitReport.pt/app.photoreport.pt`, `BitReport.pt/events.photoreport.pt`, +`BitReport.pt/PhotoReport_Studio`. Keep behaviour identical unless the task says otherwise, and note the +original file in the PR description. diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..698f3d6 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +See `AGENTS.md` (rules) and `docs/ARCHITECTURE.md` (architecture and decisions). diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e1ed19c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,173 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "lightcraft-color" +version = "0.6.0" +source = "git+https://github.com/storytold/lightcraft?rev=0dd6593d9db55a17ab559261bac4d766f015c345#0dd6593d9db55a17ab559261bac4d766f015c345" +dependencies = [ + "lightcraft-geom", + "serde", +] + +[[package]] +name = "lightcraft-develop" +version = "0.6.0" +source = "git+https://github.com/storytold/lightcraft?rev=0dd6593d9db55a17ab559261bac4d766f015c345#0dd6593d9db55a17ab559261bac4d766f015c345" +dependencies = [ + "lightcraft-color", + "lightcraft-geom", + "miniz_oxide", + "serde", + "serde_json", +] + +[[package]] +name = "lightcraft-geom" +version = "0.6.0" +source = "git+https://github.com/storytold/lightcraft?rev=0dd6593d9db55a17ab559261bac4d766f015c345#0dd6593d9db55a17ab559261bac4d766f015c345" +dependencies = [ + "serde", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", +] + +[[package]] +name = "photoreport-engine" +version = "0.1.0" +dependencies = [ + "lightcraft-develop", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1741ab7a6cc54a03a89b5d563ed60075c277d9e3cfa73ad0c1f23f23974703c6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "syn" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d62a2e0561533f2ca2561d0cf27fd9fedb640a1bf2616ff5d5c80d99017faadc" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..37e1ac7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[workspace] +resolver = "2" +members = ["engine/core"] + +[workspace.package] +edition = "2024" +license = "UNLICENSED" +publish = false + +[workspace.dependencies] +# LightCraft is consumed, never forked. Bump `rev` deliberately and run the reference-image tests. +lightcraft-develop = { git = "https://github.com/storytold/lightcraft", rev = "0dd6593d9db55a17ab559261bac4d766f015c345" } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +thiserror = "2" diff --git a/README.md b/README.md new file mode 100644 index 0000000..574c6f3 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# PhotoReport + +Unified PhotoReport platform: ingest, library, Lightroom-style editor (web + desktop, real-time sync), +galleries and sales (PhotoReport and ShootYourMove skins), events with instant printing, client delivery to +Nextcloud, and player identification (jersey OCR + faces). + +Replaces, once at parity: `app.photoreport.pt`, `events.photoreport.pt`, `PhotoReport_Studio`. +Final domain: `app.photoreport.pt` (built on the `next` environment until cutover). + +## Layout + +| Path | What | +| --- | --- | +| `apps/api` | Fastify API (TypeScript): accounts, organizations, ingest, library, op log, sales, events, delivery | +| `apps/app` | React SPA: backoffice, library and editor; runs in the browser and in `apps/desktop` | +| `apps/site` | Next.js public sites, multi-domain | +| `apps/desktop` | Tauri shell: native engine, local FTP, disk, offline queue | +| `apps/print-agent` | Print Station agent | +| `workers/media` | Node workers: previews, IPTC, ZIPs, emails, Nextcloud delivery | +| `workers/render` | Rust worker: final exports and faces (`lightcraft-faces`) | +| `workers/ml` | Python worker: jersey OCR | +| `engine/core` | Rust layer over LightCraft develop crates (pinned, never forked) | +| `engine/wasm` | Browser build of `engine/core` | +| `packages/*` | Contracts, metadata templates, UI tokens/components, SDK | + +## Develop + +```sh +pnpm install +pnpm -r build && pnpm -r test # TypeScript +cargo test --workspace # Rust +pnpm dev:api # API on :3000 (GET /health) +``` + +Architecture and decisions: [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md). Rules for agents: [`AGENTS.md`](AGENTS.md). diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..7c00170 --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,90 @@ +# 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 `next` environment; 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, behind `engine/core`. Not `lightcraft-engine`/`catalog`: + our catalog is the API. +- Faces: `lightcraft-faces` (YuNet detection + SFace recognition, pure Rust) in `workers/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 · BullMQ on Valkey · Socket.io (Valkey +adapter) · Garage (S3-compatible) · tusd + SFTPGo · 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:` and `event:`. 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, app passwords tied to the PhotoReport account) or desktop/browser -> tus. +Desktop sends a light preview first, original later; picks jump the queue. Routing picks the event from +camera serial, EXIF time and the photographer's schedule. Then: previews, event IPTC, OCR, faces. +Final export (`workers/render`) replays the op log on the original, so it matches the screen. + +## Client delivery (Nextcloud) + +Garage 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. +After upload (WebDAV chunked), create a read-only public share via OCS and store the link on the event. + +| Instance | Client | Folders today | Files | +| --- | --- | --- | --- | +| cloud.photoreport.pt | FPA | `/FPA/Fotos/2026_2027/Competições Nacionais/PO01 - Campeonato Betclic/20260923 - VSC x AAAS/` | `PS_ x _.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. + +## RAW support (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: collect real files from each body, add them to our reference set, contribute samples upstream. + +## Phases (gate to pass) + +0. Foundation: monorepo, CI, `next` containers, accounts, organizations, tokens (login on web and desktop). +1. Ingest + library: SFTPGo/tus, routing, previews, IPTC, code replacements, culling, Nextcloud delivery + (a real match arrives captioned and delivered with no manual step). +2. Synced editor: native + WASM engine, op log, Socket.io, offline, render worker (PoC demo: same photo + edited on web and desktop). +3. 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). +4. Events and printing: QR guest flow, templates, print jobs, Print Agent (a real event printed). +5. Player identification: jersey OCR, faces, global search (parity with old projects validated). +6. Cutover: final import, redirects, old projects read-only, then switched off. + +## Infrastructure (`next`) + +| Container | Services | Domain | +| --- | --- | --- | +| pr-api | `apps/api` + Socket.io (2 instances) | api.next.photoreport.pt | +| 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-queue | Valkey | internal | +| pr-storage | Garage | files.next.photoreport.pt | +| pr-ingest | SFTPGo + tusd | ftp.next.photoreport.pt (DNS-only), upload.next.photoreport.pt | +| pr-workers | `workers/media` + `workers/render` | internal | +| pr-ml | `workers/ml` | internal | diff --git a/docs/adr/0001-unified-monorepo.md b/docs/adr/0001-unified-monorepo.md new file mode 100644 index 0000000..8f06bba --- /dev/null +++ b/docs/adr/0001-unified-monorepo.md @@ -0,0 +1,18 @@ +# ADR 0001: One unified monorepo, greenfield beside the old projects + +Date: 2026-10-11 · Status: accepted + +## Context +Three overlapping projects (app.photoreport.pt in Node/JS + MySQL, events.photoreport.pt in Fastify/TS + +Prisma, PhotoReport Studio in Flutter) with separate accounts, databases and UIs. + +## Decision +Build one monorepo (`BitReport.pt/photoreport`) on new containers. Port business logic and tests, redesign +the UI. TypeScript + PostgreSQL backend, one React UI shipped to web and Tauri desktop, LightCraft crates as +the develop engine behind `engine/core`. Old projects stay in production until each phase reaches parity, +then data is imported and they are switched off. Final domain `app.photoreport.pt`. + +## Consequences +- One login, one realtime channel, one design system. +- Data migration scripts are first-class code with dry runs from phase 3. +- Flutter Studio work is kept as behaviour reference and tests, not code. diff --git a/infra/README.md b/infra/README.md new file mode 100644 index 0000000..b5b1343 --- /dev/null +++ b/infra/README.md @@ -0,0 +1,4 @@ +# infra + +Provisioning for the LXC containers on Proxmox (`next` environment first), Cloudflare DNS, per-service Compose files. +See `docs/ARCHITECTURE.md` -> Infrastructure. diff --git a/package.json b/package.json new file mode 100644 index 0000000..d4fe66c --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "photoreport", + "private": true, + "packageManager": "pnpm@10.12.1", + "engines": { "node": ">=22" }, + "scripts": { + "build": "pnpm -r build", + "typecheck": "pnpm -r typecheck", + "test": "pnpm -r test", + "dev:api": "pnpm --filter @photoreport/api dev" + }, + "devDependencies": { + "typescript": "^5.9.2", + "vitest": "^3.2.4", + "tsx": "^4.20.3", + "@types/node": "^22.15.0" + } +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..b8a97de --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,6 @@ +packages: + - "apps/*" + - "workers/*" + - "packages/*" +onlyBuiltDependencies: + - esbuild diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..f912e3d --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ES2023", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": true, + "sourceMap": true, + "resolveJsonModule": true, + "verbatimModuleSyntax": true + } +} diff --git a/workers/media/README.md b/workers/media/README.md new file mode 100644 index 0000000..4aad588 --- /dev/null +++ b/workers/media/README.md @@ -0,0 +1,4 @@ +# workers/media + +Node BullMQ workers: thumbnails and previews, IPTC/XMP writing, ZIP downloads, emails, +Nextcloud delivery (WebDAV chunked upload + OCS public share links), archive import. diff --git a/workers/ml/README.md b/workers/ml/README.md new file mode 100644 index 0000000..c2bd730 --- /dev/null +++ b/workers/ml/README.md @@ -0,0 +1,3 @@ +# workers/ml + +Python worker: jersey number OCR (PaddleOCR) cross-checked against the match squad. Local only; no third-party APIs by default. diff --git a/workers/render/README.md b/workers/render/README.md new file mode 100644 index 0000000..2079470 --- /dev/null +++ b/workers/render/README.md @@ -0,0 +1,5 @@ +# workers/render + +Rust worker. Final exports from the original + the photo's op log, using `engine/core`, so the export matches +what the photographer saw. Also face detection/recognition with `lightcraft-faces` (YuNet + SFace). +Scales to all available cores (speed over resource use).