ADR-121 — The export factory: a typed record per source, one document tree, a renderer per format¶
Status¶
Accepted (2026-10-29, the product owner's decisions on the design of issue
972 and of the hand-outs of #551). Delivery progress lives in changes/.¶
Amended 2026-11-03 by ADR-125, scope:
§1 (the answerZone block, typed labels; ADR-125 §6–§7), §2 (the student
answer hook studentAnswerDoc, the paper hook answerZone; ADR-125 §5),
§4 (a student-facing document's language; ADR-125 §7), §7 (Typst on the
server, no browser print view; ADR-125 §1–§3) and §8 steps 2, 3 and 6
(step 3's hand-out follows the evaluation's stored random paper seed, not seed 0, ADR-125 §8; step 6
comes before step 5).
Amended 2026-11-26 by ADR-148, scope: §8
step 3 (a parameterized question is no longer refused: the hand-out and the
key follow a stored paper variant; the key's record moves to version 2, its
items in the paper's order); then, the same day, §1 (a booklet block: a
paper of its own in one PDF; both records name their variant, the key at
version 3, the hand-out at 2).
Amended 2026-11-04 by ADR-126,
scope: §1 (the drawing block holds a closed drawing model, never
target-format markup; ADR-126 §1–§2).
Amended 2026-11-04 (product owner, 2026-11-04, after the first look at the
PDF), scope: §1 (a choices block; a heading's aside) and §4 (every
document in the requester's language); see the amendment at the end and
ADR-125's amendment of the same day.
Scope: every file the platform builds from its data for a person to read or process outside it — Markdown, JSON, PDF — except the results and gradebook CSV, the personal data export's JSON (ADR-112) and the canonical pool package (spec 04 §4.2), which keep their own writers.
Relations: requirements F-EXP-01..04
(02); depends on
invariant 4 and 05 §5.7
(the student exits it composes), invariant 6 (the loaders), invariant 14
(assembleCodeSource), ADR-025
(the attempt that counts), ADR-018 (a
teacher's test walk), ADR-037
(the student's key), ADR-056 (instances),
ADR-112 (§1, §4, §7;
to be amended at step 5).
Context¶
Teachers ask for files the screens already hold: every answer to one code question in one Markdown file, to read in one go or hand to a model (#972); an evaluation's statement and key, or a printed hand-out for a paper exam (#551); the results and the projects as data. Each request, built on its own, would add a writer that reads tables, decides what its reader may see, and formats — three jobs, written again each time, and each a possible second exit for answer keys beside the ones invariant 4 guards. The three writers that exist (the results CSV, F-RES-02; the gradebook CSV, F-GBOOK-04; the personal export, ADR-112) are not reusable for a document.
Question content is per type: only packages/qt-code knows how a program
answer becomes a source file, and only a type knows which of its parts are
text. packages/core never imports a type (D1), so the rendering of a
question must come from the type through its contract.
Decision¶
- One pipeline: Source → Record → Document → Renderer. No central
exportmodule. - Source: a function of the
service.tsof the module that owns the data (grading,results,privacy,evaluation, …), on an entity its route loaded through the existing loaders (invariant 6). A Source reads what its screen reads and applies no visibility rule of its own. - Record: a typed, versioned zod schema in
packages/contracts, withkindandversion(a change of shape bumpsversion). The JSON export IS the record:.jsonserves it parsed through its schema, so a field beyond the contract never travels. A student record is typed on the student schemas of the views it composes, neverz.unknown(). - Document: a small typed block tree in a new pure package,
packages/docexport(no database, no network, no clock):heading,markdown(a statement's text passed through as written),code(lang,text),list,table,tests(name,visible,ok,points),points,separator, and lateranswerZone(reserved for #551's answer space), with a front matter (point 5). The tree is internal: no route serves it. (Amended by ADR-125 §6–§7, by ADR-126 §1: adrawingblock, and by ADR-148 §10: abookletblock.) -
Renderer:
md, pure, inpackages/docexport— a code block's fence is one backtick longer than the longest run of backticks in its text, at least three, so no answer can close it early;json, the record itself;pdflater (point 7). -
A question renders itself through optional hooks of
QuestionTypeServer(packages/core/src/contract.ts), each fed only what its audience may already read: statementDoc(student): from the student view the API built withtoStudent, never from the config, so a statement carries no more than a student is served;solutionDoc(solution, student): the staff passtoSolution; a student's document passesstudentSolution's output if and only if the feedback policy shows the key (showKey, ADR-037);studentis the same student view, for what a key alone does not say (a program's language);-
answerDoc(config, answer, details): staff only.coderebuilds the source server-side withassembleCodeSource(invariant 14), never from a client's text, and lists every test, hidden ones by name. A student's answer, when step 5 needs it, gets a hook of its own typed on the student shapes only — the student view, the answer as handed back, andstudentDetails(details, policy)— so no hook decides visibility from a raw config. (Amended by ADR-125 §5.) A type without bothstatementDocandanswerDocoffers no Markdown or PDF button; its data stays in the JSON record. -
Audience rule (product owner): F-EXP-02 governs — what the requester can see in the app, and nothing more. A student-facing document is built from student shapes only, on the caller's own portal session (ADR-112 §7), and its rendered text joins the leak tests of 05 §5.7. What a student sees only in the player (the statements of an open exercise series, their own answers once a policy hides them after hand-in), which ADR-112 §4 keeps out of the personal export, is settled when ADR-112 is amended at step 5 (open question 62, 06). (Settled by ADR-125 §18.)
-
Staff documents name the students, in English. The owner overrode four points of #972: a staff document is not anonymised (only the grading screen is, F-GRADE-03), it carries no personal-data warning line, it is not audited (like F-RES-02 and F-GBOOK-04), and it holds the attempt that counts (ADR-025) rather than the last one; the stable "Copy N" numbering the issue proposed is therefore out of scope. Sending the file to a model is the teacher's own act, outside the platform's LLM path that N-DATA-05 governs. A staff document's fixed words are English, like the CSV; the language of a student document is decided with step 5. (Amended by ADR-125 §7; amended 2026-11-04: in the requester's language, not English.)
-
The front matter is provenance, YAML that docrender's
splitFrontMatterreads:export(kind,format,version),source(evaluationId,itemId,questionId,questionVersionId, as the kind has them),attempts(the ids the document holds),generatedAt(the server's clock),app(the build's commit, when known) andsha256(of the body after the front matter). Ids only, never a name. No?asOf=endpoint replays an old document (owner). -
The canonical format is not the document tree: it stays the authoring interchange of pools and questions (spec 04 §4.2).
-
PDF: Typst is the preferred engine (reproducible, real pagination, cross-references). A first version may try the web app's print view in the user's own browser (
@media print,break-inside: avoidper question; no server-side Chromium) only if its result is clean; it moves to Typst as soon as a question splits across pages, a cross-reference is needed, or #551's answer zones need a measured layout. Both render the same document tree. (Amended by ADR-125 §1–§3.) -
Sequence (each step its own PR, on this decision):
- this record;
-
972 on the minimal core: the package, the hooks on
code, the¶item's answers as Markdown and JSON, Export and Copy on the grading panel; a parameterized item is not offered (each attempt has its own statement and key, ADR-056);
- the hooks of the text types:
rich,short,math,cloze,mcq, a parameterized item still refused (rendering each attempt from its stored instance is that step's open question); - the evaluation document, staff only through the evaluation's loader (a student's series: step 5): statement and key, and a hand-out to print from the student views in the base order (seed 0, no shuffle); a parameterized question is refused in its first version (amended by ADR-148: printed from a stored paper variant);
- JSON records of the results, then of the projects;
- the student's Markdown export: the ADR-112 record and an exercise
series, by an amendment of ADR-112 (same rate limit, session rule and
privacy.exportaudit); - PDF (point 7), then #551's lots on the same tree. (Amended by ADR-125 §1–§8; step 6 before step 5.)
Consequences¶
- One place decides what a file may hold — the Source, by reusing a view — and one place formats it; a new type joins every document by its hooks.
- The record is a public contract: a reader (a teacher's script, a model)
relies on its
version. - Staff documents carry names, keys and hidden tests: they are as sensitive as the screens they come from, and leave the platform's control once downloaded.
Alternatives considered¶
- A central
exportmodule reading the tables. Rejected: a second exit for keys and unreleased grades beside every student view, as ADR-112 rejected a table dump. - Serve the document tree as the JSON. Rejected (owner): the tree is a layout; the record is the data a script wants.
- Canonical YAML as the document tree. Rejected: it is the authoring format of a question, not a document of answers, grades or hand-outs.
- A per-feature writer, as for the CSV. Rejected: each would re-decide visibility and re-implement Markdown escaping.
- One
answerDocwith an audience flag. Rejected: the type would apply the feedback policy to a raw config, a visibility rule outside the exits.
Amendment 2026-11-04: the requester's language¶
Decided by the product owner, 2026-11-04, after the first look at the PDF.
§4: a staff document's fixed words are no longer English; every document is
worded in the requester's interface language (readerLang(req)), and
answerDoc receives the labels as the other hooks do. The rest of §4 (no
anonymisation, no warning line, no audit, the attempt that counts) stands.
The other changes of that day — the choices block and a heading's
aside (§1), the page, the indented JSON record — are stated in
ADR-125's amendment of the same day.