architecture-harness 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +80 -0
- package/src/cli/check.mjs +535 -0
- package/src/cli/cli.test.mjs +120 -0
- package/src/cli/commit-attribution.mjs +68 -0
- package/src/cli/commit-attribution.test.mjs +47 -0
- package/src/cli/decisions.mjs +223 -0
- package/src/cli/doctor.mjs +135 -0
- package/src/cli/doctor.test.mjs +57 -0
- package/src/cli/init.mjs +98 -0
- package/src/cli/install-hooks.mjs +26 -0
- package/src/cli/qc.mjs +89 -0
- package/src/cli/scaffold.mjs +194 -0
- package/src/cli/sync-enforcement-map.mjs +28 -0
- package/src/cli/work-order-guard.mjs +0 -0
- package/src/cli/work-order-guard.test.mjs +79 -0
- package/src/cli/worktree-isolation.mjs +94 -0
- package/src/cli/worktree-isolation.test.mjs +82 -0
- package/src/config.mjs +338 -0
- package/src/config.test.mjs +59 -0
- package/src/decisions.mjs +198 -0
- package/src/decisions.test.mjs +183 -0
- package/src/descriptions.mjs +28 -0
- package/src/descriptions.test.mjs +27 -0
- package/src/enforcement-map.mjs +46 -0
- package/src/enforcement-map.test.mjs +60 -0
- package/src/eslint/index.mjs +37 -0
- package/src/eslint/options.mjs +53 -0
- package/src/eslint/preset.mjs +192 -0
- package/src/eslint/preset.test.mjs +96 -0
- package/src/eslint/rules/durable-idempotency-key.mjs +120 -0
- package/src/eslint/rules/external-service-only-in-adapter.mjs +52 -0
- package/src/eslint/rules/module-boundary.mjs +12 -0
- package/src/eslint/rules/name-the-pattern.mjs +111 -0
- package/src/eslint/rules/no-comment-paragraph.mjs +101 -0
- package/src/eslint/rules/no-cross-feature-internals.mjs +57 -0
- package/src/eslint/rules/no-number-in-comment.mjs +89 -0
- package/src/eslint/rules/no-offset-pagination.mjs +29 -0
- package/src/eslint/rules/no-orchestration-in-trigger.mjs +56 -0
- package/src/eslint/rules/no-promise-then.mjs +43 -0
- package/src/eslint/rules/no-promise-then.test.mjs +63 -0
- package/src/eslint/rules/no-raw-fetch.mjs +27 -0
- package/src/eslint/rules/no-status-literal.mjs +34 -0
- package/src/eslint/rules/no-supersession-trail.mjs +51 -0
- package/src/eslint/rules/scoped-repository.mjs +43 -0
- package/src/eslint/rules/signal-last-param.mjs +43 -0
- package/src/eslint/rules/storage-only-in-resource.mjs +52 -0
- package/src/eslint/rules/tenant-scoped-table.mjs +71 -0
- package/src/eslint/rules.test.mjs +627 -0
- package/src/gates/adr-format.mjs +87 -0
- package/src/gates/adr-format.test.mjs +54 -0
- package/src/gates/audit-append-only.mjs +34 -0
- package/src/gates/audit-append-only.test.mjs +36 -0
- package/src/gates/citations.mjs +93 -0
- package/src/gates/citations.test.mjs +115 -0
- package/src/gates/claimed-requirements.mjs +53 -0
- package/src/gates/claimed-requirements.test.mjs +60 -0
- package/src/gates/comment-style.mjs +76 -0
- package/src/gates/comment-style.test.mjs +46 -0
- package/src/gates/config-floor.mjs +68 -0
- package/src/gates/config-floor.test.mjs +52 -0
- package/src/gates/contract-compose.mjs +38 -0
- package/src/gates/contract-compose.test.mjs +40 -0
- package/src/gates/eight-blocks.mjs +223 -0
- package/src/gates/eight-blocks.test.mjs +359 -0
- package/src/gates/enforcement-map.mjs +62 -0
- package/src/gates/enforcement-map.test.mjs +41 -0
- package/src/gates/english-source.mjs +176 -0
- package/src/gates/english-source.test.mjs +122 -0
- package/src/gates/frontend-boundaries.mjs +154 -0
- package/src/gates/frontend-boundaries.test.mjs +72 -0
- package/src/gates/gate-tests.mjs +44 -0
- package/src/gates/gate-tests.test.mjs +41 -0
- package/src/gates/headless-sagas.mjs +54 -0
- package/src/gates/headless-sagas.test.mjs +71 -0
- package/src/gates/internal-routes.mjs +76 -0
- package/src/gates/internal-routes.test.mjs +53 -0
- package/src/gates/public-routes.mjs +67 -0
- package/src/gates/public-routes.test.mjs +38 -0
- package/src/gates/registry-agreement.mjs +37 -0
- package/src/gates/registry-agreement.test.mjs +36 -0
- package/src/gates/saga-tests.mjs +94 -0
- package/src/gates/saga-tests.test.mjs +92 -0
- package/src/gates/sql-identifiers.mjs +244 -0
- package/src/gates/sql-identifiers.test.mjs +197 -0
- package/src/gates/tenant-predicate.mjs +175 -0
- package/src/gates/tenant-predicate.test.mjs +161 -0
- package/src/gates/tenant-tables.mjs +65 -0
- package/src/gates/tenant-tables.test.mjs +56 -0
- package/src/gates/test-mirror.mjs +47 -0
- package/src/gates/test-mirror.test.mjs +31 -0
- package/src/index.mjs +9 -0
- package/templates/.jscpd.json +15 -0
- package/templates/CLAUDE.md +54 -0
- package/templates/decisions.examples.md +25 -0
- package/templates/docs/adr-template.md +58 -0
- package/templates/docs/architecture.md +179 -0
- package/templates/docs/decisions.md +72 -0
- package/templates/docs/enforcement.md +94 -0
- package/templates/docs/glossary.md +16 -0
- package/templates/docs/guards.md +23 -0
- package/templates/docs/pagination.md +113 -0
- package/templates/docs/performance.md +35 -0
- package/templates/docs/ui.md +32 -0
- package/templates/githooks/commit-msg +4 -0
- package/templates/githooks/pre-commit +18 -0
- package/templates/githooks/pre-push +6 -0
- package/templates/github/workflows/ci.yml +21 -0
- package/templates/qc.config.json +6 -0
- package/templates/quality-thresholds.json +114 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Test path mirror: every frontend test must mirror a source file in frontend/src.
|
|
2
|
+
// Tests in frontend/src/ are disallowed (they must live in frontend/tests/).
|
|
3
|
+
// Tests in frontend/tests/ must not be orphaned (a matching source file must exist).
|
|
4
|
+
|
|
5
|
+
const TEST_PATTERN = /\.test\.(tsx?)$/;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks that frontend tests strictly mirror frontend/src/ files and are not orphaned.
|
|
9
|
+
*
|
|
10
|
+
* @param {string[]} testFiles Relative paths of all test files (e.g. frontend/tests/...)
|
|
11
|
+
* @param {string[]} srcFiles Relative paths of all source files (e.g. frontend/src/...)
|
|
12
|
+
* @returns {{path: string, rule: string, detail: string}[]}
|
|
13
|
+
*/
|
|
14
|
+
export function checkTestMirror(testFiles, srcFiles) {
|
|
15
|
+
const problems = [];
|
|
16
|
+
const srcStems = new Set(
|
|
17
|
+
srcFiles.map((f) => f.replace(/\.(tsx?)$/, ""))
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
for (const testFile of testFiles) {
|
|
21
|
+
if (testFile.startsWith("frontend/src/")) {
|
|
22
|
+
problems.push({
|
|
23
|
+
path: testFile,
|
|
24
|
+
rule: "unmirrored-test",
|
|
25
|
+
detail: `${testFile}: test files must live in frontend/tests/ mirroring the src path`,
|
|
26
|
+
});
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (testFile.startsWith("frontend/tests/")) {
|
|
31
|
+
const rel = testFile.slice("frontend/tests/".length);
|
|
32
|
+
const stem = rel.replace(TEST_PATTERN, "");
|
|
33
|
+
const directSource = `frontend/src/${stem}`;
|
|
34
|
+
const indexSource = `frontend/src/${stem}/index`;
|
|
35
|
+
|
|
36
|
+
if (!srcStems.has(directSource) && !srcStems.has(indexSource)) {
|
|
37
|
+
problems.push({
|
|
38
|
+
path: testFile,
|
|
39
|
+
rule: "orphaned-test",
|
|
40
|
+
detail: `${testFile}: no matching source file at frontend/src/${stem}.{ts,tsx}`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return problems;
|
|
47
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { checkTestMirror } from "./test-mirror.mjs";
|
|
4
|
+
|
|
5
|
+
test("a test perfectly mirroring a source file passes", () => {
|
|
6
|
+
const tests = ["frontend/tests/features/photos/slices/get-photo.test.ts"];
|
|
7
|
+
const src = ["frontend/src/features/photos/slices/get-photo.ts"];
|
|
8
|
+
assert.deepEqual(checkTestMirror(tests, src), []);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("a test mirroring a view folder index passes", () => {
|
|
12
|
+
const tests = ["frontend/tests/features/photos/components/photo-viewer.test.tsx"];
|
|
13
|
+
const src = ["frontend/src/features/photos/components/photo-viewer/index.ts"];
|
|
14
|
+
assert.deepEqual(checkTestMirror(tests, src), []);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("a test file remaining in frontend/src is flagged as unmirrored", () => {
|
|
18
|
+
const tests = ["frontend/src/features/photos/slices/get-photo.test.ts"];
|
|
19
|
+
const src = ["frontend/src/features/photos/slices/get-photo.ts"];
|
|
20
|
+
const problems = checkTestMirror(tests, src);
|
|
21
|
+
assert.equal(problems.length, 1);
|
|
22
|
+
assert.equal(problems[0].rule, "unmirrored-test");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("an orphaned test with no matching source file is flagged", () => {
|
|
26
|
+
const tests = ["frontend/tests/features/photos/slices/unknown-slice.test.ts"];
|
|
27
|
+
const src = ["frontend/src/features/photos/slices/get-photo.ts"];
|
|
28
|
+
const problems = checkTestMirror(tests, src);
|
|
29
|
+
assert.equal(problems.length, 1);
|
|
30
|
+
assert.equal(problems[0].rule, "orphaned-test");
|
|
31
|
+
});
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The package surface. A consumer imports the preset and the config; the gates are
|
|
2
|
+
// reachable individually for a repository that wants to run one on its own.
|
|
3
|
+
|
|
4
|
+
export { load, defaults, merge, thresholds, enabled, CONFIG_FILE } from "./config.mjs";
|
|
5
|
+
export { preset } from "./eslint/preset.mjs";
|
|
6
|
+
export { default as plugin, rules } from "./eslint/index.mjs";
|
|
7
|
+
export { gateDescriptions, describedGates } from "./descriptions.mjs";
|
|
8
|
+
export { runCheck } from "./cli/check.mjs";
|
|
9
|
+
export { enforcementMap, withEnforcementMap, OPEN as ENFORCEMENT_MAP_OPEN, CLOSE as ENFORCEMENT_MAP_CLOSE } from "./enforcement-map.mjs";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"threshold": 2,
|
|
3
|
+
"minLines": 10,
|
|
4
|
+
"minTokens": 75,
|
|
5
|
+
"reporters": ["console"],
|
|
6
|
+
"ignore": [
|
|
7
|
+
"**/node_modules/**",
|
|
8
|
+
"**/dist/**",
|
|
9
|
+
"**/*.test.*",
|
|
10
|
+
"**/*.generated.*",
|
|
11
|
+
"**/fixtures/**"
|
|
12
|
+
],
|
|
13
|
+
"format": ["typescript", "tsx"],
|
|
14
|
+
"absolute": false
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# <repository>
|
|
2
|
+
|
|
3
|
+
<One line: what this system does, and the domain it does it in.>
|
|
4
|
+
|
|
5
|
+
## Authority
|
|
6
|
+
|
|
7
|
+
`docs/decisions.md` — every id cited in this repo is defined there. Self-contained: a citation to an
|
|
8
|
+
undefined id, a missing doc path, or a reference to another repository fails the build.
|
|
9
|
+
|
|
10
|
+
| Read | For |
|
|
11
|
+
|---|---|
|
|
12
|
+
| `docs/architecture.md` | Layers, feature anatomy, unit of work, data, auth |
|
|
13
|
+
| `docs/guards.md` | Create / update / offline guards. **Do not reconcile them** |
|
|
14
|
+
| `docs/ui.md` | Parity, realtime, presenters |
|
|
15
|
+
| `docs/enforcement.md` | Every rule beside the check that enforces it |
|
|
16
|
+
| `docs/performance.md` | Budgets. The one home for these numbers |
|
|
17
|
+
| `docs/pagination.md` | Keyset, cursors, counting, and the one exemption |
|
|
18
|
+
| `docs/glossary.md` | Domain terms |
|
|
19
|
+
| `STATE.md` | What is true now |
|
|
20
|
+
|
|
21
|
+
## Commands
|
|
22
|
+
|
|
23
|
+
`qc init` added the first three. Add the rest as the repository grows them, and list
|
|
24
|
+
every one here — this table is what an agent reads instead of guessing.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm spec:check # every structural gate (qc check)
|
|
28
|
+
pnpm gen:feature <name> # scaffold a feature. Full domain name, never a code
|
|
29
|
+
npx qc check <file> # the fast path a post-edit hook takes
|
|
30
|
+
npx qc config # print the configuration in force
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Non-negotiable
|
|
34
|
+
|
|
35
|
+
- Bounded Vertical Slices (ADR-0054) or the flat pipeline anatomy (ADR-0047). An empty block or
|
|
36
|
+
slice is a review finding.
|
|
37
|
+
- Zero copy-pasting across files; extract shared logic to utilities, `shared/`, or packages.
|
|
38
|
+
- Only a feature's `index` crosses a feature boundary.
|
|
39
|
+
- Tenant column on every business table; repositories `scoped`, never `singleton`; row-level
|
|
40
|
+
security; a two-tenant test asserting zero cross-reads.
|
|
41
|
+
- Keyset pagination only.
|
|
42
|
+
- Throw a domain error; never write an HTTP status by hand.
|
|
43
|
+
- The cancellation token is last on anything that can outlive the interaction.
|
|
44
|
+
- One module calls `fetch`.
|
|
45
|
+
- Never write a number or quantity threshold in a comment (neither digits nor words like "five
|
|
46
|
+
seconds") — cite the registry, config constant, or the doc that owns it.
|
|
47
|
+
- A change is rewritten in place. No supersession trail, no deprecation note (QC-008).
|
|
48
|
+
|
|
49
|
+
## Working with agents
|
|
50
|
+
|
|
51
|
+
`.claude/rules/swarm.md` is the protocol: exclusive paths, index-first, generated registries,
|
|
52
|
+
never two edits to one file.
|
|
53
|
+
|
|
54
|
+
Hooks run the gates on every edit and refuse to end a red turn.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Decision examples — not shipped into a new repository
|
|
2
|
+
|
|
3
|
+
These are the domain decisions from the repository this kit was extracted from. They are here as
|
|
4
|
+
worked examples of the register's shape: a decision states the rule it imposes, in one line, and
|
|
5
|
+
names something a check can see. Copy the shape, not the content.
|
|
6
|
+
|
|
7
|
+
They are deliberately **not** in `decisions.md`: a new repository that carried them would be citing
|
|
8
|
+
decisions it never made, and the citations gate would be enforcing somebody else's domain.
|
|
9
|
+
|
|
10
|
+
| id | decision | the rule it imposes |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| ADR-0006 | Pin coordinates are normalized page fractions | Never pixels. One screen-to-page helper |
|
|
13
|
+
| ADR-0009 | Offline conflicts resolve last-write-wins on the server clock | Per field for free-form values, per item for checklist results. The losing value is kept for audit |
|
|
14
|
+
| ADR-0013 | Photo authenticity is a stored hash chain computed at ingest | Never recomputed on the device |
|
|
15
|
+
| ADR-0033 | Photos are range-partitioned by capture month | A row outside every partition is rejected, never silently routed |
|
|
16
|
+
| QC-004 | The canvas renders with GPU instancing and a 2D overlay | One instanced mesh per archetype. Text and IME stay on the 2D layer. Hit-testing is a quadtree, never a hidden render pass |
|
|
17
|
+
| QC-005 | ECS data discipline applies to any hot loop; the registry only to the canvas | Trigger: per frame, or over a threshold count of items, or allocating per iteration on the interaction thread. Asserted by allocation measurement |
|
|
18
|
+
| QC-006 | Visual parity with the predecessor is the default | Divergence is argued in the work order, with a before and after |
|
|
19
|
+
| QC-009 | Identity externalizes tenancy and quota to a control plane | The access token carries identity only. Tenant memberships, roles and quota live in the control plane and are queried by the edge service |
|
|
20
|
+
|
|
21
|
+
## What makes one of these a good entry
|
|
22
|
+
|
|
23
|
+
- **It names the rule, not the reasoning.** The reasoning belongs in the doc the rule points to.
|
|
24
|
+
- **A check can see it.** "Never pixels" is greppable. "Coordinates should be sensible" is not.
|
|
25
|
+
- **It is one line.** A decision that needs a paragraph is two decisions, or it is a doc.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# ADR-NNNN — <the decision, as a claim, not a topic>
|
|
2
|
+
|
|
3
|
+
<!-- Copy to docs/decisions/ADR-NNNN-<slug>.md. Every heading below is required and checked by
|
|
4
|
+
`qc check` (adr-format). Write in English. A heading with nothing under it fails. -->
|
|
5
|
+
|
|
6
|
+
| | |
|
|
7
|
+
|---|---|
|
|
8
|
+
| **Status** | proposed \| accepted \| corrected |
|
|
9
|
+
| **Decided** | YYYY-MM-DD |
|
|
10
|
+
| **Deciders** | who was in the room |
|
|
11
|
+
| **Register row** | the one line this expands, copied verbatim from `docs/decisions.md` |
|
|
12
|
+
|
|
13
|
+
## Prerequisite
|
|
14
|
+
|
|
15
|
+
What a reader must already know or have in place for this decision to make sense: the decisions it
|
|
16
|
+
builds on, the constraint that was already fixed, the system state it assumes. If someone would
|
|
17
|
+
reach a different conclusion without knowing X, X belongs here.
|
|
18
|
+
|
|
19
|
+
## Context
|
|
20
|
+
|
|
21
|
+
The forces in tension when this was decided. Requirements, constraints, deadlines, team size, what
|
|
22
|
+
was already built. Facts only -- no advocacy. A reader must be able to disagree with the decision
|
|
23
|
+
while accepting every sentence in this section.
|
|
24
|
+
|
|
25
|
+
## Decision
|
|
26
|
+
|
|
27
|
+
One paragraph, in the present tense, stating what is true now. This is the claim the register row
|
|
28
|
+
summarises, and code cites this id because of this paragraph.
|
|
29
|
+
|
|
30
|
+
## Why this, specifically
|
|
31
|
+
|
|
32
|
+
The reasoning from the context to the decision. Not the benefits -- the argument. Which force
|
|
33
|
+
dominated, and why it outweighed the others that pulled the other way.
|
|
34
|
+
|
|
35
|
+
## What this buys
|
|
36
|
+
|
|
37
|
+
The concrete benefits, each one something a reader could check later. "Simpler" is not a benefit;
|
|
38
|
+
"one place to change a tenant predicate instead of nine" is.
|
|
39
|
+
|
|
40
|
+
## What this costs
|
|
41
|
+
|
|
42
|
+
The price paid, honestly. Every real decision has one. An ADR with an empty cost section is
|
|
43
|
+
advocacy, not a record -- and the reviewer's first question is what it left out.
|
|
44
|
+
|
|
45
|
+
## Alternatives considered and not chosen
|
|
46
|
+
|
|
47
|
+
One subsection per alternative that was genuinely on the table. An alternative nobody considered
|
|
48
|
+
does not belong here; padding this section with straw men is worse than leaving it short.
|
|
49
|
+
|
|
50
|
+
### <alternative>
|
|
51
|
+
|
|
52
|
+
What it was, and the specific reason it lost. If it lost on a measurement, name the number. If it
|
|
53
|
+
would win under different conditions, say which -- that is the trigger to revisit this decision.
|
|
54
|
+
|
|
55
|
+
## Related decisions
|
|
56
|
+
|
|
57
|
+
The ids this depends on, constrains, or is in tension with, each with one line on the relationship.
|
|
58
|
+
Every id must resolve in `docs/decisions.md`, or the citations gate fails.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Layers — ADR-0001
|
|
4
|
+
|
|
5
|
+
**This is vertical slices over a thin shared kernel, not a layered application.** Most of the code
|
|
6
|
+
is in `features/`; the numbered directories hold a fraction as much, and they exist to keep the
|
|
7
|
+
shared substrate's dependencies pointing one way. Read `features/` first — the layers are what it
|
|
8
|
+
stands on, not where the system lives.
|
|
9
|
+
|
|
10
|
+
The domain layer is a shared package, imported by both surfaces so an invariant cannot diverge
|
|
11
|
+
between them; there is no per-surface domain directory.
|
|
12
|
+
|
|
13
|
+
`infrastructure` → `adapters` → `application` → `domain`. One legal direction, enforced by lint
|
|
14
|
+
because the compiler cannot.
|
|
15
|
+
|
|
16
|
+
| Layer | May import | Never |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `domain` | nothing | any package, any framework, any I/O |
|
|
19
|
+
| `application` | `domain`, the validator | SDKs, the web framework, the ORM, env |
|
|
20
|
+
| `adapters` | `application`, `domain`, vendor SDKs | the web framework, the container, a peer-capability adapter |
|
|
21
|
+
| `infrastructure` | everything | — |
|
|
22
|
+
|
|
23
|
+
Ports take the `I` prefix. Nothing else does.
|
|
24
|
+
|
|
25
|
+
The layer set is `layers` in `qc.config.json`. A repository with different layers replaces the whole
|
|
26
|
+
block; a repository with these layers changes nothing.
|
|
27
|
+
|
|
28
|
+
## Feature anatomy — ADR-0047, ADR-0054
|
|
29
|
+
|
|
30
|
+
Features adopt one of two verified anatomies. Which one a feature may use is `anatomy` in
|
|
31
|
+
`qc.config.json`; `sliceOnlyRoots` names the roots where the flat anatomy is no longer allowed.
|
|
32
|
+
|
|
33
|
+
### Anatomy selection policy
|
|
34
|
+
|
|
35
|
+
- **Bounded Vertical Slices (ADR-0054)**: multi-operation features with several workflows or
|
|
36
|
+
endpoints must adopt this layout. Operations are partitioned into discrete vertical slices to keep
|
|
37
|
+
context bounded, avoid oversized files, and let people and agents change the feature concurrently
|
|
38
|
+
without merge conflicts.
|
|
39
|
+
- **Flat pipeline (ADR-0047)**: narrow, single-operation features whose logic fits one coherent
|
|
40
|
+
pipeline may keep the flat anatomy.
|
|
41
|
+
|
|
42
|
+
### Bounded Vertical Slices — ADR-0054
|
|
43
|
+
|
|
44
|
+
Scaffolder: `qc feature <domain-name>`.
|
|
45
|
+
|
|
46
|
+
| Path | Required | Owns |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `index.ts` | yes | Public surface. The only file another feature imports |
|
|
49
|
+
| `schema.ts` | yes | DDL, tables, indexes. The only file defining schema |
|
|
50
|
+
| `trigger.ts` | yes | Thin composition point: maps routes to slice handlers |
|
|
51
|
+
| `slices/<action>.ts` | yes | Discrete operation: input validation, pipeline, and write |
|
|
52
|
+
| `shared/types.ts` | when needed | Row types, domain interfaces, column projections |
|
|
53
|
+
| `shared/queries.ts` | when reused | Common lookups imported by multiple slices |
|
|
54
|
+
| `shared/guards.ts` | when reused | Access checks, standing invariants, domain validations |
|
|
55
|
+
| `shared/runner.ts` | when needed | Pipeline runner execution helper |
|
|
56
|
+
|
|
57
|
+
Subfolders are restricted to `slices/` and `shared/`. Files under `shared/` are limited to the four
|
|
58
|
+
taxonomy roles above. Disallowed subfolders, unknown shared files, or empty slices fail review.
|
|
59
|
+
|
|
60
|
+
### Flat pipeline — ADR-0047
|
|
61
|
+
|
|
62
|
+
One block, one file. No subfolders. Scaffolder: `qc feature <domain-name> --flat`.
|
|
63
|
+
|
|
64
|
+
| File | Required | Owns |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `index.ts` | yes | Public surface. The only file another feature imports |
|
|
67
|
+
| `trigger.ts` | yes | Routes, queue handlers, timers |
|
|
68
|
+
| `pipeline.ts` | yes | Ordered named steps |
|
|
69
|
+
| `resource.ts` | yes | Queries, writes, schema slice. The only block touching storage |
|
|
70
|
+
| `branch.ts` | when a flow splits on domain state | Conditional sub-flows |
|
|
71
|
+
| `fragment.ts` | when steps are reused in-feature | Named step groups |
|
|
72
|
+
| `ledger.ts` | when history outlives the rows | Append-only step history |
|
|
73
|
+
| `record.ts` | when the feature has an aggregate | The aggregate and its invariants |
|
|
74
|
+
|
|
75
|
+
An empty block is a review finding. A feature that needs one more file is split. Cross-feature reuse
|
|
76
|
+
is a kernel fragment, requested from the orchestrator.
|
|
77
|
+
|
|
78
|
+
## Unit of work
|
|
79
|
+
|
|
80
|
+
One step, one unit of work, one transaction.
|
|
81
|
+
|
|
82
|
+
- Repositories are built from the unit of work, never from the pool.
|
|
83
|
+
- The ledger append and any outbox insert enlist in the same unit of work.
|
|
84
|
+
- Repositories and sagas are `scoped`, never `singleton`.
|
|
85
|
+
- Reads outside a write take the reader pool; the writer is the default — ADR-0030.
|
|
86
|
+
- Raw SQL on a user-input path is a Critical finding.
|
|
87
|
+
|
|
88
|
+
## Composition root
|
|
89
|
+
|
|
90
|
+
The one place that names a concrete dependency. It builds the container and the route table; nothing
|
|
91
|
+
below it constructs a dependency for itself.
|
|
92
|
+
|
|
93
|
+
- Routes come from feature indexes only. Codegen writes the index list, the root mounts it, and an
|
|
94
|
+
index that publishes no `trigger` fails at construction rather than at the first request.
|
|
95
|
+
- A route declares `auth`. A `tenant` route gets a verified principal before its handler runs; a
|
|
96
|
+
`public` route declares itself a trust boundary and gets none, and no write path.
|
|
97
|
+
- Anything carrying a tenant is `scoped`, built from the request's principal. A `tenant` handler
|
|
98
|
+
receives a unit of work already bound to its own tenant, so it cannot name another.
|
|
99
|
+
- Cache lifetimes come from the lifetimes registry, never a literal.
|
|
100
|
+
- The API enqueues; it never consumes. A worker's own entrypoint polls its queue — ADR-0016 — so a
|
|
101
|
+
feature's `trigger` declares routes, and the enqueue seam is a port.
|
|
102
|
+
- A worker reports its outcome back through an `internal` route: no user principal, authenticated by
|
|
103
|
+
a shared key compared in constant time, carrying the tenant the API put in the queue message. The
|
|
104
|
+
key reaches the task through its secrets block. A browser can never reach one of these, and a
|
|
105
|
+
worker can never reach a `tenant` route.
|
|
106
|
+
|
|
107
|
+
## Data
|
|
108
|
+
|
|
109
|
+
- The tenant column is on every business table; composite indexes lead with it.
|
|
110
|
+
- Isolation is three independent levels: repository predicate, row-level security, and a two-tenant
|
|
111
|
+
test asserting zero cross-reads. A repository without that test fails review. The predicate is also
|
|
112
|
+
checked structurally, across every feature at once — a statement on a business table that names no
|
|
113
|
+
tenant fails the build, including the one nobody wrote a test for.
|
|
114
|
+
- Keyset pagination only, with an opaque cursor — ADR-0055. `docs/pagination.md` owns the query,
|
|
115
|
+
the index, counting, and the one exemption.
|
|
116
|
+
- Migrations are generated, reviewed like code, never edited after merge, expand/contract only, and
|
|
117
|
+
run as a one-off task before the service update — never on boot. The ledger holds each file's
|
|
118
|
+
checksum, so an edited file fails the task instead of drifting.
|
|
119
|
+
- Row-level security is generated from the schema slices that declare a tenant column, and re-applied
|
|
120
|
+
after every migration. It is never ledgered: the file changes whenever a feature is added, and
|
|
121
|
+
every statement in it is idempotent. No work order edits a shared policy file.
|
|
122
|
+
- Object keys start with the tenant. Presigned lifetimes are a closed set.
|
|
123
|
+
- Errors: `{ code, message, requestId, details }`. Domain code throws; one handler maps — ADR-0044.
|
|
124
|
+
- The audit log is append-only. No repository has an update or delete path for it.
|
|
125
|
+
|
|
126
|
+
## Auth — QC-002, QC-003, ADR-0037
|
|
127
|
+
|
|
128
|
+
The browser holds a session cookie and never a token.
|
|
129
|
+
|
|
130
|
+
- The edge service completes the code exchange, keeps tokens server-side, issues a `__Host-` session
|
|
131
|
+
cookie (`HttpOnly`, `Secure`, `SameSite=Lax`, `Path=/`), and proxies to the API with the bearer.
|
|
132
|
+
- The API is bearer-only and knows nothing about cookies, so a native client needs no API change.
|
|
133
|
+
- The session store is the one database — ADR-0010.
|
|
134
|
+
- CSRF: `SameSite=Lax` plus an `Origin` allow-list on every mutating handler. No `GET` mutates.
|
|
135
|
+
- A route the API serves without a session is unreachable unless the edge forwards it without one.
|
|
136
|
+
The edge holds that closed set, a gate asserts it equals the set of `auth: "public"` routes, and a
|
|
137
|
+
public route is forwarded with no `Authorization` header at all — a caller's own bearer is stripped
|
|
138
|
+
with the hop-by-hop headers, never merely overwritten.
|
|
139
|
+
- **One origin, and it is load-bearing.** The `__Host-` prefix requires `Secure`, `Path=/` and no
|
|
140
|
+
`Domain`, so the app and the edge must share an origin or the browser drops the cookie and every
|
|
141
|
+
request is silently unauthenticated. The CDN serves the app and routes the edge prefix to the load
|
|
142
|
+
balancer. On that prefix the CDN forwards cookies, `Origin`, `Authorization`, `Upgrade` and
|
|
143
|
+
`Connection`, caches nothing, and allows every method — a cached authenticated response is a
|
|
144
|
+
session leak, a stripped `Origin` fails the CSRF guard, and a stripped `Upgrade` fails the socket.
|
|
145
|
+
- The socket upgrade uses a single-use ticket minted by the edge and verified by the API, which binds
|
|
146
|
+
the connection to the user before admitting it. Its lifetime lives in the lifetimes registry.
|
|
147
|
+
- A token with no organization claim is rejected before any handler runs. Revocation is read on every
|
|
148
|
+
request from the tenant mirror — no denylist, no shared cache.
|
|
149
|
+
|
|
150
|
+
## Headless-first and sagas — QC-010
|
|
151
|
+
|
|
152
|
+
Every multi-step or business workflow is designed headless-first:
|
|
153
|
+
|
|
154
|
+
- Workflows are executable commands or pipeline sagas.
|
|
155
|
+
- UI components are thin presenters: views gather input and invoke the headless saga, never embedding
|
|
156
|
+
orchestration in event handlers.
|
|
157
|
+
- Sagas define discrete steps, idempotency replay keyed on the mutation id, and backward compensation
|
|
158
|
+
when an intermediate step fails.
|
|
159
|
+
- Complete scenarios run and verify headlessly via CLI or test runner in milliseconds, eliminating
|
|
160
|
+
fragile browser automation.
|
|
161
|
+
- Browser automation is confined to smoke checks: visual token application, input-method composition
|
|
162
|
+
guards, and canvas mount.
|
|
163
|
+
|
|
164
|
+
## Realtime — ADR-0048
|
|
165
|
+
|
|
166
|
+
The stream is sequenced. Every frame carries a sequence number and names a row.
|
|
167
|
+
|
|
168
|
+
- A client holding the **complete set** applies the frame as a delta.
|
|
169
|
+
- A client holding a **window** onto a set — anything paginated — invalidates and refetches,
|
|
170
|
+
because a new row has no placement in a page nobody has fetched.
|
|
171
|
+
- A gap in the sequence is closed by refetching, never by guessing.
|
|
172
|
+
- Authorization is per subscriber: a frame carrying data must be filtered for the connection
|
|
173
|
+
that receives it, which the refetch path gets for free by going through the normal read.
|
|
174
|
+
|
|
175
|
+
## Shared packages
|
|
176
|
+
|
|
177
|
+
The domain package is `domain`, imported by both surfaces, so invariants cannot diverge. The kernel
|
|
178
|
+
holds the runner and fragments — one implementation, wired in twice. The contracts package is
|
|
179
|
+
generated — ADR-0020.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Decisions
|
|
2
|
+
|
|
3
|
+
Self-contained: every id cited in this repository's code or docs is defined here. A citation to an
|
|
4
|
+
id not listed below fails the citations gate.
|
|
5
|
+
|
|
6
|
+
Ids are stable. A decision is corrected in place before its first consumer and superseded by a new
|
|
7
|
+
id after it — ADR-0028. Numbers are not renumbered to close gaps: a gap is a decision that was
|
|
8
|
+
never portable, and renumbering would break every citation that already points here.
|
|
9
|
+
|
|
10
|
+
## Architecture
|
|
11
|
+
|
|
12
|
+
| id | decision | the rule it imposes |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| ADR-0001 | Four layers, one direction | `domain` imports nothing, not even a validator. `application` may import the validator. `adapters` never imports the web framework, the container, or a peer-capability adapter. Direction is enforced by lint, not by a naming convention and not by the compiler |
|
|
15
|
+
| ADR-0002 | One cloud | No provider abstraction layer |
|
|
16
|
+
| ADR-0010 | One database, no second datastore | No cache server, no search cluster. Sessions and caches live in the database |
|
|
17
|
+
| ADR-0016 | Queues for asynchronous work, no event bus | One consumer and one dead-letter queue per message. In-process domain events are a synchronous typed emitter |
|
|
18
|
+
| ADR-0020 | Contracts outrank prose | Validation schemas are generated from the contract, never hand-written beside it |
|
|
19
|
+
| ADR-0028 | Before the first consumer, a decision is corrected in place | After it, a change is a new id that supersedes |
|
|
20
|
+
| ADR-0030 | Reader and writer pools exist before a replica does | The writer is the default; a read joins the reader list only by being named |
|
|
21
|
+
| ADR-0031 | State machines are a client concern | Durable server state is columns plus a transition table |
|
|
22
|
+
| ADR-0046 | The database major is the current one | The registry is the pin; the minor comes from the cloud catalog at apply time |
|
|
23
|
+
| ADR-0047 | Every feature is a pipeline of named blocks | One block, one file. An empty block is a review finding. Only `index` crosses a feature boundary |
|
|
24
|
+
| ADR-0055 | Pagination is keyset, and its cursor is opaque | `offset` and `skip` are rejected. A total is a bounded count or a documented estimate, never an exact count by default. `docs/pagination.md` owns the query, the index and the exemption |
|
|
25
|
+
| ADR-0054 | Bounded vertical slices with prescribed taxonomy | Operations are discrete vertical slices under `slices/`; `index`, `schema`, `trigger` at root. Disallowed subfolders fail review |
|
|
26
|
+
|
|
27
|
+
## Correctness
|
|
28
|
+
|
|
29
|
+
| id | decision | the rule it imposes |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| ADR-0044 | A code is for a client that acts differently; a reason is for a person who reads | `code` is an enum the client switches on; `details[].rule` keys a localized message |
|
|
32
|
+
| ADR-0050 | The client mints one mutation id per user operation attempt | Persisted so a reload cannot lose it. A repeated id is a resume, not a new operation |
|
|
33
|
+
| ADR-0051 | Interactive edits are guarded by a version column | A mismatch is a conflict. Offline replay is excluded and stays last-write-wins |
|
|
34
|
+
| ADR-0052 | The version check is the double-apply guard for updates | An update pipeline needs no ledger. A repeated update is never answered by replaying the old result |
|
|
35
|
+
| ADR-0053 | A multi-row action is independent single-row operations | Partial success is the intended shape. A bulk resume returns the full set |
|
|
36
|
+
|
|
37
|
+
## Security and infrastructure
|
|
38
|
+
|
|
39
|
+
| id | decision | the rule it imposes |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| ADR-0029 | Three-tier private network | Only the load balancer is reachable. Security groups and network ACLs are two independent controls. No bastion, no SSH |
|
|
42
|
+
| ADR-0037 | The browser holds a session cookie and never an access token | The token lives server-side in the edge service |
|
|
43
|
+
| ADR-0011 | Media transfers are direct client-to-object-store | Bytes never pass through the API |
|
|
44
|
+
| ADR-0018 | Derivatives are made server-side | Client-side derivative generation is forbidden |
|
|
45
|
+
|
|
46
|
+
## Client
|
|
47
|
+
|
|
48
|
+
| id | decision | the rule it imposes |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| ADR-0038 | Client work is cancellable, off-thread and event-driven by construction | The cancellation token is the last parameter of every function that can outlive the interaction. A write is never cancelled by navigation |
|
|
51
|
+
| ADR-0040 | Accessibility is WCAG 2.2 AA | Every drag has a non-drag equivalent. The focus ring is never removed |
|
|
52
|
+
| ADR-0048 | Realtime is a sequenced stream, and a frame is applied only where the client holds the whole set | Every frame carries a sequence number and names a row. A client holding the complete set applies the frame as a delta; a client holding a window onto a set invalidates and refetches, because a new row has no placement in a page nobody has fetched. A gap in the sequence is closed by refetching, never by guessing. Fan-out is in-process first, then the database notification channel |
|
|
53
|
+
|
|
54
|
+
## Process
|
|
55
|
+
|
|
56
|
+
| id | decision | the rule it imposes |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| ADR-0032 | A gate is tested code | Every gate ships a case that must fail. A warning is not a check |
|
|
59
|
+
|
|
60
|
+
## Local decisions
|
|
61
|
+
|
|
62
|
+
Decisions this repository made on its own. New ids start at `QC-001`. The entries below are the
|
|
63
|
+
portable ones; delete any that do not apply and add your own rather than renumbering.
|
|
64
|
+
|
|
65
|
+
| id | decision | the rule it imposes |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| QC-001 | One responsive application, no separate mobile build | A screen adapts; it never forks into two implementations |
|
|
68
|
+
| QC-002 | The edge service is a thin service of its own | It owns the code exchange, the session store and the cookie. The API stays bearer-only |
|
|
69
|
+
| QC-003 | The realtime upgrade uses a single-use ticket minted by the edge | The API validates and binds the connection before admitting it |
|
|
70
|
+
| QC-007 | A rule that cannot name its check is deleted or converted into one | `docs/enforcement.md` carries the map |
|
|
71
|
+
| QC-008 | A change is rewritten in place, as if it had always been that way | No supersession trail, no deprecation note, no "what this replaces". The repository states what is true now; git holds the history |
|
|
72
|
+
| QC-010 | Headless-first command and saga architecture | Every multi-step workflow is an executable pipeline or command callable headlessly without a browser. UI components are thin presenters invoking these workflows. Headless tests verify state transitions, idempotency, and compensations |
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Enforcement — QC-007
|
|
2
|
+
|
|
3
|
+
A rule that cannot name its check is deleted or converted into one.
|
|
4
|
+
|
|
5
|
+
| Layer | Mechanism |
|
|
6
|
+
|---|---|
|
|
7
|
+
| Types | Features are built only through `define*`. A wrong shape does not compile |
|
|
8
|
+
| Generators | `qc feature` scaffolds; codegen writes every shared registry. The right thing is cheaper than the wrong thing |
|
|
9
|
+
| Lint | `error`, thresholds imported from `quality-thresholds.json` |
|
|
10
|
+
| Hooks | the agent's post-edit gate (fast, per file) and stop gate (full, blocks a red turn), plus `.githooks/pre-commit` |
|
|
11
|
+
| CI | Required for merge |
|
|
12
|
+
|
|
13
|
+
Every gate and every rule is switchable in `qc.config.json` under `gates` and `rules`. Ship all;
|
|
14
|
+
turn off what this repository does not have. A gate whose input path does not exist disables itself.
|
|
15
|
+
|
|
16
|
+
## Rule to check
|
|
17
|
+
|
|
18
|
+
Generated from the kit's own rule and gate metadata, so a renamed check cannot leave a stale row.
|
|
19
|
+
Read it as an index; the reasoning is under the headings that follow.
|
|
20
|
+
|
|
21
|
+
<!-- generated: rule-to-check. -->
|
|
22
|
+
|
|
23
|
+
| Rule | Check |
|
|
24
|
+
|---|---|
|
|
25
|
+
| An idempotency key comes from a durable id, never the clock or fresh randomness | `qc/durable-idempotency-key` |
|
|
26
|
+
| An external service's SDK belongs behind an adapter, or the composition root that selects a provider | `qc/external-service-only-in-adapter` |
|
|
27
|
+
| A comment is one line of why, never a paragraph, a banner or code | `qc/no-comment-paragraph` |
|
|
28
|
+
| A feature exposes only its public file to other features | `qc/no-cross-feature-internals` |
|
|
29
|
+
| No numeric literal or quantity threshold in a comment; cite the registry instead | `qc/no-number-in-comment` |
|
|
30
|
+
| Keyset pagination only | `qc/no-offset-pagination` |
|
|
31
|
+
| UI triggers cannot orchestrate multi-step asynchronous business flows | `qc/no-orchestration-in-trigger` |
|
|
32
|
+
| A promise is awaited, never continued with .then() or .catch() | `qc/no-promise-then` |
|
|
33
|
+
| Fetch belongs to the api client | `qc/no-raw-fetch` |
|
|
34
|
+
| No hand-written HTTP status | `qc/no-status-literal` |
|
|
35
|
+
| No supersession trail in a comment; the repository states what is true now | `qc/no-supersession-trail` |
|
|
36
|
+
| Repositories and sagas are scoped, never singleton | `qc/scoped-repository` |
|
|
37
|
+
| An exported async function takes a cancellation token last | `qc/signal-last-param` |
|
|
38
|
+
| Storage imports belong in the resource block | `qc/storage-only-in-resource` |
|
|
39
|
+
| Every business table carries the tenant column | `qc/tenant-scoped-table` |
|
|
40
|
+
| Every cited id and doc path resolves, and nothing references another repository | `qc check` (citations) |
|
|
41
|
+
| A comment under infra/ is one line of why, never a paragraph, a banner or code | `qc check` (comment-style) |
|
|
42
|
+
| A repository's own gates each ship a case that must fail | `qc check` (gate-tests) |
|
|
43
|
+
|
|
44
|
+
<!-- /generated -->
|
|
45
|
+
|
|
46
|
+
Checks a repository owns rather than the kit:
|
|
47
|
+
|
|
48
|
+
| Rule | Check |
|
|
49
|
+
|---|---|
|
|
50
|
+
| Layer direction | `boundaries/element-types` |
|
|
51
|
+
| `domain` imports nothing | `boundaries/external` |
|
|
52
|
+
| No `any` | `@typescript-eslint/no-explicit-any` |
|
|
53
|
+
| Function, nesting, file size | `max-lines-per-function`, `max-depth`, `max-lines` |
|
|
54
|
+
| Cross-file duplication | `jscpd`, threshold from `quality-thresholds.json` |
|
|
55
|
+
| Every tenant-scoped table has a policy | codegen, from the `tenant-tables` generator |
|
|
56
|
+
| Two features cannot claim one path or schema | codegen, from the `contract-compose` generator |
|
|
57
|
+
| A generated registry is current | your codegen's `--check` |
|
|
58
|
+
|
|
59
|
+
## File length
|
|
60
|
+
|
|
61
|
+
A block is one file, and the gate is `filelength` in `quality-thresholds.json`. Blanks and comments
|
|
62
|
+
do not count, so a file is never shortened by deleting the reasoning — that reasoning is often the
|
|
63
|
+
most valuable thing in the file.
|
|
64
|
+
|
|
65
|
+
Set the number by measuring, not by taste. Apply the anatomy repo-wide first: move every genuinely
|
|
66
|
+
reused step into `shared/`, every invariant into its aggregate. Then see what is left. What remains
|
|
67
|
+
is usually not misplaced code — a long block is a feature that owns several tables, and the only
|
|
68
|
+
thing that shortens it is splitting the feature. Some of those splits are clean; some are refused by
|
|
69
|
+
the architecture, because a guard must run in the same transaction as the write it guards. Buying a
|
|
70
|
+
smaller number with a cross-feature call in place of an in-transaction authorize step is a bad trade,
|
|
71
|
+
so the number is the thing that gives.
|
|
72
|
+
|
|
73
|
+
**Never lower this gate ahead of the work it demands**: a gate that lands first blocks only the
|
|
74
|
+
person doing that work.
|
|
75
|
+
|
|
76
|
+
An oversized block has two architectural answers: extract genuinely reused steps into `shared/`
|
|
77
|
+
(ADR-0054) or `fragment.ts` (ADR-0047), or split the feature.
|
|
78
|
+
|
|
79
|
+
## Comments
|
|
80
|
+
|
|
81
|
+
Code carries the meaning. A comment exists only where it cannot.
|
|
82
|
+
|
|
83
|
+
- **One line.** Reasoning that wants a paragraph is a decision: give it an id and cite that.
|
|
84
|
+
- No banners, no commented-out code, no "what" comments. A JSDoc `@param` line is not prose.
|
|
85
|
+
- Cite a decision — `ADR-0052`, `QC-008`, `docs/guards.md`. Never restate one.
|
|
86
|
+
- Never write a number or quantity threshold (neither digits nor spelled-out words). Cite the
|
|
87
|
+
registry or the doc that owns it. Citation ids are the exception.
|
|
88
|
+
|
|
89
|
+
Prose quality is a review concern, deliberately not a rule: a second rule demanding a citation on
|
|
90
|
+
every comment would fight the numeric one, and each false positive costs an agent round-trip.
|
|
91
|
+
|
|
92
|
+
## Gates are proven
|
|
93
|
+
|
|
94
|
+
Every rule and gate ships a case that **must fail** — ADR-0032.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Glossary
|
|
2
|
+
|
|
3
|
+
Domain terms, in the domain's own language, with the meaning the code relies on. This file is where
|
|
4
|
+
a reader resolves a word they met in a feature name.
|
|
5
|
+
|
|
6
|
+
Replace every row. The two below are the shape: a term, and what the system does about it.
|
|
7
|
+
|
|
8
|
+
| Term | Meaning |
|
|
9
|
+
|---|---|
|
|
10
|
+
| *(domain term)* | *(what it is, and the unit of work it corresponds to)* |
|
|
11
|
+
| Tenant | One organization. The unit of data isolation |
|
|
12
|
+
|
|
13
|
+
Conventions this repository holds to:
|
|
14
|
+
|
|
15
|
+
- Business timezone and storage timezone are stated here, once.
|
|
16
|
+
- User-facing strings are in the product's language; code, comments, logs and API codes are English.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Guards
|
|
2
|
+
|
|
3
|
+
Three rules. They must not be "fixed" against each other.
|
|
4
|
+
|
|
5
|
+
| Operation | Guard | Why |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| Create | The client mutation id | The durable record is keyed on it; a repeated id is answered from the record. A multi-row create returns the full set. ADR-0050, ADR-0053 |
|
|
8
|
+
| Interactive update | The **version check**, not the id | The server does not resume an update from the ledger: the row may have moved between submissions, so replaying the old result would hide the move. ADR-0052 |
|
|
9
|
+
| Offline replay | Last-write-wins on the server clock | An offline client cannot be told to refetch. The losing value is kept for audit. ADR-0051 |
|
|
10
|
+
|
|
11
|
+
- A stale update is `conflict`. The error carries **no** fresh state — the client refetches and
|
|
12
|
+
re-applies as a new operation with a new id.
|
|
13
|
+
- An update pipeline therefore needs no `ledger.ts`.
|
|
14
|
+
- The client mutation id stays required on every mutating request regardless: the outbox receipt and
|
|
15
|
+
the audit trail key on it.
|
|
16
|
+
|
|
17
|
+
**Also do not "reconcile" these:** the database notification channel is rejected for durable
|
|
18
|
+
workflows and adopted for realtime fan-out. Both are correct — realtime frames are non-durable and
|
|
19
|
+
recoverable by sequence number. ADR-0016, ADR-0048.
|
|
20
|
+
|
|
21
|
+
Why this page exists: each guard looks like a special case of the others, and each time someone
|
|
22
|
+
unifies them a real bug comes back. If you are about to make two of these the same mechanism, that
|
|
23
|
+
is the thing this page is asking you not to do.
|