ADR: engineering standards + ARCHITECTURE.md #917

Closed
kayg wants to merge 3 commits from docs/engineering-standards into dev
Owner

Adds ADR 0070 (enforceable engineering standards), ARCHITECTURE.md (matklad-style map), and three small CI guards. No product code changes.

Audit and ranked refactor list: #916 (also covers research sources).

Guards (Node only, no install, run in the web job, no runtime cost):

  • ci/check-size-budgets.mjs: Rust 600 / Rust test 1000 / web 500 lines; inline #[cfg(test)] not counted. 40 existing offenders are in ci/size-allowlist.json with a ceiling at today's size; a listed file may only shrink and must be removed once under the limit.
  • ci/check-crate-layers.mjs: dependency-direction table for all 24 crates, plus cycle check. Passes on dev (0 wrong-way edges).
  • ci/check-web-cycles.mjs: no new import cycles; 4 existing ones in ci/cycle-allowlist.json.
  • ci/check-architecture.test.mjs: 6 unit tests for the above.

Verified: on calternal-dev-01-compute02 at the pushed head: the 6 unit tests pass and all three checks pass; the existing evidence and case-path checks still pass.

Decisions (no questions asked):

  • Thresholds are ours, picked so the worst offenders are flagged and nothing else; they only get stricter.
  • The clippy-based rules (function length 150, cognitive complexity 30, unwrap/expect ratchet), cargo-machete, cargo-deny and an ESLint/dependency-cruiser layer check are specified in the ADR as follow-up PRs (B1-B8) because they need cargo/bun runs on the VMs and each changes many files.
  • apps/mockup is excluded from the size and cycle checks (not shipped).

Needs kayg's review of ADR 0070 (status: proposed). Not for merge until approved.

Adds [ADR 0070](docs/adr/0070-engineering-standards.md) (enforceable engineering standards), `ARCHITECTURE.md` (matklad-style map), and three small CI guards. No product code changes. Audit and ranked refactor list: #916 (also covers research sources). **Guards (Node only, no install, run in the web job, no runtime cost):** - `ci/check-size-budgets.mjs`: Rust 600 / Rust test 1000 / web 500 lines; inline `#[cfg(test)]` not counted. 40 existing offenders are in `ci/size-allowlist.json` with a ceiling at today's size; a listed file may only shrink and must be removed once under the limit. - `ci/check-crate-layers.mjs`: dependency-direction table for all 24 crates, plus cycle check. Passes on dev (0 wrong-way edges). - `ci/check-web-cycles.mjs`: no new import cycles; 4 existing ones in `ci/cycle-allowlist.json`. - `ci/check-architecture.test.mjs`: 6 unit tests for the above. **Verified:** on calternal-dev-01-compute02 at the pushed head: the 6 unit tests pass and all three checks pass; the existing evidence and case-path checks still pass. **Decisions (no questions asked):** - Thresholds are ours, picked so the worst offenders are flagged and nothing else; they only get stricter. - The clippy-based rules (function length 150, cognitive complexity 30, unwrap/expect ratchet), cargo-machete, cargo-deny and an ESLint/dependency-cruiser layer check are specified in the ADR as follow-up PRs (B1-B8) because they need cargo/bun runs on the VMs and each changes many files. - `apps/mockup` is excluded from the size and cycle checks (not shipped). Needs kayg's review of ADR 0070 (status: proposed). Not for merge until approved.
Three small Node checks that need no install. Today's offenders sit on
shrinking allow-lists (ceiling per file, one entry per known cycle).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ADR 0070: correct the crate-docs count
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled
1dc4d59c01
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Owner

Review of ADR 0070 (head 803ff81f)

Result: 14 rules before, 4 after. Only rules with a check that fails the build stay. Changes are pushed to this branch.

