archidocs 0.0.0-stage → 1.2.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.
Files changed (167) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -2
  3. package/dist/cli/commands.d.ts +322 -0
  4. package/dist/cli/commands.js +174 -0
  5. package/dist/cli/dev.d.ts +31 -0
  6. package/dist/cli/dev.js +156 -0
  7. package/dist/cli/diff-format.d.ts +9 -0
  8. package/dist/cli/diff-format.js +50 -0
  9. package/dist/cli/format.d.ts +15 -0
  10. package/dist/cli/format.js +64 -0
  11. package/dist/cli/init.d.ts +17 -0
  12. package/dist/cli/init.js +82 -0
  13. package/dist/cli/main.d.ts +2 -0
  14. package/dist/cli/main.js +330 -0
  15. package/dist/core/adr.d.ts +28 -0
  16. package/dist/core/adr.js +88 -0
  17. package/dist/core/adrs.d.ts +20 -0
  18. package/dist/core/adrs.js +86 -0
  19. package/dist/core/catalogue.d.ts +7 -0
  20. package/dist/core/catalogue.js +35 -0
  21. package/dist/core/compare.d.ts +21 -0
  22. package/dist/core/compare.js +62 -0
  23. package/dist/core/deployment-views.d.ts +28 -0
  24. package/dist/core/deployment-views.js +108 -0
  25. package/dist/core/deployments.d.ts +18 -0
  26. package/dist/core/deployments.js +21 -0
  27. package/dist/core/diff.d.ts +44 -0
  28. package/dist/core/diff.js +138 -0
  29. package/dist/core/dynamic-views.d.ts +73 -0
  30. package/dist/core/dynamic-views.js +162 -0
  31. package/dist/core/files.d.ts +2 -0
  32. package/dist/core/files.js +1 -0
  33. package/dist/core/fs.d.ts +19 -0
  34. package/dist/core/fs.js +21 -0
  35. package/dist/core/history-scope.d.ts +40 -0
  36. package/dist/core/history-scope.js +63 -0
  37. package/dist/core/impact.d.ts +34 -0
  38. package/dist/core/impact.js +62 -0
  39. package/dist/core/index.d.ts +20 -0
  40. package/dist/core/index.js +18 -0
  41. package/dist/core/load.d.ts +32 -0
  42. package/dist/core/load.js +465 -0
  43. package/dist/core/model.d.ts +150 -0
  44. package/dist/core/model.js +1 -0
  45. package/dist/core/ownership.d.ts +34 -0
  46. package/dist/core/ownership.js +65 -0
  47. package/dist/core/paths.d.ts +47 -0
  48. package/dist/core/paths.js +115 -0
  49. package/dist/core/query.d.ts +51 -0
  50. package/dist/core/query.js +77 -0
  51. package/dist/core/refs.d.ts +31 -0
  52. package/dist/core/refs.js +50 -0
  53. package/dist/core/rules.d.ts +41 -0
  54. package/dist/core/rules.js +1033 -0
  55. package/dist/core/save-as-view.d.ts +45 -0
  56. package/dist/core/save-as-view.js +114 -0
  57. package/dist/core/saved-views.d.ts +48 -0
  58. package/dist/core/saved-views.js +243 -0
  59. package/dist/core/schema-check.d.ts +13 -0
  60. package/dist/core/schema-check.js +79 -0
  61. package/dist/core/search.d.ts +27 -0
  62. package/dist/core/search.js +63 -0
  63. package/dist/core/suggest.d.ts +3 -0
  64. package/dist/core/suggest.js +30 -0
  65. package/dist/core/views.d.ts +126 -0
  66. package/dist/core/views.js +217 -0
  67. package/dist/core/yaml.d.ts +16 -0
  68. package/dist/core/yaml.js +52 -0
  69. package/dist/git.d.ts +7 -0
  70. package/dist/git.js +23 -0
  71. package/dist/guide/index.d.ts +53 -0
  72. package/dist/guide/index.js +57 -0
  73. package/dist/history/git.d.ts +39 -0
  74. package/dist/history/git.js +126 -0
  75. package/dist/history/index.d.ts +118 -0
  76. package/dist/history/index.js +223 -0
  77. package/dist/history/migrate.d.ts +16 -0
  78. package/dist/history/migrate.js +30 -0
  79. package/dist/mcp/history.d.ts +36 -0
  80. package/dist/mcp/history.js +175 -0
  81. package/dist/mcp/http.d.ts +23 -0
  82. package/dist/mcp/http.js +85 -0
  83. package/dist/mcp/index.d.ts +3 -0
  84. package/dist/mcp/index.js +3 -0
  85. package/dist/mcp/server.d.ts +54 -0
  86. package/dist/mcp/server.js +824 -0
  87. package/dist/mcp/source.d.ts +50 -0
  88. package/dist/mcp/source.js +132 -0
  89. package/dist/mcp/writes.d.ts +10 -0
  90. package/dist/mcp/writes.js +267 -0
  91. package/dist/render/font.d.ts +14 -0
  92. package/dist/render/font.js +11 -0
  93. package/dist/render/index.d.ts +8 -0
  94. package/dist/render/index.js +8 -0
  95. package/dist/render/layout.d.ts +53 -0
  96. package/dist/render/layout.js +199 -0
  97. package/dist/render/node.d.ts +3 -0
  98. package/dist/render/node.js +8 -0
  99. package/dist/render/png.d.ts +11 -0
  100. package/dist/render/png.js +29 -0
  101. package/dist/render/sequence-svg.d.ts +33 -0
  102. package/dist/render/sequence-svg.js +98 -0
  103. package/dist/render/sequence.d.ts +103 -0
  104. package/dist/render/sequence.js +142 -0
  105. package/dist/render/svg.d.ts +36 -0
  106. package/dist/render/svg.js +222 -0
  107. package/dist/render/teams.d.ts +12 -0
  108. package/dist/render/teams.js +31 -0
  109. package/dist/render/text.d.ts +15 -0
  110. package/dist/render/text.js +29 -0
  111. package/dist/render/tokens.d.ts +53 -0
  112. package/dist/render/tokens.js +71 -0
  113. package/dist/schema/adr.d.ts +36 -0
  114. package/dist/schema/adr.js +27 -0
  115. package/dist/schema/bundle.d.ts +726 -0
  116. package/dist/schema/bundle.js +171 -0
  117. package/dist/schema/index.d.ts +4 -0
  118. package/dist/schema/index.js +4 -0
  119. package/dist/schema/json-schema.d.ts +8 -0
  120. package/dist/schema/json-schema.js +19 -0
  121. package/dist/schema/workspace.d.ts +1066 -0
  122. package/dist/schema/workspace.js +271 -0
  123. package/dist/viewer/assets/index-DvKgCpBr.css +1 -0
  124. package/dist/viewer/assets/index-gucix3xm.js +113 -0
  125. package/dist/viewer/assets/index_bg-Blvrv-U2.wasm +0 -0
  126. package/dist/viewer/assets/index_bg-D3t31u3-.js +1 -0
  127. package/dist/viewer/assets/layout.worker-Bg-OaLVN.js +26 -0
  128. package/dist/viewer/assets/overpass-latin-QyaMbcmi.woff2 +0 -0
  129. package/dist/viewer/assets/overpass-latin-ext-DSRhPfzW.woff2 +0 -0
  130. package/dist/viewer/assets/overpass-mono-latin-BTquVRaO.woff2 +0 -0
  131. package/dist/viewer/assets/overpass-mono-latin-ext-D47EiU4_.woff2 +0 -0
  132. package/dist/viewer/assets/png-BDKIXtm5.js +1 -0
  133. package/dist/viewer/assets/svg-Bulv5YWn.js +2 -0
  134. package/dist/viewer/favicon.svg +1 -0
  135. package/dist/viewer/index.html +53 -0
  136. package/dist/writer/adrs.d.ts +21 -0
  137. package/dist/writer/adrs.js +72 -0
  138. package/dist/writer/deployments.d.ts +51 -0
  139. package/dist/writer/deployments.js +145 -0
  140. package/dist/writer/diff.d.ts +6 -0
  141. package/dist/writer/diff.js +77 -0
  142. package/dist/writer/document.d.ts +25 -0
  143. package/dist/writer/document.js +79 -0
  144. package/dist/writer/edit.d.ts +78 -0
  145. package/dist/writer/edit.js +63 -0
  146. package/dist/writer/index.d.ts +67 -0
  147. package/dist/writer/index.js +310 -0
  148. package/dist/writer/overlay.d.ts +7 -0
  149. package/dist/writer/overlay.js +26 -0
  150. package/dist/writer/views.d.ts +29 -0
  151. package/dist/writer/views.js +78 -0
  152. package/dist/writer/workspace.d.ts +25 -0
  153. package/dist/writer/workspace.js +56 -0
  154. package/guide/SKILL.md +36 -0
  155. package/guide/topics/add-service.md +30 -0
  156. package/guide/topics/bootstrap.md +28 -0
  157. package/guide/topics/change.md +32 -0
  158. package/guide/topics/deployments.md +36 -0
  159. package/guide/topics/dynamic-view.md +39 -0
  160. package/guide/topics/propose-adr.md +12 -0
  161. package/guide/topics/relationships.md +39 -0
  162. package/guide/topics/saved-view.md +36 -0
  163. package/package.json +75 -4
  164. package/schemas/adr.schema.json +82 -0
  165. package/schemas/model.schema.json +1381 -0
  166. package/schemas/project.schema.json +24 -0
  167. package/schemas/workspace.schema.json +72 -0
