Repository Public
1# Architecture23```mermaid4flowchart LR5 V[Visitor] -->|HTTPS| C[Caddy · BHS64<br/>TLS, compression]6 O[Owner] -->|HTTPS + passkey| C7 C -->|WireGuard| W[orix-web · Next.js 16<br/>node m4mm :8830]8 W --> DB[(SQLite<br/>orix.db)]9 W --> UP[uploads/]10 W --> AR[artifacts/<br/>approved DMGs]11 W -->|read-only JSON API| G[SPB Git<br/>git.spboucher.ai]12 R[Release script] -->|signed webhook| C13 B[orix-backup · 03:40] --> DB14```1516One Next.js process serves everything: public pages (server-rendered on each request from SQLite), the admin area, the JSON API and the download route. There is no separate backend, queue or cache server.1718## Layers1920| Path | Role |21|---|---|22| `src/models/` | `app.ts` (zod schema of an application document), `constants.ts` (vocabularies, dependency-free for client bundles), `filter.ts` (pure catalog search/filter/sort). |23| `src/lib/database/db.ts` | Opens the database, applies migrations, exposes `db()`, `tx()`, settings. |24| `src/lib/catalog.ts` | CMS operations: seed, draft, publish, unpublish, archive. |25| `src/lib/git/spbgit.ts` | Forge client: timeout, retries with exponential backoff, asset URL allow-list. |26| `src/lib/releases/` | `sync.ts` (discovery), `pipeline.ts` (approval, checksum, notarization, withdrawal), `store.ts`, `version.ts`. |27| `src/lib/testflight/` | Invitation URL rule, server-side link check, `betaAccess()` decision. |28| `src/lib/downloads/metrics.ts` | Anonymous daily counters. |29| `src/lib/auth/` | `enroll.ts` (one-time tokens), `webauthn.ts` (ceremonies), `session.ts` (cookies, CSRF). |30| `src/lib/security/` | Crypto helpers, HTTP error handling, rate limiter. |31| `src/lib/view.ts` | The single function that decides what a primary button does (`primaryAction`). |32| `src/app/[locale]/` | Public pages. English at the root, French-Canadian under `/fr` (`src/proxy.ts` rewrites). |33| `src/app/admin/` | Passkey sign-in, dashboard, application editor, release review, announcements. |34| `src/app/api/` | `health`, `metrics/click`, `hooks/release`, `auth/*`, `admin/*`. |35| `src/app/download/` | The only route that serves a release image. |3637## Data model (SQLite)3839| Table | Content |40|---|---|41| `apps` | One row per application: published document (`data`), pending draft (`draft`), publish state. |42| `releases` | One row per forge tag/asset: declared and computed SHA-256, state, notarization evidence, local artifact path. |43| `repo_meta`, `sync_runs` | Last forge metadata per app; history of synchronizations with their outcome. |44| `announcements` | Editorial entries of What's New (EN + FR, draft/published/archived). |45| `admins`, `credentials`, `sessions`, `enroll_tokens`, `challenges` | Passkey authentication. Tokens and sessions are stored as SHA-256 hashes. |46| `downloads` | `(day, slug, version, kind) → n`. Nothing else. |47| `audit`, `webhook_nonces`, `settings` | Audit trail, replay protection, publication policy. |4849## Release states5051```mermaid52stateDiagram-v253 [*] --> note: tag without a DMG54 [*] --> validated: DMG + size + SHA-256 + forge URL55 [*] --> invalid: anything missing or foreign56 validated --> published: admin approves · checksum ok · notarized57 validated --> held: approved but notarization not verified58 validated --> invalid: checksum / size / download failure59 held --> published: re-verified, or policy switched off60 published --> withdrawn: admin, or asset changed upstream61 held --> withdrawn62 withdrawn --> validated: re-queue (manual withdrawals only)63```6465Only `published` rows with a file on disk are downloadable. The default download is the highest published **stable** version, so withdrawing it rolls back to the previous one automatically.6667## Rendering and performance6869- Pages are dynamic but cheap: synchronous SQLite reads, no network call on the request path.70- Client JavaScript is limited to: header, hero parallax, universe, catalog filtering, gallery lightbox, scroll reveals, click beacon. The schema library (zod) is kept out of client bundles.71- Images go through `next/image` (AVIF/WebP, responsive `srcset`, lazy loading below the fold).72- Animation uses transform, opacity and CSS motion paths; everything pauses off screen and under `prefers-reduced-motion`.73