Old rule Verdict Why Check / evidence
A1 Rust file ≤ 600 lines (incl. comments) changed → rule 1 Now counts code lines only (no blanks, comments, doc comments, inline tests), one limit of 500 for Rust and web. Measured on code lines: median 133 Rust / 52 web, p90 436 / 234; 24 of 272 Rust and 7 of 338 web files are over. It catches the audit's god modules (meta.rs, history.rs, isolation.rs). Judgement number, not from a paper; listed files can only shrink so the exact value matters little. ci/check-size-budgets.mjs
A2 Rust test file ≤ 1000 cut Tests are flat lists of independent cases; length is not coupling. 5 entries of upkeep for no benefit. –
A3 Web file ≤ 500 merged into rule 1 One limit, one rule. same
A4 Listed file never grows changed (self-tightening) The check lowers or drops entries itself when run locally; CI only fails when the list is stale. Nobody edits numbers by hand. Tested: grow → fail, shrink → file rewritten. same
A5 Crate layers table + no cycles changed → rule 2 Hand table of 24 crates replaced by 7 layers; a crate adds one layerOf line, edges that already point down need no edit. Cargo already rejects crate cycles, so cycle check cut. Now also covers web packages (ui/editor may use only text). Tested: notes -> server fails. ci/check-layers.mjs
A6 No new web import cycles kept → rule 3 4 real cycles today and no other guard. Self-tightening list. ci/check-web-cycles.mjs
A7 -D warnings, unsafe forbid, fs ban cut (duplicate) Already enforced in ci.yml/Cargo.toml/clippy.toml; ADR now just points at them. existing
B1 fn length 150, B2 cognitive complexity cut Unenforced, needs 22+ #[expect] annotations to maintain; Ousterhout argues for depth over short functions. –
B3 args ≤ 7 cut Clippy default, already on. clippy
B4 unwrap count ratchet cut Count includes test-gate code (isolation.rs), noisy; unwrap policy belongs to clippy config if wanted. –
B5 machete, B6 cargo-deny, B8 public-api cut Not built; extra tools to install and keep in CI; no incident behind them. Can return as their own ADR. –
B7 ESLint boundaries / dep-cruiser cut Rule 2 now covers package direction in 20 lines; no new dependency. check-layers.mjs
C1–C12 reviewer checklists cut Not checkable by CI, so advice, not standards (they remain good PR-review prompts, but not in an ADR we must keep true). C10 (docs next to code) became rule 4. C9 (small public API) and C2 (actions) are already in 0010/0011. –
(new, kayg 11-04) docs from code added → rule 4 Every production file opens with a plain comment (//! Rust, ////*/<!-- --> TS/Svelte). 32 files lacked one; I wrote them (what the file is for, limits, failure behaviour; no restating code). Public-item /// docs are a review point; rustc missing_docs per crate is listed as a follow-up PR because it needs a cargo build and dev-01/02 are held by the bm14e train (my cargo check sat in ~/bin/slot ~1 h, then I stopped it rather than push unverified lint). Close: store, memory, engine, plugin-hello have 0–1 undocumented public items. ci/check-file-docs.mjs

CI wiring and evidence

  • .forgejo/workflows/ci.yml, job web, step "Keep the code maintainable (ADR 0070)": node --test ci/check-0070.test.mjs, then the four checks. Runs on pull_request and push to dev/main, no cargo, no build input, adds nothing to the shipped app.
  • Run on the PR head (control host, Node 22): check-size-budgets ok (610 files, 31 over 500 on the list), check-layers ok (27 manifests), check-web-cycles ok (365 files, 4 listed), check-file-docs ok; node --test ci/check-0070.test.mjs: 8 pass, 0 fail. All four together: 0.39 s.
  • Negative runs (all exit 1 with a readable message): a new 700-line Rust file; a listed file grown by one line (Settings.svelte ceiling 803 → 804); a new 638-line web file; calternal-notes -> calternal-server.
  • The Forgejo run for this head has not reported yet (runner queue); I did not run the web job's full suite.
  • No runtime/build cost: Node scripts over git ls-files, nothing in the shipped binary or bundle.

Open

  • missing_docs per crate: follow-up PR (verify with cargo when a dev VM slot frees).
  • Splitting the 31 listed files is the audit's (#916) job; this PR changes no behaviour.
## Review of ADR 0070 (head 803ff81f) Result: 14 rules before, 4 after. Only rules with a check that fails the build stay. Changes are pushed to this branch. | Old rule | Verdict | Why | Check / evidence | |---|---|---|---| | A1 Rust file ≤ 600 lines (incl. comments) | **changed → rule 1** | Now counts code lines only (no blanks, comments, doc comments, inline tests), one limit of **500** for Rust and web. Measured on code lines: median 133 Rust / 52 web, p90 436 / 234; 24 of 272 Rust and 7 of 338 web files are over. It catches the audit's god modules (`meta.rs`, `history.rs`, `isolation.rs`). Judgement number, not from a paper; listed files can only shrink so the exact value matters little. | `ci/check-size-budgets.mjs` | | A2 Rust test file ≤ 1000 | **cut** | Tests are flat lists of independent cases; length is not coupling. 5 entries of upkeep for no benefit. | – | | A3 Web file ≤ 500 | **merged into rule 1** | One limit, one rule. | same | | A4 Listed file never grows | **changed (self-tightening)** | The check lowers or drops entries itself when run locally; CI only fails when the list is stale. Nobody edits numbers by hand. Tested: grow → fail, shrink → file rewritten. | same | | A5 Crate layers table + no cycles | **changed → rule 2** | Hand table of 24 crates replaced by 7 layers; a crate adds one `layerOf` line, edges that already point down need no edit. Cargo already rejects crate cycles, so cycle check cut. Now also covers web packages (`ui`/`editor` may use only `text`). Tested: `notes -> server` fails. | `ci/check-layers.mjs` | | A6 No new web import cycles | **kept → rule 3** | 4 real cycles today and no other guard. Self-tightening list. | `ci/check-web-cycles.mjs` | | A7 `-D warnings`, `unsafe` forbid, fs ban | **cut (duplicate)** | Already enforced in `ci.yml`/`Cargo.toml`/`clippy.toml`; ADR now just points at them. | existing | | B1 fn length 150, B2 cognitive complexity | **cut** | Unenforced, needs 22+ `#[expect]` annotations to maintain; Ousterhout argues for depth over short functions. | – | | B3 args ≤ 7 | **cut** | Clippy default, already on. | clippy | | B4 unwrap count ratchet | **cut** | Count includes test-gate code (`isolation.rs`), noisy; unwrap policy belongs to clippy config if wanted. | – | | B5 machete, B6 cargo-deny, B8 public-api | **cut** | Not built; extra tools to install and keep in CI; no incident behind them. Can return as their own ADR. | – | | B7 ESLint boundaries / dep-cruiser | **cut** | Rule 2 now covers package direction in 20 lines; no new dependency. | `check-layers.mjs` | | C1–C12 reviewer checklists | **cut** | Not checkable by CI, so advice, not standards (they remain good PR-review prompts, but not in an ADR we must keep true). C10 (docs next to code) became rule 4. C9 (small public API) and C2 (actions) are already in 0010/0011. | – | | (new, kayg 11-04) docs from code | **added → rule 4** | Every production file opens with a plain comment (`//!` Rust, `//`/`/*`/`<!-- -->` TS/Svelte). 32 files lacked one; I wrote them (what the file is for, limits, failure behaviour; no restating code). Public-item `///` docs are a review point; rustc `missing_docs` per crate is listed as a follow-up PR because it needs a cargo build and dev-01/02 are held by the `bm14e` train (my `cargo check` sat in `~/bin/slot` ~1 h, then I stopped it rather than push unverified lint). Close: `store`, `memory`, `engine`, `plugin-hello` have 0–1 undocumented public items. | `ci/check-file-docs.mjs` | ### CI wiring and evidence - `.forgejo/workflows/ci.yml`, job `web`, step "Keep the code maintainable (ADR 0070)": `node --test ci/check-0070.test.mjs`, then the four checks. Runs on `pull_request` and push to `dev`/`main`, no cargo, no build input, adds nothing to the shipped app. - Run on the PR head (control host, Node 22): `check-size-budgets` ok (610 files, 31 over 500 on the list), `check-layers` ok (27 manifests), `check-web-cycles` ok (365 files, 4 listed), `check-file-docs` ok; `node --test ci/check-0070.test.mjs`: 8 pass, 0 fail. All four together: **0.39 s**. - Negative runs (all exit 1 with a readable message): a new 700-line Rust file; a listed file grown by one line (`Settings.svelte` ceiling 803 → 804); a new 638-line web file; `calternal-notes -> calternal-server`. - The Forgejo run for this head has not reported yet (runner queue); I did not run the web job's full suite. - No runtime/build cost: Node scripts over `git ls-files`, nothing in the shipped binary or bundle. ### Open - `missing_docs` per crate: follow-up PR (verify with cargo when a dev VM slot frees). - Splitting the 31 listed files is the audit's (#916) job; this PR changes no behaviour.
Author
Owner

housekeeping #1009: rebased+failing, left open for review.

rebased engineering standards and combined current architecture/primitive CI checks. kept deleted Inspector removed and current zoom guards.

head: b64783e5a5c6523692f0256ddea65606eaee2ef7; based on dev cd7f84432febfc63b788fbb9b9f9950452982d74, pushed with the original exact force-with-lease.

frontend frozen install, check, lint, build and unit tests passed. bundle gate passed. first-paint brotli vs dev: JS 230777 B (+0 B), CSS 18386 B (+0 B).

Rust gate results (Mac VM):

exit command
0 cargo fmt -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes -- --check
101 cargo check -j4 --locked -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes --all-targets
101 cargo clippy -j4 --locked -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes --all-targets -- -D warnings
101 cargo test -j4 --locked -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes

server-wide all-target checks/tests are blocked on macOS by storage_startup.rs:147 borrowing Child immutably; clippy also reports unused state in storage.rs:265. both reproduce on dev.

all executed gates used the VM Nix environment, shared Mac lock and slot. exact commands, source heads, logs and dev baseline. frontend inputs are identical to the tested frontend tree when a Rust-only repair changed the head.

original-head cherry/patch inventory, pr-917.md; unmatched entries are missing-patch candidates, with semantic overlap/replacements noted above.

housekeeping #1009: rebased+failing, left open for review. rebased engineering standards and combined current architecture/primitive CI checks. kept deleted Inspector removed and current zoom guards. head: `b64783e5a5c6523692f0256ddea65606eaee2ef7`; based on dev `cd7f84432febfc63b788fbb9b9f9950452982d74`, pushed with the original exact force-with-lease. frontend frozen install, check, lint, build and unit tests passed. bundle gate passed. first-paint brotli vs dev: JS 230777 B (+0 B), CSS 18386 B (+0 B). Rust gate results (Mac VM): | exit | command | |---|---| | 0 | `cargo fmt -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes -- --check` | | 101 | `cargo check -j4 --locked -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes --all-targets` | | 101 | `cargo clippy -j4 --locked -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes --all-targets -- -D warnings` | | 101 | `cargo test -j4 --locked -p calternal-auth -p calternal-backdrops -p calternal -p calternal-notes` | server-wide all-target checks/tests are blocked on macOS by `storage_startup.rs:147` borrowing Child immutably; clippy also reports unused `state` in `storage.rs:265`. both reproduce on dev. all executed gates used the VM Nix environment, shared Mac lock and slot. [exact commands, source heads, logs and dev baseline](https://git.kayg.org/attachments/bdb8d284-b80d-4185-b0be-6fa74f48a191). frontend inputs are identical to the tested frontend tree when a Rust-only repair changed the head. [original-head cherry/patch inventory](https://git.kayg.org/attachments/e05a38dc-c028-4d77-8655-efa9d5c8ea50), `pr-917.md`; unmatched entries are missing-patch candidates, with semantic overlap/replacements noted above.
Author
Owner

Merged into dev (4274dafb4, integration merge with #1043/#928/#917/#934; clippy -D warnings + workspace tests green on dev-01). Closing.

Merged into dev (4274dafb4, integration merge with #1043/#928/#917/#934; clippy -D warnings + workspace tests green on dev-01). Closing.
kayg closed this pull request 2026-11-10 10:09:24 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!917
No description provided.