diff --git a/apps/api/.env.example b/apps/api/.env.example new file mode 100644 index 0000000..d978725 --- /dev/null +++ b/apps/api/.env.example @@ -0,0 +1,5 @@ +PORT=3000 +LOG_LEVEL=info +APP_VERSION=dev +# DATABASE_URL=postgresql://photoreport:***@pr-db:5432/photoreport +# VALKEY_URL=redis://pr-queue:6379 diff --git a/apps/api/package.json b/apps/api/package.json new file mode 100644 index 0000000..319405b --- /dev/null +++ b/apps/api/package.json @@ -0,0 +1,17 @@ +{ + "name": "@photoreport/api", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "dev": "tsx watch src/server.ts", + "build": "tsc -p tsconfig.json", + "start": "node dist/server.js", + "typecheck": "tsc -p tsconfig.json --noEmit", + "test": "vitest run" + }, + "dependencies": { + "@photoreport/contracts": "workspace:*", + "fastify": "^5.4.0" + } +} diff --git a/apps/api/src/app.test.ts b/apps/api/src/app.test.ts new file mode 100644 index 0000000..bbe21eb --- /dev/null +++ b/apps/api/src/app.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from "vitest"; +import { buildApp } from "./app.js"; + +describe("api", () => { + it("reports health", async () => { + const app = buildApp({ version: "test" }); + const res = await app.inject({ method: "GET", url: "/health" }); + expect(res.json()).toEqual({ status: "ok", version: "test" }); + }); + + it("rejects malformed edits", async () => { + const app = buildApp({ version: "test" }); + const res = await app.inject({ method: "POST", url: "/v1/edits/validate", payload: { edit: {} } }); + expect(res.statusCode).toBe(400); + }); +}); diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts new file mode 100644 index 0000000..a243f5c --- /dev/null +++ b/apps/api/src/app.ts @@ -0,0 +1,27 @@ +import Fastify, { type FastifyInstance } from "fastify"; +import { EditEnvelope } from "@photoreport/contracts"; + +export interface AppOptions { + version: string; +} + +/** + * Builds the API. Modules (accounts, ingest, library, oplog, galleries, sales, events, print, nextcloud) + * register here as Fastify plugins as they are ported. + */ +export function buildApp(opts: AppOptions): FastifyInstance { + const app = Fastify({ logger: { level: process.env.LOG_LEVEL ?? "info" } }); + + app.get("/health", async () => ({ status: "ok", version: opts.version })); + + // Validation-only endpoint for the edit contract; the realtime path reuses the same schema. + app.post("/v1/edits/validate", async (req, reply) => { + const parsed = EditEnvelope.safeParse(req.body); + if (!parsed.success) { + return reply.code(400).send({ error: "invalid_edit", issues: parsed.error.issues }); + } + return { ok: true }; + }); + + return app; +} diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts new file mode 100644 index 0000000..cb0ec45 --- /dev/null +++ b/apps/api/src/server.ts @@ -0,0 +1,9 @@ +import { buildApp } from "./app.js"; + +const port = Number(process.env.PORT ?? 3000); +const app = buildApp({ version: process.env.APP_VERSION ?? "dev" }); + +app.listen({ port, host: "0.0.0.0" }).catch((err: unknown) => { + app.log.error(err); + process.exit(1); +}); diff --git a/apps/api/tsconfig.json b/apps/api/tsconfig.json new file mode 100644 index 0000000..bd19a4d --- /dev/null +++ b/apps/api/tsconfig.json @@ -0,0 +1 @@ +{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist", "rootDir": "src" }, "include": ["src"], "exclude": ["src/**/*.test.ts"] } diff --git a/apps/app/README.md b/apps/app/README.md new file mode 100644 index 0000000..0f691a1 --- /dev/null +++ b/apps/app/README.md @@ -0,0 +1,7 @@ +# apps/app + +React + TypeScript + Vite SPA: backoffice, library (culling, metadata) and the Lightroom-style editor. +The same build runs in the browser and inside `apps/desktop` (Tauri). + +Port from: `app.photoreport.pt/frontend` (screens only, redesigned), `PhotoReport_Studio` (culling rules, IPTC editor behaviour). +Design base: ShootYourMove design handoff (`tokens.css`, `BACKOFFICE.md`) via `packages/ui`. diff --git a/apps/desktop/README.md b/apps/desktop/README.md new file mode 100644 index 0000000..598e12b --- /dev/null +++ b/apps/desktop/README.md @@ -0,0 +1,6 @@ +# apps/desktop + +Tauri 2 shell around `apps/app`. Adds: native `engine/core` (Rust), local FTP receive from cameras, +disk access for RAW files, offline command queue (SQLite), auto-updater fed by Gitea releases. + +Replaces: `PhotoReport_Studio` (Flutter) and the archived `bridge.photoreport.pt`. diff --git a/apps/print-agent/README.md b/apps/print-agent/README.md new file mode 100644 index 0000000..7c4fe8f --- /dev/null +++ b/apps/print-agent/README.md @@ -0,0 +1,6 @@ +# apps/print-agent + +Print Station agent (Node + TypeScript, packaged per OS). Pairs with the API, claims print jobs, prints via a +PrintProvider (Mock / CUPS / Windows). + +Port from: `events.photoreport.pt/agent` (almost unchanged; only the API base and pairing endpoints move). diff --git a/apps/site/README.md b/apps/site/README.md new file mode 100644 index 0000000..b26c8cc --- /dev/null +++ b/apps/site/README.md @@ -0,0 +1,6 @@ +# apps/site + +Next.js public sites, multi-domain: photoreport.pt, shootyourmove.com, events guest flow (`/{eventSlug}`). +Domain -> organization, brand, theme and templates. + +Port from: `app.photoreport.pt/storefront`, `events.photoreport.pt/web` (guest flow), ShootYourMove mockup. diff --git a/packages/contracts/package.json b/packages/contracts/package.json new file mode 100644 index 0000000..09524de --- /dev/null +++ b/packages/contracts/package.json @@ -0,0 +1,15 @@ +{ + "name": "@photoreport/contracts", + "version": "0.1.0", + "private": true, + "type": "module", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } }, + "scripts": { + "build": "tsc -p tsconfig.json", + "typecheck": "tsc -p tsconfig.json --noEmit", + "test": "vitest run" + }, + "dependencies": { "zod": "^4.0.5" } +} diff --git a/packages/contracts/src/commands.test.ts b/packages/contracts/src/commands.test.ts new file mode 100644 index 0000000..e358c15 --- /dev/null +++ b/packages/contracts/src/commands.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vitest"; +import { EditCommand, EditEnvelope } from "./commands.js"; + +describe("EditCommand", () => { + it("accepts a develop.set with control ids", () => { + const parsed = EditCommand.parse({ command: "develop.set", params: { values: { "light.exposure": 0.4 } } }); + expect(parsed.command).toBe("develop.set"); + }); + + it("rejects non-numeric values", () => { + expect(() => EditCommand.parse({ command: "develop.set", params: { values: { "light.exposure": "x" } } })).toThrow(); + }); + + it("wraps commands in an envelope", () => { + const ok = EditEnvelope.safeParse({ + photoId: "3f2a9c1e-5b7d-4e8a-9c21-7d4e5f6a8b90", + clientId: "desktop-1", + clientOpId: "op-1", + edit: { command: "develop.reset" }, + }); + expect(ok.success).toBe(true); + }); +}); diff --git a/packages/contracts/src/commands.ts b/packages/contracts/src/commands.ts new file mode 100644 index 0000000..24f36c8 --- /dev/null +++ b/packages/contracts/src/commands.ts @@ -0,0 +1,42 @@ +import { z } from "zod"; + +/** + * Edit commands mirror `engine/core` (`EditCommand`). They carry no pixels: only control ids and values, + * so they are cheap to broadcast and to store in the op log. + */ +export const DevelopSetCommand = z.object({ + command: z.literal("develop.set"), + params: z.object({ values: z.record(z.string().regex(/^[a-z]+(\.[a-zA-Z0-9_]+)+$/), z.number().finite()) }), +}); + +export const DevelopMergeCommand = z.object({ + command: z.literal("develop.merge"), + params: z.object({ partial: z.record(z.string(), z.unknown()) }), +}); + +export const DevelopResetCommand = z.object({ command: z.literal("develop.reset") }); + +export const EditCommand = z.discriminatedUnion("command", [DevelopSetCommand, DevelopMergeCommand, DevelopResetCommand]); +export type EditCommand = z.infer; + +/** What a client sends over the realtime channel. */ +export const EditEnvelope = z.object({ + photoId: z.uuid(), + clientId: z.string().min(1).max(64), + /** Client-side id so the sender can match the server ack and drop it from its offline queue. */ + clientOpId: z.string().min(1).max(64), + edit: EditCommand, +}); +export type EditEnvelope = z.infer; + +/** What the server broadcasts after persisting: the envelope plus the per-photo sequence it assigned. */ +export const EditBroadcast = EditEnvelope.extend({ + seq: z.number().int().nonnegative(), + userId: z.uuid(), + at: z.iso.datetime(), +}); +export type EditBroadcast = z.infer; + +/** Realtime rooms. A user's own windows share `user:`; a whole event's team shares `event:`. */ +export const roomForUser = (userId: string): string => `user:${userId}`; +export const roomForEvent = (eventId: string): string => `event:${eventId}`; diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts new file mode 100644 index 0000000..e322021 --- /dev/null +++ b/packages/contracts/src/index.ts @@ -0,0 +1 @@ +export * from "./commands.js"; diff --git a/packages/contracts/tsconfig.json b/packages/contracts/tsconfig.json new file mode 100644 index 0000000..bd19a4d --- /dev/null +++ b/packages/contracts/tsconfig.json @@ -0,0 +1 @@ +{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist", "rootDir": "src" }, "include": ["src"], "exclude": ["src/**/*.test.ts"] } diff --git a/packages/metadata/README.md b/packages/metadata/README.md new file mode 100644 index 0000000..c8fb804 --- /dev/null +++ b/packages/metadata/README.md @@ -0,0 +1,6 @@ +# packages/metadata + +Photo Mechanic-style variables, code replacements, caption/IPTC templates and folder/file-name templates +(also used for per-client Nextcloud destinations). Shared by web, desktop and server. + +Port from: `PhotoReport_Studio` (120+ variables), `app.photoreport.pt` (`codeReplacements*`, `renameTemplateService`, `iptcWriteService`). diff --git a/packages/sdk/README.md b/packages/sdk/README.md new file mode 100644 index 0000000..d4a058a --- /dev/null +++ b/packages/sdk/README.md @@ -0,0 +1,3 @@ +# packages/sdk + +Typed API client + realtime command sync (Socket.io, sequence numbers, offline queue, replay on reconnect). diff --git a/packages/ui/README.md b/packages/ui/README.md new file mode 100644 index 0000000..fc49932 --- /dev/null +++ b/packages/ui/README.md @@ -0,0 +1,3 @@ +# packages/ui + +Shared React components and Tailwind design tokens (PhotoReport light, ShootYourMove dark) for `apps/app`, `apps/site`, `apps/desktop`.