@@ -0,0 +1,1033 @@
1
+ import { generatedViews, MAX_VIEW_NODES } from "./views.js";
2
+ import { resolveSaved } from "./saved-views.js";
3
+ import { Id, parentKindOf } from "../schema/workspace.js";
4
+ import { qualified, qualify, referenceResolver } from "./refs.js";
5
+ import { resolveDynamic } from "./dynamic-views.js";
6
+ import { didYouMean } from "./suggest.js";
7
+ import { AdrFrontmatter } from "../schema/adr.js";
8
+ import { checkSchema } from "./schema-check.js";
9
+ import { qualifyAdr } from "./adr.js";
10
+ const base = {
11
+ "workspace.yaml": "teams:\n core:\n name: Core\nenvironments:\n prod:\n name: Production\n",
12
+ "shop/project.yaml": "id: shop\nname: Shop\nowner: core\n",
13
+ };
14
+ const withServices = (yaml, extra = {}) => ({
15
+ ...base,
16
+ "shop/services.yaml": yaml,
17
+ ...extra,
18
+ });
19
+ /** A Service, a Target it can run on, and `deployments` (a YAML list) in one Project file. */
20
+ const withDeployments = (deployments, extra = {}) => withServices(`services:\n web:\n name: Web\n checkout:\n name: Checkout\n components:\n cart:\n name: Cart\ntargets:\n eks-prod:\n name: EKS prod\n kind: cluster\ndeployments:\n${deployments}`, extra);
21
+ const findings = (rule) => (ws) => ws.files.flatMap((file) => file.findings.filter((f) => f.rule === rule).map((f) => ({ file: file.path, line: f.line, column: f.column, message: f.message })));
22
+ const at = (file, path, message, key = false) => {
23
+ const pos = file.parsed.positionOf(path, { key });
24
+ return { file: file.path, line: pos.line, column: pos.column, message };
25
+ };
26
+ const kindName = { person: "Person", system: "System", service: "Service", component: "Component" };
27
+ const named = (e) => `${kindName[e.kind]} "${e.id}"`;
28
+ /** Where each kind belongs, said when it is nested somewhere it can't be. */
29
+ const belongs = {
30
+ person: "a Person is declared only at the top level, under `people`",
31
+ system: "Systems don't nest; declare it at the top level, under `systems`",
32
+ service: "a Service goes inside a System, or at the top level",
33
+ component: "a Component goes inside a Service",
34
+ };
35
+ /** The qualified ids of declarations in Projects that have a usable id. */
36
+ const qualifiedIds = (decls) => new Set(decls.filter((d) => d.project.id !== undefined && !d.project.duplicateOf).map((d) => `${d.project.id}:${d.id}`));
37
+ /** "Unknown <what> "id" in Project "p"", suggesting the nearest id declared in that Project. */
38
+ const unknownIn = (what, qualified, decls) => {
39
+ const [project, id] = qualified.split(":");
40
+ const ids = decls.filter((d) => d.project.id === project && !d.project.duplicateOf).map((d) => d.id);
41
+ return `Unknown ${what} "${id}" in Project "${project}"${didYouMean(id, ids)}`;
42
+ };
43
+ /** The `in:` an Element names, if it is a usable id. */
44
+ const inRef = (e) => (Id.safeParse(e.data.in).success ? e.data.in : undefined);
45
+ /** A second Project for examples that reference across Projects. */
46
+ const payments = {
47
+ "payments/project.yaml": "id: payments\nname: Payments\nowner: core\n",
48
+ "payments/services.yaml": "services:\n payments-api:\n name: Payments API\n",
49
+ };
50
+ /** A Service with one Relationship, given as the YAML lines under `- `. */
51
+ const relating = (fields, extra = "") => withServices(`services:\n web:\n name: Web\n relationships:\n - ${fields.split("\n").join("\n ")}\n${extra}`);
52
+ const cart = " cart:\n name: Cart\n";
53
+ const events = (type) => ` events:\n name: Events\n type: ${type}\n`;
54
+ /** Two Relationships from `web` to `cart`, with the given ids. */
55
+ const twoToCart = (first, second) => withServices(`services:\n web:\n name: Web\n relationships:\n - id: ${first}\n to: cart\n - id: ${second}\n to: cart\n description: Adds a gift card\n${cart}`);
56
+ /** The Element references a Relationship makes: `to`, and `via` if given. */
57
+ const refsOf = (r) => ["to", "via"].filter((field) => r.data[field] !== undefined).map((field) => ({ field, ref: r.data[field] }));
58
+ /** Each Relationship reference with what it resolves to. */
59
+ const resolvedRefs = (ws) => {
60
+ const resolve = referenceResolver(ws);
61
+ return ws.relationships.flatMap((r) => refsOf(r).map(({ field, ref }) => ({ r, field, ref: ref, resolved: resolve(ref, r.from.project) })));
62
+ };
63
+ /** The provider a Relationship's `to` resolves to, if it does. */
64
+ const providers = (ws) => resolvedRefs(ws).flatMap(({ r, field, resolved }) => (field === "to" && resolved.ok ? [{ r, to: resolved.element }] : []));
65
+ const ancestors = (e) => {
66
+ const seen = [];
67
+ for (let p = e.parent; p && !seen.includes(p); p = p.parent)
68
+ seen.push(p);
69
+ return seen;
70
+ };
71
+ const isSync = (r) => r.data.interaction !== "async";
72
+ const asRecord = (v) => (v !== null && typeof v === "object" && !Array.isArray(v) ? v : {});
73
+ const asList = (v) => (Array.isArray(v) ? v : []);
74
+ /** The Element references a Saved View makes: bare-id and `{element}` and path selectors, `expand`, `collapse` and the Lens; a Dynamic View's `participants` and Step ends. */
75
+ function viewElementRefs(v) {
76
+ const out = [];
77
+ for (const key of ["include", "exclude"]) {
78
+ asList(v.data[key]).forEach((s, i) => {
79
+ if (typeof s === "string")
80
+ out.push({ path: [key, i], value: s });
81
+ else
82
+ for (const field of ["element", "from", "to"])
83
+ if (field in asRecord(s))
84
+ out.push({ path: [key, i, field], value: asRecord(s)[field] });
85
+ });
86
+ }
87
+ for (const key of ["expand", "collapse", "participants"])
88
+ asList(v.data[key]).forEach((id, i) => out.push({ path: [key, i], value: id }));
89
+ asList(v.data.steps).forEach((step, i) => {
90
+ for (const end of ["from", "to"])
91
+ if (end in asRecord(step))
92
+ out.push({ path: ["steps", i, end], value: asRecord(step)[end] });
93
+ });
94
+ const lens = asRecord(v.data.lens);
95
+ if ("impact" in lens)
96
+ out.push({ path: ["lens", "impact"], value: lens.impact });
97
+ const path = asRecord(lens.path);
98
+ for (const field of ["from", "to"])
99
+ if (field in path)
100
+ out.push({ path: ["lens", "path", field], value: path[field] });
101
+ return out;
102
+ }
103
+ /** The Team references a Saved View makes: `{team}` selectors and a Team Lens. */
104
+ function viewTeamRefs(v) {
105
+ const out = [];
106
+ for (const key of ["include", "exclude"])
107
+ asList(v.data[key]).forEach((s, i) => "team" in asRecord(s) && out.push({ path: [key, i, "team"], value: asRecord(s).team }));
108
+ if ("team" in asRecord(v.data.lens))
109
+ out.push({ path: ["lens", "team"], value: asRecord(v.data.lens).team });
110
+ return out;
111
+ }
112
+ /** Every Element reference made by a Relationship (`to`, `via`) or a Saved View. */
113
+ const elementRefs = (ws) => {
114
+ const resolve = referenceResolver(ws);
115
+ return [
116
+ ...resolvedRefs(ws).map(({ r, field, ref, resolved }) => ({ file: r.file, path: [...r.path, field], project: r.from.project, ref, resolved })),
117
+ ...ws.views.flatMap((v) => viewElementRefs(v).flatMap(({ path, value }) => (typeof value === "string" ? [{ file: v.file, path: [...v.path, ...path], project: v.project, ref: value, resolved: resolve(value, v.project) }] : []))),
118
+ ];
119
+ };
120
+ /**
121
+ * Each Saved View that made it into the Bundle (the first of a repeated id), with its definition and resolution;
122
+ * a Deployment View with a missing or unknown Environment, which other rules report, isn't resolved.
123
+ */
124
+ const resolvedSavedViews = (ws, bundle) => ws.views.flatMap((decl) => {
125
+ const def = bundledView(decl, bundle);
126
+ if (def?.kind !== "structural")
127
+ return [];
128
+ if (def.level === "deployment" && !bundle.environments.some((e) => e.id === def.environment))
129
+ return [];
130
+ return [{ decl, def, resolution: resolveSaved(bundle, def) }];
131
+ });
132
+ /** The Bundle definition a View declaration became, if it made it into the Bundle (the first of a repeated id). */
133
+ const bundledView = (decl, bundle) => bundle.views.find((v) => v.id === `${decl.project.id}:${decl.id}` && v.source.file === decl.file.path && v.source.line === decl.line);
134
+ /** Each Dynamic View that made it into the Bundle, with its resolution. */
135
+ const resolvedDynamicViews = (ws, bundle) => ws.views.flatMap((decl) => {
136
+ const def = bundledView(decl, bundle);
137
+ return def?.kind === "dynamic" ? [{ decl, def, resolution: resolveDynamic(bundle, def) }] : [];
138
+ });
139
+ /** A rule reporting one kind of Dynamic View problem, at the Step or participant it is about. */
140
+ const dynamicProblems = (rule) => (ws, bundle) => resolvedDynamicViews(ws, bundle).flatMap(({ decl, resolution }) => resolution.problems.filter((p) => p.rule === rule).map((p) => at(decl.file, [...decl.path, ...p.at], p.message)));
141
+ const targetAncestry = (t) => {
142
+ const out = [t];
143
+ for (let p = t.parent; p && !out.includes(p); p = p.parent)
144
+ out.push(p);
145
+ return out;
146
+ };
147
+ /**
148
+ * A Dynamic View example: web calls cart; orders publishes `order-placed` on
149
+ * the events broker, which mailer subscribes to. `views: dynamic:` is given
150
+ * as the YAML under it, and `extra` adds fields to orders.
151
+ */
152
+ const scenario = (views, extra = "") => withServices(`services:\n web:\n name: Web\n relationships:\n - to: cart\n cart:\n name: Cart\n components:\n cart-api:\n name: Cart API\n orders:\n name: Orders\n${extra}${events("broker")} mailer:\n name: Mailer\n relationships:\n - to: orders\n interaction: async\n via: events\n channel: order-placed\nviews:\n dynamic:\n${views.replace(/^/gm, " ")}\n`);
153
+ /** A Saved View example: two Services, one with a Component, and `views: structural:` given as the YAML under it. */
154
+ const viewing = (views, extra = {}) => withServices(`services:\n web:\n name: Web\n relationships:\n - to: cart\n cart:\n name: Cart\n components:\n cart-api:\n name: Cart API\n search:\n name: Search\nviews:\n structural:\n${views.replace(/^/gm, " ")}\n`, extra);
155
+ /** A position in an ADR's frontmatter, as an issue at its line in the file; line 1 when it has none. */
156
+ const atAdr = (adr, path, message, key = false) => {
157
+ if (!adr.frontmatter)
158
+ return { file: adr.path, line: 1, message };
159
+ const pos = adr.frontmatter.positionOf(path, { key });
160
+ return { file: adr.path, line: pos.line + adr.lineOffset, column: pos.column, message };
161
+ };
162
+ /** An ADR file for examples: frontmatter lines, a `# ` title and a short body. */
163
+ const adrText = (frontmatter, title = "Use Kafka for events") => `---\n${frontmatter}\n---\n\n# ${title}\n\nWe publish domain events on Kafka.\n`;
164
+ /** An ADR example: one Service, a Saved View, and the given files under `shop/adr/`. */
165
+ const deciding = (adrs) => withServices("services:\n web:\n name: Web\ntargets:\n eks-prod:\n name: EKS prod\n kind: cluster\nviews:\n structural:\n front:\n title: Front\n level: c2\n", Object.fromEntries(Object.entries(adrs).map(([name, text]) => [`shop/adr/${name}`, text])));
166
+ /** ADRs in a usable Project with an `NNNN` number, by qualified id (the first file of each number). */
167
+ const numberedAdrs = (ws) => {
168
+ const byId = new Map();
169
+ for (const a of ws.adrs) {
170
+ if (a.project.id === undefined || a.project.duplicateOf || a.number === undefined)
171
+ continue;
172
+ const id = `${a.project.id}:${a.number}`;
173
+ if (!byId.has(id))
174
+ byId.set(id, a);
175
+ }
176
+ return byId;
177
+ };
178
+ /** Each well-formed `supersedes` entry of a numbered ADR, qualified, with the ADR it names if any. */
179
+ const supersedesEntries = (ws) => {
180
+ const adrs = numberedAdrs(ws);
181
+ return [...adrs].flatMap(([id, a]) => asList(a.data.supersedes).flatMap((ref, i) => {
182
+ const to = qualifyAdr(ref, a.project);
183
+ return to === undefined ? [] : [{ id, adr: a, index: i, to, target: adrs.get(to) }];
184
+ }));
185
+ };
186
+ export const rules = [
187
+ {
188
+ id: "yaml-syntax",
189
+ severity: "error",
190
+ summary: "A file can't be parsed as YAML.",
191
+ fix: "Correct the YAML syntax at the reported position.",
192
+ example: {
193
+ failing: withServices("services:\n web:\n name: [Web\n"),
194
+ passing: withServices("services:\n web:\n name: Web\n"),
195
+ },
196
+ check: (ws) => ws.files.flatMap((file) => {
197
+ const e = file.parsed.syntaxError;
198
+ return e ? [{ file: file.path, line: e.line, column: e.column, message: e.message }] : [];
199
+ }),
200
+ },
201
+ {
202
+ id: "unknown-field",
203
+ severity: "error",
204
+ summary: "A key isn't in the schema.",
205
+ fix: "Remove the key, or correct its spelling to the suggested field.",
206
+ example: {
207
+ failing: withServices("services:\n web:\n name: Web\n techology: Go\n"),
208
+ passing: withServices("services:\n web:\n name: Web\n technology: Go\n"),
209
+ },
210
+ check: findings("unknown-field"),
211
+ },
212
+ {
213
+ id: "missing-field",
214
+ severity: "error",
215
+ summary: "A required field is absent.",
216
+ fix: "Add the missing field.",
217
+ example: {
218
+ failing: withServices("services:\n web:\n technology: Go\n"),
219
+ passing: withServices("services:\n web:\n name: Web\n technology: Go\n"),
220
+ },
221
+ check: findings("missing-field"),
222
+ },
223
+ {
224
+ id: "invalid-value",
225
+ severity: "error",
226
+ summary: "A value has the wrong type, a bad enum value or a malformed URL.",
227
+ fix: "Change the value to one the field accepts.",
228
+ example: {
229
+ failing: withServices("services:\n orders-db:\n name: Orders DB\n type: database\n"),
230
+ passing: withServices("services:\n orders-db:\n name: Orders DB\n type: datastore\n"),
231
+ },
232
+ check: findings("invalid-value"),
233
+ },
234
+ {
235
+ id: "nested-project",
236
+ severity: "error",
237
+ summary: "A `project.yaml` sits inside another Project's folder.",
238
+ fix: "Move the inner Project's folder out of the outer Project's folder.",
239
+ example: {
240
+ failing: { ...base, "shop/legacy/project.yaml": "id: legacy\nname: Legacy\nowner: core\n" },
241
+ passing: { ...base, "legacy/project.yaml": "id: legacy\nname: Legacy\nowner: core\n" },
242
+ },
243
+ check: (ws) => ws.projects.flatMap((p) => p.nestedIn
244
+ ? [at(p.file, [], `Project folder ${p.folder} is inside Project "${p.nestedIn.id ?? p.nestedIn.folder}" (${p.nestedIn.folder}); Projects can't nest`)]
245
+ : []),
246
+ },
247
+ {
248
+ id: "file-outside-project",
249
+ severity: "error",
250
+ summary: "A model file is under no Project.",
251
+ fix: "Move the file into a Project folder (one with a `project.yaml`).",
252
+ example: {
253
+ failing: { ...base, "services.yaml": "services:\n web:\n name: Web\n" },
254
+ passing: withServices("services:\n web:\n name: Web\n"),
255
+ },
256
+ check: (ws) => ws.files
257
+ .filter((f) => f.role === "outside")
258
+ .map((f) => ({ file: f.path, line: 1, message: "File is in no Project; move it into a folder with a project.yaml" })),
259
+ },
260
+ {
261
+ id: "duplicate-project-id",
262
+ severity: "error",
263
+ summary: "Two Projects share an id.",
264
+ fix: "Give one of the Projects a different id.",
265
+ example: {
266
+ failing: { ...base, "shop-admin/project.yaml": "id: shop\nname: Shop admin\nowner: core\n" },
267
+ passing: { ...base, "shop-admin/project.yaml": "id: shop-admin\nname: Shop admin\nowner: core\n" },
268
+ },
269
+ check: (ws) => ws.projects.flatMap((p) => p.duplicateOf ? [at(p.file, ["id"], `Project id "${p.id}" is already used by ${p.duplicateOf.file.path}`)] : []),
270
+ },
271
+ {
272
+ id: "definition-outside-workspace",
273
+ severity: "error",
274
+ summary: "`teams` or `environments` declared outside `workspace.yaml`.",
275
+ fix: "Move the definitions into `workspace.yaml` at the Workspace root.",
276
+ example: {
277
+ failing: withServices("teams:\n web-team:\n name: Web\n"),
278
+ passing: {
279
+ ...base,
280
+ "workspace.yaml": "teams:\n core:\n name: Core\n web-team:\n name: Web\nenvironments:\n prod:\n name: Production\n",
281
+ },
282
+ },
283
+ check: findings("definition-outside-workspace"),
284
+ },
285
+ {
286
+ id: "unknown-team",
287
+ severity: "error",
288
+ summary: "An `owner`, or a Saved View's `{team}` selector or Team Lens, names no Team.",
289
+ fix: "Use the id of a Team defined in `workspace.yaml`, or define the Team there.",
290
+ example: {
291
+ failing: withServices("services:\n web:\n name: Web\n owner: cor\n"),
292
+ passing: withServices("services:\n web:\n name: Web\n owner: core\n"),
293
+ },
294
+ check: (ws) => {
295
+ const teams = new Set(ws.teams.map((t) => t.id));
296
+ const message = (owner) => `Unknown Team "${owner}"${didYouMean(owner, teams)}`;
297
+ // A malformed owner is already an `invalid-value`; report only that root cause.
298
+ const unknown = (owner) => typeof owner === "string" && Id.safeParse(owner).success && !teams.has(owner);
299
+ const issues = [];
300
+ for (const p of ws.projects) {
301
+ if (unknown(p.owner))
302
+ issues.push(at(p.file, ["owner"], message(p.owner)));
303
+ }
304
+ for (const e of [...ws.elements, ...ws.targets]) {
305
+ const owner = e.data.owner;
306
+ if (unknown(owner))
307
+ issues.push(at(e.file, [...e.path, "owner"], message(owner)));
308
+ }
309
+ for (const v of ws.views) {
310
+ for (const { path, value } of viewTeamRefs(v))
311
+ if (unknown(value))
312
+ issues.push(at(v.file, [...v.path, ...path], message(value)));
313
+ }
314
+ return issues;
315
+ },
316
+ },
317
+ {
318
+ id: "duplicate-id",
319
+ severity: "error",
320
+ summary: "An Element or Deployment Target id is declared twice in a Project, across files too, whatever its kind or nesting.",
321
+ fix: "Rename one of the Elements or Targets, or remove the second declaration.",
322
+ example: {
323
+ failing: withServices("services:\n web:\n name: Web\n", { "shop/more.yaml": "services:\n web:\n name: Web v2\n" }),
324
+ passing: withServices("services:\n web:\n name: Web\n", { "shop/more.yaml": "services:\n web-v2:\n name: Web v2\n" }),
325
+ },
326
+ check: (ws) => {
327
+ const seen = new Map();
328
+ const issues = [];
329
+ // Elements and Targets share one namespace; the first in file order keeps the id.
330
+ const decls = [...ws.elements, ...ws.targets].sort((a, b) => (a.file.path < b.file.path ? -1 : a.file.path > b.file.path ? 1 : a.line - b.line));
331
+ for (const e of decls) {
332
+ if (e.project.duplicateOf || e.project.id === undefined)
333
+ continue;
334
+ const key = `${e.project.id}:${e.id}`;
335
+ const first = seen.get(key);
336
+ if (first) {
337
+ issues.push(at(e.file, e.path, `Id "${e.id}" is already declared in Project "${e.project.id}" at ${first.file}:${first.line}`, true));
338
+ }
339
+ else {
340
+ seen.set(key, { file: e.file.path, line: e.line });
341
+ }
342
+ }
343
+ return issues;
344
+ },
345
+ },
346
+ {
347
+ id: "invalid-nesting",
348
+ severity: "error",
349
+ summary: "System > Service > Component is broken, by nesting or `in:`.",
350
+ fix: "Move the Element under a parent of the right kind (a Service under a System, a Component under a Service), or point `in:` at one.",
351
+ example: {
352
+ failing: withServices("systems:\n checkout:\n name: Checkout\n components:\n cart-api:\n name: Cart API\n"),
353
+ passing: withServices("systems:\n checkout:\n name: Checkout\n services:\n cart:\n name: Cart\n components:\n cart-api:\n name: Cart API\n"),
354
+ },
355
+ check: (ws) => ws.elements.flatMap((e) => {
356
+ const ref = inRef(e);
357
+ if (e.nestedIn) {
358
+ const issues = [];
359
+ if (parentKindOf[e.kind] !== e.nestedIn.kind)
360
+ issues.push(at(e.file, e.path, `${named(e)} can't sit inside ${named(e.nestedIn)}; ${belongs[e.kind]}`, true));
361
+ if (ref !== undefined)
362
+ issues.push(at(e.file, [...e.path, "in"], `${named(e)} is nested under ${named(e.nestedIn)} and also names \`in: ${ref}\`; remove \`in:\``));
363
+ return issues;
364
+ }
365
+ if (e.parent && parentKindOf[e.kind] !== e.parent.kind) {
366
+ return [at(e.file, [...e.path, "in"], `${named(e)} can't sit inside ${named(e.parent)}; \`in:\` must name a ${kindName[parentKindOf[e.kind]]}`)];
367
+ }
368
+ if (e.kind === "component" && ref === undefined) {
369
+ return [at(e.file, e.path, `${named(e)} has no parent; nest it under a Service or add \`in: <service>\``, true)];
370
+ }
371
+ return [];
372
+ }),
373
+ },
374
+ {
375
+ id: "external-with-components",
376
+ severity: "error",
377
+ summary: "An External System or Service declares Components.",
378
+ fix: "Remove the Components, or drop `external` if the organisation runs the Element itself.",
379
+ example: {
380
+ failing: withServices("services:\n stripe:\n name: Stripe\n external: true\n components:\n stripe-sdk:\n name: Stripe SDK\n"),
381
+ passing: withServices("services:\n stripe:\n name: Stripe\n external: true\n"),
382
+ },
383
+ check: (ws) => ws.elements
384
+ .filter((e) => e.kind === "component")
385
+ .flatMap((e) => {
386
+ const seen = new Set();
387
+ for (let p = e.parent; p && !seen.has(p); p = p.parent) {
388
+ seen.add(p);
389
+ if (p.data.external === true && (p.kind === "service" || p.kind === "system")) {
390
+ return [at(e.file, e.path, `${named(e)} is inside External ${named(p)}; an External Element can't contain declared Components`, true)];
391
+ }
392
+ }
393
+ return [];
394
+ }),
395
+ },
396
+ {
397
+ id: "unknown-element",
398
+ severity: "error",
399
+ summary: "A reference names no Element: in `to`, `via`, `in`, a Deployment's `service`, or a Saved View's selectors, `expand`, `collapse` or Lens.",
400
+ fix: "Use the id of an Element declared in the Project, or declare it.",
401
+ example: {
402
+ failing: withServices("systems:\n checkout:\n name: Checkout\n", { "shop/cart.yaml": "services:\n cart:\n name: Cart\n in: chekout\n" }),
403
+ passing: withServices("systems:\n checkout:\n name: Checkout\n", { "shop/cart.yaml": "services:\n cart:\n name: Cart\n in: checkout\n" }),
404
+ },
405
+ check: (ws) => {
406
+ const projectName = (e) => e.project.id ?? e.project.folder;
407
+ const parents = ws.elements.flatMap((e) => {
408
+ const ref = inRef(e);
409
+ if (ref === undefined || e.nestedIn || e.parent)
410
+ return [];
411
+ const ids = ws.elements.filter((o) => o.project === e.project).map((o) => o.id);
412
+ return [at(e.file, [...e.path, "in"], `Unknown Element "${ref}" in Project "${projectName(e)}"${didYouMean(ref, ids)}`)];
413
+ });
414
+ const references = elementRefs(ws).flatMap(({ file, path, project, resolved }) => {
415
+ if (resolved.ok || resolved.reason !== "unknown-element")
416
+ return [];
417
+ const own = resolved.project === project;
418
+ const ids = ws.elements.filter((o) => o.project === resolved.project).map((o) => (own ? o.id : qualified(o)));
419
+ const input = own ? resolved.id : `${resolved.project.id}:${resolved.id}`;
420
+ return [at(file, path, `Unknown Element "${resolved.id}" in Project "${resolved.project.id}"${didYouMean(input, ids)}`)];
421
+ });
422
+ const deployments = ws.deployments.flatMap((d) => {
423
+ const ref = qualify(d.data.service, d.project);
424
+ if (ref === undefined || d.service || qualifiedIds(ws.targets).has(ref))
425
+ return [];
426
+ return [at(d.file, [...d.path, "service"], unknownIn("Element", ref, ws.elements))];
427
+ });
428
+ return [...parents, ...references, ...deployments];
429
+ },
430
+ },
431
+ {
432
+ id: "unknown-project",
433
+ severity: "error",
434
+ summary: "A `project:` prefix names no Project.",
435
+ fix: "Correct the prefix to the id of an existing Project.",
436
+ example: {
437
+ failing: { ...relating("to: paymnts:payments-api"), ...payments },
438
+ passing: { ...relating("to: payments:payments-api"), ...payments },
439
+ },
440
+ check: (ws) => {
441
+ const projectIds = ws.projects.flatMap((p) => (p.id !== undefined && !p.duplicateOf ? [p.id] : []));
442
+ const elementIds = ws.elements.filter((e) => e.project.id !== undefined && !e.project.duplicateOf).map(qualified);
443
+ return elementRefs(ws).flatMap(({ file, path, ref, resolved }) => {
444
+ if (resolved.ok || resolved.reason !== "unknown-project")
445
+ return [];
446
+ // The nearest qualified id names the Element meant; failing that, the nearest Project.
447
+ const hint = didYouMean(ref, elementIds) || didYouMean(resolved.project, projectIds);
448
+ return [at(file, path, `Unknown Project "${resolved.project}" in "${ref}"${hint}`)];
449
+ });
450
+ },
451
+ },
452
+ {
453
+ id: "own-project-prefix",
454
+ severity: "error",
455
+ summary: "A Project qualifies its own ids.",
456
+ fix: "Drop the `project:` prefix; within its own Project an id is written bare.",
457
+ example: {
458
+ failing: relating("to: shop:cart", cart),
459
+ passing: relating("to: cart", cart),
460
+ },
461
+ check: (ws) => elementRefs(ws).flatMap(({ file, path, project, ref, resolved }) => resolved.ok && resolved.ownPrefix ? [at(file, path, `Write "${resolved.element.id}", not "${ref}", inside Project "${project.id}"`)] : []),
462
+ },
463
+ {
464
+ id: "duplicate-relationship-id",
465
+ severity: "error",
466
+ summary: "A Relationship `id` repeats in a Project.",
467
+ fix: "Give one of the Relationships a different id.",
468
+ example: {
469
+ failing: twoToCart("add-item", "add-item"),
470
+ passing: twoToCart("add-item", "add-gift-card"),
471
+ },
472
+ check: (ws) => {
473
+ const seen = new Map();
474
+ return ws.relationships.flatMap((r) => {
475
+ const id = r.data.id;
476
+ if (typeof id !== "string" || r.from.project.id === undefined)
477
+ return [];
478
+ const key = `${r.from.project.id}:${id}`;
479
+ const first = seen.get(key);
480
+ if (!first) {
481
+ seen.set(key, r);
482
+ return [];
483
+ }
484
+ return [at(r.file, [...r.path, "id"], `Relationship id "${id}" is already used in Project "${r.from.project.id}" at ${first.file.path}:${first.line}`)];
485
+ });
486
+ },
487
+ },
488
+ {
489
+ id: "self-relationship",
490
+ severity: "error",
491
+ summary: "An Element has a Relationship to itself.",
492
+ fix: "Point `to` at the Element depended on, or remove the Relationship.",
493
+ example: {
494
+ failing: relating("to: web", cart),
495
+ passing: relating("to: cart", cart),
496
+ },
497
+ check: (ws) => providers(ws).flatMap(({ r, to }) => (to === r.from ? [at(r.file, [...r.path, "to"], `${named(r.from)} has a Relationship to itself`)] : [])),
498
+ },
499
+ {
500
+ id: "person-as-provider",
501
+ severity: "error",
502
+ summary: "The provider of a Relationship is a Person.",
503
+ fix: "A Person is only ever a consumer: declare the Relationship under the Person, pointing at what it uses.",
504
+ example: {
505
+ failing: relating("to: shopper", "people:\n shopper:\n name: Shopper\n"),
506
+ passing: withServices("services:\n web:\n name: Web\npeople:\n shopper:\n name: Shopper\n relationships:\n - to: web\n"),
507
+ },
508
+ check: (ws) => providers(ws).flatMap(({ r, to }) => to.kind === "person" ? [at(r.file, [...r.path, "to"], `${named(to)} can't be a provider; declare the Relationship under the Person instead`)] : []),
509
+ },
510
+ {
511
+ id: "ancestor-descendant-relationship",
512
+ severity: "error",
513
+ summary: "An Element is linked to its own ancestor or descendant.",
514
+ fix: "Point `to` at an Element outside the consumer's own branch, such as a sibling.",
515
+ example: {
516
+ failing: withServices("services:\n web:\n name: Web\n components:\n web-ui:\n name: Web UI\n relationships:\n - to: web\n"),
517
+ passing: withServices("services:\n web:\n name: Web\n components:\n web-ui:\n name: Web UI\n relationships:\n - to: web-api\n web-api:\n name: Web API\n"),
518
+ },
519
+ check: (ws) => providers(ws).flatMap(({ r, to }) => {
520
+ if (ancestors(r.from).includes(to))
521
+ return [at(r.file, [...r.path, "to"], `${named(r.from)} is inside ${named(to)}, so it can't have a Relationship to it`)];
522
+ if (ancestors(to).includes(r.from))
523
+ return [at(r.file, [...r.path, "to"], `${named(to)} is inside ${named(r.from)}, so ${named(r.from)} can't have a Relationship to it`)];
524
+ return [];
525
+ }),
526
+ },
527
+ {
528
+ id: "via-on-sync",
529
+ severity: "error",
530
+ summary: "`via` or `channel` on a sync Relationship.",
531
+ fix: "Set `interaction: async` if the Relationship runs through a broker, or remove `via` and `channel`.",
532
+ example: {
533
+ failing: relating("to: cart\nvia: events\nchannel: cart.updated", `${cart}${events("broker")}`),
534
+ passing: relating("to: cart\ninteraction: async\nvia: events\nchannel: cart.updated", `${cart}${events("broker")}`),
535
+ },
536
+ check: (ws) => ws.relationships.filter(isSync).flatMap((r) => ["via", "channel"]
537
+ .filter((field) => r.data[field] !== undefined)
538
+ .map((field) => at(r.file, [...r.path, field], `\`${field}\` is only for an async Relationship; add \`interaction: async\` or remove \`${field}\``, true))),
539
+ },
540
+ {
541
+ id: "via-not-broker",
542
+ severity: "error",
543
+ summary: "`via` names a Service that isn't `type: broker`.",
544
+ fix: "Point `via` at a broker Service, or mark the Service `type: broker`.",
545
+ example: {
546
+ failing: relating("to: cart\ninteraction: async\nvia: events", `${cart}${events("app")}`),
547
+ passing: relating("to: cart\ninteraction: async\nvia: events", `${cart}${events("broker")}`),
548
+ },
549
+ check: (ws) => resolvedRefs(ws).flatMap(({ r, field, resolved }) => {
550
+ if (field !== "via" || !resolved.ok || resolved.element.kind !== "service")
551
+ return [];
552
+ const type = resolved.element.data.type ?? "app";
553
+ return type === "broker" ? [] : [at(r.file, [...r.path, field], `\`via\` must name a broker Service, but ${named(resolved.element)} has type "${String(type)}"`)];
554
+ }),
555
+ },
556
+ {
557
+ id: "duplicate-deployment",
558
+ severity: "error",
559
+ summary: "The same Service, Environment and Target appear twice.",
560
+ fix: "Remove the second Deployment, or merge its `url` and `endpoints` into the first.",
561
+ example: {
562
+ failing: withDeployments(" - { service: web, environment: prod, target: eks-prod, url: https://shop.example.com }\n", { "shop/more.yaml": "deployments:\n - { service: web, environment: prod, target: eks-prod, url: https://www.shop.example.com }\n" }),
563
+ passing: withDeployments(" - { service: web, environment: prod, target: eks-prod, url: https://shop.example.com }\n"),
564
+ },
565
+ check: (ws) => {
566
+ const seen = new Map();
567
+ const issues = [];
568
+ for (const d of ws.deployments) {
569
+ const service = qualify(d.data.service, d.project);
570
+ const target = qualify(d.data.target, d.project);
571
+ const environment = d.data.environment;
572
+ if (service === undefined || target === undefined || typeof environment !== "string" || d.project.duplicateOf)
573
+ continue;
574
+ const key = `${service}\0${environment}\0${target}`;
575
+ const first = seen.get(key);
576
+ if (first) {
577
+ issues.push({ file: d.file.path, line: d.line, column: d.column, message: `Service "${service}" is already deployed to "${target}" in Environment "${environment}" at ${first.file}:${first.line}` });
578
+ }
579
+ else {
580
+ seen.set(key, { file: d.file.path, line: d.line });
581
+ }
582
+ }
583
+ return issues;
584
+ },
585
+ },
586
+ {
587
+ id: "unknown-environment",
588
+ severity: "error",
589
+ summary: "A Deployment, or a Saved Deployment View, names no Environment.",
590
+ fix: "Use the id of an Environment defined in `workspace.yaml`, or define the Environment there.",
591
+ example: {
592
+ failing: withDeployments(" - { service: web, environment: production, target: eks-prod }\n"),
593
+ passing: withDeployments(" - { service: web, environment: prod, target: eks-prod }\n"),
594
+ },
595
+ check: (ws) => {
596
+ const environments = new Set(ws.environments.map((e) => e.id));
597
+ return [...ws.deployments, ...ws.views].flatMap((d) => {
598
+ const env = d.data.environment;
599
+ // A malformed id is already an `invalid-value`.
600
+ if (env === undefined || !Id.safeParse(env).success || environments.has(env))
601
+ return [];
602
+ return [at(d.file, [...d.path, "environment"], `Unknown Environment "${env}"${didYouMean(env, environments)}`)];
603
+ });
604
+ },
605
+ },
606
+ {
607
+ id: "unknown-target",
608
+ severity: "error",
609
+ summary: "A Deployment, or a Saved Deployment View's `targets`, names no Deployment Target.",
610
+ fix: "Use the id of a Target declared in the Project, or `project:id` for one declared in another Project.",
611
+ example: {
612
+ failing: withDeployments(" - { service: web, environment: prod, target: eks-prd }\n"),
613
+ passing: withDeployments(" - { service: web, environment: prod, target: eks-prod }\n"),
614
+ },
615
+ check: (ws) => {
616
+ const known = qualifiedIds(ws.targets);
617
+ const deployments = ws.deployments.flatMap((d) => {
618
+ const ref = qualify(d.data.target, d.project);
619
+ if (ref === undefined || d.target)
620
+ return [];
621
+ return [at(d.file, [...d.path, "target"], unknownIn("Deployment Target", ref, ws.targets))];
622
+ });
623
+ const views = ws.views.flatMap((v) => asList(v.data.targets).flatMap((target, i) => {
624
+ const ref = qualify(target, v.project);
625
+ return ref === undefined || known.has(ref) ? [] : [at(v.file, [...v.path, "targets", i], unknownIn("Deployment Target", ref, ws.targets))];
626
+ }));
627
+ return [...deployments, ...views];
628
+ },
629
+ },
630
+ {
631
+ id: "wrong-kind",
632
+ severity: "error",
633
+ summary: "An id resolves to a kind the field doesn't accept, such as a Deployment's `service` naming a Component or System, or a Relationship's `via` naming something other than a Service.",
634
+ fix: "Point the field at an id of the kind it accepts: a Deployment's `service` and a Relationship's `via` each name a Service.",
635
+ example: {
636
+ failing: withDeployments(" - { service: cart, environment: prod, target: eks-prod }\n"),
637
+ passing: withDeployments(" - { service: web, environment: prod, target: eks-prod }\n"),
638
+ },
639
+ check: (ws) => {
640
+ const targets = qualifiedIds(ws.targets);
641
+ const deployments = ws.deployments.flatMap((d) => {
642
+ const ref = qualify(d.data.service, d.project);
643
+ if (ref === undefined)
644
+ return [];
645
+ const kind = d.service ? (d.service.kind === "service" ? undefined : kindName[d.service.kind]) : targets.has(ref) ? "Deployment Target" : undefined;
646
+ return kind ? [at(d.file, [...d.path, "service"], `A Deployment's \`service\` must name a Service, but "${ref}" is a ${kind}`)] : [];
647
+ });
648
+ const vias = resolvedRefs(ws).flatMap(({ r, field, ref, resolved }) => field === "via" && resolved.ok && resolved.element.kind !== "service"
649
+ ? [at(r.file, [...r.path, field], `\`via\` must name a broker Service, but "${ref}" is a ${kindName[resolved.element.kind]}`)]
650
+ : []);
651
+ return [...deployments, ...vias];
652
+ },
653
+ },
654
+ {
655
+ id: "oversized-view",
656
+ severity: "warning",
657
+ summary: `A View has more than ${MAX_VIEW_NODES} nodes, too many for a readable diagram. A Generated View is reported at its System or Service, or at \`workspace.yaml\` for the Landscapes; a Saved View at its id.`,
658
+ fix: "Split the System, or group top-level Services and Systems, so each Generated View stays within the limit; narrow a Saved View's selectors or raise its `level`.",
659
+ example: {
660
+ failing: withServices(`systems:\n big:\n name: Big\n services:\n${numbered(MAX_VIEW_NODES, "s", 6)}`),
661
+ passing: withServices(`systems:\n big:\n name: Big\n services:\n${numbered(MAX_VIEW_NODES / 2, "s", 6)} more:\n name: More\n services:\n${numbered(MAX_VIEW_NODES / 2, "s", 6, MAX_VIEW_NODES / 2)}`),
662
+ },
663
+ check: (ws, bundle) => {
664
+ const workspaceFile = ws.files.find((f) => f.role === "workspace");
665
+ const generated = generatedViews(bundle)
666
+ .filter((v) => v.nodes.length > MAX_VIEW_NODES)
667
+ .flatMap((v) => {
668
+ const focus = bundle.elements.find((e) => e.id === v.id.slice(v.id.indexOf("/") + 1));
669
+ const where = focus ? focus.source : workspaceFile ? { file: workspaceFile.path, line: 1 } : undefined;
670
+ if (!where)
671
+ return [];
672
+ return [{ file: where.file, line: where.line, message: `Generated View "${v.id}" has ${v.nodes.length} nodes, more than the ${MAX_VIEW_NODES} a diagram stays readable at` }];
673
+ });
674
+ const saved = resolvedSavedViews(ws, bundle)
675
+ .filter(({ resolution }) => resolution.view.nodes.length > MAX_VIEW_NODES)
676
+ .map(({ decl, def, resolution }) => at(decl.file, decl.path, `Saved View "${def.id}" has ${resolution.view.nodes.length} nodes, more than the ${MAX_VIEW_NODES} a diagram stays readable at`, true));
677
+ return [...generated, ...saved];
678
+ },
679
+ },
680
+ {
681
+ id: "duplicate-view-id",
682
+ severity: "error",
683
+ summary: "A Saved View id repeats in a Project, across files too.",
684
+ fix: "Give one of the Views a different id.",
685
+ example: {
686
+ failing: viewing("front:\n title: Front\n level: c2", { "shop/more.yaml": "views:\n structural:\n front:\n title: Front again\n level: c2\n" }),
687
+ passing: viewing("front:\n title: Front\n level: c2", { "shop/more.yaml": "views:\n structural:\n front-v2:\n title: Front again\n level: c2\n" }),
688
+ },
689
+ check: (ws) => {
690
+ const seen = new Map();
691
+ return ws.views.flatMap((v) => {
692
+ if (v.project.id === undefined || v.project.duplicateOf)
693
+ return [];
694
+ const key = `${v.project.id}:${v.id}`;
695
+ const first = seen.get(key);
696
+ if (!first) {
697
+ seen.set(key, v);
698
+ return [];
699
+ }
700
+ return [at(v.file, v.path, `View id "${v.id}" is already used in Project "${v.project.id}" at ${first.file.path}:${first.line}`, true)];
701
+ });
702
+ },
703
+ },
704
+ {
705
+ id: "missing-step",
706
+ severity: "error",
707
+ summary: "A Dynamic View Step has no Relationship or derived edge between `from` and `to` (nor a `via` subscription of `to` to `from`), or the named `relationship` doesn't connect them.",
708
+ fix: "Point the Step at two Elements a Relationship connects, declare the Relationship, or name one that connects them.",
709
+ example: {
710
+ failing: scenario("purchase:\n title: Purchase\n steps:\n - { from: cart, to: web }"),
711
+ passing: scenario("purchase:\n title: Purchase\n steps:\n - { from: web, to: cart }"),
712
+ },
713
+ check: dynamicProblems("missing-step"),
714
+ },
715
+ {
716
+ id: "ambiguous-step",
717
+ severity: "error",
718
+ summary: "Several Relationships match a Dynamic View Step (several between the pair, or both a call and an event) and no `relationship` names one.",
719
+ fix: "Name the Relationship the Step takes with `relationship: <id>`.",
720
+ example: {
721
+ failing: scenario("purchase:\n title: Purchase\n steps:\n - { from: orders, to: mailer }", " relationships:\n - id: notify\n to: mailer\n"),
722
+ passing: scenario("purchase:\n title: Purchase\n steps:\n - { from: orders, to: mailer, relationship: notify }", " relationships:\n - id: notify\n to: mailer\n"),
723
+ },
724
+ check: dynamicProblems("ambiguous-step"),
725
+ },
726
+ {
727
+ id: "return-without-relationship",
728
+ severity: "error",
729
+ summary: "A Dynamic View return Step has no Relationship the other way, from its `to` to its `from`.",
730
+ fix: "Turn the Step round, or remove `return: true` if it is a call of its own.",
731
+ example: {
732
+ failing: scenario("purchase:\n title: Purchase\n steps:\n - { from: web, to: cart, return: true }"),
733
+ passing: scenario("purchase:\n title: Purchase\n steps:\n - { from: web, to: cart }\n - { from: cart, to: web, return: true }"),
734
+ },
735
+ check: dynamicProblems("return-without-relationship"),
736
+ },
737
+ {
738
+ id: "return-on-async",
739
+ severity: "error",
740
+ summary: "A Dynamic View return Step resolves to an async Relationship, which has no reply.",
741
+ fix: "Remove the return Step, or model the callback as a Relationship of its own and add a Step for it.",
742
+ example: {
743
+ failing: scenario("purchase:\n title: Purchase\n steps:\n - { from: orders, to: mailer, return: true }"),
744
+ passing: scenario("purchase:\n title: Purchase\n steps:\n - { from: orders, to: mailer }"),
745
+ },
746
+ check: dynamicProblems("return-on-async"),
747
+ },
748
+ {
749
+ id: "ancestor-descendant-participants",
750
+ severity: "error",
751
+ summary: "An Element and its own ancestor are both participants of a Dynamic View.",
752
+ fix: "Tell the scenario at one level: use the ancestor throughout, or its descendants throughout.",
753
+ example: {
754
+ failing: scenario("purchase:\n title: Purchase\n participants: [cart]\n steps:\n - { from: web, to: cart-api }"),
755
+ passing: scenario("purchase:\n title: Purchase\n participants: [cart]\n steps:\n - { from: web, to: cart }"),
756
+ },
757
+ check: dynamicProblems("ancestor-descendant-participants"),
758
+ },
759
+ {
760
+ id: "target-outside-environment",
761
+ severity: "error",
762
+ summary: "A Saved Deployment View's `targets` entry has no Deployment in the View's `environment`, on it or on any Target inside it.",
763
+ fix: "Remove the Target from `targets`, or point the View at the Environment that runs on it.",
764
+ example: {
765
+ failing: withDeployments(" - { service: web, environment: prod, target: eks-prod }\n", {
766
+ "shop/views.yaml": "targets:\n eks-staging:\n name: EKS staging\n kind: cluster\nviews:\n structural:\n runtime:\n title: Runtime\n level: deployment\n environment: prod\n targets: [eks-staging]\n",
767
+ }),
768
+ passing: withDeployments(" - { service: web, environment: prod, target: eks-prod }\n", {
769
+ "shop/views.yaml": "targets:\n eks-staging:\n name: EKS staging\n kind: cluster\nviews:\n structural:\n runtime:\n title: Runtime\n level: deployment\n environment: prod\n targets: [eks-prod]\n",
770
+ }),
771
+ },
772
+ check: (ws) => {
773
+ const targets = new Map(ws.targets.filter((t) => t.project.id !== undefined).map((t) => [`${t.project.id}:${t.id}`, t]));
774
+ return ws.views.flatMap((v) => {
775
+ const env = v.data.environment;
776
+ if (v.data.level !== "deployment" || typeof env !== "string" || !ws.environments.some((e) => e.id === env))
777
+ return [];
778
+ return asList(v.data.targets).flatMap((ref, i) => {
779
+ const id = qualify(ref, v.project);
780
+ const target = id === undefined ? undefined : targets.get(id);
781
+ if (!target)
782
+ return [];
783
+ const hosts = ws.deployments.some((d) => d.data.environment === env && d.target && targetAncestry(d.target).includes(target));
784
+ return hosts ? [] : [at(v.file, [...v.path, "targets", i], `Deployment Target "${id}" has no Deployment in Environment "${env}"`)];
785
+ });
786
+ });
787
+ },
788
+ },
789
+ {
790
+ id: "bad-expand",
791
+ severity: "error",
792
+ summary: "A Saved View's `expand` or `collapse` id is not a node of the View once collapsed to its `level`, or has no children.",
793
+ fix: "Remove the id, include the Element in the View, or name an Element that has children.",
794
+ example: {
795
+ failing: viewing("front:\n title: Front\n level: c2\n include: [web]\n expand: [web]"),
796
+ passing: viewing("front:\n title: Front\n level: c2\n include: [web, cart]\n expand: [cart]"),
797
+ },
798
+ check: (ws, bundle) => {
799
+ const known = new Set(bundle.elements.map((e) => e.id));
800
+ return resolvedSavedViews(ws, bundle).flatMap(({ decl, resolution }) => resolution.badExpand
801
+ .filter((b) => known.has(b.id))
802
+ .map((b) => at(decl.file, [...decl.path, b.field, b.index], `Can't ${b.field} "${b.id}": ${b.reason === "no-children" ? "it has no children" : "it is not in the View"}`)));
803
+ },
804
+ },
805
+ {
806
+ id: "empty-view",
807
+ severity: "warning",
808
+ summary: "A Saved View resolves to no nodes.",
809
+ fix: "Correct the selectors so they name Elements, or remove the View.",
810
+ example: {
811
+ failing: viewing("front:\n title: Front\n level: c2\n include: [{ tag: storefront }]"),
812
+ passing: withServices("services:\n web:\n name: Web\n tags: [storefront]\nviews:\n structural:\n front:\n title: Front\n level: c2\n include: [{ tag: storefront }]\n"),
813
+ },
814
+ check: (ws, bundle) => resolvedSavedViews(ws, bundle)
815
+ .filter(({ resolution }) => resolution.view.nodes.length === 0)
816
+ .map(({ decl, def }) => at(decl.file, decl.path, `Saved View "${def.id}" resolves to no nodes`, true)),
817
+ },
818
+ {
819
+ id: "unresolved-path",
820
+ severity: "warning",
821
+ summary: "A Saved View's path selector, or path Lens, finds no path between its two Elements.",
822
+ fix: "Check the Relationships between the two Elements, or raise `paths`; remove the selector if the path is gone for good.",
823
+ example: {
824
+ failing: viewing("front:\n title: Front\n level: c2\n include: [{ from: web, to: search }]"),
825
+ passing: viewing("front:\n title: Front\n level: c2\n include: [{ from: web, to: cart }]"),
826
+ },
827
+ check: (ws, bundle) => resolvedSavedViews(ws, bundle).flatMap(({ decl, resolution }) => resolution.unresolvedPaths.map((u) => at(decl.file, [...decl.path, ...u.at], `No path between "${u.from}" and "${u.to}"`))),
828
+ },
829
+ {
830
+ id: "invalid-adr-frontmatter",
831
+ severity: "error",
832
+ summary: "An ADR has no frontmatter, frontmatter that isn't valid YAML, or a field that is unknown, missing (`status`, `date`) or invalid, such as a `status` outside proposed, accepted, rejected, deprecated and superseded.",
833
+ fix: "Start the file with `---`, `status` and `date` (YYYY-MM-DD), then `---`; use only the MADR fields and the `elements`, `views` and `supersedes` links.",
834
+ example: {
835
+ failing: deciding({ "0001-use-kafka.md": adrText("status: approved\ndate: 2026-03-01") }),
836
+ passing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01") }),
837
+ },
838
+ check: (ws) => ws.adrs.flatMap((a) => {
839
+ if (!a.frontmatter)
840
+ return [{ file: a.path, line: 1, message: "ADR has no frontmatter: start the file with `---`, then `status` and `date`, then `---`" }];
841
+ const e = a.frontmatter.syntaxError;
842
+ if (e)
843
+ return [{ file: a.path, line: e.line + a.lineOffset, column: e.column, message: e.message }];
844
+ return checkSchema(AdrFrontmatter, a.frontmatter.data, a.frontmatter).map((f) => ({ file: a.path, line: f.line + a.lineOffset, column: f.column, message: f.message }));
845
+ }),
846
+ },
847
+ {
848
+ id: "missing-adr-title",
849
+ severity: "error",
850
+ summary: "An ADR's body has no `# ` heading to take its title from.",
851
+ fix: "Start the body with a `# ` heading naming the decision.",
852
+ example: {
853
+ failing: deciding({ "0001-use-kafka.md": "---\nstatus: accepted\ndate: 2026-03-01\n---\n\nWe publish domain events on Kafka.\n" }),
854
+ passing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01") }),
855
+ },
856
+ check: (ws) => ws.adrs.flatMap((a) => (a.title || !a.frontmatter ? [] : [{ file: a.path, line: a.bodyLine, message: "ADR has no title: start the body with a `# ` heading" }])),
857
+ },
858
+ {
859
+ id: "bad-adr-filename",
860
+ severity: "error",
861
+ summary: "A file in a Project's `adr/` folder isn't named `NNNN-slug.md` (and isn't `template.md`).",
862
+ fix: "Rename it to the next free four-digit number and a lowercase slug, such as `0002-use-kafka.md`.",
863
+ example: {
864
+ failing: deciding({ "use-kafka.md": adrText("status: accepted\ndate: 2026-03-01") }),
865
+ passing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01") }),
866
+ },
867
+ check: (ws) => {
868
+ const next = new Map();
869
+ for (const a of ws.adrs)
870
+ if (a.number !== undefined)
871
+ next.set(a.project, Math.max(next.get(a.project) ?? 0, Number(a.number)));
872
+ return ws.adrs.flatMap((a) => {
873
+ if (a.number !== undefined)
874
+ return [];
875
+ const slug = a.filename.replace(/\.md$/, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "decision";
876
+ const number = String((next.get(a.project) ?? 0) + 1).padStart(4, "0");
877
+ return [{ file: a.path, line: 1, message: `ADR file "${a.filename}" must be named NNNN-slug.md, such as ${number}-${slug}.md` }];
878
+ });
879
+ },
880
+ },
881
+ {
882
+ id: "duplicate-adr-number",
883
+ severity: "error",
884
+ summary: "Two ADRs in a Project share a number, as when two pull requests each take the next free one.",
885
+ fix: "Renumber the later ADR to the next free number, and update any `supersedes` that meant it.",
886
+ example: {
887
+ failing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01"), "0001-use-redis.md": adrText("status: proposed\ndate: 2026-03-02", "Use Redis for carts") }),
888
+ passing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01"), "0002-use-redis.md": adrText("status: proposed\ndate: 2026-03-02", "Use Redis for carts") }),
889
+ },
890
+ check: (ws) => {
891
+ const first = numberedAdrs(ws);
892
+ return ws.adrs.flatMap((a) => {
893
+ const earlier = a.number === undefined || a.project.id === undefined ? undefined : first.get(`${a.project.id}:${a.number}`);
894
+ return earlier && earlier !== a ? [{ file: a.path, line: 1, message: `ADR number ${a.number} is already used in Project "${a.project.id}" by ${earlier.path}` }] : [];
895
+ });
896
+ },
897
+ },
898
+ {
899
+ id: "unknown-adr-link",
900
+ severity: "error",
901
+ summary: "An ADR's `elements` names no Element or Deployment Target, its `views` no Saved View, or its `supersedes` no ADR.",
902
+ fix: "Use an id declared in the ADR's Project, or `project:id` (`project:NNNN` for an ADR) for one in another Project.",
903
+ example: {
904
+ failing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nelements: [wbe]") }),
905
+ passing: deciding({ "0001-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nelements: [web]") }),
906
+ },
907
+ check: (ws) => {
908
+ const projects = new Set(ws.projects.filter((p) => p.id !== undefined && !p.duplicateOf).map((p) => p.id));
909
+ const linkable = [...ws.elements, ...ws.targets];
910
+ const adrIds = ws.adrs.flatMap((a) => (a.number === undefined ? [] : [{ id: a.number, project: a.project }]));
911
+ const kinds = [
912
+ { field: "elements", what: "Element or Deployment Target", decls: linkable, qualifyRef: qualify },
913
+ { field: "views", what: "Saved View", decls: ws.views, qualifyRef: qualify },
914
+ { field: "supersedes", what: "ADR", decls: adrIds, qualifyRef: qualifyAdr },
915
+ ];
916
+ return ws.adrs.flatMap((a) => kinds.flatMap(({ field, what, decls, qualifyRef }) => {
917
+ const known = qualifiedIds(decls);
918
+ return asList(a.data[field]).flatMap((ref, i) => {
919
+ const id = qualifyRef(ref, a.project);
920
+ if (id === undefined || known.has(id))
921
+ return [];
922
+ const project = id.slice(0, id.indexOf(":"));
923
+ return [atAdr(a, [field, i], projects.has(project) ? unknownIn(what, id, decls) : `Unknown Project "${project}"`)];
924
+ });
925
+ }));
926
+ },
927
+ },
928
+ {
929
+ id: "hand-written-superseded",
930
+ severity: "error",
931
+ summary: "An ADR's `status` is written as `superseded`; that status is derived once an accepted ADR lists it in `supersedes`.",
932
+ fix: "Give the old ADR back the status it had (usually accepted), and declare `supersedes` on the new ADR instead.",
933
+ example: {
934
+ failing: deciding({ "0001-use-rabbitmq.md": adrText("status: superseded\ndate: 2025-01-10", "Use RabbitMQ"), "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01") }),
935
+ passing: deciding({ "0001-use-rabbitmq.md": adrText("status: accepted\ndate: 2025-01-10", "Use RabbitMQ"), "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nsupersedes: [\"0001\"]") }),
936
+ },
937
+ check: (ws) => ws.adrs.flatMap((a) => a.data.status === "superseded" ? [atAdr(a, ["status"], "`superseded` is derived, never written: give this ADR the status it had, and list it in the new ADR's `supersedes`")] : []),
938
+ },
939
+ {
940
+ id: "supersedes-cycle",
941
+ severity: "error",
942
+ summary: "ADRs supersede each other in a cycle, directly or through others. Reported once, at the cycle's last file.",
943
+ fix: "Remove the `supersedes` entry that points back to a newer ADR.",
944
+ example: {
945
+ failing: deciding({ "0001-use-rabbitmq.md": adrText("status: accepted\ndate: 2025-01-10\nsupersedes: [\"0002\"]", "Use RabbitMQ"), "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nsupersedes: [\"0001\"]") }),
946
+ passing: deciding({ "0001-use-rabbitmq.md": adrText("status: accepted\ndate: 2025-01-10", "Use RabbitMQ"), "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nsupersedes: [\"0001\"]") }),
947
+ },
948
+ check: (ws) => {
949
+ const entries = supersedesEntries(ws);
950
+ const next = new Map();
951
+ for (const e of entries)
952
+ if (e.target)
953
+ next.set(e.id, [...(next.get(e.id) ?? []), e.to]);
954
+ const reach = (from) => {
955
+ const seen = new Set();
956
+ const todo = [...(next.get(from) ?? [])];
957
+ while (todo.length) {
958
+ const id = todo.pop();
959
+ if (!seen.has(id))
960
+ todo.push(...(seen.add(id), next.get(id) ?? []));
961
+ }
962
+ return seen;
963
+ };
964
+ const reachable = new Map([...next.keys()].map((id) => [id, reach(id)]));
965
+ const done = new Set();
966
+ return [...reachable].flatMap(([id, seen]) => {
967
+ if (!seen.has(id) || done.has(id))
968
+ return [];
969
+ const cycle = [...seen].filter((other) => reachable.get(other)?.has(id)).sort();
970
+ cycle.forEach((c) => done.add(c));
971
+ const last = entries
972
+ .filter((e) => cycle.includes(e.id) && cycle.includes(e.to))
973
+ .sort((a, b) => (a.adr.path < b.adr.path ? 1 : a.adr.path > b.adr.path ? -1 : a.index - b.index))[0];
974
+ return [atAdr(last.adr, ["supersedes", last.index], `ADRs supersede each other in a cycle: ${cycle.join(", ")}`)];
975
+ });
976
+ },
977
+ },
978
+ {
979
+ id: "superseded-twice",
980
+ severity: "warning",
981
+ summary: "An ADR is superseded by more than one accepted ADR. Reported at the last of them.",
982
+ fix: "Keep `supersedes` on the one ADR that replaces it; have the later one supersede that ADR instead, if it replaces it in turn.",
983
+ example: {
984
+ failing: deciding({
985
+ "0001-use-rabbitmq.md": adrText("status: accepted\ndate: 2025-01-10", "Use RabbitMQ"),
986
+ "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nsupersedes: [\"0001\"]"),
987
+ "0003-use-nats.md": adrText("status: accepted\ndate: 2026-04-01\nsupersedes: [\"0001\"]", "Use NATS for events"),
988
+ }),
989
+ passing: deciding({
990
+ "0001-use-rabbitmq.md": adrText("status: accepted\ndate: 2025-01-10", "Use RabbitMQ"),
991
+ "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nsupersedes: [\"0001\"]"),
992
+ "0003-use-nats.md": adrText("status: accepted\ndate: 2026-04-01\nsupersedes: [\"0002\"]", "Use NATS for events"),
993
+ }),
994
+ },
995
+ check: (ws, bundle) => {
996
+ const entries = supersedesEntries(ws);
997
+ return bundle.adrs
998
+ .filter((a) => a.supersededBy.length > 1)
999
+ .map((a) => {
1000
+ const last = entries.filter((e) => e.to === a.id && a.supersededBy.includes(e.id)).sort((x, y) => (x.adr.path < y.adr.path ? 1 : -1))[0];
1001
+ return atAdr(last.adr, ["supersedes", last.index], `${a.id} is superseded by more than one accepted ADR: ${a.supersededBy.join(", ")}`);
1002
+ });
1003
+ },
1004
+ },
1005
+ {
1006
+ id: "supersedes-unaccepted",
1007
+ severity: "warning",
1008
+ summary: "An ADR supersedes one that isn't accepted or deprecated, such as a proposed or rejected ADR.",
1009
+ fix: "Remove the entry from `supersedes`, or point it at the accepted ADR this one replaces.",
1010
+ example: {
1011
+ failing: deciding({ "0001-use-rabbitmq.md": adrText("status: rejected\ndate: 2025-01-10", "Use RabbitMQ"), "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01\nsupersedes: [\"0001\"]") }),
1012
+ passing: deciding({ "0001-use-rabbitmq.md": adrText("status: rejected\ndate: 2025-01-10", "Use RabbitMQ"), "0002-use-kafka.md": adrText("status: accepted\ndate: 2026-03-01") }),
1013
+ },
1014
+ check: (ws) => supersedesEntries(ws).flatMap(({ adr, index, to, target }) => {
1015
+ const status = target?.data.status;
1016
+ if (typeof status !== "string" || ["accepted", "deprecated", "superseded"].includes(status))
1017
+ return [];
1018
+ return [atAdr(adr, ["supersedes", index], `Supersedes ${to}, which is ${status}; only an accepted or deprecated ADR is superseded`)];
1019
+ }),
1020
+ },
1021
+ ];
1022
+ /** `count` Services as one-line YAML entries `<prefix>N: { name: <PREFIX>N }`, indented by `indent`, numbered from `from + 1`. */
1023
+ function numbered(count, prefix, indent, from = 0) {
1024
+ return Array.from({ length: count }, (_, i) => `${" ".repeat(indent)}${prefix}${from + i + 1}: { name: ${prefix.toUpperCase()}${from + i + 1} }\n`).join("");
1025
+ }
1026
+ /** Base URL of the per-rule pages on the docs site; a rule's page is `<base><rule-id>/`. */
1027
+ export const RULE_DOCS_BASE_URL = "https://archidocs.dev/docs/reference/rules/";
1028
+ /** The docs page for a check rule. The site keeps a page for every rule id, removed ones included. */
1029
+ export const ruleDocsUrl = (ruleId) => `${RULE_DOCS_BASE_URL}${ruleId}/`;
1030
+ /** An issue with a link to its rule's docs page, as `check --format json` and MCP report it. */
1031
+ export const withDocs = (issue) => ({ ...issue, docs: ruleDocsUrl(issue.rule) });
1032
+ /** Rules removed from the registry, oldest first. An id here never returns to `rules`. */
1033
+ export const removed = [];