Repository Public
1# Architecture23Status of this document: §1–§3 and §5 describe Phases 0–3; §4 and §6 were rewritten for Phase 4 (studio, media pipeline) and the buildable part of Phase 5, as built on 2026-11-22. Anything not built is marked **not implemented**.45## 1. Phase 0 — verified findings (2026-11-22)67Recorded as given by the project lead, who performed the reconnaissance; not re-investigated here.89| Subject | Finding |10|---|---|11| IMM1003 / IMM1033 platform | Two apps, `uqo-imm1003` and `uqo-imm1033` (« Notes de cours interactives »). Each is a prebuilt static `dist/` served by a tiny `node server.mjs <port> <dist>` under PM2, with `/api/health`. No video player, no administration, no authentication, no storage layer. Nothing reusable for a video MOOC beyond the deployment pattern. Their source repository was not inspected further. |12| `atlas.spboucher.ai` | Resolves to the owner's public gateway (51.161.112.61, Caddy, automatic TLS). No route exists yet (connections fail). There is no existing deployment and no data to preserve. |13| House stack | Next.js 16 (App Router), React 19, strict TypeScript, Tailwind CSS 4, zod, @simplewebauthn (passkeys), vitest, Playwright + axe, pnpm, Node ≥ 24; one Next server process under PM2 behind the Caddy gateway; SQLite/filesystem state in a `data/` directory outside git; `/api/health`. Proven on a dozen of the owner's production sites. Reference read for conventions: `orix-spboucher-ai`. |14| Curriculum repository | `atlas-ai-mooc` (read-only for this project). 24 sessions in 6 parts; its plan supersedes the placeholder list of the platform specification §4. At the time of the last import (2026-11-22), sessions S01–S08 declared `implemented`, S09 `draft`, the others `planned`; other people were writing sessions in that repository while this platform was built. No video is recorded. No licence is chosen. No session has been reviewed by the instructor. |15| Production port | 8840 (default `PORT`). |1617## 2. Stack chosen, and why not the specification's « default candidate »1819The specification (§14) proposes PostgreSQL, S3-compatible object storage, containers and FFmpeg workers as a default, and adds: *prefer the existing proven stack when warranted; avoid complexity for its own sake.* The house stack is used because:2021- **The public site is read-only.** Phases 1–3 have no write path at all: no database is needed to serve a manifest of 24 sessions. A committed, schema-validated JSON snapshot is simpler, diffable, and cannot be corrupted at runtime.22- **One operator, one node.** The owner runs every site as a single Next process under PM2 behind one Caddy gateway, with state in `data/`. A second runtime (Postgres, MinIO, a container engine) would be the only one of its kind to operate, back up and patch.23- **Nothing is lost for Phase 4.** Authoring metadata fits SQLite (as in the reference project); media bytes go through a storage interface (`src/modules/storage`) for which an S3 implementation can be added without touching routes.24- **Scale.** The corpus is 24 sessions, a few hundred transcript segments per capsule, a few hundred glossary terms: a local search index is the right size (specification §10 prefers it).2526Single package rather than a monorepo: the four domain modules live in `src/modules/*` and depend on nothing in `src/app` or `src/components` (enforced by convention and by the unit tests, which import them without Next). Splitting them into workspace packages later is mechanical.2728## 3. Layers2930```31content/course.manifest.json ─┐32content/import/** ├─► src/lib/content.ts ──► buildView(manifest, mode) ──► CourseView ──► pages, search index,33content/preview/overlay.json ─┘ (server only) (publication.ts) sitemap, JSON-LD,34ATLAS_DATA_DIR/media/** ──────────► MediaStorage (FsStorage) ◄── /media/[...path] (mediaAllowed) media routes35```3637- **`src/modules/content-schema`** — `schema.ts` (zod: manifest, sections, quiz, glossary…), `publication.ts` (the only place that decides visibility), `urls.ts`, `adapter.ts` (pure conversions from the course repository's formats).38- **`src/modules/learning-engine`** — `quiz.ts` (grading), `state.ts` (local state, export/import, completion rule), `vtt.ts` (captions, transcript), `text.ts`.39- **`src/modules/search`** — tokenisation, typo-tolerant matching, ranking, facets, highlighting.40- **`src/modules/diagram-library`** — `logic.ts` (the model behind each diagram, unit-tested), `registry.ts` (catalogue).41- **`src/modules/storage`** — `MediaStorage` interface, `FsStorage`, range parsing, MIME allow-list.42- **`src/lib`** — server glue: `content.ts` (loader), `search-index.ts`, `seo.ts`, `serve.ts`, `env.ts`; `client/store.ts` (localStorage holder).43- **`src/app`** — routes. **`src/components`** — UI.4445### The publication rule (one function)4647`buildView(manifest, mode)` returns the `CourseView`. Pages never see the manifest.4849| Session state | production | preview |50|---|---|---|51| `planned`, `draft` | « À venir » — public plan only | « À venir » — public plan only |52| `preview` | « À venir » — public plan only | open, bannered, never counted as published |53| `published` | open | open |54| `archived` | withdrawn notice, not indexed | same |5556Within an open session, each section and capsule has its own visibility (`private` / `preview` / `public`). Downloads additionally require `download: true` **and** a recorded licence (`canDownload`). Counts shown to visitors (`counts.published`, `counts.capsules`) exclude preview-only sessions and synthetic capsules.5758### Modes5960`ATLAS_PREVIEW=1` selects the preview mode. It is read at **build** time (pages are static) and at **run** time (media and content routes). The preview build goes to `.next-preview/`, so it cannot be started by mistake as the production build; it sends `X-Robots-Tag: noindex`, serves `Disallow: /` in robots.txt, an empty sitemap, `no-store` media, and shows a non-dismissible banner on every page.6162## 4. Rendering and caching (changed in Phase 4)6364- **Public pages are rendered on demand** (`export const dynamic = "force-dynamic"` on the `(public)` layout) from the publications in force. Publishing, scheduling, rolling back and withdrawing take effect at the next request, with no rebuild, and there is no cached copy of a withdrawn page that could be served by mistake. The cost is a server render per request (SQLite is in-process; the public manifest is cached per content revision). Static generation and ISR were rejected for this reason: a stale page after a rollback is a leak.65- No `loading.tsx` in the public tree any more: under a Suspense boundary a `notFound()` or a redirect would answer 200. Unknown addresses are real 404s and former addresses real 308s (`(public)/[...rest]`, session pages).66- The search corpus (`/recherche/index.json`) and the sitemap are dynamic too; the corpus is kept in memory per content revision, one minute at most.67- `/media`, `/contenu`, `/telecharger`, `/api/health*`, everything under `/admin` are dynamic.68- The development preview (`ATLAS_PREVIEW=1`, separate `.next-preview`) still exists for the committed snapshot; it never reads the database and closes the studio.6970## 5. What is deliberately not here7172No service worker (no offline promise is made; the site only tells the visitor when the connection drops). No analytics. No cookie. No server-side learner state. No third-party origin (CSP: `default-src 'self'`, no remote host listed). No AI API.7374## 6. Phase 4 as built7576```77 ┌──────────── /admin (pages) ── requireEditorPage ─┐78browser (passkey) ───▶│ /admin/api/[...path] ── dispatch(): session, role, origin, CSRF, rate limit ──▶ src/server/*79 └──────────── /admin/apercu/** (private preview: working copy) ┘ │80 ▼81course repository ──importer (data only)──▶ sync.ts (3-way diff) ──▶ working copy ──publish.ts──▶ publications (immutable)82 (content.ts) │ publicManifest(now)83uploads (chunks) ──▶ masters/ ──jobs──▶ worker (ffmpeg) ──▶ media/<session>/<capsule>/<encode>/ ▼84 buildView(manifest, "production") ──▶ public site85```8687- **`src/server/`** — plain Node modules shared by the Next server, the worker and the CLI: `db.ts` (node:sqlite, WAL, forward-only migrations), `auth.ts`, `audit.ts` (+ content-addressed `blobs`), `content.ts` (working copy), `publish.ts` (publications, public manifest), `sync.ts` (bootstrap, diff, apply), `importer.ts` (moved from `scripts/lib`), `uploads.ts`, `magic.ts`, `archive.ts`, `captions.ts`, `jobs.ts`, `transcode.ts`, `worker.ts`, `storage.ts`, `ops.ts`, `backup.ts`, `log.ts`, `http.ts`.88- **`src/lib/studio/`** — the Next-side gate (`guard.ts`: cookies, page and API guards) and the API table (`api.ts`).89- **`src/app/admin/`** — sign-in and enrolment pages, studio pages, the API route, the private preview (pages + media, figures, downloads for editors). **`src/components/studio/`** — the interface.90- **One gate, unchanged in spirit.** `loadPublicManifest()` in `src/lib/content.ts` returns either `publicManifest()` (live publications) or the committed snapshot (no database yet); `buildView` filters it as before. `getPreviewCourse()` builds the editors' view from the working copy in `preview` mode and is only called under `/admin` after the session check. Section bodies are read by hash through references present in a view.91- **Database** `ATLAS_DATA_DIR/atlas.db`: `editors`, `credentials`, `auth_sessions`, `enroll_tokens`, `challenges`, `audit`, `blobs`, `course`, `course_sessions`, `sections`, `capsules`, `resources`, `resource_versions`, `publications`, `imports`, `uploads`, `upload_chunks`, `masters`, `jobs`, `meta`, `schema_migrations`.92- **Files**: `media/` (servable when published), `masters/` (originals by SHA-256), `resources/`, `uploads/` (staging), `work/` (scratch), `backups/`.9394Why SQLite through `node:sqlite` rather than better-sqlite3: nothing to compile on macOS arm64 across Node 24–26, and the synchronous API fits a single-node tool. Verified here on Node 26.13 only; `node:sqlite` exists unflagged from Node 22.13/24 (it may print an experimental warning on 24).9596### Interactive lessons (added 2026-11-22)9798- `src/modules/content-schema/lesson-tex.ts` — pure conversion of deck sources to lesson text (notes stripped first; unknown constructs dropped). `src/server/lessons.ts` — build from the repository (allow-listed files), pack, import, `publishLesson` / `unpublishLesson`.99- `src/modules/explorables/` — `pyrandom.ts` (Python's seeded generator, reproduced), one model file per session (`s01.ts`…), `registry.ts` (catalogue, anchor slide of each explorable, library diagrams placed in lessons). `src/components/explorables/` — the interfaces; `src/components/lesson/` — the lesson view (server-rendered text; only explorables, checks and progress marks are client components).100- Still one gate: the `lesson` section is a section like the others; `buildView` shows it only when public in a live publication, and adds `lessonOnly` (lesson online, no video → not counted as published) and `counts.lessons`.101102## 7. Known limits of the current design103104- Public pages cost a server render each; no page cache exists in the application (a gateway micro-cache would be safe only for anonymous GETs outside `/admin`, and would delay rollbacks by its lifetime).105- Limits kept in memory (rate limits, search corpus, public manifest cache) assume one web process.106- The JavaScript of the player, the quiz engine and the diagram library is part of every build, including production, where the diagram routes are 404. That is platform code, not course content; the leak check covers content.107- CSP uses `'unsafe-inline'` for scripts and styles, because statically generated Next pages cannot carry a per-request nonce. No remote origin is allowed, which bounds the risk; see `SECURITY.md`.108- Importing a session trusts its `metadata.yaml` status. A session marked `implemented` while still being edited would be snapshotted as it is; it stays `draft` (invisible) until someone decides otherwise.109