@radicaltools/mcp 0.1.1 → 0.3.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 (161) hide show
  1. package/README.md +52 -26
  2. package/dist/chunk-Z7THA3L5.js +3200 -0
  3. package/dist/elkLayout-TAUBPPVN.js +8 -0
  4. package/dist/hub-catalogue/concern/concern-api-evolution.radical +935 -0
  5. package/dist/hub-catalogue/concern/concern-architecture-style.radical +1112 -0
  6. package/dist/hub-catalogue/concern/concern-authentication.radical +685 -0
  7. package/dist/hub-catalogue/concern/concern-authorization.radical +1464 -0
  8. package/dist/hub-catalogue/concern/concern-availability.radical +804 -0
  9. package/dist/hub-catalogue/concern/concern-backend-stack.radical +1118 -0
  10. package/dist/hub-catalogue/concern/concern-backup-recovery.radical +1304 -0
  11. package/dist/hub-catalogue/concern/concern-capacity.radical +802 -0
  12. package/dist/hub-catalogue/concern/concern-communication-style.radical +1202 -0
  13. package/dist/hub-catalogue/concern/concern-data-consistency.radical +1081 -0
  14. package/dist/hub-catalogue/concern/concern-data-store.radical +960 -0
  15. package/dist/hub-catalogue/concern/concern-decomposition.radical +1143 -0
  16. package/dist/hub-catalogue/concern/concern-deployment.radical +952 -0
  17. package/dist/hub-catalogue/concern/concern-encryption.radical +1055 -0
  18. package/dist/hub-catalogue/concern/concern-frontend-stack.radical +1340 -0
  19. package/dist/hub-catalogue/concern/concern-infrastructure.radical +1151 -0
  20. package/dist/hub-catalogue/concern/concern-integration-resilience.radical +1079 -0
  21. package/dist/hub-catalogue/concern/concern-messaging.radical +940 -0
  22. package/dist/hub-catalogue/concern/concern-module-boundaries.radical +864 -0
  23. package/dist/hub-catalogue/concern/concern-observability.radical +1048 -0
  24. package/dist/hub-catalogue/concern/concern-personal-data.radical +1434 -0
  25. package/dist/hub-catalogue/concern/concern-rate-limiting.radical +1153 -0
  26. package/dist/hub-catalogue/concern/concern-secrets.radical +1026 -0
  27. package/dist/hub-catalogue/concern/concern-supply-chain.radical +1312 -0
  28. package/dist/hub-catalogue/concern/concern-tenant-isolation.radical +1306 -0
  29. package/dist/hub-catalogue/concern/concern-test-strategy.radical +1193 -0
  30. package/dist/index.js +22690 -6064
  31. package/package.json +1 -1
  32. package/dist/chunk-KI4NVSTU.js +0 -1763
  33. package/dist/elkLayout-WC6AXWOG.js +0 -185
  34. package/dist/hub-catalogue/adr/adr-api-versioning.radical +0 -53
  35. package/dist/hub-catalogue/adr/adr-auth-strategy.radical +0 -53
  36. package/dist/hub-catalogue/adr/adr-caching-strategy.radical +0 -59
  37. package/dist/hub-catalogue/adr/adr-data-consistency-model.radical +0 -40
  38. package/dist/hub-catalogue/adr/adr-data-store.radical +0 -47
  39. package/dist/hub-catalogue/adr/adr-deployment-strategy.radical +0 -53
  40. package/dist/hub-catalogue/adr/adr-event-schema-evolution.radical +0 -53
  41. package/dist/hub-catalogue/adr/adr-integration-style.radical +0 -50
  42. package/dist/hub-catalogue/adr/adr-ledger-reconciliation-strategy.radical +0 -38
  43. package/dist/hub-catalogue/adr/adr-llm-provider-strategy.radical +0 -40
  44. package/dist/hub-catalogue/adr/adr-marketplace-payments-model.radical +0 -39
  45. package/dist/hub-catalogue/adr/adr-multi-region.radical +0 -60
  46. package/dist/hub-catalogue/adr/adr-multi-tenancy-strategy.radical +0 -41
  47. package/dist/hub-catalogue/adr/adr-observability.radical +0 -59
  48. package/dist/hub-catalogue/adr/adr-realtime-transport.radical +0 -38
  49. package/dist/hub-catalogue/adr/adr-tech-stack.radical +0 -45
  50. package/dist/hub-catalogue/adr/adr-zero-trust-network.radical +0 -40
  51. package/dist/hub-catalogue/blueprint/bp-ai-assistant-platform.radical +0 -1641
  52. package/dist/hub-catalogue/blueprint/bp-analytical-data-platform.radical +0 -1428
  53. package/dist/hub-catalogue/blueprint/bp-ecommerce-platform.radical +0 -1989
  54. package/dist/hub-catalogue/blueprint/bp-fintech-ledger-platform.radical +0 -1701
  55. package/dist/hub-catalogue/blueprint/bp-marketplace-platform.radical +0 -1792
  56. package/dist/hub-catalogue/blueprint/bp-realtime-collaboration.radical +0 -1421
  57. package/dist/hub-catalogue/blueprint/bp-saas-b2b-platform.radical +0 -1713
  58. package/dist/hub-catalogue/fitness-function/ff-accessibility-scan.radical +0 -34
  59. package/dist/hub-catalogue/fitness-function/ff-ai-eval-gate.radical +0 -52
  60. package/dist/hub-catalogue/fitness-function/ff-api-contract.radical +0 -36
  61. package/dist/hub-catalogue/fitness-function/ff-capacity-load-test.radical +0 -67
  62. package/dist/hub-catalogue/fitness-function/ff-carbon-footprint-guard.radical +0 -62
  63. package/dist/hub-catalogue/fitness-function/ff-change-failure-rate.radical +0 -45
  64. package/dist/hub-catalogue/fitness-function/ff-chaos-resilience-test.radical +0 -53
  65. package/dist/hub-catalogue/fitness-function/ff-cost-efficiency-guard.radical +0 -64
  66. package/dist/hub-catalogue/fitness-function/ff-coupling-guard.radical +0 -45
  67. package/dist/hub-catalogue/fitness-function/ff-data-integrity-check.radical +0 -51
  68. package/dist/hub-catalogue/fitness-function/ff-data-residency.radical +0 -43
  69. package/dist/hub-catalogue/fitness-function/ff-dependency-rules.radical +0 -37
  70. package/dist/hub-catalogue/fitness-function/ff-deploy-frequency.radical +0 -46
  71. package/dist/hub-catalogue/fitness-function/ff-dr-drill-success.radical +0 -52
  72. package/dist/hub-catalogue/fitness-function/ff-duplication-guard.radical +0 -53
  73. package/dist/hub-catalogue/fitness-function/ff-error-budget.radical +0 -59
  74. package/dist/hub-catalogue/fitness-function/ff-fail-safe-verification.radical +0 -34
  75. package/dist/hub-catalogue/fitness-function/ff-infra-drift.radical +0 -34
  76. package/dist/hub-catalogue/fitness-function/ff-latency-slo.radical +0 -59
  77. package/dist/hub-catalogue/fitness-function/ff-lead-time.radical +0 -44
  78. package/dist/hub-catalogue/fitness-function/ff-ledger-balance-integrity.radical +0 -45
  79. package/dist/hub-catalogue/fitness-function/ff-license-compliance.radical +0 -43
  80. package/dist/hub-catalogue/fitness-function/ff-mttr.radical +0 -45
  81. package/dist/hub-catalogue/fitness-function/ff-noisy-neighbor-guard.radical +0 -66
  82. package/dist/hub-catalogue/fitness-function/ff-sast-scan.radical +0 -35
  83. package/dist/hub-catalogue/fitness-function/ff-scale-out-verification.radical +0 -66
  84. package/dist/hub-catalogue/fitness-function/ff-security-scan.radical +0 -45
  85. package/dist/hub-catalogue/fitness-function/ff-startup-shutdown-check.radical +0 -66
  86. package/dist/hub-catalogue/fitness-function/ff-sync-convergence-test.radical +0 -45
  87. package/dist/hub-catalogue/fitness-function/ff-test-coverage.radical +0 -43
  88. package/dist/hub-catalogue/fitness-function/ff-web-vitals.radical +0 -57
  89. package/dist/hub-catalogue/pattern/pattern-anti-corruption-layer.radical +0 -88
  90. package/dist/hub-catalogue/pattern/pattern-api-gateway.radical +0 -168
  91. package/dist/hub-catalogue/pattern/pattern-bff.radical +0 -179
  92. package/dist/hub-catalogue/pattern/pattern-bulkhead.radical +0 -114
  93. package/dist/hub-catalogue/pattern/pattern-circuit-breaker.radical +0 -219
  94. package/dist/hub-catalogue/pattern/pattern-cqrs.radical +0 -195
  95. package/dist/hub-catalogue/pattern/pattern-crdt-sync.radical +0 -200
  96. package/dist/hub-catalogue/pattern/pattern-event-driven.radical +0 -210
  97. package/dist/hub-catalogue/pattern/pattern-event-sourced-ledger.radical +0 -211
  98. package/dist/hub-catalogue/pattern/pattern-hexagonal.radical +0 -196
  99. package/dist/hub-catalogue/pattern/pattern-microservices.radical +0 -262
  100. package/dist/hub-catalogue/pattern/pattern-rag-pipeline.radical +0 -213
  101. package/dist/hub-catalogue/pattern/pattern-rate-limiter.radical +0 -114
  102. package/dist/hub-catalogue/pattern/pattern-saga.radical +0 -208
  103. package/dist/hub-catalogue/pattern/pattern-sidecar.radical +0 -123
  104. package/dist/hub-catalogue/pattern/pattern-strangler-fig.radical +0 -227
  105. package/dist/hub-catalogue/pattern/pattern-transactional-outbox.radical +0 -209
  106. package/dist/hub-catalogue/requirement/req-accessibility.radical +0 -48
  107. package/dist/hub-catalogue/requirement/req-ai-autonomous-resolution.radical +0 -51
  108. package/dist/hub-catalogue/requirement/req-ai-groundedness.radical +0 -45
  109. package/dist/hub-catalogue/requirement/req-ai-human-handoff.radical +0 -46
  110. package/dist/hub-catalogue/requirement/req-alerting.radical +0 -52
  111. package/dist/hub-catalogue/requirement/req-api-response-time.radical +0 -51
  112. package/dist/hub-catalogue/requirement/req-api-standard.radical +0 -45
  113. package/dist/hub-catalogue/requirement/req-audit-logging.radical +0 -43
  114. package/dist/hub-catalogue/requirement/req-auth-response-time.radical +0 -45
  115. package/dist/hub-catalogue/requirement/req-auth.radical +0 -43
  116. package/dist/hub-catalogue/requirement/req-autoscaling.radical +0 -62
  117. package/dist/hub-catalogue/requirement/req-availability.radical +0 -50
  118. package/dist/hub-catalogue/requirement/req-backward-compatibility.radical +0 -46
  119. package/dist/hub-catalogue/requirement/req-batch-job-completion.radical +0 -50
  120. package/dist/hub-catalogue/requirement/req-carbon-efficiency.radical +0 -64
  121. package/dist/hub-catalogue/requirement/req-centralised-logging.radical +0 -45
  122. package/dist/hub-catalogue/requirement/req-ci-pipeline-time.radical +0 -43
  123. package/dist/hub-catalogue/requirement/req-code-complexity.radical +0 -43
  124. package/dist/hub-catalogue/requirement/req-config-propagation.radical +0 -45
  125. package/dist/hub-catalogue/requirement/req-data-integrity.radical +0 -35
  126. package/dist/hub-catalogue/requirement/req-data-retention.radical +0 -44
  127. package/dist/hub-catalogue/requirement/req-db-query-response.radical +0 -44
  128. package/dist/hub-catalogue/requirement/req-disaster-recovery.radical +0 -59
  129. package/dist/hub-catalogue/requirement/req-distributed-tracing.radical +0 -45
  130. package/dist/hub-catalogue/requirement/req-encryption.radical +0 -49
  131. package/dist/hub-catalogue/requirement/req-error-rate.radical +0 -45
  132. package/dist/hub-catalogue/requirement/req-error-recovery.radical +0 -34
  133. package/dist/hub-catalogue/requirement/req-event-schema-compatibility.radical +0 -37
  134. package/dist/hub-catalogue/requirement/req-fail-safe-default.radical +0 -55
  135. package/dist/hub-catalogue/requirement/req-fast-startup-graceful-shutdown.radical +0 -69
  136. package/dist/hub-catalogue/requirement/req-gdpr-erasure.radical +0 -44
  137. package/dist/hub-catalogue/requirement/req-graceful-degradation.radical +0 -39
  138. package/dist/hub-catalogue/requirement/req-health-checks.radical +0 -43
  139. package/dist/hub-catalogue/requirement/req-iac.radical +0 -36
  140. package/dist/hub-catalogue/requirement/req-idempotency.radical +0 -47
  141. package/dist/hub-catalogue/requirement/req-input-validation.radical +0 -37
  142. package/dist/hub-catalogue/requirement/req-least-privilege.radical +0 -47
  143. package/dist/hub-catalogue/requirement/req-ledger-immutability.radical +0 -38
  144. package/dist/hub-catalogue/requirement/req-mfa.radical +0 -36
  145. package/dist/hub-catalogue/requirement/req-ml-extraction-accuracy.radical +0 -42
  146. package/dist/hub-catalogue/requirement/req-onboarding-time.radical +0 -42
  147. package/dist/hub-catalogue/requirement/req-page-load-time.radical +0 -59
  148. package/dist/hub-catalogue/requirement/req-payout-latency.radical +0 -46
  149. package/dist/hub-catalogue/requirement/req-presence-latency.radical +0 -46
  150. package/dist/hub-catalogue/requirement/req-rate-limiting.radical +0 -45
  151. package/dist/hub-catalogue/requirement/req-report-generation.radical +0 -44
  152. package/dist/hub-catalogue/requirement/req-resource-efficiency.radical +0 -64
  153. package/dist/hub-catalogue/requirement/req-resource-headroom.radical +0 -53
  154. package/dist/hub-catalogue/requirement/req-resource-isolation.radical +0 -37
  155. package/dist/hub-catalogue/requirement/req-search-response-time.radical +0 -44
  156. package/dist/hub-catalogue/requirement/req-secrets-management.radical +0 -45
  157. package/dist/hub-catalogue/requirement/req-task-success-rate.radical +0 -42
  158. package/dist/hub-catalogue/requirement/req-test-coverage.radical +0 -42
  159. package/dist/hub-catalogue/requirement/req-throughput.radical +0 -55
  160. package/dist/hub-catalogue/requirement/req-vulnerability-scanning.radical +0 -52
  161. package/dist/hub-catalogue/requirement/req-zero-downtime-deploy.radical +0 -39
@@ -0,0 +1,3200 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+
30
+ // <define:__RADICAL_BUILD__>
31
+ var define_RADICAL_BUILD_default;
32
+ var init_define_RADICAL_BUILD = __esm({
33
+ "<define:__RADICAL_BUILD__>"() {
34
+ define_RADICAL_BUILD_default = { version: "0.3.0", commit: "f76cbf9", date: "2026-10-27", release: true };
35
+ }
36
+ });
37
+
38
+ // ../../packages/layout/src/elkLayout.ts
39
+ init_define_RADICAL_BUILD();
40
+ import ELK from "elkjs/lib/elk.bundled.js";
41
+
42
+ // ../../packages/common/src/c4.ts
43
+ init_define_RADICAL_BUILD();
44
+
45
+ // ../../packages/common/src/metamodel/index.ts
46
+ init_define_RADICAL_BUILD();
47
+
48
+ // ../../packages/common/src/metamodel/types.ts
49
+ init_define_RADICAL_BUILD();
50
+
51
+ // ../../packages/common/src/metamodel/lookup.ts
52
+ init_define_RADICAL_BUILD();
53
+ function isRelationAllowed(metamodel, fromType, toType) {
54
+ if (!metamodel) return true;
55
+ const rts = Object.values(metamodel.relationTypes);
56
+ if (rts.length === 0) return true;
57
+ if (rts.some((rt) => rt.allowedPairs.length === 0)) return true;
58
+ return rts.some((rt) => rt.allowedPairs.some((p) => p.from === fromType && p.to === toType));
59
+ }
60
+ function relationTypesFitting(metamodel, fromType, toType) {
61
+ if (!metamodel) return [];
62
+ return Object.values(metamodel.relationTypes).filter(
63
+ (rt) => rt.allowedPairs.length === 0 || rt.allowedPairs.some((p) => p.from === fromType && p.to === toType)
64
+ );
65
+ }
66
+ function inferRelationType(metamodel, fromType, toType) {
67
+ const matches = relationTypesFitting(metamodel, fromType, toType);
68
+ return matches.length === 1 ? matches[0].id : void 0;
69
+ }
70
+ function isParentAllowed(metamodel, childType, parentType) {
71
+ if (!metamodel) return true;
72
+ const def = metamodel.nodeTypes[childType];
73
+ if (!def) return true;
74
+ const allowed = def.allowedParents;
75
+ if (parentType == null) {
76
+ if (def.allowedAtRoot !== void 0) return def.allowedAtRoot;
77
+ return !allowed || allowed.length === 0;
78
+ }
79
+ return !!allowed && allowed.includes(parentType);
80
+ }
81
+ function hasAnyPlace(metamodel, type) {
82
+ const def = metamodel?.nodeTypes[type];
83
+ if (!def) return true;
84
+ return (def.allowedParents?.length ?? 0) > 0 || isParentAllowed(metamodel, type, void 0);
85
+ }
86
+ function allowedPlacesText(metamodel, type) {
87
+ const label = (t) => metamodel?.nodeTypes[t]?.label ?? t;
88
+ const places = (metamodel?.nodeTypes[type]?.allowedParents ?? []).map(label);
89
+ if (isParentAllowed(metamodel, type, void 0)) places.push("the canvas root");
90
+ return places.length ? places.join(", ") : `none (${noPlaceText(metamodel, type)})`;
91
+ }
92
+ function noPlaceText(metamodel, type) {
93
+ return `${metamodel?.nodeTypes[type]?.label ?? type} has no place in the metamodel`;
94
+ }
95
+ var GROUP_TYPE = "group";
96
+ function placeOf(node, nodes) {
97
+ const seen = /* @__PURE__ */ new Set();
98
+ let cur = node;
99
+ while (cur && cur.type === GROUP_TYPE && !seen.has(cur)) {
100
+ seen.add(cur);
101
+ cur = cur.parentId ? nodes[cur.parentId] : void 0;
102
+ }
103
+ return cur && cur.type !== GROUP_TYPE ? cur : void 0;
104
+ }
105
+ function hasPlaceUnder(metamodel, childType, placeType) {
106
+ if (!metamodel || !metamodel.nodeTypes[childType]) return true;
107
+ if (placeType == null) return isParentAllowed(metamodel, childType, void 0);
108
+ const seen = /* @__PURE__ */ new Set();
109
+ const queue = [childType];
110
+ while (queue.length > 0) {
111
+ for (const parent of metamodel.nodeTypes[queue.pop()]?.allowedParents ?? []) {
112
+ if (parent === placeType) return true;
113
+ if (parent === GROUP_TYPE || seen.has(parent)) continue;
114
+ seen.add(parent);
115
+ queue.push(parent);
116
+ }
117
+ }
118
+ return false;
119
+ }
120
+ function isFinalState(node) {
121
+ return node?.type === "state" && node.kind === "final";
122
+ }
123
+ function isPlacementAllowed(metamodel, childType, parent, nodes) {
124
+ if (!isParentAllowed(metamodel, childType, parent?.type)) return false;
125
+ if (isFinalState(parent)) return false;
126
+ if (!parent || parent.type !== GROUP_TYPE) return true;
127
+ return hasPlaceUnder(metamodel, childType, placeOf(parent, nodes)?.type);
128
+ }
129
+ function canAddMoreOfType(metamodel, typeId, currentCount) {
130
+ if (!metamodel) return true;
131
+ const def = metamodel.nodeTypes[typeId];
132
+ if (!def?.cardinality?.max) return true;
133
+ return currentCount < def.cardinality.max;
134
+ }
135
+ var RESERVED_PROPERTY_KEYS = {
136
+ node: /* @__PURE__ */ new Set(["id", "type", "parentId", "x", "y", "width", "height", "collapsed"]),
137
+ relation: /* @__PURE__ */ new Set(["id", "sourceId", "targetId", "relationType"])
138
+ };
139
+ function isReservedPropertyKey(key, of) {
140
+ return RESERVED_PROPERTY_KEYS[of].has(key);
141
+ }
142
+ function propertyKeyProblem(key, of) {
143
+ if (!isReservedPropertyKey(key, of)) return null;
144
+ return `"${key}" is a field every ${of === "node" ? "element" : "relation"} has (${[...RESERVED_PROPERTY_KEYS[of]].join(", ")}): give the property another key.`;
145
+ }
146
+ function chainTypeNames(raw) {
147
+ const nodeTypes = /* @__PURE__ */ new Set();
148
+ const relationTypes = /* @__PURE__ */ new Set();
149
+ const strings = (v) => Array.isArray(v) ? v.filter((t) => typeof t === "string") : [];
150
+ const levels = raw && typeof raw === "object" ? raw.levels : void 0;
151
+ for (const level of Array.isArray(levels) ? levels : []) {
152
+ if (!level || typeof level !== "object") continue;
153
+ const l = level;
154
+ for (const way of Array.isArray(l.ways) ? l.ways : [l]) {
155
+ if (!way || typeof way !== "object") continue;
156
+ const w = way;
157
+ for (const t of strings(w.types)) nodeTypes.add(t);
158
+ if (typeof w.via?.relationType === "string") relationTypes.add(w.via.relationType);
159
+ }
160
+ for (const filter of Array.isArray(l.filters) ? l.filters : []) {
161
+ const f = filter ?? {};
162
+ if (f.kind === "type") for (const t of strings(f.types)) nodeTypes.add(t);
163
+ if (f.kind === "relation" && typeof f.relationType === "string") relationTypes.add(f.relationType);
164
+ }
165
+ }
166
+ return { nodeTypes: [...nodeTypes], relationTypes: [...relationTypes] };
167
+ }
168
+
169
+ // ../../packages/common/src/metamodel/validate.ts
170
+ init_define_RADICAL_BUILD();
171
+
172
+ // ../../packages/common/src/metamodel/statechart.ts
173
+ init_define_RADICAL_BUILD();
174
+
175
+ // ../../packages/common/src/metamodel/refs.ts
176
+ init_define_RADICAL_BUILD();
177
+ function refIds(value) {
178
+ if (typeof value === "string") return value ? [value] : [];
179
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string" && v !== "");
180
+ return [];
181
+ }
182
+ function refLabels(value, nodes) {
183
+ return refIds(value).map((id) => nodes[id]?.label ?? id);
184
+ }
185
+ function refValue(def, ids) {
186
+ return def.multiple ? ids : ids[0] ?? "";
187
+ }
188
+ function refProblem(def, id, nodes) {
189
+ const node = nodes[id];
190
+ if (!node) return `no node has id "${id}"`;
191
+ if (def.refType && node.type !== def.refType) return `"${node.label}" is of type ${node.type}, not ${def.refType}`;
192
+ return null;
193
+ }
194
+
195
+ // ../../packages/common/src/metamodel/statechart.ts
196
+ var prop = (item, key) => {
197
+ const value = item[key];
198
+ return typeof value === "string" ? value.trim() : "";
199
+ };
200
+ var stateKind = (n) => prop(n, "kind") || "normal";
201
+ var pseudoKind = (n) => prop(n, "kind") || "initial";
202
+ var isState = (n) => n?.type === "state";
203
+ var isPseudo = (n) => n?.type === "pseudostate";
204
+ function transitionLabel(r, nodes) {
205
+ const props = r;
206
+ const event = refLabels(props.event, nodes).join(", ");
207
+ const guard = prop(r, "guard");
208
+ const actions = prop(r, "actions");
209
+ const raises = refLabels(props.raises, nodes).map((label) => `^${label}`).join(" ");
210
+ return [event, guard && `[${guard}]`, actions && `/ ${actions}`, raises].filter(Boolean).join(" ");
211
+ }
212
+ var entityCache = /* @__PURE__ */ new WeakMap();
213
+ function machineEntity(machineId, nodes, relations) {
214
+ let map = entityCache.get(relations);
215
+ if (!map) {
216
+ map = /* @__PURE__ */ new Map();
217
+ for (const r of Object.values(relations)) {
218
+ if (r.relationType === "lifecycle-of" && !map.has(r.sourceId)) map.set(r.sourceId, r.targetId);
219
+ }
220
+ entityCache.set(relations, map);
221
+ }
222
+ const id = map.get(machineId);
223
+ return id ? nodes[id] : void 0;
224
+ }
225
+ function machineOf(node, nodes) {
226
+ let cur = node;
227
+ for (let depth = 0; cur && depth < 64; depth++) {
228
+ if (cur.type === "state-machine") return cur;
229
+ cur = cur.parentId ? nodes[cur.parentId] : void 0;
230
+ }
231
+ return void 0;
232
+ }
233
+ function requirementStatePhrase(requirement, nodes, relations) {
234
+ const state = nodes[refIds(requirement.precondition_state)[0] ?? ""];
235
+ if (!state) return "";
236
+ const machine = machineOf(state, nodes);
237
+ const entity = machine ? machineEntity(machine.id, nodes, relations) : void 0;
238
+ return entity ? `the ${entity.label} is ${state.label}` : `in ${state.label}`;
239
+ }
240
+ function transitionRefusal(src, dst, nodes, relations, exceptId) {
241
+ const inLabel = (n) => n.parentId ? nodes[n.parentId]?.label ?? "" : "";
242
+ if (isState(src) && stateKind(src) === "final") return `Final state "${src.label}" cannot have outgoing transitions.`;
243
+ if (isPseudo(dst) && pseudoKind(dst) === "initial") return `A transition cannot point at the initial pseudostate of "${inLabel(dst)}"; target the state itself.`;
244
+ if (isPseudo(src) && pseudoKind(src) === "initial" && Object.values(relations).some((r) => r.id !== exceptId && r.sourceId === src.id && r.relationType === "transition")) {
245
+ return `The initial pseudostate of "${inLabel(src)}" has its one transition, to the default state, already.`;
246
+ }
247
+ const from = machineOf(src, nodes);
248
+ const to = machineOf(dst, nodes);
249
+ if (from && to && from.id !== to.id) return `A transition cannot leave its state machine ("${from.label}" \u2192 "${to.label}").`;
250
+ return null;
251
+ }
252
+ function lifecycleRefusal(machine, entity, nodes, relations, exceptId) {
253
+ for (const r of Object.values(relations)) {
254
+ if (r.id === exceptId || r.relationType !== "lifecycle-of") continue;
255
+ if (r.targetId === entity.id && r.sourceId !== machine.id && nodes[r.sourceId]) {
256
+ return `Entity "${entity.label}" has a state machine already ("${nodes[r.sourceId].label}"); model one lifecycle, with parallel regions if parts of it progress at once.`;
257
+ }
258
+ if (r.sourceId === machine.id && r.targetId !== entity.id && nodes[r.targetId]) {
259
+ return `State machine "${machine.label}" is the lifecycle of "${nodes[r.targetId].label}" already.`;
260
+ }
261
+ }
262
+ return null;
263
+ }
264
+ function initialPseudostateRefusal(parent, nodes, exceptId) {
265
+ if (!parent) return null;
266
+ if (isState(parent) && stateKind(parent) === "parallel") return `Parallel state "${parent.label}" enters all its regions; it takes no initial pseudostate.`;
267
+ const held = Object.values(nodes).some((n) => n.id !== exceptId && n.parentId === parent.id && isPseudo(n) && pseudoKind(n) === "initial");
268
+ if (held) return `"${parent.label}" has an initial pseudostate already; keep one.`;
269
+ return null;
270
+ }
271
+ function newPseudostateKind(parent, nodes) {
272
+ return initialPseudostateRefusal(parent, nodes) ? "choice" : "initial";
273
+ }
274
+ function isInitialPseudostate(node) {
275
+ return isPseudo(node) && pseudoKind(node) === "initial";
276
+ }
277
+ function outgoingTransitionCount(id, relations) {
278
+ return Object.values(relations).filter((r) => r.sourceId === id && r.relationType === "transition").length;
279
+ }
280
+ function validateStateMachines(nodes, relations) {
281
+ const nodeList = Object.values(nodes);
282
+ if (!nodeList.some((n) => n.type === "state-machine" || n.type === "state" || n.type === "pseudostate")) return [];
283
+ const issues = [];
284
+ const warn = (id, message, at) => {
285
+ issues.push({ id, severity: "warning", message, ...at });
286
+ };
287
+ const children = /* @__PURE__ */ new Map();
288
+ for (const n of nodeList) {
289
+ if (!n.parentId) continue;
290
+ const list = children.get(n.parentId);
291
+ if (list) list.push(n);
292
+ else children.set(n.parentId, [n]);
293
+ }
294
+ const childStates = (id) => (children.get(id) ?? []).filter(isState);
295
+ const initialsOf = (id) => (children.get(id) ?? []).filter((c) => isPseudo(c) && pseudoKind(c) === "initial");
296
+ const transitions = Object.values(relations).filter((r) => r.relationType === "transition" && nodes[r.sourceId] && nodes[r.targetId]);
297
+ const outgoing = /* @__PURE__ */ new Map();
298
+ const incoming = /* @__PURE__ */ new Set();
299
+ for (const t of transitions) {
300
+ const list = outgoing.get(t.sourceId);
301
+ if (list) list.push(t);
302
+ else outgoing.set(t.sourceId, [t]);
303
+ incoming.add(t.targetId);
304
+ }
305
+ const regions = nodeList.filter((n) => n.type === "state-machine" || isState(n) && stateKind(n) === "normal");
306
+ for (const owner of regions) {
307
+ if (childStates(owner.id).length === 0) continue;
308
+ const initials = initialsOf(owner.id);
309
+ const what = owner.type === "state-machine" ? "State machine" : "Compound state";
310
+ if (initials.length === 0) {
311
+ warn(`sm-no-initial:${owner.id}`, `${what} "${owner.label}" has child states but no initial pseudostate to enter them.`, { nodeId: owner.id });
312
+ } else if (initials.length > 1) {
313
+ warn(`sm-many-initials:${owner.id}`, `${what} "${owner.label}" has ${initials.length} initial pseudostates; keep one.`, { nodeId: owner.id });
314
+ }
315
+ }
316
+ for (const n of nodeList) {
317
+ if (isPseudo(n) && pseudoKind(n) === "initial") {
318
+ const out = outgoing.get(n.id) ?? [];
319
+ if (out.length !== 1) {
320
+ warn(`sm-initial-out:${n.id}`, `Initial pseudostate in "${n.parentId ? nodes[n.parentId]?.label : ""}" needs exactly one transition, to the default state (it has ${out.length}).`, { nodeId: n.id });
321
+ }
322
+ if (incoming.has(n.id)) {
323
+ warn(`sm-initial-in:${n.id}`, `A transition points at the initial pseudostate in "${n.parentId ? nodes[n.parentId]?.label : ""}"; target the state itself.`, { nodeId: n.id });
324
+ }
325
+ }
326
+ if (!isState(n)) continue;
327
+ const kind = stateKind(n);
328
+ if (kind === "parallel") {
329
+ if (childStates(n.id).length < 2) {
330
+ warn(`sm-parallel-regions:${n.id}`, `Parallel state "${n.label}" needs at least two child states (regions) active at once.`, { nodeId: n.id });
331
+ }
332
+ if (initialsOf(n.id).length > 0) {
333
+ warn(`sm-parallel-initial:${n.id}`, `Parallel state "${n.label}" enters all its regions; it takes no initial pseudostate.`, { nodeId: n.id });
334
+ }
335
+ }
336
+ if (kind === "final") {
337
+ if ((children.get(n.id) ?? []).length > 0) {
338
+ warn(`sm-final-children:${n.id}`, `Final state "${n.label}" cannot contain other states.`, { nodeId: n.id });
339
+ }
340
+ if ((outgoing.get(n.id) ?? []).length > 0) {
341
+ warn(`sm-final-out:${n.id}`, `Final state "${n.label}" cannot have outgoing transitions.`, { nodeId: n.id });
342
+ }
343
+ }
344
+ }
345
+ for (const t of transitions) {
346
+ const src = nodes[t.sourceId];
347
+ const dst = nodes[t.targetId];
348
+ if (machineOf(src, nodes)?.id !== machineOf(dst, nodes)?.id) {
349
+ warn(`sm-cross-machine:${t.id}`, `Transition "${src.label}" \u2192 "${dst.label}" leaves its state machine.`, { relationId: t.id });
350
+ }
351
+ }
352
+ for (const [sourceId, out] of outgoing) {
353
+ const byEvent = /* @__PURE__ */ new Map();
354
+ for (const t of out) {
355
+ if (prop(t, "guard")) continue;
356
+ const key = refIds(t.event)[0] ?? "";
357
+ const list = byEvent.get(key);
358
+ if (list) list.push(t);
359
+ else byEvent.set(key, [t]);
360
+ }
361
+ for (const [event, list] of byEvent) {
362
+ if (list.length < 2) continue;
363
+ const on = event ? `on "${nodes[event]?.label ?? event}"` : "without an event";
364
+ warn(`sm-nondeterministic:${sourceId}:${event}`, `"${nodes[sourceId].label}" has ${list.length} unguarded transitions ${on}; only one can fire.`, { nodeId: sourceId });
365
+ }
366
+ }
367
+ const machinesOfEntity = /* @__PURE__ */ new Map();
368
+ for (const machine of nodeList.filter((n) => n.type === "state-machine")) {
369
+ const entity = machineEntity(machine.id, nodes, relations);
370
+ if (!entity) {
371
+ warn(`sm-no-entity:${machine.id}`, `State machine "${machine.label}" is the lifecycle of no entity; link it to one with "lifecycle-of".`, { nodeId: machine.id });
372
+ continue;
373
+ }
374
+ machinesOfEntity.set(entity.id, [...machinesOfEntity.get(entity.id) ?? [], machine]);
375
+ }
376
+ for (const [entityId, machines] of machinesOfEntity) {
377
+ if (machines.length < 2) continue;
378
+ warn(`sm-many-machines:${entityId}`, `Entity "${nodes[entityId].label}" has ${machines.length} state machines (${machines.map((m) => m.label).join(", ")}); model one lifecycle, with parallel regions if parts of it progress at once.`, { nodeId: entityId });
379
+ }
380
+ for (const machine of nodeList.filter((n) => n.type === "state-machine")) {
381
+ if (initialsOf(machine.id).length === 0) continue;
382
+ const reached = /* @__PURE__ */ new Set();
383
+ const queue = [machine.id];
384
+ const visit = (id) => {
385
+ if (!reached.has(id)) {
386
+ reached.add(id);
387
+ queue.push(id);
388
+ }
389
+ };
390
+ while (queue.length > 0) {
391
+ const id = queue.shift();
392
+ const n = nodes[id];
393
+ if (!n) continue;
394
+ if (n.parentId && n.parentId !== machine.id && nodes[n.parentId]) visit(n.parentId);
395
+ if (n.type === "state-machine" || isState(n) && stateKind(n) === "normal") {
396
+ for (const init of initialsOf(id)) visit(init.id);
397
+ } else if (isState(n) && stateKind(n) === "parallel") {
398
+ for (const region of childStates(id)) visit(region.id);
399
+ }
400
+ for (const t of outgoing.get(id) ?? []) visit(t.targetId);
401
+ }
402
+ const unreached = (id) => {
403
+ for (const child of children.get(id) ?? []) {
404
+ if (isState(child) && !reached.has(child.id)) {
405
+ warn(`sm-unreachable:${child.id}`, `State "${child.label}" cannot be reached from the initial state of "${machine.label}".`, { nodeId: child.id });
406
+ continue;
407
+ }
408
+ unreached(child.id);
409
+ }
410
+ };
411
+ unreached(machine.id);
412
+ }
413
+ return issues;
414
+ }
415
+
416
+ // ../../packages/common/src/metamodel/domainModel.ts
417
+ init_define_RADICAL_BUILD();
418
+ var kindOf = (n) => {
419
+ const kind = n.kind;
420
+ return typeof kind === "string" && kind ? kind : "aggregate-root";
421
+ };
422
+ function validateDomainModel(nodes, relations) {
423
+ const entities = Object.values(nodes).filter((n) => n.type === "entity");
424
+ if (entities.length === 0) return [];
425
+ const issues = [];
426
+ const warn = (id, message, at) => {
427
+ issues.push({ id, severity: "warning", message, ...at });
428
+ };
429
+ const rootsOf = /* @__PURE__ */ new Map();
430
+ for (const r of Object.values(relations)) {
431
+ if (r.relationType !== "part-of") continue;
432
+ const part = nodes[r.sourceId];
433
+ const root = nodes[r.targetId];
434
+ if (part?.type !== "entity" || root?.type !== "entity") continue;
435
+ if (kindOf(part) === "aggregate-root") {
436
+ warn(`ddd-root-part-of:${r.id}`, `Aggregate root "${part.label}" is part of "${root.label}"; aggregates refer to each other with "references" instead.`, { relationId: r.id });
437
+ continue;
438
+ }
439
+ if (kindOf(root) !== "aggregate-root") {
440
+ warn(`ddd-part-of-entity:${r.id}`, `"${part.label}" is part of "${root.label}", which is not an aggregate root.`, { relationId: r.id });
441
+ }
442
+ rootsOf.set(part.id, [...rootsOf.get(part.id) ?? [], root.label]);
443
+ }
444
+ for (const entity of entities) {
445
+ if (kindOf(entity) !== "entity") continue;
446
+ const roots = rootsOf.get(entity.id) ?? [];
447
+ if (roots.length === 0) {
448
+ warn(`ddd-loose-entity:${entity.id}`, `Entity "${entity.label}" is not an aggregate root and part of no aggregate; link it to its root with "part-of", or make it a root.`, { nodeId: entity.id });
449
+ } else if (roots.length > 1) {
450
+ warn(`ddd-many-roots:${entity.id}`, `Entity "${entity.label}" is part of ${roots.length} aggregates (${roots.join(", ")}); it belongs to one.`, { nodeId: entity.id });
451
+ }
452
+ }
453
+ return issues;
454
+ }
455
+
456
+ // ../../packages/common/src/metamodel/validate.ts
457
+ var isNoValue = (v) => v == null || v === "" || Array.isArray(v) && v.length === 0;
458
+ function validateModel(nodes, relations, metamodel) {
459
+ const issues = [];
460
+ const nodeList = Object.values(nodes);
461
+ const checkValues = (item, props, at, what) => {
462
+ const key = at.nodeId ?? at.relationId;
463
+ for (const p of props ?? []) {
464
+ const v = item[p.key];
465
+ if (p.required && isNoValue(v) && isNoValue(p.default)) {
466
+ issues.push({ id: `missing-prop:${key}:${p.key}`, severity: "warning", message: `${what} is missing required property "${p.label}".`, ...at });
467
+ }
468
+ if (p.type === "enum" && p.options?.length && !isNoValue(v) && !p.options.includes(String(v))) {
469
+ issues.push({ id: `bad-option:${key}:${p.key}`, severity: "warning", message: `${what}: "${p.label}" is "${String(v)}", which is not one of its options (${p.options.join(", ")}).`, ...at });
470
+ }
471
+ if (p.type === "ref" && !p.multiple && refIds(v).length > 1) {
472
+ issues.push({ id: `many-refs:${key}:${p.key}`, severity: "warning", message: `${what}: "${p.label}" points at ${refIds(v).length} elements, but takes one.`, ...at });
473
+ }
474
+ }
475
+ };
476
+ for (const n of nodeList) {
477
+ const def = metamodel.nodeTypes[n.type];
478
+ if (!def) {
479
+ issues.push({
480
+ id: `unknown-type:${n.id}`,
481
+ severity: "error",
482
+ message: `Node "${n.label}" has unknown type "${n.type}".`,
483
+ nodeId: n.id
484
+ });
485
+ continue;
486
+ }
487
+ const allowed = def.allowedParents;
488
+ if (n.parentId) {
489
+ const parent = nodes[n.parentId];
490
+ if (!parent) {
491
+ issues.push({
492
+ id: `parent-missing:${n.id}`,
493
+ severity: "error",
494
+ message: `Node "${n.label}" references a missing parent.`,
495
+ nodeId: n.id
496
+ });
497
+ } else if (!allowed?.includes(parent.type)) {
498
+ const parentLabel = metamodel.nodeTypes[parent.type]?.label ?? parent.type;
499
+ const none = isParentAllowed(metamodel, n.type, void 0) ? "(none \u2014 must be root)" : "(none)";
500
+ issues.push({
501
+ id: `bad-parent:${n.id}`,
502
+ severity: "error",
503
+ message: `${def.label} "${n.label}" cannot be inside ${parentLabel}. Allowed parents: ${allowed?.length ? allowed.join(", ") : none}.`,
504
+ nodeId: n.id
505
+ });
506
+ } else if (parent.type === GROUP_TYPE && !hasPlaceUnder(metamodel, n.type, placeOf(parent, nodes)?.type)) {
507
+ const place = placeOf(parent, nodes);
508
+ const where = place ? `inside ${metamodel.nodeTypes[place.type]?.label ?? place.type} "${place.label}"` : "at the top of the model";
509
+ issues.push({
510
+ id: `bad-place:${n.id}`,
511
+ severity: "warning",
512
+ message: `${def.label} "${n.label}" is in group "${parent.label}", which is ${where}, where a ${def.label} has no place.`,
513
+ nodeId: n.id
514
+ });
515
+ }
516
+ } else if (def.allowedAtRoot === false || def.allowedAtRoot === void 0 && allowed && allowed.length > 0) {
517
+ issues.push({
518
+ id: `needs-parent:${n.id}`,
519
+ severity: "error",
520
+ message: `${def.label} "${n.label}" must be inside ${allowed && allowed.length ? allowed.join(" or ") : "a parent"}.`,
521
+ nodeId: n.id
522
+ });
523
+ }
524
+ checkValues(n, def.properties, { nodeId: n.id }, `${def.label} "${n.label}"`);
525
+ }
526
+ for (const def of Object.values(metamodel.nodeTypes)) {
527
+ const c = def.cardinality;
528
+ if (!c) continue;
529
+ const count = nodeList.filter((n) => n.type === def.id).length;
530
+ if (c.min != null && count < c.min) {
531
+ issues.push({
532
+ id: `cardinality-min:${def.id}`,
533
+ severity: "warning",
534
+ message: `Model has ${count} ${def.label} (minimum ${c.min}).`,
535
+ nodeTypeId: def.id
536
+ });
537
+ }
538
+ if (c.max != null && count > c.max) {
539
+ issues.push({
540
+ id: `cardinality-max:${def.id}`,
541
+ severity: "warning",
542
+ message: `Model has ${count} ${def.label} (maximum ${c.max}).`,
543
+ nodeTypeId: def.id
544
+ });
545
+ }
546
+ }
547
+ for (const def of Object.values(metamodel.nodeTypes)) {
548
+ if (hasAnyPlace(metamodel, def.id)) continue;
549
+ issues.push({
550
+ id: `no-place:${def.id}`,
551
+ severity: "warning",
552
+ message: `${noPlaceText(metamodel, def.id)}: no allowed parent, and not at the root, so nothing can be placed as a ${def.label}.`,
553
+ nodeTypeId: def.id
554
+ });
555
+ }
556
+ for (const def of [...Object.values(metamodel.nodeTypes), ...Object.values(metamodel.relationTypes)]) {
557
+ const seen = /* @__PURE__ */ new Set();
558
+ for (const p of def.properties ?? []) {
559
+ if (seen.has(p.key)) {
560
+ const isNode = !!metamodel.nodeTypes[def.id] && metamodel.nodeTypes[def.id] === def;
561
+ issues.push({ id: `dup-prop:${def.id}:${p.key}`, severity: "error", message: `${isNode ? def.label : `Relation type "${def.label}"`}: two properties have the key "${p.key}"; give one another key.`, ...isNode ? { nodeTypeId: def.id } : {} });
562
+ }
563
+ seen.add(p.key);
564
+ }
565
+ }
566
+ for (const def of Object.values(metamodel.nodeTypes)) {
567
+ for (const p of def.properties ?? []) {
568
+ const problem = propertyKeyProblem(p.key, "node");
569
+ if (problem) {
570
+ issues.push({ id: `reserved-prop:${def.id}:${p.key}`, severity: "error", message: `${def.label}: property key ${problem}`, nodeTypeId: def.id });
571
+ }
572
+ }
573
+ }
574
+ for (const def of Object.values(metamodel.relationTypes)) {
575
+ for (const p of def.properties ?? []) {
576
+ const problem = propertyKeyProblem(p.key, "relation");
577
+ if (problem) {
578
+ issues.push({ id: `reserved-rel-prop:${def.id}:${p.key}`, severity: "error", message: `Relation type "${def.label}": property key ${problem}` });
579
+ }
580
+ }
581
+ }
582
+ for (const vp of Array.isArray(metamodel.viewpoints) ? metamodel.viewpoints : []) {
583
+ if (!vp || typeof vp !== "object") continue;
584
+ const named = chainTypeNames(vp.pipeline);
585
+ const subject = Array.isArray(vp.subject?.types) ? vp.subject.types : [];
586
+ for (const t of /* @__PURE__ */ new Set([...subject, ...named.nodeTypes])) {
587
+ if (metamodel.nodeTypes[t]) continue;
588
+ issues.push({ id: `viewpoint-unknown-type:${vp.id}:${t}`, severity: "warning", message: `Viewpoint "${vp.label}" names node type "${t}", which the metamodel does not have.` });
589
+ }
590
+ for (const t of named.relationTypes) {
591
+ if (metamodel.relationTypes[t]) continue;
592
+ issues.push({ id: `viewpoint-unknown-rel-type:${vp.id}:${t}`, severity: "warning", message: `Viewpoint "${vp.label}" names relation type "${t}", which the metamodel does not have.` });
593
+ }
594
+ }
595
+ const restrictiveTypes = Object.values(metamodel.relationTypes).filter((rt) => rt.allowedPairs.length > 0);
596
+ const anyAllows = Object.values(metamodel.relationTypes).some((rt) => rt.allowedPairs.length === 0);
597
+ if (restrictiveTypes.length > 0 && !anyAllows) {
598
+ for (const r of Object.values(relations)) {
599
+ const src = nodes[r.sourceId];
600
+ const dst = nodes[r.targetId];
601
+ if (!src || !dst) continue;
602
+ const ok = restrictiveTypes.some(
603
+ (rt) => rt.allowedPairs.some((p) => p.from === src.type && p.to === dst.type)
604
+ );
605
+ if (!ok) {
606
+ issues.push({
607
+ id: `bad-rel:${r.id}`,
608
+ severity: "warning",
609
+ message: `Relation "${src.label}" \u2192 "${dst.label}" (${src.type}\u2192${dst.type}) is not allowed by metamodel.`,
610
+ relationId: r.id
611
+ });
612
+ }
613
+ }
614
+ }
615
+ for (const r of Object.values(relations)) {
616
+ const missing = [r.sourceId, r.targetId].filter((id) => !nodes[id]);
617
+ if (missing.length) {
618
+ issues.push({
619
+ id: `rel-end-missing:${r.id}`,
620
+ severity: "error",
621
+ message: `Relation "${r.label ?? r.id}" ${missing.length === 2 ? "has no element at either end" : `points at "${missing[0]}", which is no element of the model`}.`,
622
+ relationId: r.id
623
+ });
624
+ }
625
+ if (r.relationType && !metamodel.relationTypes[r.relationType]) {
626
+ issues.push({
627
+ id: `unknown-rel-type:${r.id}`,
628
+ severity: "error",
629
+ message: `Relation "${r.label ?? r.id}" has unknown type "${r.relationType}".`,
630
+ relationId: r.id
631
+ });
632
+ }
633
+ }
634
+ for (const r of Object.values(relations)) {
635
+ const def = r.relationType ? metamodel.relationTypes[r.relationType] : void 0;
636
+ if (!def) continue;
637
+ const src = nodes[r.sourceId]?.label ?? r.sourceId;
638
+ const dst = nodes[r.targetId]?.label ?? r.targetId;
639
+ checkValues(r, def.properties, { relationId: r.id }, `Relation "${src}" \u2192 "${dst}" (${def.label})`);
640
+ }
641
+ for (const r of Object.values(relations)) {
642
+ if (r.relationType) continue;
643
+ const src = nodes[r.sourceId];
644
+ const dst = nodes[r.targetId];
645
+ if (!src || !dst) continue;
646
+ const fitting = relationTypesFitting(metamodel, src.type, dst.type);
647
+ if (fitting.length < 2) continue;
648
+ issues.push({
649
+ id: `untyped-rel:${r.id}`,
650
+ severity: "warning",
651
+ message: `Relation "${src.label}" \u2192 "${dst.label}" has no type; give it one of ${fitting.map((rt) => `"${rt.label}"`).join(", ")}.`,
652
+ relationId: r.id
653
+ });
654
+ }
655
+ for (const r of Object.values(relations)) {
656
+ const def = r.relationType ? metamodel.relationTypes[r.relationType] : void 0;
657
+ const src = nodes[r.sourceId];
658
+ const dst = nodes[r.targetId];
659
+ if (!def || !src || !dst || def.allowedPairs.length === 0) continue;
660
+ if (def.allowedPairs.some((p) => p.from === src.type && p.to === dst.type)) continue;
661
+ issues.push({
662
+ id: `bad-rel-type:${r.id}`,
663
+ severity: "warning",
664
+ message: `Relation "${src.label}" \u2192 "${dst.label}" is "${def.label}", which does not connect ${src.type}\u2192${dst.type}.`,
665
+ relationId: r.id
666
+ });
667
+ }
668
+ const checkRefs = (item, props, at, what) => {
669
+ for (const p of props ?? []) {
670
+ if (p.type !== "ref") continue;
671
+ for (const id of refIds(item[p.key])) {
672
+ const problem = refProblem(p, id, nodes);
673
+ if (problem) {
674
+ issues.push({
675
+ id: `bad-ref:${at.nodeId ?? at.relationId}:${p.key}:${id}`,
676
+ severity: "warning",
677
+ message: `${what}: "${p.label}" points at nothing valid (${problem}).`,
678
+ ...at
679
+ });
680
+ }
681
+ }
682
+ }
683
+ };
684
+ for (const n of nodeList) {
685
+ const def = metamodel.nodeTypes[n.type];
686
+ if (def) checkRefs(n, def.properties, { nodeId: n.id }, `${def.label} "${n.label}"`);
687
+ }
688
+ for (const r of Object.values(relations)) {
689
+ const def = r.relationType ? metamodel.relationTypes[r.relationType] : void 0;
690
+ if (!def) continue;
691
+ const src = nodes[r.sourceId]?.label ?? r.sourceId;
692
+ const dst = nodes[r.targetId]?.label ?? r.targetId;
693
+ checkRefs(r, def.properties, { relationId: r.id }, `${def.label} "${src}" \u2192 "${dst}"`);
694
+ }
695
+ if (metamodel.nodeTypes.entity && metamodel.relationTypes["part-of"]) {
696
+ issues.push(...validateDomainModel(nodes, relations));
697
+ }
698
+ if (metamodel.nodeTypes.state && metamodel.relationTypes.transition) {
699
+ issues.push(...validateStateMachines(nodes, relations));
700
+ }
701
+ return issues;
702
+ }
703
+
704
+ // ../../packages/common/src/metamodel/prose.ts
705
+ init_define_RADICAL_BUILD();
706
+ function relationPhrase(def, direction, ends) {
707
+ if (!def) return { text: direction === "out" ? "Relates to" : "Linked from", reads: true };
708
+ const pair = ends ? def.allowedPairs.find((p) => p.from === ends.from && p.to === ends.to) : void 0;
709
+ if (direction === "out") return { text: pair?.forwardLabel?.trim() || def.forwardLabel?.trim() || def.label, reads: true };
710
+ const inverse = pair?.inverseLabel?.trim() || def.inverseLabel?.trim();
711
+ return inverse ? { text: inverse, reads: true } : { text: def.label, reads: false };
712
+ }
713
+ function relationTypeName(metamodel, typeId, lower = false, ends) {
714
+ const def = metamodel?.relationTypes[typeId];
715
+ const text = def ? relationPhrase(def, "out", ends).text : typeId;
716
+ return lower ? text.charAt(0).toLowerCase() + text.slice(1) : text;
717
+ }
718
+
719
+ // ../../packages/common/src/metamodel/ears.ts
720
+ init_define_RADICAL_BUILD();
721
+ function capitalize(s) {
722
+ return s.charAt(0).toUpperCase() + s.slice(1);
723
+ }
724
+ function earsActionIsClause(action) {
725
+ return /\S\s+shall\s+\S/i.test(action);
726
+ }
727
+ function composeEarsSentence(node, subject, statePrecondition) {
728
+ const earsType = String(node.ears_type ?? "ubiquitous");
729
+ const subj = (subject || "the system").trim();
730
+ const action = String(node.action ?? "").trim();
731
+ const trigger = String(node.trigger ?? "").trim();
732
+ const precondition = (statePrecondition ?? "").trim() || String(node.precondition ?? "").trim();
733
+ const unwanted = String(node.unwanted_condition ?? "").trim();
734
+ const feature = String(node.feature ?? "").trim();
735
+ const actionPart = action.replace(/\.+$/, "") || "\u2039action\u203A";
736
+ const ownClause = earsActionIsClause(actionPart);
737
+ const shallClause = ownClause ? actionPart.replace(/^(The|A|An)\b/, (w) => w.toLowerCase()) : `${subj} shall ${actionPart}`;
738
+ let sentence;
739
+ let complete = !!action;
740
+ switch (earsType) {
741
+ case "event-driven":
742
+ sentence = `When ${trigger || "\u2039trigger\u203A"}, ${shallClause}.`;
743
+ complete = complete && !!trigger;
744
+ break;
745
+ case "state-driven":
746
+ sentence = `While ${precondition || "\u2039precondition\u203A"}, ${shallClause}.`;
747
+ complete = complete && !!precondition;
748
+ break;
749
+ case "unwanted-behaviour":
750
+ sentence = `If ${unwanted || "\u2039condition\u203A"}, then ${shallClause}.`;
751
+ complete = complete && !!unwanted;
752
+ break;
753
+ case "optional":
754
+ sentence = `Where ${feature || "\u2039feature\u203A"}, ${shallClause}.`;
755
+ complete = complete && !!feature;
756
+ break;
757
+ case "complex": {
758
+ const parts = [];
759
+ if (precondition) parts.push(`While ${precondition}`);
760
+ if (trigger) parts.push(`when ${trigger}`);
761
+ if (unwanted) parts.push(`if ${unwanted}`);
762
+ if (feature) parts.push(`where ${feature}`);
763
+ const hasCondition = parts.length > 0;
764
+ if (!hasCondition) parts.push("\u2039conditions\u203A");
765
+ else parts[0] = capitalize(parts[0]);
766
+ sentence = `${parts.join(", ")}, ${shallClause}.`;
767
+ complete = complete && hasCondition;
768
+ break;
769
+ }
770
+ default:
771
+ sentence = ownClause ? `${capitalize(actionPart)}.` : `${capitalize(subj)} shall ${actionPart}.`;
772
+ break;
773
+ }
774
+ return { sentence, complete };
775
+ }
776
+
777
+ // ../../packages/common/src/metamodel/wizard.ts
778
+ init_define_RADICAL_BUILD();
779
+
780
+ // ../../packages/common/src/metamodel/categories.ts
781
+ init_define_RADICAL_BUILD();
782
+
783
+ // ../../packages/common/src/metamodel/layoutHints.ts
784
+ init_define_RADICAL_BUILD();
785
+
786
+ // ../../packages/common/src/metamodel/presets/governance.ts
787
+ init_define_RADICAL_BUILD();
788
+
789
+ // ../../packages/common/src/metamodel/presets/ddd.ts
790
+ init_define_RADICAL_BUILD();
791
+
792
+ // ../../packages/common/src/metamodel/presets/c4.ts
793
+ init_define_RADICAL_BUILD();
794
+
795
+ // ../../packages/common/src/metamodel/presets/viewpoints.ts
796
+ init_define_RADICAL_BUILD();
797
+ var DEPLOYABLE = ["container", "webapp", "database", "queue"];
798
+ var BUILDING_BLOCKS = ["system", "container", "webapp", "component", "database", "queue"];
799
+ function among(types) {
800
+ return { levels: [{ ways: [{ types }] }], edges: "all" };
801
+ }
802
+ function aroundOne(types, around) {
803
+ return { levels: [{ ways: [{ types }] }, { ways: [{ via: { anyRelation: true }, types: around }] }], edges: "all" };
804
+ }
805
+ function c4Viewpoints() {
806
+ return [
807
+ {
808
+ id: "system-context",
809
+ label: "System context",
810
+ group: "C4",
811
+ description: "The people and software systems, and how they use each other (C4 level 1).",
812
+ kind: "static",
813
+ pipeline: among(["person", "system"])
814
+ },
815
+ {
816
+ id: "containers",
817
+ label: "Containers",
818
+ group: "C4",
819
+ description: "The software systems with the containers, web apps, databases and queues inside them, the people who use them, and every relation between them (C4 level 2).",
820
+ kind: "static",
821
+ pipeline: among(["person", "system", ...DEPLOYABLE])
822
+ },
823
+ {
824
+ id: "system-containers",
825
+ label: "Containers of a system",
826
+ group: "C4",
827
+ description: "One software system with the containers, web apps, databases and queues inside it, and the people, systems and containers they are related to: a view per system (C4 level 2).",
828
+ kind: "static",
829
+ subject: { types: ["system"] },
830
+ pipeline: aroundOne(["system", ...DEPLOYABLE], ["person", "system", ...DEPLOYABLE])
831
+ },
832
+ {
833
+ id: "components",
834
+ label: "Components",
835
+ group: "C4",
836
+ description: "The containers and web apps with the components inside them, the databases and queues they use, and every relation between them (C4 level 3).",
837
+ kind: "static",
838
+ pipeline: among(["container", "webapp", "component", "database", "queue"])
839
+ },
840
+ {
841
+ id: "container-components",
842
+ label: "Components of a container",
843
+ group: "C4",
844
+ description: "One container or web app with the components inside it, and the people, systems, containers and components they are related to: a view per container (C4 level 3).",
845
+ kind: "static",
846
+ subject: { types: ["container", "webapp"] },
847
+ pipeline: aroundOne(["container", "webapp", "component"], ["person", "system", ...DEPLOYABLE, "component"])
848
+ },
849
+ {
850
+ id: "container-dependencies",
851
+ label: "Container dependencies",
852
+ group: "C4",
853
+ description: "A matrix of the containers, web apps, databases and queues: who uses whom, and where the cycles are.",
854
+ kind: "matrix",
855
+ pipeline: among(DEPLOYABLE)
856
+ }
857
+ ];
858
+ }
859
+ function radicalViewpoints() {
860
+ return [
861
+ ...c4Viewpoints(),
862
+ {
863
+ id: "domain-map",
864
+ label: "Domain map",
865
+ group: "Domain",
866
+ description: "The domains and subdomains, and how they depend on and partner with each other.",
867
+ kind: "static",
868
+ pipeline: among(["domain"])
869
+ },
870
+ {
871
+ id: "domain-model",
872
+ label: "Domain model",
873
+ group: "Domain",
874
+ description: "The entities and aggregates, what they are part of and what they reference.",
875
+ kind: "static",
876
+ pipeline: among(["entity"])
877
+ },
878
+ {
879
+ id: "domain-entities",
880
+ label: "Entities of a domain",
881
+ group: "Domain",
882
+ description: "One domain with its subdomains and entities, and the entities of other domains they reference or are part of: a view per domain.",
883
+ kind: "static",
884
+ subject: { types: ["domain"] },
885
+ pipeline: {
886
+ levels: [
887
+ { ways: [{ types: ["domain", "entity"] }] },
888
+ { ways: [{ via: { relationType: "references", direction: "out" }, types: ["entity"] }, { via: { relationType: "part-of", direction: "out" }, types: ["entity"] }] }
889
+ ],
890
+ edges: "all"
891
+ }
892
+ },
893
+ {
894
+ id: "domain-realisation",
895
+ label: "Domain realisation",
896
+ group: "Domain",
897
+ description: "A table of domains, their entities, and the systems, containers and components that realise each.",
898
+ kind: "table",
899
+ pipeline: { levels: [
900
+ { ways: [{ types: ["domain"] }] },
901
+ { ways: [{ via: { contains: true }, types: ["entity"] }, { via: { relationType: "realises", direction: "in" } }] },
902
+ { ways: [{ via: { relationType: "realises", direction: "in" } }] }
903
+ ] }
904
+ },
905
+ {
906
+ id: "traceability",
907
+ label: "Traceability",
908
+ group: "Requirements",
909
+ description: "A table of needs, the requirements refined from each, and the scenarios that verify those.",
910
+ kind: "table",
911
+ pipeline: { levels: [
912
+ { ways: [{ types: ["need"] }] },
913
+ { ways: [{ via: { relationType: "derives", direction: "in" }, types: ["requirement"] }] },
914
+ { ways: [{ via: { relationType: "verifies", direction: "in" }, types: ["scenario"] }] }
915
+ ] }
916
+ },
917
+ {
918
+ id: "requirement-coverage",
919
+ label: "Requirement coverage",
920
+ group: "Requirements",
921
+ description: "A table of requirements, the elements that satisfy each and the scenarios that verify it.",
922
+ kind: "table",
923
+ pipeline: { levels: [
924
+ { ways: [{ types: ["requirement"] }] },
925
+ { ways: [{ via: { relationType: "satisfies", direction: "in" } }, { via: { relationType: "verifies", direction: "in" }, types: ["scenario"] }] }
926
+ ] }
927
+ },
928
+ {
929
+ id: "requirement-gaps",
930
+ label: "Requirement gaps",
931
+ group: "Requirements",
932
+ description: "The requirements no scenario verifies or nothing satisfies yet.",
933
+ kind: "table",
934
+ pipeline: { levels: [
935
+ { ways: [{ types: ["requirement"] }], filters: [
936
+ { kind: "relation", relationType: "verifies", direction: "in", has: false },
937
+ { kind: "relation", relationType: "satisfies", direction: "in", has: false, join: "or" }
938
+ ] }
939
+ ] }
940
+ },
941
+ {
942
+ id: "responsibilities",
943
+ label: "Responsibilities",
944
+ group: "Requirements",
945
+ description: "A table of the systems, containers and components that satisfy requirements, each with its requirements and the scenarios that verify them.",
946
+ kind: "table",
947
+ pipeline: { levels: [
948
+ { ways: [{ types: BUILDING_BLOCKS }], filters: [{ kind: "relation", relationType: "satisfies", direction: "out", has: true }] },
949
+ { ways: [{ via: { relationType: "satisfies", direction: "out" }, types: ["requirement"] }] },
950
+ { ways: [{ via: { relationType: "verifies", direction: "in" }, types: ["scenario"] }] }
951
+ ] }
952
+ },
953
+ {
954
+ id: "specification",
955
+ label: "Specification",
956
+ group: "Requirements",
957
+ description: "A document of the needs, the requirements refined from each, and the scenarios and screens for each requirement.",
958
+ kind: "wiki",
959
+ pipeline: { levels: [
960
+ { ways: [{ types: ["need"] }] },
961
+ { ways: [{ via: { relationType: "derives", direction: "in" }, types: ["requirement"] }] },
962
+ { ways: [{ via: { relationType: "verifies", direction: "in" }, types: ["scenario"] }, { via: { relationType: "illustrates", direction: "in" }, types: ["mockup"] }] }
963
+ ] }
964
+ },
965
+ {
966
+ id: "decisions",
967
+ label: "Decisions",
968
+ group: "Decisions",
969
+ description: "A table of ADRs, the fitness functions that check each and the elements it constrains.",
970
+ kind: "table",
971
+ pipeline: { levels: [
972
+ { ways: [{ types: ["adr"] }] },
973
+ { ways: [{ via: { relationType: "implements", direction: "in" }, types: ["fitness-fn"] }, { via: { relationType: "constrains", direction: "out" } }] }
974
+ ] }
975
+ },
976
+ {
977
+ id: "decision-log",
978
+ label: "Decision log",
979
+ group: "Decisions",
980
+ description: "A document of the ADRs, the newest first, each with the decisions it supersedes.",
981
+ kind: "wiki",
982
+ pipeline: {
983
+ levels: [
984
+ { ways: [{ types: ["adr"] }] },
985
+ { ways: [{ via: { relationType: "supersedes", direction: "out" }, types: ["adr"] }] }
986
+ ],
987
+ sort: { by: "property", key: "date", desc: true }
988
+ }
989
+ },
990
+ {
991
+ id: "fitness-functions",
992
+ label: "Fitness functions",
993
+ group: "Decisions",
994
+ description: "A table of the fitness functions by category, each with the decisions it checks and the elements it constrains.",
995
+ kind: "table",
996
+ pipeline: {
997
+ levels: [
998
+ { ways: [{ types: ["fitness-fn"] }] },
999
+ { ways: [{ via: { relationType: "implements", direction: "out" }, types: ["adr"] }, { via: { relationType: "constrains", direction: "out" } }] }
1000
+ ],
1001
+ sort: { by: "property", key: "category" }
1002
+ }
1003
+ },
1004
+ {
1005
+ id: "screen-flow",
1006
+ label: "Screen flow",
1007
+ group: "UX",
1008
+ description: "The screens and how users navigate from one to the next.",
1009
+ kind: "static",
1010
+ pipeline: among(["mockup"])
1011
+ },
1012
+ {
1013
+ id: "screens",
1014
+ label: "Screens",
1015
+ group: "UX",
1016
+ description: "A table of the screens, each with the requirements and scenarios it illustrates and the elements that present it.",
1017
+ kind: "table",
1018
+ pipeline: { levels: [
1019
+ { ways: [{ types: ["mockup"] }] },
1020
+ { ways: [{ via: { relationType: "illustrates", direction: "out" } }, { via: { relationType: "presented-by", direction: "out" } }] }
1021
+ ] }
1022
+ },
1023
+ {
1024
+ id: "entity-lifecycles",
1025
+ label: "Entity lifecycles",
1026
+ group: "States",
1027
+ description: "A table of the entities with a lifecycle, the state machine of each, and what implements and verifies it.",
1028
+ kind: "table",
1029
+ pipeline: { levels: [
1030
+ { ways: [{ types: ["entity"] }], filters: [{ kind: "relation", relationType: "lifecycle-of", direction: "in", has: true }] },
1031
+ { ways: [{ via: { relationType: "lifecycle-of", direction: "in" }, types: ["state-machine"] }] },
1032
+ { ways: [{ via: { relationType: "implements", direction: "in" } }, { via: { relationType: "verifies", direction: "in" }, types: ["scenario"] }] }
1033
+ ] }
1034
+ },
1035
+ {
1036
+ id: "state-machine",
1037
+ label: "State machine",
1038
+ group: "States",
1039
+ description: "One state machine with its states, pseudostates, events and transitions, and the entity it is the lifecycle of: a view per machine.",
1040
+ kind: "static",
1041
+ subject: { types: ["state-machine"] },
1042
+ pipeline: {
1043
+ levels: [
1044
+ { ways: [{ types: ["state-machine", "state", "pseudostate", "event"] }] },
1045
+ { ways: [{ via: { relationType: "lifecycle-of", direction: "out" }, types: ["entity"] }] }
1046
+ ],
1047
+ edges: "all"
1048
+ }
1049
+ },
1050
+ {
1051
+ id: "event-catalogue",
1052
+ label: "Event catalogue",
1053
+ group: "States",
1054
+ description: "A table of the events, each with what emits it.",
1055
+ kind: "table",
1056
+ pipeline: { levels: [
1057
+ { ways: [{ types: ["event"] }] },
1058
+ { ways: [{ via: { relationType: "emits", direction: "in" } }] }
1059
+ ] }
1060
+ },
1061
+ {
1062
+ id: "process-warnier",
1063
+ label: "Process (Warnier)",
1064
+ group: "Process",
1065
+ description: "The processes and their steps as Warnier\u2013Orr diagrams: what each is made of, what repeats, what is an alternative and what runs at once.",
1066
+ kind: "warnier",
1067
+ pipeline: { levels: [{ ways: [{ types: ["process", "step"] }] }] }
1068
+ },
1069
+ {
1070
+ id: "process",
1071
+ label: "Process",
1072
+ group: "Process",
1073
+ description: "One process and its steps as a Warnier\u2013Orr diagram: a view per process.",
1074
+ kind: "warnier",
1075
+ subject: { types: ["process"] },
1076
+ pipeline: { levels: [{ ways: [{ types: ["process", "step"] }] }] }
1077
+ }
1078
+ ];
1079
+ }
1080
+
1081
+ // ../../packages/common/src/metamodel/presets/c4.ts
1082
+ var VISUALS = {
1083
+ person: {
1084
+ label: "Person",
1085
+ color: "#08427b",
1086
+ fg: "#fff",
1087
+ description: "Someone who uses or runs the system: a customer, an operator, another team.",
1088
+ iconPath: "M8 2a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5ZM3 12.5C3 10.01 5.24 8 8 8s5 2.01 5 4.5V14H3v-1.5Z",
1089
+ width: 150,
1090
+ height: 170,
1091
+ collapsedWidth: 150,
1092
+ collapsedHeight: 170
1093
+ },
1094
+ system: {
1095
+ label: "Software System",
1096
+ color: "#1168bd",
1097
+ fg: "#fff",
1098
+ description: "Something that delivers value to its users and is owned by one team: yours, or one you depend on.",
1099
+ iconPath: "M2 3.5A1.5 1.5 0 0 1 3.5 2h9A1.5 1.5 0 0 1 14 3.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 12.5v-9ZM4 5h8v1H4V5Zm0 2.5h8v1H4v-1Zm0 2.5h5v1H4V10Z",
1100
+ width: 360,
1101
+ height: 260,
1102
+ collapsedWidth: 280,
1103
+ collapsedHeight: 180
1104
+ },
1105
+ container: {
1106
+ label: "Container",
1107
+ color: "#438dd5",
1108
+ fg: "#fff",
1109
+ description: "Something that runs or stores data and is deployed on its own: a service, a worker, a mobile app, a serverless function.",
1110
+ iconPath: "M1 4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v1H1V4Zm0 2.5h14V12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V6.5ZM3 3a.5.5 0 1 0 0 1 .5.5 0 0 0 0-1Zm2 0a.5.5 0 1 0 0 1 .5.5 0 0 0 0-1Z",
1111
+ width: 300,
1112
+ height: 200,
1113
+ collapsedWidth: 240,
1114
+ collapsedHeight: 160
1115
+ },
1116
+ component: {
1117
+ label: "Component",
1118
+ color: "#85bbf0",
1119
+ fg: "#000",
1120
+ description: "A part of a container behind a clear interface: a controller, a domain service, an adapter.",
1121
+ iconPath: "M5 1v2H3a1 1 0 0 0-1 1v2h2v2H2v2h2v2H2v2a1 1 0 0 0 1 1h2v2h2v-2h2v2h2v-2h2a1 1 0 0 0 1-1v-2h-2v-2h2V8h-2V6h2V4a1 1 0 0 0-1-1h-2V1H9v2H7V1H5Z",
1122
+ width: 200,
1123
+ height: 120,
1124
+ collapsedWidth: 200,
1125
+ collapsedHeight: 120
1126
+ },
1127
+ database: {
1128
+ label: "Database",
1129
+ color: "#438dd5",
1130
+ fg: "#fff",
1131
+ description: "A container that stores data. It never starts an interaction.",
1132
+ iconPath: "M8 1C4.7 1 2 2.3 2 4v8c0 1.7 2.7 3 6 3s6-1.3 6-3V4c0-1.7-2.7-3-6-3ZM2 4c0 1.7 2.7 3 6 3s6-1.3 6-3",
1133
+ width: 190,
1134
+ height: 130,
1135
+ collapsedWidth: 190,
1136
+ collapsedHeight: 130
1137
+ },
1138
+ webapp: {
1139
+ label: "Web App",
1140
+ color: "#438dd5",
1141
+ fg: "#fff",
1142
+ description: "A container that is a browser front end.",
1143
+ iconPath: "M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Zm1 2.5V13h10V5.5H3ZM4 3.5a.5.5 0 1 0 0 1 .5.5 0 0 0 0-1Zm1.5 0a.5.5 0 1 0 0 1 .5.5 0 0 0 0-1Zm1.5 0a.5.5 0 1 0 0 1 .5.5 0 0 0 0-1Z",
1144
+ width: 210,
1145
+ height: 140,
1146
+ collapsedWidth: 210,
1147
+ collapsedHeight: 140
1148
+ },
1149
+ queue: {
1150
+ label: "Queue",
1151
+ color: "#438dd5",
1152
+ fg: "#fff",
1153
+ description: "A container that carries messages between other containers.",
1154
+ iconPath: "M4 3a3 2 0 1 0 0 4h8a3 2 0 1 0 0-4H4Zm-2 5.5a3 2 0 0 0 4 0v-1a3 2 0 0 1-4 0v1Zm10 0a3 2 0 0 0 4 0v-1a3 2 0 0 1-4 0v1Z",
1155
+ width: 220,
1156
+ height: 95,
1157
+ collapsedWidth: 220,
1158
+ collapsedHeight: 95
1159
+ },
1160
+ group: {
1161
+ label: "Group",
1162
+ color: "#64748b",
1163
+ fg: "#fff",
1164
+ description: "A labelled boundary with no meaning of its own: a team, a layer, a deployment zone.",
1165
+ // Folder icon.
1166
+ iconPath: "M2 3.5C2 2.67 2.67 2 3.5 2H7l1.5 2h4c.83 0 1.5.67 1.5 1.5v7c0 .83-.67 1.5-1.5 1.5h-9C2.67 14 2 13.33 2 12.5v-9Z",
1167
+ width: 520,
1168
+ height: 360,
1169
+ collapsedWidth: 360,
1170
+ collapsedHeight: 220
1171
+ }
1172
+ };
1173
+ var LAYOUT = {
1174
+ person: { role: "actor", side: "top" },
1175
+ database: { role: "store", side: "right" },
1176
+ queue: { role: "broker" }
1177
+ };
1178
+ function builtInC4Metamodel() {
1179
+ const nodeTypes = {};
1180
+ const allowedParentsMap = {
1181
+ person: ["group"],
1182
+ system: ["system", "group"],
1183
+ container: ["system", "group"],
1184
+ component: ["container", "webapp", "group"],
1185
+ database: ["system", "group"],
1186
+ webapp: ["system", "group"],
1187
+ queue: ["system", "group"],
1188
+ group: ["group", "system"]
1189
+ };
1190
+ const techTypes = /* @__PURE__ */ new Set(["container", "component", "database", "webapp", "queue"]);
1191
+ const types = [
1192
+ "person",
1193
+ "system",
1194
+ "container",
1195
+ "component",
1196
+ "database",
1197
+ "webapp",
1198
+ "queue",
1199
+ "group"
1200
+ ];
1201
+ for (const t of types) {
1202
+ const props = [
1203
+ { key: "description", label: "Description", type: "textarea" }
1204
+ ];
1205
+ if (techTypes.has(t)) props.push({ key: "technology", label: "Technology", type: "text" });
1206
+ if (t !== "group") props.push({ key: "external", label: "External", type: "boolean" });
1207
+ const v = VISUALS[t];
1208
+ nodeTypes[t] = {
1209
+ id: t,
1210
+ label: v.label,
1211
+ ...LAYOUT[t] ? { layout: LAYOUT[t] } : {},
1212
+ description: v.description,
1213
+ color: v.color,
1214
+ fg: v.fg,
1215
+ iconPath: v.iconPath,
1216
+ width: v.width,
1217
+ height: v.height,
1218
+ collapsedWidth: v.collapsedWidth,
1219
+ collapsedHeight: v.collapsedHeight,
1220
+ allowedParents: allowedParentsMap[t],
1221
+ // person, system, and group are top-level concepts and may live at the root.
1222
+ allowedAtRoot: t === "person" || t === "system" || t === "group",
1223
+ builtin: true,
1224
+ properties: props
1225
+ };
1226
+ }
1227
+ const DELIVERS = { forwardLabel: "Delivers to", inverseLabel: "Receives from" };
1228
+ const interactsPairs = [
1229
+ // Person interacts with the system surface, and with other people (a
1230
+ // customer asks the support staff: Structurizr models it)
1231
+ { from: "person", to: "person", forwardLabel: "Interacts with", inverseLabel: "Interacts with" },
1232
+ { from: "person", to: "system" },
1233
+ { from: "person", to: "container" },
1234
+ { from: "person", to: "webapp" },
1235
+ { from: "person", to: "component" },
1236
+ // System-level dependencies; to a person a relation delivers (Structurizr's
1237
+ // delivers(): "Sends e-mails to")
1238
+ { from: "system", to: "person", ...DELIVERS },
1239
+ { from: "system", to: "system" },
1240
+ { from: "system", to: "container" },
1241
+ { from: "system", to: "database" },
1242
+ { from: "system", to: "webapp" },
1243
+ { from: "system", to: "queue" },
1244
+ { from: "system", to: "component" },
1245
+ // Container-level calls
1246
+ { from: "container", to: "person", ...DELIVERS },
1247
+ { from: "container", to: "system" },
1248
+ { from: "container", to: "container" },
1249
+ { from: "container", to: "database" },
1250
+ { from: "container", to: "webapp" },
1251
+ { from: "container", to: "queue" },
1252
+ // …and calls a component of another container (a single-page app calls
1253
+ // the API's controllers, as Structurizr models it)
1254
+ { from: "container", to: "component" },
1255
+ // Web / UI container
1256
+ { from: "webapp", to: "person", ...DELIVERS },
1257
+ { from: "webapp", to: "system" },
1258
+ { from: "webapp", to: "container" },
1259
+ { from: "webapp", to: "database" },
1260
+ { from: "webapp", to: "webapp" },
1261
+ { from: "webapp", to: "queue" },
1262
+ { from: "webapp", to: "component" },
1263
+ // Queues fan out to consumers
1264
+ { from: "queue", to: "container" },
1265
+ { from: "queue", to: "webapp" },
1266
+ { from: "queue", to: "component" },
1267
+ // Component-level calls
1268
+ { from: "component", to: "component" },
1269
+ { from: "component", to: "container" },
1270
+ { from: "component", to: "webapp" },
1271
+ { from: "component", to: "database" },
1272
+ { from: "component", to: "queue" },
1273
+ { from: "component", to: "system" }
1274
+ ];
1275
+ const relationTypes = {
1276
+ interacts: {
1277
+ id: "interacts",
1278
+ label: "Interacts",
1279
+ description: "Any meaningful interaction: the source calls, uses, sends to or delivers to the target. The label says what happens, the technology how.",
1280
+ forwardLabel: "Uses",
1281
+ inverseLabel: "Used by",
1282
+ allowedPairs: interactsPairs,
1283
+ properties: [
1284
+ { key: "technology", label: "Technology", type: "text" }
1285
+ ],
1286
+ builtin: true,
1287
+ layout: { flow: "forward" }
1288
+ }
1289
+ };
1290
+ return { id: "c4-builtin", name: "C4 (built-in)", nodeTypes, relationTypes, viewpoints: c4Viewpoints() };
1291
+ }
1292
+
1293
+ // ../../packages/common/src/metamodel/presets/ddd.ts
1294
+ function builtInDddC4Metamodel() {
1295
+ const base = builtInC4Metamodel();
1296
+ const patchedSystem = {
1297
+ ...base.nodeTypes.system,
1298
+ allowedParents: ["system", "domain", "group"],
1299
+ allowedAtRoot: true
1300
+ };
1301
+ const domainProps = [
1302
+ { key: "description", label: "Description", type: "textarea" },
1303
+ { key: "vision", label: "Vision", type: "textarea" },
1304
+ {
1305
+ key: "kind",
1306
+ label: "Kind",
1307
+ type: "enum",
1308
+ options: ["core", "supporting", "generic"],
1309
+ default: "core"
1310
+ }
1311
+ ];
1312
+ const domain = {
1313
+ id: "domain",
1314
+ layout: { role: "element" },
1315
+ label: "Domain",
1316
+ description: "A part of the problem space, in the language of the business rather than of the software.",
1317
+ color: "#4c1d95",
1318
+ fg: "#fff",
1319
+ iconPath: "M2 3.5A1.5 1.5 0 0 1 3.5 2h9A1.5 1.5 0 0 1 14 3.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 12.5v-9Zm1.5 1A.5.5 0 0 0 3 5v6a.5.5 0 0 0 .5.5h9A.5.5 0 0 0 13 11V5a.5.5 0 0 0-.5-.5h-9ZM5 7h2v2H5V7Zm4 0h2v2H9V7Z",
1320
+ width: 520,
1321
+ height: 360,
1322
+ collapsedWidth: 360,
1323
+ collapsedHeight: 220,
1324
+ // A domain may be nested inside another domain or a group.
1325
+ allowedParents: ["domain", "group"],
1326
+ allowedAtRoot: true,
1327
+ builtin: true,
1328
+ properties: domainProps
1329
+ };
1330
+ const entity = {
1331
+ id: "entity",
1332
+ layout: { role: "element" },
1333
+ label: "Entity",
1334
+ description: "A thing the domain keeps track of and that has an identity over time: a reservation, an order, a payment.",
1335
+ color: "#7e22ce",
1336
+ fg: "#fff",
1337
+ // A record card with a key
1338
+ iconPath: "M3 2.5A1.5 1.5 0 0 1 4.5 1h7A1.5 1.5 0 0 1 13 2.5v11a1.5 1.5 0 0 1-1.5 1.5h-7A1.5 1.5 0 0 1 3 13.5v-11ZM4.5 2a.5.5 0 0 0-.5.5V5h8V2.5a.5.5 0 0 0-.5-.5h-7ZM12 6H4v1.5h8V6Zm0 2.5H4V10h8V8.5Zm0 2.5H4v2.5c0 .28.22.5.5.5h7a.5.5 0 0 0 .5-.5V11Z",
1339
+ width: 170,
1340
+ height: 56,
1341
+ allowedParents: ["domain", "group"],
1342
+ allowedAtRoot: true,
1343
+ builtin: true,
1344
+ // The parts of an aggregate list under its root in Table and Wiki views.
1345
+ hierarchyRelation: "part-of",
1346
+ properties: [
1347
+ {
1348
+ key: "kind",
1349
+ label: "Kind",
1350
+ type: "enum",
1351
+ options: ["aggregate-root", "entity"],
1352
+ default: "aggregate-root"
1353
+ },
1354
+ { key: "description", label: "Description", type: "textarea" }
1355
+ ]
1356
+ };
1357
+ const realises = {
1358
+ id: "realises",
1359
+ layout: { flow: "side" },
1360
+ label: "Realises",
1361
+ description: "The software behind a domain or an entity: the bounded context that implements the domain, or the element that owns the entity's data.",
1362
+ inverseLabel: "Realised by",
1363
+ allowedPairs: [
1364
+ { from: "system", to: "domain" },
1365
+ { from: "container", to: "domain" },
1366
+ ...["system", "container", "component", "webapp"].map((from) => ({ from, to: "entity" }))
1367
+ ],
1368
+ properties: [],
1369
+ builtin: true
1370
+ };
1371
+ const partOf = {
1372
+ id: "part-of",
1373
+ layout: { flow: "reverse", axis: "vertical" },
1374
+ label: "Part of",
1375
+ description: "A part of an aggregate points to its root.",
1376
+ inverseLabel: "Made up of",
1377
+ allowedPairs: [{ from: "entity", to: "entity" }],
1378
+ properties: [],
1379
+ color: "#7e22ce",
1380
+ builtin: true
1381
+ };
1382
+ const references = {
1383
+ id: "references",
1384
+ layout: { flow: "side", axis: "horizontal" },
1385
+ label: "References",
1386
+ description: "One aggregate refers to another by id.",
1387
+ inverseLabel: "Referenced by",
1388
+ allowedPairs: [{ from: "entity", to: "entity" }],
1389
+ properties: [
1390
+ {
1391
+ key: "cardinality",
1392
+ label: "Cardinality",
1393
+ type: "enum",
1394
+ options: ["one", "many"],
1395
+ default: "one"
1396
+ },
1397
+ { key: "description", label: "Description", type: "text" }
1398
+ ],
1399
+ color: "#a855f7",
1400
+ builtin: true
1401
+ };
1402
+ const ddPairs = [
1403
+ { from: "domain", to: "domain" }
1404
+ ];
1405
+ const dependsOn = {
1406
+ id: "depends-on",
1407
+ layout: { flow: "forward" },
1408
+ label: "Depends on",
1409
+ description: "The source domain needs the target to do its work.",
1410
+ inverseLabel: "Depended on by",
1411
+ allowedPairs: ddPairs,
1412
+ properties: [
1413
+ { key: "description", label: "Description", type: "text" }
1414
+ ],
1415
+ builtin: true
1416
+ };
1417
+ const partnership = {
1418
+ id: "partnership",
1419
+ layout: { flow: "side", axis: "horizontal" },
1420
+ label: "Partnership",
1421
+ description: "How the models of two domains meet, with a context-mapping pattern.",
1422
+ forwardLabel: "Partners with",
1423
+ inverseLabel: "Partners with",
1424
+ allowedPairs: ddPairs,
1425
+ properties: [
1426
+ {
1427
+ key: "pattern",
1428
+ label: "Pattern",
1429
+ type: "enum",
1430
+ options: [
1431
+ "partnership",
1432
+ "shared-kernel",
1433
+ "customer-supplier",
1434
+ "conformist",
1435
+ "anti-corruption-layer",
1436
+ "open-host-service",
1437
+ "published-language",
1438
+ "separate-ways"
1439
+ ],
1440
+ default: "partnership"
1441
+ },
1442
+ { key: "description", label: "Description", type: "text" }
1443
+ ],
1444
+ builtin: true
1445
+ };
1446
+ return {
1447
+ id: "c4-ddd-builtin",
1448
+ name: "C4 + DDD Domains",
1449
+ nodeTypes: {
1450
+ ...base.nodeTypes,
1451
+ system: patchedSystem,
1452
+ domain,
1453
+ entity
1454
+ },
1455
+ relationTypes: {
1456
+ ...base.relationTypes,
1457
+ realises,
1458
+ "part-of": partOf,
1459
+ references,
1460
+ "depends-on": dependsOn,
1461
+ partnership
1462
+ }
1463
+ };
1464
+ }
1465
+
1466
+ // ../../packages/common/src/metamodel/presets/governance.ts
1467
+ var RADICAL_METAMODEL_NAME = "Radical";
1468
+ var TESTS_PROPERTY = {
1469
+ key: "tests",
1470
+ label: "Tests (one per line: file \u203A title)",
1471
+ type: "textarea"
1472
+ };
1473
+ function builtInGovernanceMetamodel() {
1474
+ const base = builtInDddC4Metamodel();
1475
+ const adrProps = [
1476
+ {
1477
+ key: "status",
1478
+ label: "Status",
1479
+ type: "enum",
1480
+ options: ["proposed", "accepted", "deprecated", "superseded"],
1481
+ default: "proposed"
1482
+ },
1483
+ { key: "date", label: "Date", type: "text" },
1484
+ { key: "context", label: "Context", type: "textarea" },
1485
+ { key: "decision", label: "Decision", type: "textarea" },
1486
+ { key: "consequences", label: "Consequences", type: "textarea" },
1487
+ { key: "alternatives", label: "Alternatives considered", type: "textarea" },
1488
+ // The Hub concern pack the decision settles (its concern id), for the
1489
+ // check's concern-unaddressed rule; set by a pack's import.
1490
+ { key: "concern", label: "Concern (Hub)", type: "text" }
1491
+ ];
1492
+ const adr = {
1493
+ id: "adr",
1494
+ layout: { role: "note", side: "left" },
1495
+ label: "ADR",
1496
+ description: "An architecture decision record: the context of a decision, the decision itself, its consequences and the alternatives that were considered.",
1497
+ color: "#92400e",
1498
+ fg: "#fff",
1499
+ // ADR: document with text lines
1500
+ iconPath: "M4.5 1C3.67 1 3 1.67 3 2.5v11c0 .83.67 1.5 1.5 1.5h7c.83 0 1.5-.67 1.5-1.5V6L9 1H4.5ZM9 2l3 3.5H9V2ZM5 8h6v1H5V8Zm0 2.5h6v1H5v-1Zm0 2.5h3.5v1H5V13Z",
1501
+ width: 180,
1502
+ height: 52,
1503
+ collapsedWidth: 160,
1504
+ collapsedHeight: 52,
1505
+ allowedParents: ["system", "domain", "group"],
1506
+ allowedAtRoot: true,
1507
+ builtin: true,
1508
+ properties: adrProps,
1509
+ wizard: {
1510
+ trigger: "create",
1511
+ prefill: { status: "proposed", date: "{{today}}" },
1512
+ steps: [
1513
+ {
1514
+ kind: "fields",
1515
+ title: "Title & status",
1516
+ fields: ["label", "status", "date"],
1517
+ help: 'Name the decision in a few words, e.g. "Use PostgreSQL for order storage".'
1518
+ },
1519
+ {
1520
+ kind: "fields",
1521
+ title: "Context",
1522
+ fields: ["context"],
1523
+ help: "What forces are at play \u2014 the problem, constraints and drivers that make a decision necessary now?"
1524
+ },
1525
+ {
1526
+ kind: "fields",
1527
+ title: "Decision",
1528
+ fields: ["decision"],
1529
+ help: 'What did you decide? State it actively: "We will \u2026".'
1530
+ },
1531
+ {
1532
+ kind: "fields",
1533
+ title: "Alternatives",
1534
+ fields: ["alternatives"],
1535
+ help: "Which other options did you consider, and why were they rejected?"
1536
+ },
1537
+ {
1538
+ kind: "fields",
1539
+ title: "Consequences",
1540
+ fields: ["consequences"],
1541
+ help: "What becomes easier or harder? Include the downsides and the risks you accept."
1542
+ },
1543
+ {
1544
+ kind: "relations",
1545
+ title: "Affected elements",
1546
+ relationType: "constrains",
1547
+ direction: "out",
1548
+ help: "Which parts of the architecture must follow this decision?"
1549
+ },
1550
+ {
1551
+ kind: "relations",
1552
+ title: "Supersedes",
1553
+ relationType: "supersedes",
1554
+ direction: "out",
1555
+ help: "Does this decision replace an earlier one? Leave empty if not."
1556
+ }
1557
+ ]
1558
+ }
1559
+ };
1560
+ const fitnessFnProps = [
1561
+ { key: "description", label: "Description", type: "textarea" },
1562
+ {
1563
+ key: "category",
1564
+ label: "Category",
1565
+ type: "enum",
1566
+ options: ["structural", "operational", "process", "holistic"],
1567
+ default: "structural"
1568
+ },
1569
+ { key: "threshold", label: "Threshold / Success criteria", type: "text" },
1570
+ TESTS_PROPERTY
1571
+ ];
1572
+ const fitnessFn = {
1573
+ id: "fitness-fn",
1574
+ layout: { role: "note", side: "left" },
1575
+ label: "Fitness Function",
1576
+ description: "An objective, preferably automated check that the architecture still has a property it was designed for.",
1577
+ color: "#5b21b6",
1578
+ fg: "#fff",
1579
+ // Concentric circles (target / gauge)
1580
+ iconPath: "M8 2a6 6 0 1 0 0 12A6 6 0 0 0 8 2Zm0 1.5a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9ZM8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5Zm0 1a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3Z",
1581
+ width: 180,
1582
+ height: 52,
1583
+ collapsedWidth: 160,
1584
+ collapsedHeight: 52,
1585
+ allowedParents: ["system", "domain", "group"],
1586
+ allowedAtRoot: true,
1587
+ builtin: true,
1588
+ properties: fitnessFnProps,
1589
+ wizard: {
1590
+ trigger: "create",
1591
+ steps: [
1592
+ {
1593
+ kind: "fields",
1594
+ title: "Name & category",
1595
+ fields: ["label", "category"],
1596
+ help: 'Name the architectural characteristic this function protects, e.g. "Checkout p95 latency".'
1597
+ },
1598
+ {
1599
+ kind: "fields",
1600
+ title: "What it measures",
1601
+ fields: ["description"],
1602
+ help: "How is the characteristic measured \u2014 a test, a metric, a static check?"
1603
+ },
1604
+ {
1605
+ kind: "fields",
1606
+ title: "Success criteria",
1607
+ fields: ["threshold"],
1608
+ help: 'When does it pass? Give a concrete threshold, e.g. "p95 < 300 ms".'
1609
+ },
1610
+ {
1611
+ kind: "relations",
1612
+ title: "Verified decisions",
1613
+ relationType: "implements",
1614
+ direction: "out",
1615
+ help: "Which ADRs does this fitness function verify?"
1616
+ },
1617
+ {
1618
+ kind: "relations",
1619
+ title: "Guarded elements",
1620
+ relationType: "constrains",
1621
+ direction: "out",
1622
+ help: "Which elements does it check?"
1623
+ }
1624
+ ]
1625
+ }
1626
+ };
1627
+ const needProps = [
1628
+ { key: "description", label: "Text", type: "textarea" },
1629
+ {
1630
+ key: "kind",
1631
+ label: "Kind",
1632
+ type: "enum",
1633
+ options: ["brief", "user-story", "stakeholder-note", "meeting-notes", "regulation", "other"],
1634
+ default: "brief"
1635
+ },
1636
+ { key: "source", label: "Source (who / where from)", type: "text" }
1637
+ ];
1638
+ const need = {
1639
+ id: "need",
1640
+ layout: { role: "element" },
1641
+ label: "Need",
1642
+ description: "Raw input in the stakeholder's own words, kept verbatim: a brief, a user story, a note, a regulation.",
1643
+ color: "#475569",
1644
+ fg: "#fff",
1645
+ // Speech bubble with text lines
1646
+ iconPath: "M3 2a1.5 1.5 0 0 0-1.5 1.5v7A1.5 1.5 0 0 0 3 12h1.5v2.5L8 12h5a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13 2H3Zm1.5 3h7v1h-7V5Zm0 2.5h5v1h-5v-1Z",
1647
+ width: 200,
1648
+ height: 80,
1649
+ collapsedWidth: 180,
1650
+ collapsedHeight: 80,
1651
+ allowedParents: ["system", "domain", "group"],
1652
+ allowedAtRoot: true,
1653
+ builtin: true,
1654
+ // A need's wiki page and table tab list what derives from it — sub-needs
1655
+ // and requirements — as its children; "add child" creates either.
1656
+ hierarchyRelation: "derives",
1657
+ properties: needProps,
1658
+ wizard: {
1659
+ trigger: "create",
1660
+ steps: [
1661
+ {
1662
+ kind: "fields",
1663
+ title: "Name & kind",
1664
+ fields: ["label", "kind"],
1665
+ help: 'A short name, e.g. "Checkout brief from Sales". Pick what kind of input it is.'
1666
+ },
1667
+ {
1668
+ kind: "fields",
1669
+ title: "Text",
1670
+ fields: ["description"],
1671
+ help: "Paste the input as-is \u2014 a brief, user story, notes or raw requirements. No format needed; Radical Forge or you can turn it into EARS requirements later."
1672
+ },
1673
+ {
1674
+ kind: "fields",
1675
+ title: "Source",
1676
+ fields: ["source"],
1677
+ help: "Who it came from or where it lives (a person, meeting, ticket or link)."
1678
+ },
1679
+ {
1680
+ kind: "relations",
1681
+ title: "Part of",
1682
+ relationType: "derives",
1683
+ direction: "out",
1684
+ help: "Is this part of a broader need, e.g. one stakeholder's notes within a discovery? Leave empty if not."
1685
+ }
1686
+ ]
1687
+ }
1688
+ };
1689
+ const requirementProps = [
1690
+ {
1691
+ key: "ears_type",
1692
+ label: "EARS type",
1693
+ type: "enum",
1694
+ options: ["ubiquitous", "event-driven", "state-driven", "unwanted-behaviour", "optional", "complex"],
1695
+ default: "ubiquitous"
1696
+ },
1697
+ { key: "trigger", label: "When (trigger)", type: "text", visibleWhen: { key: "ears_type", values: ["event-driven", "complex"] } },
1698
+ { key: "precondition", label: "While (precondition)", type: "text", visibleWhen: { key: "ears_type", values: ["state-driven", "complex"] } },
1699
+ // The state the precondition is, when it is one of a state machine's:
1700
+ // "While the Reservation is Confirmed". Takes the place of the text.
1701
+ { key: "precondition_state", label: "While in state", type: "ref", refType: "state", visibleWhen: { key: "ears_type", values: ["state-driven", "complex"] } },
1702
+ { key: "unwanted_condition", label: "If (unwanted condition)", type: "text", visibleWhen: { key: "ears_type", values: ["unwanted-behaviour", "complex"] } },
1703
+ { key: "feature", label: "Where (feature)", type: "text", visibleWhen: { key: "ears_type", values: ["optional", "complex"] } },
1704
+ { key: "action", label: "The system shall (action)", type: "textarea" },
1705
+ { key: "rationale", label: "Rationale", type: "textarea" }
1706
+ ];
1707
+ const requirement = {
1708
+ id: "requirement",
1709
+ layout: { role: "note", side: "left" },
1710
+ label: "Requirement",
1711
+ description: "One thing the system shall do, written as an EARS sentence.",
1712
+ color: "#0e7490",
1713
+ fg: "#fff",
1714
+ // Checklist / clipboard with checkmark
1715
+ iconPath: "M5 1a1 1 0 0 0-1 1H3a1 1 0 0 0-1 1v11a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1h-1a1 1 0 0 0-1-1H5Zm0 1h6v1H5V2ZM4 5.5h1.5v1.5H4V5.5Zm3 .25h5v1H7v-1ZM4 9h1.5v1.5H4V9Zm3 .25h5v1H7v-1Z",
1716
+ width: 200,
1717
+ height: 80,
1718
+ collapsedWidth: 180,
1719
+ collapsedHeight: 80,
1720
+ allowedParents: ["system", "domain", "group"],
1721
+ allowedAtRoot: true,
1722
+ builtin: true,
1723
+ hierarchyRelation: "derives",
1724
+ properties: requirementProps,
1725
+ wizard: {
1726
+ trigger: "create",
1727
+ steps: [
1728
+ {
1729
+ kind: "fields",
1730
+ title: "Name",
1731
+ fields: ["label"],
1732
+ help: 'A short name for the requirement, e.g. "Lock account after failed logins".'
1733
+ },
1734
+ {
1735
+ kind: "custom",
1736
+ title: "Sentence",
1737
+ component: "ears-quick-entry",
1738
+ help: "Type the requirement as one sentence and press Enter \u2014 the EARS fields are filled for you. Or skip and fill them in the next step."
1739
+ },
1740
+ {
1741
+ kind: "fields",
1742
+ title: "EARS fields",
1743
+ fields: ["ears_type", "trigger", "precondition", "precondition_state", "unwanted_condition", "feature", "action"],
1744
+ help: "Pick the EARS pattern; only the clauses it uses are shown."
1745
+ },
1746
+ {
1747
+ kind: "fields",
1748
+ title: "Rationale",
1749
+ fields: ["rationale"],
1750
+ help: "Why is this requirement needed? Who asked for it?"
1751
+ },
1752
+ {
1753
+ kind: "relations",
1754
+ title: "Satisfied by",
1755
+ relationType: "satisfies",
1756
+ direction: "in",
1757
+ help: "Which elements must satisfy this requirement?"
1758
+ },
1759
+ {
1760
+ kind: "relations",
1761
+ title: "Derives from",
1762
+ relationType: "derives",
1763
+ direction: "out",
1764
+ help: "Is this a refinement of a broader requirement, or derived from a need?"
1765
+ },
1766
+ {
1767
+ kind: "relations",
1768
+ title: "Traces to",
1769
+ relationType: "traces-to",
1770
+ direction: "out",
1771
+ help: "Which decisions or fitness functions follow from it?"
1772
+ }
1773
+ ]
1774
+ }
1775
+ };
1776
+ const constraintSources = ["adr", "fitness-fn", "requirement"];
1777
+ const constraintTargets = ["person", "system", "domain", "container", "component", "database", "webapp", "queue"];
1778
+ const constrainsPairs = constraintSources.flatMap(
1779
+ (from) => constraintTargets.map((to) => ({ from, to }))
1780
+ );
1781
+ const constrains = {
1782
+ id: "constrains",
1783
+ layout: { flow: "side" },
1784
+ label: "Constrains",
1785
+ description: "The decision, check or requirement applies to the target element.",
1786
+ inverseLabel: "Constrained by",
1787
+ allowedPairs: constrainsPairs,
1788
+ properties: [
1789
+ { key: "description", label: "Note", type: "text" }
1790
+ ],
1791
+ color: "#dc2626",
1792
+ governance: true,
1793
+ builtin: true
1794
+ };
1795
+ const supersedes = {
1796
+ id: "supersedes",
1797
+ layout: { flow: "forward" },
1798
+ label: "Supersedes",
1799
+ description: "The newer decision replaces the older one.",
1800
+ inverseLabel: "Superseded by",
1801
+ allowedPairs: [{ from: "adr", to: "adr" }],
1802
+ properties: [],
1803
+ color: "#f59e0b",
1804
+ governance: true,
1805
+ builtin: true
1806
+ };
1807
+ const implements_ = {
1808
+ id: "implements",
1809
+ layout: { flow: "side" },
1810
+ label: "Implements",
1811
+ description: "A fitness function checks that a decision still holds; a C4 element runs a state machine.",
1812
+ inverseLabel: "Implemented by",
1813
+ allowedPairs: [{ from: "fitness-fn", to: "adr" }],
1814
+ properties: [],
1815
+ color: "#7c3aed",
1816
+ governance: true,
1817
+ builtin: true
1818
+ };
1819
+ const satisfiesTargets = ["person", "system", "domain", "container", "component", "database", "webapp", "queue"];
1820
+ const satisfies = {
1821
+ id: "satisfies",
1822
+ layout: { flow: "side" },
1823
+ label: "Satisfies",
1824
+ description: "The element is what makes the requirement true.",
1825
+ inverseLabel: "Satisfied by",
1826
+ allowedPairs: satisfiesTargets.map((to) => ({ from: to, to: "requirement" })),
1827
+ properties: [
1828
+ { key: "description", label: "Note", type: "text" }
1829
+ ],
1830
+ color: "#0891b2",
1831
+ governance: true,
1832
+ builtin: true
1833
+ };
1834
+ const derives = {
1835
+ id: "derives",
1836
+ layout: { flow: "reverse", axis: "vertical" },
1837
+ label: "Derives from",
1838
+ description: "A requirement turns stakeholder input into a shall-statement or refines a broader requirement; a need sits inside a broader need.",
1839
+ inverseLabel: "Refined into",
1840
+ allowedPairs: [
1841
+ { from: "requirement", to: "requirement" },
1842
+ { from: "requirement", to: "need" },
1843
+ { from: "need", to: "need" }
1844
+ ],
1845
+ properties: [],
1846
+ color: "#0d9488",
1847
+ governance: true,
1848
+ builtin: true
1849
+ };
1850
+ const tracesTo = {
1851
+ id: "traces-to",
1852
+ layout: { flow: "reverse", axis: "vertical" },
1853
+ label: "Traces to",
1854
+ description: "The decision the requirement led to, or the check that keeps it.",
1855
+ inverseLabel: "Traced from",
1856
+ allowedPairs: [
1857
+ { from: "requirement", to: "adr" },
1858
+ { from: "requirement", to: "fitness-fn" }
1859
+ ],
1860
+ properties: [],
1861
+ color: "#06b6d4",
1862
+ governance: true,
1863
+ builtin: true
1864
+ };
1865
+ const scenarioProps = [
1866
+ { key: "given", label: "Given", type: "textarea" },
1867
+ { key: "when", label: "When", type: "textarea" },
1868
+ { key: "then", label: "Then", type: "textarea" },
1869
+ { key: "gherkin", label: "Extra steps (And/But, raw Gherkin)", type: "textarea" },
1870
+ TESTS_PROPERTY
1871
+ ];
1872
+ const scenario = {
1873
+ id: "scenario",
1874
+ layout: { role: "note", side: "left" },
1875
+ label: "Scenario",
1876
+ description: "An acceptance example in Gherkin: given a starting situation, when something happens, then the outcome.",
1877
+ color: "#166534",
1878
+ fg: "#fff",
1879
+ // Play/run triangle in a rounded frame
1880
+ iconPath: "M3 2a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1H3Zm3.5 2.5 5 3.5-5 3.5v-7Z",
1881
+ width: 200,
1882
+ height: 80,
1883
+ collapsedWidth: 180,
1884
+ collapsedHeight: 80,
1885
+ allowedParents: ["system", "domain", "group"],
1886
+ allowedAtRoot: true,
1887
+ builtin: true,
1888
+ properties: scenarioProps,
1889
+ wizard: {
1890
+ trigger: "create",
1891
+ steps: [
1892
+ {
1893
+ kind: "fields",
1894
+ title: "Name",
1895
+ fields: ["label"],
1896
+ help: 'Name the behaviour, e.g. "Card payment declined".'
1897
+ },
1898
+ {
1899
+ kind: "fields",
1900
+ title: "Given",
1901
+ fields: ["given"],
1902
+ help: "The starting state: who is involved and what is already true."
1903
+ },
1904
+ {
1905
+ kind: "fields",
1906
+ title: "When",
1907
+ fields: ["when"],
1908
+ help: "The single action or event under test."
1909
+ },
1910
+ {
1911
+ kind: "fields",
1912
+ title: "Then",
1913
+ fields: ["then", "gherkin"],
1914
+ help: "The observable outcome. Add And/But steps below if needed."
1915
+ },
1916
+ {
1917
+ kind: "relations",
1918
+ title: "Verified requirements",
1919
+ relationType: "verifies",
1920
+ direction: "out",
1921
+ help: "Which requirements does this scenario verify?"
1922
+ }
1923
+ ]
1924
+ }
1925
+ };
1926
+ const verifiesTargets = ["requirement"];
1927
+ const verifies = {
1928
+ id: "verifies",
1929
+ layout: { flow: "reverse", axis: "vertical" },
1930
+ label: "Verifies",
1931
+ description: "The scenario is the acceptance test of the requirement or state machine.",
1932
+ inverseLabel: "Verified by",
1933
+ allowedPairs: verifiesTargets.map((to) => ({ from: "scenario", to })),
1934
+ properties: [],
1935
+ color: "#16a34a",
1936
+ governance: true,
1937
+ builtin: true
1938
+ };
1939
+ const blueprintProps = [
1940
+ { key: "description", label: "Description", type: "textarea" },
1941
+ {
1942
+ key: "status",
1943
+ label: "Status",
1944
+ type: "enum",
1945
+ options: ["draft", "reviewed", "approved", "deprecated"],
1946
+ default: "draft"
1947
+ },
1948
+ { key: "domain", label: "Domain / Context", type: "text" },
1949
+ { key: "rationale", label: "Rationale", type: "textarea" }
1950
+ ];
1951
+ const blueprint = {
1952
+ id: "blueprint",
1953
+ layout: { role: "element" },
1954
+ label: "Blueprint",
1955
+ description: "A curated reference architecture imported from the Concept Hub.",
1956
+ color: "#1e3a5f",
1957
+ fg: "#fff",
1958
+ // Blueprint grid / technical drawing
1959
+ iconPath: "M2 2h12v12H2V2Zm1 1v2h2V3H3Zm3 0v2h2V3H6Zm3 0v2h2V3H9Zm3 0v2h1V3h-1ZM3 6v2h2V6H3Zm3 0v2h2V6H6Zm3 0v2h2V6H9Zm3 0v2h1V6h-1ZM3 9v2h2V9H3Zm3 0v2h2V9H6Zm3 0v2h2V9H9Zm3 0v2h1V9h-1ZM3 12v1h2v-1H3Zm3 0v1h2v-1H6Zm3 0v1h2v-1H9Zm3 0v1h1v-1h-1Z",
1960
+ width: 520,
1961
+ height: 360,
1962
+ collapsedWidth: 360,
1963
+ collapsedHeight: 220,
1964
+ allowedParents: ["domain", "group"],
1965
+ allowedAtRoot: true,
1966
+ builtin: true,
1967
+ hubOnly: true,
1968
+ properties: blueprintProps
1969
+ };
1970
+ const mockupProps = [
1971
+ { key: "description", label: "Description", type: "textarea" },
1972
+ { key: "screen", label: "Screen / route", type: "text" },
1973
+ { key: "link", label: "Design link", type: "text" }
1974
+ ];
1975
+ const mockup = {
1976
+ id: "mockup",
1977
+ layout: { role: "screen" },
1978
+ label: "Mockup",
1979
+ description: "One screen of the product, optionally with a low-fi wireframe.",
1980
+ color: "#be185d",
1981
+ fg: "#fff",
1982
+ // Browser window with a header bar and content blocks
1983
+ iconPath: "M2 2.5A1.5 1.5 0 0 1 3.5 1h9A1.5 1.5 0 0 1 14 2.5v11a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 13.5v-11ZM3 5v8.5c0 .28.22.5.5.5h9a.5.5 0 0 0 .5-.5V5H3Zm1 1.5h8v2H4v-2Zm0 3h3.5V13H4V9.5Zm4.5 0H12v1H8.5v-1Zm0 2H12v1H8.5v-1Z",
1984
+ width: 220,
1985
+ height: 190,
1986
+ collapsedWidth: 220,
1987
+ collapsedHeight: 190,
1988
+ allowedParents: ["system", "domain", "group"],
1989
+ allowedAtRoot: true,
1990
+ builtin: true,
1991
+ properties: mockupProps,
1992
+ wizard: {
1993
+ trigger: "create",
1994
+ steps: [
1995
+ {
1996
+ kind: "fields",
1997
+ title: "Screen",
1998
+ fields: ["label", "screen", "description"],
1999
+ help: "Which screen is this, and what does the user do on it?"
2000
+ },
2001
+ {
2002
+ kind: "fields",
2003
+ title: "Design link",
2004
+ fields: ["link"],
2005
+ help: "A Figma / Penpot link, if the design exists. You can generate a wireframe from the properties panel later."
2006
+ },
2007
+ {
2008
+ kind: "relations",
2009
+ title: "Illustrates",
2010
+ relationType: "illustrates",
2011
+ direction: "out",
2012
+ help: "Which requirements or scenarios does this screen show?"
2013
+ },
2014
+ {
2015
+ kind: "relations",
2016
+ title: "Presented by",
2017
+ relationType: "presented-by",
2018
+ direction: "out",
2019
+ help: "Which part of the system renders it?"
2020
+ }
2021
+ ]
2022
+ }
2023
+ };
2024
+ const illustrates = {
2025
+ id: "illustrates",
2026
+ layout: { flow: "side" },
2027
+ label: "Illustrates",
2028
+ description: "The screen shows the requirement being met, the step of the scenario, or what the user sees in the state.",
2029
+ inverseLabel: "Illustrated by",
2030
+ allowedPairs: [
2031
+ { from: "mockup", to: "requirement" },
2032
+ { from: "mockup", to: "scenario" }
2033
+ ],
2034
+ properties: [],
2035
+ color: "#db2777",
2036
+ governance: true,
2037
+ builtin: true
2038
+ };
2039
+ const presentedBy = {
2040
+ id: "presented-by",
2041
+ layout: { flow: "side" },
2042
+ label: "Presented by",
2043
+ description: "The part of the architecture that renders the screen.",
2044
+ inverseLabel: "Presents",
2045
+ allowedPairs: ["webapp", "container", "component", "system"].map((to) => ({ from: "mockup", to })),
2046
+ properties: [],
2047
+ color: "#be185d",
2048
+ governance: true,
2049
+ builtin: true
2050
+ };
2051
+ const navigatesTo = {
2052
+ id: "navigates-to",
2053
+ layout: { flow: "forward", axis: "horizontal" },
2054
+ label: "Navigates to",
2055
+ description: "One step of a screen flow, with what triggers it.",
2056
+ inverseLabel: "Reached from",
2057
+ allowedPairs: [{ from: "mockup", to: "mockup" }],
2058
+ properties: [
2059
+ { key: "description", label: "Trigger", type: "text" }
2060
+ ],
2061
+ color: "#f472b6",
2062
+ builtin: true
2063
+ };
2064
+ const stateMachine = {
2065
+ id: "state-machine",
2066
+ layout: { role: "element" },
2067
+ label: "State Machine",
2068
+ description: "The lifecycle of one entity: the states it can be in and the transitions between them.",
2069
+ color: "#3730a3",
2070
+ fg: "#fff",
2071
+ // Two states joined by a transition
2072
+ iconPath: "M1 3.5A1.5 1.5 0 0 1 2.5 2h3A1.5 1.5 0 0 1 7 3.5v2A1.5 1.5 0 0 1 5.5 7h-3A1.5 1.5 0 0 1 1 5.5v-2Zm8 7A1.5 1.5 0 0 1 10.5 9h3a1.5 1.5 0 0 1 1.5 1.5v2a1.5 1.5 0 0 1-1.5 1.5h-3A1.5 1.5 0 0 1 9 12.5v-2ZM3.5 8h1v3h2.8v-1l2 1.5-2 1.5v-1H3.5V8Z",
2073
+ width: 560,
2074
+ height: 380,
2075
+ collapsedWidth: 200,
2076
+ collapsedHeight: 64,
2077
+ allowedParents: ["system", "domain", "group"],
2078
+ allowedAtRoot: true,
2079
+ builtin: true,
2080
+ properties: [
2081
+ { key: "description", label: "Description", type: "textarea" }
2082
+ ]
2083
+ };
2084
+ const state = {
2085
+ id: "state",
2086
+ layout: { role: "element", byProperty: { key: "kind", roles: { final: "end" } } },
2087
+ label: "State",
2088
+ description: "A situation the entity can be in.",
2089
+ color: "#4f46e5",
2090
+ fg: "#fff",
2091
+ // Rounded rectangle
2092
+ iconPath: "M3.5 3h9A2.5 2.5 0 0 1 15 5.5v5a2.5 2.5 0 0 1-2.5 2.5h-9A2.5 2.5 0 0 1 1 10.5v-5A2.5 2.5 0 0 1 3.5 3Zm0 1.5a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1h-9Z",
2093
+ width: 320,
2094
+ height: 220,
2095
+ collapsedWidth: 170,
2096
+ collapsedHeight: 72,
2097
+ allowedParents: ["state-machine", "state"],
2098
+ allowedAtRoot: false,
2099
+ builtin: true,
2100
+ properties: [
2101
+ {
2102
+ key: "kind",
2103
+ label: "Kind",
2104
+ type: "enum",
2105
+ options: ["normal", "parallel", "final"],
2106
+ default: "normal"
2107
+ },
2108
+ { key: "entry", label: "Entry actions", type: "text", visibleWhen: { key: "kind", values: ["normal", "parallel"] } },
2109
+ { key: "exit", label: "Exit actions", type: "text", visibleWhen: { key: "kind", values: ["normal", "parallel"] } },
2110
+ { key: "do", label: "Do (ongoing activity)", type: "text", visibleWhen: { key: "kind", values: ["normal"] } },
2111
+ { key: "description", label: "Description", type: "textarea" }
2112
+ ]
2113
+ };
2114
+ const pseudostate = {
2115
+ id: "pseudostate",
2116
+ layout: { role: "element", byProperty: { key: "kind", roles: { initial: "start" } } },
2117
+ label: "Pseudostate",
2118
+ description: "A point a state machine passes through but never rests in: where it starts, a choice, a history.",
2119
+ color: "#1e1b4b",
2120
+ fg: "#fff",
2121
+ // Filled dot (initial)
2122
+ iconPath: "M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Z",
2123
+ width: 36,
2124
+ height: 36,
2125
+ allowedParents: ["state-machine", "state"],
2126
+ allowedAtRoot: false,
2127
+ builtin: true,
2128
+ properties: [
2129
+ {
2130
+ key: "kind",
2131
+ label: "Kind",
2132
+ type: "enum",
2133
+ options: ["initial", "shallow-history", "deep-history", "choice"],
2134
+ default: "initial"
2135
+ }
2136
+ ]
2137
+ };
2138
+ const event = {
2139
+ id: "event",
2140
+ layout: { role: "note", side: "left" },
2141
+ label: "Event",
2142
+ description: "Something that happens and can trigger a transition.",
2143
+ color: "#c2410c",
2144
+ fg: "#fff",
2145
+ // Lightning bolt
2146
+ iconPath: "M9.5 1 3 9h4l-1 6 6.5-8h-4l1-6Z",
2147
+ width: 170,
2148
+ height: 52,
2149
+ allowedParents: ["state-machine", "system", "domain", "group"],
2150
+ allowedAtRoot: true,
2151
+ builtin: true,
2152
+ properties: [
2153
+ {
2154
+ key: "source",
2155
+ label: "Source",
2156
+ type: "enum",
2157
+ options: ["external", "internal", "timer"],
2158
+ default: "external"
2159
+ },
2160
+ { key: "payload", label: "Payload", type: "text" },
2161
+ { key: "description", label: "Description", type: "textarea" }
2162
+ ]
2163
+ };
2164
+ const stateNodeTypes = ["state", "pseudostate"];
2165
+ const transition = {
2166
+ id: "transition",
2167
+ layout: { flow: "forward", axis: "vertical" },
2168
+ label: "Transition",
2169
+ description: "The machine moves from one state to another: on an event, under a guard, running actions.",
2170
+ forwardLabel: "Transitions to",
2171
+ inverseLabel: "Entered from",
2172
+ allowedPairs: stateNodeTypes.flatMap((from) => stateNodeTypes.map((to) => ({ from, to }))),
2173
+ properties: [
2174
+ { key: "event", label: "Event (trigger; none = completion)", type: "ref", refType: "event" },
2175
+ { key: "guard", label: "Guard [condition]", type: "text" },
2176
+ { key: "actions", label: "Actions (/ effect)", type: "text" },
2177
+ { key: "raises", label: "Raises (events it publishes)", type: "ref", refType: "event", multiple: true },
2178
+ {
2179
+ key: "kind",
2180
+ label: "Kind",
2181
+ type: "enum",
2182
+ options: ["external", "internal"],
2183
+ default: "external"
2184
+ }
2185
+ ],
2186
+ color: "#6366f1",
2187
+ builtin: true
2188
+ };
2189
+ const lifecycleOf = {
2190
+ id: "lifecycle-of",
2191
+ layout: { flow: "side" },
2192
+ label: "Lifecycle of",
2193
+ description: "The machine is the lifecycle of that entity.",
2194
+ inverseLabel: "Lifecycle modelled by",
2195
+ allowedPairs: [{ from: "state-machine", to: "entity" }],
2196
+ properties: [],
2197
+ color: "#3730a3",
2198
+ builtin: true
2199
+ };
2200
+ const emits = {
2201
+ id: "emits",
2202
+ layout: { flow: "side" },
2203
+ label: "Emits",
2204
+ description: "The element raises the event.",
2205
+ inverseLabel: "Emitted by",
2206
+ allowedPairs: ["person", "system", "container", "component", "webapp", "queue", "state-machine", "state"].map((from) => ({ from, to: "event" })),
2207
+ properties: [
2208
+ {
2209
+ key: "on",
2210
+ label: "On (for a state: entry, exit or do)",
2211
+ type: "enum",
2212
+ options: ["entry", "exit", "do"],
2213
+ default: "entry"
2214
+ }
2215
+ ],
2216
+ color: "#ea580c",
2217
+ builtin: true
2218
+ };
2219
+ const childrenProperty = {
2220
+ key: "children",
2221
+ label: "Children run",
2222
+ type: "enum",
2223
+ options: ["sequence", "choice", "concurrent"],
2224
+ default: "sequence"
2225
+ };
2226
+ const process_ = {
2227
+ id: "process",
2228
+ layout: { role: "element" },
2229
+ label: "Process",
2230
+ description: "A procedure: the steps it is made of, what repeats and what is an alternative.",
2231
+ color: "#0f766e",
2232
+ fg: "#fff",
2233
+ // A brace with three lines
2234
+ iconPath: "M5 2c-1.1 0-2 .9-2 2v2.2c0 .5-.3.8-.8.8H1.5v2h.7c.5 0 .8.3.8.8V12c0 1.1.9 2 2 2h.5v-1.5H5c-.3 0-.5-.2-.5-.5V9.5c0-.9-.4-1.6-1-2 .6-.4 1-1.1 1-2V4c0-.3.2-.5.5-.5h.5V2H5Zm3 1.5h7V5H8V3.5Zm0 3.75h7v1.5H8v-1.5ZM8 11h7v1.5H8V11Z",
2235
+ width: 260,
2236
+ height: 160,
2237
+ collapsedWidth: 200,
2238
+ collapsedHeight: 64,
2239
+ allowedParents: ["system", "domain", "group"],
2240
+ allowedAtRoot: true,
2241
+ builtin: true,
2242
+ properties: [
2243
+ // Its place among the processes beside it, as a step's among steps.
2244
+ { key: "order", label: "Order", type: "number" },
2245
+ childrenProperty,
2246
+ { key: "description", label: "Description", type: "textarea" }
2247
+ ]
2248
+ };
2249
+ const step = {
2250
+ id: "step",
2251
+ layout: { role: "element" },
2252
+ label: "Step",
2253
+ description: "One part of a process, itself made of steps or not.",
2254
+ color: "#14b8a6",
2255
+ fg: "#042f2e",
2256
+ // An arrow into a box
2257
+ iconPath: "M2 4.5A1.5 1.5 0 0 1 3.5 3h9A1.5 1.5 0 0 1 14 4.5v7a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 11.5v-7Zm1.5 0v7h9v-7h-9Zm1 2.75h3.8V5.5L11 8l-2.7 2.5V8.75H4.5v-1.5Z",
2258
+ width: 220,
2259
+ height: 80,
2260
+ collapsedWidth: 180,
2261
+ collapsedHeight: 64,
2262
+ allowedParents: ["process", "step"],
2263
+ allowedAtRoot: false,
2264
+ builtin: true,
2265
+ properties: [
2266
+ { key: "order", label: "Order", type: "number" },
2267
+ {
2268
+ key: "repeat",
2269
+ label: "Repeat",
2270
+ type: "enum",
2271
+ options: ["1", "0..1", "1..n", "0..n"],
2272
+ default: "1"
2273
+ },
2274
+ { key: "condition", label: "Condition (for each\u2026, while\u2026, if\u2026)", type: "text" },
2275
+ childrenProperty,
2276
+ { key: "description", label: "Description", type: "textarea" }
2277
+ ]
2278
+ };
2279
+ const performedBy = {
2280
+ id: "performed-by",
2281
+ layout: { flow: "side" },
2282
+ label: "Performed by",
2283
+ description: "The person or part of the architecture that does the step.",
2284
+ inverseLabel: "Performs",
2285
+ allowedPairs: ["person", "system", "container", "component", "webapp"].map((to) => ({ from: "step", to })),
2286
+ properties: [],
2287
+ color: "#0d9488",
2288
+ builtin: true
2289
+ };
2290
+ implements_.allowedPairs.push(...["system", "container", "component", "webapp"].map((from) => ({ from, to: "state-machine" })));
2291
+ satisfies.allowedPairs.push({ from: "state-machine", to: "requirement" }, { from: "entity", to: "requirement" });
2292
+ verifies.allowedPairs.push({ from: "scenario", to: "state-machine" }, { from: "scenario", to: "process" });
2293
+ satisfies.allowedPairs.push({ from: "process", to: "requirement" });
2294
+ illustrates.allowedPairs.push({ from: "mockup", to: "state" });
2295
+ return {
2296
+ id: "c4-ddd-governance-builtin",
2297
+ name: RADICAL_METAMODEL_NAME,
2298
+ nodeTypes: {
2299
+ ...base.nodeTypes,
2300
+ adr,
2301
+ "fitness-fn": fitnessFn,
2302
+ need,
2303
+ requirement,
2304
+ scenario,
2305
+ blueprint,
2306
+ mockup,
2307
+ "state-machine": stateMachine,
2308
+ state,
2309
+ pseudostate,
2310
+ event,
2311
+ process: process_,
2312
+ step
2313
+ },
2314
+ relationTypes: {
2315
+ ...base.relationTypes,
2316
+ constrains,
2317
+ supersedes,
2318
+ implements: implements_,
2319
+ satisfies,
2320
+ derives,
2321
+ "traces-to": tracesTo,
2322
+ verifies,
2323
+ illustrates,
2324
+ "presented-by": presentedBy,
2325
+ "navigates-to": navigatesTo,
2326
+ transition,
2327
+ "lifecycle-of": lifecycleOf,
2328
+ emits,
2329
+ "performed-by": performedBy
2330
+ },
2331
+ viewpoints: radicalViewpoints()
2332
+ };
2333
+ }
2334
+
2335
+ // ../../packages/common/src/metamodel/layoutHints.ts
2336
+ var preset = null;
2337
+ var presetHints = () => preset ??= builtInGovernanceMetamodel();
2338
+ function nodeLayoutHint(typeId, mm) {
2339
+ return mm?.nodeTypes[typeId]?.layout ?? presetHints().nodeTypes[typeId]?.layout ?? {};
2340
+ }
2341
+ function layoutRoleOf(node, mm) {
2342
+ const hint = nodeLayoutHint(node.type, mm);
2343
+ if (hint.byProperty) {
2344
+ const value = node[hint.byProperty.key];
2345
+ const byValue = typeof value === "string" ? hint.byProperty.roles[value] : void 0;
2346
+ if (byValue) return byValue;
2347
+ }
2348
+ return hint.role ?? "element";
2349
+ }
2350
+ var FORWARD = { flow: "forward", axis: "free" };
2351
+ function relationLayoutHint(typeId, mm) {
2352
+ if (!typeId) return FORWARD;
2353
+ const hint = mm?.relationTypes[typeId]?.layout ?? presetHints().relationTypes[typeId]?.layout;
2354
+ return hint ? { axis: "free", ...hint } : FORWARD;
2355
+ }
2356
+ var LAYOUT_ROLES = ["element", "actor", "store", "note", "start", "end", "broker", "screen"];
2357
+ var LAYOUT_FLOWS = ["forward", "reverse", "side"];
2358
+ var LAYOUT_AXES = ["free", "vertical", "horizontal"];
2359
+
2360
+ // ../../packages/common/src/metamodel/presets/index.ts
2361
+ init_define_RADICAL_BUILD();
2362
+
2363
+ // ../../packages/common/src/c4.ts
2364
+ var CONTAINER_TYPES = /* @__PURE__ */ new Set([
2365
+ "system",
2366
+ "container",
2367
+ "webapp",
2368
+ "domain",
2369
+ "group",
2370
+ "blueprint",
2371
+ "state-machine",
2372
+ "state",
2373
+ "process",
2374
+ "step"
2375
+ ]);
2376
+ function isContainerType(type) {
2377
+ return !!type && CONTAINER_TYPES.has(type);
2378
+ }
2379
+ function isBackwardStep(sequence, i) {
2380
+ return sequence?.stepBackward?.[i] === true;
2381
+ }
2382
+ function trimStepBackward(flags) {
2383
+ const out = Array.from(flags ?? [], (flag) => flag === true);
2384
+ while (out.length > 0 && !out[out.length - 1]) out.pop();
2385
+ return out.length ? out : void 0;
2386
+ }
2387
+ function pinnedNodeIds(constraints) {
2388
+ return constraints?.find((c) => c.type === "pin")?.nodeIds ?? [];
2389
+ }
2390
+ function defaultGridColumns(count) {
2391
+ return Math.max(1, Math.ceil(Math.sqrt(count)));
2392
+ }
2393
+ var LANDSCAPE_WIDTH = 2;
2394
+ function landscapeSlot(index) {
2395
+ if (index <= 0) return { column: 0, row: 0 };
2396
+ let columns = 1;
2397
+ let rows = 1;
2398
+ let filled = 1;
2399
+ for (; ; ) {
2400
+ if (columns < LANDSCAPE_WIDTH * rows) {
2401
+ if (index < filled + rows) return { column: columns, row: index - filled };
2402
+ filled += rows;
2403
+ columns++;
2404
+ } else {
2405
+ if (index < filled + columns) return { column: index - filled, row: rows };
2406
+ filled += columns;
2407
+ rows++;
2408
+ }
2409
+ }
2410
+ }
2411
+ function landscapeGridColumns(count) {
2412
+ let columns = 1;
2413
+ for (let i = 0; i < count; i++) columns = Math.max(columns, landscapeSlot(i).column + 1);
2414
+ return columns;
2415
+ }
2416
+ function gridCells(c) {
2417
+ const cols = Math.max(1, Math.min(Math.floor(c.columns), c.nodeIds.length));
2418
+ const rows = [];
2419
+ for (let i = 0; i < c.nodeIds.length; i += cols) rows.push(c.nodeIds.slice(i, i + cols));
2420
+ const columns = [];
2421
+ for (let k = 0; k < cols; k++) columns.push(c.nodeIds.filter((_, i) => i % cols === k));
2422
+ return { rows, columns };
2423
+ }
2424
+ function constraintLines(constraints) {
2425
+ return constraints.flatMap((c) => {
2426
+ if (c.type === "align") return [c];
2427
+ if (c.type === "pin") return [];
2428
+ const { rows, columns } = gridCells(c);
2429
+ return [
2430
+ ...rows.map((ids, r) => ({ id: `${c.id}:row${r}`, type: "align", axis: "horizontal", nodeIds: ids, ordered: true })),
2431
+ ...columns.map((ids, k) => ({ id: `${c.id}:col${k}`, type: "align", axis: "vertical", nodeIds: ids, ordered: true }))
2432
+ ];
2433
+ });
2434
+ }
2435
+ function slideWithoutMilestone(slide) {
2436
+ return { id: slide.id, name: slide.name, snapshotId: null, viewId: slide.viewId ?? null, viewport: { x: 0, y: 0, zoom: 0 } };
2437
+ }
2438
+ var BUILTIN_NODE_TYPES = builtInGovernanceMetamodel().nodeTypes;
2439
+ function pluckPerType(fn) {
2440
+ const out = {};
2441
+ for (const [id, def] of Object.entries(BUILTIN_NODE_TYPES)) {
2442
+ out[id] = fn(def);
2443
+ }
2444
+ return out;
2445
+ }
2446
+ var NODE_SIZES = pluckPerType((def) => ({ width: def.width, height: def.height }));
2447
+ function nodeTypeSize(type, metamodel) {
2448
+ const def = metamodel?.nodeTypes[type];
2449
+ const builtIn = NODE_SIZES[type];
2450
+ return {
2451
+ width: def?.width ?? builtIn?.width ?? 160,
2452
+ height: def?.height ?? builtIn?.height ?? 90
2453
+ };
2454
+ }
2455
+ var COLLAPSED_HEIGHT = pluckPerType((def) => def.collapsedHeight ?? def.height);
2456
+ var COLLAPSED_WIDTH = pluckPerType((def) => def.collapsedWidth ?? def.width);
2457
+ var NODE_COLORS = pluckPerType((def) => def.color);
2458
+ var NODE_FG = pluckPerType((def) => def.fg);
2459
+ var TYPE_LABELS = pluckPerType((def) => def.label);
2460
+ var TYPE_ICON_PATHS = pluckPerType((def) => def.iconPath);
2461
+ function normalizeViewFolder(folder) {
2462
+ return (folder ?? "").split("/").map((part) => part.trim()).filter(Boolean).join("/");
2463
+ }
2464
+ function viewFolderPaths(views) {
2465
+ const paths = /* @__PURE__ */ new Set();
2466
+ for (const view of views) {
2467
+ const parts = normalizeViewFolder(view.folder).split("/").filter(Boolean);
2468
+ for (let i = 1; i <= parts.length; i++) paths.add(parts.slice(0, i).join("/"));
2469
+ }
2470
+ return [...paths].sort((a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" }));
2471
+ }
2472
+ var WIKI_DEPTH_MIN = 1;
2473
+ var WIKI_DEPTH_MAX = 5;
2474
+ function wikiDepthOf(view) {
2475
+ const d = view?.wikiDepth;
2476
+ if (typeof d !== "number" || !Number.isFinite(d)) return WIKI_DEPTH_MIN;
2477
+ return Math.min(WIKI_DEPTH_MAX, Math.max(WIKI_DEPTH_MIN, Math.floor(d)));
2478
+ }
2479
+ function holderOf(nodes, a, b) {
2480
+ const holds = (outer, inner) => {
2481
+ const seen = /* @__PURE__ */ new Set();
2482
+ for (let id = inner.parentId; id && !seen.has(id); id = nodes[id]?.parentId) {
2483
+ if (id === outer.id) return true;
2484
+ seen.add(id);
2485
+ }
2486
+ return false;
2487
+ };
2488
+ return holds(a, b) ? a : holds(b, a) ? b : void 0;
2489
+ }
2490
+ function viewShowsEveryNode(view) {
2491
+ return view.nodeIds.length === 0 && !view.empty;
2492
+ }
2493
+ function viewCanvasPositions(view, nodes, positions, drawn) {
2494
+ if (view.kind === "explore") return Object.fromEntries(view.nodeIds.filter((id) => id in positions && nodes[id]).map((id) => [id, positions[id]]));
2495
+ if (view.kind && view.kind !== "static") positions = view.positions ?? {};
2496
+ const ids = drawn ?? (viewShowsEveryNode(view) ? void 0 : view.nodeIds);
2497
+ if (!ids) return positions;
2498
+ const kept = {};
2499
+ const seen = /* @__PURE__ */ new Set();
2500
+ for (const id of ids) {
2501
+ for (let cur = id; cur && nodes[cur] && !seen.has(cur); cur = nodes[cur].parentId) {
2502
+ seen.add(cur);
2503
+ if (cur in positions) kept[cur] = positions[cur];
2504
+ }
2505
+ }
2506
+ return kept;
2507
+ }
2508
+ function withCanvasPositions(views, nodes, drawnOf) {
2509
+ return views.map((view) => {
2510
+ const kept = viewCanvasPositions(view, nodes, view.positions ?? {}, drawnOf?.(view));
2511
+ return view.positions && Object.keys(kept).length === Object.keys(view.positions).length ? view : { ...view, positions: kept };
2512
+ });
2513
+ }
2514
+ function removeFromViewList(view, removed) {
2515
+ if (view.nodeIds.length === 0) return;
2516
+ view.nodeIds = view.nodeIds.filter((nid) => !removed.has(nid));
2517
+ if (view.nodeIds.length === 0) view.empty = true;
2518
+ }
2519
+ function addToViewList(view, ids) {
2520
+ if (viewShowsEveryNode(view)) return;
2521
+ for (const id of ids) if (!view.nodeIds.includes(id)) view.nodeIds.push(id);
2522
+ if (view.nodeIds.length > 0) delete view.empty;
2523
+ }
2524
+
2525
+ // ../../packages/layout/src/elkSpacingBase.ts
2526
+ init_define_RADICAL_BUILD();
2527
+ var ELK_ROOT_SPACING = {
2528
+ "elk.spacing.nodeNode": "60",
2529
+ "elk.layered.spacing.nodeNodeBetweenLayers": "80",
2530
+ "elk.spacing.edgeNode": "20",
2531
+ "elk.spacing.edgeEdge": "10",
2532
+ "elk.spacing.componentComponent": "80"
2533
+ };
2534
+ var ELK_CHILD_SPACING = {
2535
+ "elk.spacing.nodeNode": "30",
2536
+ "elk.layered.spacing.nodeNodeBetweenLayers": "50",
2537
+ "elk.spacing.edgeNode": "12",
2538
+ "elk.spacing.edgeEdge": "8",
2539
+ "elk.spacing.componentComponent": "40"
2540
+ };
2541
+
2542
+ // ../../packages/layout/src/geometry.ts
2543
+ init_define_RADICAL_BUILD();
2544
+ function effectiveWidth(n) {
2545
+ if (isContainerType(n.type) && n.collapsed) return COLLAPSED_WIDTH[n.type];
2546
+ return n.width ?? NODE_SIZES[n.type].width;
2547
+ }
2548
+ function effectiveHeight(n) {
2549
+ if (isContainerType(n.type) && n.collapsed) return COLLAPSED_HEIGHT[n.type];
2550
+ return n.height ?? NODE_SIZES[n.type].height;
2551
+ }
2552
+ var FIXED_SIZE_TYPES = /* @__PURE__ */ new Set(["adr", "fitness-fn", "need", "requirement", "scenario", "mockup", "pseudostate", "event", "entity"]);
2553
+ function drawnSize(n, hasChildren) {
2554
+ if (FIXED_SIZE_TYPES.has(n.type)) return NODE_SIZES[n.type];
2555
+ if (isContainerType(n.type) && (n.collapsed || !hasChildren)) {
2556
+ return { width: COLLAPSED_WIDTH[n.type], height: COLLAPSED_HEIGHT[n.type] };
2557
+ }
2558
+ return { width: n.width, height: n.height };
2559
+ }
2560
+ function isVisible(node, allNodes) {
2561
+ if (!node.parentId) return true;
2562
+ const parent = allNodes[node.parentId];
2563
+ if (!parent) return true;
2564
+ if (parent.collapsed) return false;
2565
+ return isVisible(parent, allNodes);
2566
+ }
2567
+ function compoundPadding(type) {
2568
+ const margin = type === "container" || type === "webapp" ? 20 : 30;
2569
+ return { top: 120, side: margin, bottom: margin };
2570
+ }
2571
+ function fittedParentSize(parent, children) {
2572
+ const pad = compoundPadding(parent.type);
2573
+ let maxRight = 0;
2574
+ let maxBottom = 0;
2575
+ for (const child of children) {
2576
+ maxRight = Math.max(maxRight, child.x + child.width);
2577
+ maxBottom = Math.max(maxBottom, child.y + child.height);
2578
+ }
2579
+ return {
2580
+ width: Math.max(maxRight + pad.side, COLLAPSED_WIDTH[parent.type] ?? NODE_SIZES[parent.type].width),
2581
+ height: Math.max(maxBottom + pad.bottom, COLLAPSED_HEIGHT[parent.type] ?? NODE_SIZES[parent.type].height)
2582
+ };
2583
+ }
2584
+ function placeNewNode(nodes, parentId) {
2585
+ const parent = parentId ? nodes[parentId] : void 0;
2586
+ const siblings = Object.values(nodes).filter((n) => (n.parentId ?? void 0) === (parent?.id ?? void 0));
2587
+ const right = Math.max(...siblings.map((n) => n.x + effectiveWidth(n)));
2588
+ if (!parent) return { x: siblings.length ? right + 80 : 0, y: 0 };
2589
+ const pad = compoundPadding(parent.type);
2590
+ return { x: siblings.length ? right + 20 : pad.side, y: pad.top };
2591
+ }
2592
+ function placeBesideSiblings(nodes, parentId, counts = () => true) {
2593
+ const parent = parentId ? nodes[parentId] : void 0;
2594
+ const siblings = Object.values(nodes).filter((s) => (s.parentId ?? void 0) === (parent?.id ?? void 0) && counts(s));
2595
+ if (siblings.length === 0) {
2596
+ const pad = parent ? compoundPadding(parent.type) : { top: 0, side: 0 };
2597
+ return { x: pad.side, y: pad.top };
2598
+ }
2599
+ return {
2600
+ x: Math.max(...siblings.map((s) => s.x + effectiveWidth(s))) + (parent ? 20 : 80),
2601
+ y: Math.min(...siblings.map((s) => s.y))
2602
+ };
2603
+ }
2604
+ function centredIn(frame, size, pad) {
2605
+ return {
2606
+ x: Math.max(pad.side, Math.round((frame.width - size.width) / 2)),
2607
+ y: pad.top + Math.max(0, Math.round((frame.height - pad.top - pad.bottom - size.height) / 2))
2608
+ };
2609
+ }
2610
+ var GRID_GAP = 60;
2611
+ function gridSlotIn(nodes, parentId, size, counts = () => true, frame) {
2612
+ const parent = nodes[parentId];
2613
+ const pad = compoundPadding(parent?.type ?? "system");
2614
+ const kids = Object.values(nodes).filter((c) => c.parentId === parentId && counts(c));
2615
+ if (!kids.length) return centredIn(frame ?? { width: parent?.width ?? 0, height: parent?.height ?? 0 }, size, pad);
2616
+ const cellW = Math.max(size.width, ...kids.map(effectiveWidth));
2617
+ const cellH = Math.max(size.height, ...kids.map(effectiveHeight));
2618
+ const taken = kids.map((c) => ({ x: c.x, y: c.y, w: effectiveWidth(c), h: effectiveHeight(c) }));
2619
+ const left = Math.max(pad.side, Math.min(...kids.map((c) => c.x)));
2620
+ const top = Math.max(pad.top, Math.min(...kids.map((c) => c.y)));
2621
+ for (let i = 0; i < 1e4; i++) {
2622
+ const { column, row } = landscapeSlot(i);
2623
+ const box = { x: left + column * (cellW + GRID_GAP), y: top + row * (cellH + GRID_GAP), w: size.width, h: size.height };
2624
+ if (!taken.some((t) => boxesOverlap(box, t))) return { x: box.x, y: box.y };
2625
+ }
2626
+ return placeBesideSiblings(nodes, parentId, counts);
2627
+ }
2628
+ function modelCanvas(nodes, shownIds, frames) {
2629
+ const shown = (n) => (!shownIds || shownIds.has(n.id)) && isVisible(n, nodes);
2630
+ const parents = new Set(Object.values(nodes).filter(shown).map((n) => n.parentId).filter((id) => !!id));
2631
+ const boxOf = (n) => {
2632
+ const size = drawnSize(n, parents.has(n.id));
2633
+ return { x: n.x, y: n.y, w: size.width, h: size.height };
2634
+ };
2635
+ return frames?.size ? { shown, boxOf, frame: (n) => frames.has(n.id) } : { shown, boxOf };
2636
+ }
2637
+ var boxesOverlap = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
2638
+ function liesClearInParent(node, nodes, canvas, ignore = () => false) {
2639
+ const box = canvas.boxOf(node);
2640
+ const parent = node.parentId ? nodes[node.parentId] : void 0;
2641
+ if (parent) {
2642
+ const frame = canvas.boxOf(parent);
2643
+ if (box.x < 0 || box.y < 0 || box.x + box.w > frame.w || box.y + box.h > frame.h) return false;
2644
+ }
2645
+ return !Object.values(nodes).some((s) => s.id !== node.id && (s.parentId ?? void 0) === (node.parentId ?? void 0) && canvas.shown(s) && !ignore(s) && drawnBoxesOf(s, nodes, canvas, (c) => c.id !== node.id && !ignore(c)).some((b) => boxesOverlap(box, b)));
2646
+ }
2647
+ function drawnBoxesOf(node, nodes, canvas, keep = () => true) {
2648
+ const box = canvas.boxOf(node);
2649
+ if (!canvas.frame?.(node)) return [box];
2650
+ return Object.values(nodes).filter((c) => c.parentId === node.id && canvas.shown(c) && keep(c)).flatMap((c) => drawnBoxesOf(c, nodes, canvas, keep).map((b) => ({ ...b, x: b.x + box.x, y: b.y + box.y })));
2651
+ }
2652
+ function settleMovedNodes(nodes, ids, canvas, fit = (parentId) => fitShown(nodes, parentId, canvas), opened) {
2653
+ const touched = [];
2654
+ const settle = (moved, on) => {
2655
+ const waiting = new Set(moved);
2656
+ const alone = [];
2657
+ for (const id of moved) {
2658
+ const node = nodes[id];
2659
+ if (!liesClearInParent(node, nodes, on, (s) => waiting.has(s.id))) {
2660
+ const counts = (s) => s.id !== id && !waiting.has(s.id) && on.shown(s);
2661
+ const box = on.boxOf(node);
2662
+ const at = node.parentId && nodes[node.parentId] ? gridSlotIn(nodes, node.parentId, { width: box.w, height: box.h }, (s) => counts(s), { width: on.boxOf(nodes[node.parentId]).w, height: on.boxOf(nodes[node.parentId]).h }) : freeSpotNear(
2663
+ Object.values(nodes).filter((s) => !s.parentId && counts(s)).flatMap((s) => drawnBoxesOf(s, nodes, on, counts)).map((b) => ({ x: b.x, y: b.y, width: b.w, height: b.h })),
2664
+ { width: box.w, height: box.h },
2665
+ { x: box.x + box.w / 2, y: box.y + box.h / 2 }
2666
+ );
2667
+ node.x = at.x;
2668
+ node.y = at.y;
2669
+ touched.push(id);
2670
+ if (node.parentId && !Object.values(nodes).some((s) => s.parentId === node.parentId && counts(s)) && moved.filter((m) => nodes[m]?.parentId === node.parentId).length === 1) alone.push(id);
2671
+ }
2672
+ waiting.delete(id);
2673
+ }
2674
+ const parents = [...new Set(moved.map((id) => nodes[id].parentId).filter((p) => !!p && !!nodes[p]))];
2675
+ for (const parentId of parents) touched.push(...growWithRoom(nodes, parentId, on, fit));
2676
+ for (const id of alone) {
2677
+ const node = nodes[id];
2678
+ const frame = on.boxOf(nodes[node.parentId]);
2679
+ const box = on.boxOf(node);
2680
+ Object.assign(node, centredIn({ width: frame.w, height: frame.h }, { width: box.w, height: box.h }, compoundPadding(nodes[node.parentId].type)));
2681
+ }
2682
+ };
2683
+ settle(ids.filter((id) => nodes[id] && canvas.shown(nodes[id])), canvas);
2684
+ if (opened) settle(ids.filter((id) => nodes[id] && !canvas.shown(nodes[id]) && opened.shown(nodes[id])), opened);
2685
+ return touched;
2686
+ }
2687
+ function growWithRoom(nodes, startId, canvas, fit = (parentId) => fitShown(nodes, parentId, canvas)) {
2688
+ const pushed = [];
2689
+ const seen = /* @__PURE__ */ new Set();
2690
+ for (let cur = nodes[startId]; cur && !seen.has(cur.id); cur = cur.parentId ? nodes[cur.parentId] : void 0) {
2691
+ seen.add(cur.id);
2692
+ const was = canvas.boxOf(cur);
2693
+ fit(cur.id);
2694
+ const now = canvas.boxOf(nodes[cur.id]);
2695
+ if (now.w <= was.w && now.h <= was.h) continue;
2696
+ if (canvas.frame?.(cur)) continue;
2697
+ for (const [id, at] of Object.entries(makeRoomAround(cur.id, nodes, canvas))) {
2698
+ nodes[id].x = at.x;
2699
+ nodes[id].y = at.y;
2700
+ pushed.push(id);
2701
+ }
2702
+ if (cur.parentId) growFrameLeftUp(nodes, cur.parentId, canvas.shown);
2703
+ }
2704
+ return pushed;
2705
+ }
2706
+ var CHILD_TOP_MIN = 50;
2707
+ function growFrameLeftUp(nodes, parentId, shown = () => true) {
2708
+ const parent = nodes[parentId];
2709
+ if (!parent) return;
2710
+ const kids = Object.values(nodes).filter((c) => c.parentId === parentId && shown(c));
2711
+ if (!kids.length) return;
2712
+ const pad = compoundPadding(parent.type);
2713
+ const minX = Math.min(...kids.map((c) => c.x));
2714
+ const minY = Math.min(...kids.map((c) => c.y));
2715
+ const dx = minX < 0 ? pad.side - minX : 0;
2716
+ const dy = minY < CHILD_TOP_MIN ? pad.top - minY : 0;
2717
+ if (!dx && !dy) return;
2718
+ parent.x -= dx;
2719
+ parent.y -= dy;
2720
+ for (const k of kids) {
2721
+ k.x += dx;
2722
+ k.y += dy;
2723
+ }
2724
+ }
2725
+ function fitShown(nodes, parentId, canvas) {
2726
+ const parent = nodes[parentId];
2727
+ if (!parent || !isContainerType(parent.type) || parent.collapsed) return;
2728
+ const children = Object.values(nodes).filter((c) => c.parentId === parentId && canvas.shown(c));
2729
+ if (!children.length) return;
2730
+ const size = fittedParentSize(parent, children.map((c) => ({ x: c.x, y: c.y, width: effectiveWidth(c), height: effectiveHeight(c) })));
2731
+ parent.width = size.width;
2732
+ parent.height = size.height;
2733
+ }
2734
+ var EXPAND_GAP = 20;
2735
+ var HIT_COST = 200;
2736
+ function makeRoomAround(grownId, nodes, canvas) {
2737
+ const grown = nodes[grownId];
2738
+ if (!grown) return {};
2739
+ const { shown, boxOf } = canvas;
2740
+ const siblings = Object.values(nodes).filter((n) => (n.parentId ?? void 0) === (grown.parentId ?? void 0) && shown(n));
2741
+ if (siblings.length < 2) return {};
2742
+ const box = new Map(siblings.map((n) => [n.id, boxOf(n)]));
2743
+ const before = new Map(siblings.map((n) => [n.id, boxOf(n)]));
2744
+ const g = box.get(grownId);
2745
+ const gx = g.x + g.w / 2;
2746
+ const gy = g.y + g.h / 2;
2747
+ const gapTo = (b) => Math.max(g.x - (b.x + b.w), b.x - (g.x + g.w), g.y - (b.y + b.h), b.y - (g.y + g.h), 0);
2748
+ const order = siblings.filter((n) => n.id !== grownId).map((n) => ({ id: n.id, gap: gapTo(box.get(n.id)), centre: Math.hypot(box.get(n.id).x + box.get(n.id).w / 2 - gx, box.get(n.id).y + box.get(n.id).h / 2 - gy) })).sort((a, b) => a.gap - b.gap || a.centre - b.centre || (a.id < b.id ? -1 : 1));
2749
+ const placed = [grownId];
2750
+ const moved = /* @__PURE__ */ new Set([grownId]);
2751
+ const hits = (a, b, gap) => a.x < b.x + b.w + gap && b.x < a.x + a.w + gap && a.y < b.y + b.h + gap && b.y < a.y + a.h + gap;
2752
+ const gapOf = (a, b) => {
2753
+ if (a === grownId || b === grownId) return EXPAND_GAP;
2754
+ const [p, q] = [before.get(a), before.get(b)];
2755
+ return Math.min(EXPAND_GAP, Math.max(0, p.x - (q.x + q.w), q.x - (p.x + p.w), p.y - (q.y + q.h), q.y - (p.y + p.h)));
2756
+ };
2757
+ for (const { id } of order) {
2758
+ const b = box.get(id);
2759
+ const cx = b.x + b.w / 2 - gx;
2760
+ const cy = b.y + b.h / 2 - gy;
2761
+ for (let step = 0; step < placed.length * 4 + 8; step++) {
2762
+ const at = placed.findIndex((pid) => (moved.has(pid) || moved.has(id)) && hits(b, box.get(pid), gapOf(id, pid)));
2763
+ if (at < 0) break;
2764
+ const blocker = box.get(placed[at]);
2765
+ const gap = gapOf(id, placed[at]);
2766
+ const ways = [
2767
+ { dx: blocker.x + blocker.w + gap - b.x, dy: 0, ok: cx >= 0 },
2768
+ { dx: blocker.x - gap - (b.x + b.w), dy: 0, ok: cx <= 0 },
2769
+ { dx: 0, dy: blocker.y + blocker.h + gap - b.y, ok: cy >= 0 },
2770
+ { dx: 0, dy: blocker.y - gap - (b.y + b.h), ok: cy <= 0 }
2771
+ ].filter((w) => w.ok);
2772
+ const cost = (w) => {
2773
+ const to = { x: b.x + w.dx, y: b.y + w.dy, w: b.w, h: b.h };
2774
+ let hit = 0;
2775
+ for (const n of siblings) if (n.id !== id && n.id !== grownId && hits(to, box.get(n.id), 0)) hit++;
2776
+ return Math.abs(w.dx) + Math.abs(w.dy) + HIT_COST * hit;
2777
+ };
2778
+ const way = ways.reduce((best, w) => cost(w) < cost(best) ? w : best);
2779
+ b.x += way.dx;
2780
+ b.y += way.dy;
2781
+ moved.add(id);
2782
+ }
2783
+ placed.push(id);
2784
+ }
2785
+ const result = {};
2786
+ for (const n of siblings) {
2787
+ const b = box.get(n.id);
2788
+ if (n.id !== grownId && (b.x !== n.x || b.y !== n.y)) result[n.id] = { x: b.x, y: b.y };
2789
+ }
2790
+ return result;
2791
+ }
2792
+ function freeSpotNear(taken, size, center, gap = 60) {
2793
+ const fits = (x, y) => taken.every((b) => x + size.width + gap <= b.x || b.x + b.width + gap <= x || y + size.height + gap <= b.y || b.y + b.height + gap <= y);
2794
+ const start = { x: center.x - size.width / 2, y: center.y - size.height / 2 };
2795
+ const step = 80;
2796
+ for (let ring = 0; ring <= 40; ring++) {
2797
+ const spots = [];
2798
+ if (ring === 0) spots.push(start);
2799
+ for (let k = -ring; k <= ring && ring > 0; k++) {
2800
+ spots.push({ x: start.x + k * step, y: start.y - ring * step }, { x: start.x + k * step, y: start.y + ring * step });
2801
+ if (k !== -ring && k !== ring) spots.push({ x: start.x - ring * step, y: start.y + k * step }, { x: start.x + ring * step, y: start.y + k * step });
2802
+ }
2803
+ spots.sort((a, b) => Math.hypot(a.x - start.x, a.y - start.y) - Math.hypot(b.x - start.x, b.y - start.y));
2804
+ for (const s of spots) if (fits(s.x, s.y)) return s;
2805
+ }
2806
+ const right = taken.length ? Math.max(...taken.map((b) => b.x + b.width)) : start.x;
2807
+ return { x: right + gap, y: start.y };
2808
+ }
2809
+ var BATCH_CELL = { width: 360, height: 280 };
2810
+ var BATCH_GAP = 120;
2811
+ function createBatchPlacer(getNodes, visible = () => void 0) {
2812
+ const batches = /* @__PURE__ */ new Map();
2813
+ return (parentId) => {
2814
+ const key = parentId ?? "";
2815
+ let batch = batches.get(key);
2816
+ if (!batch) {
2817
+ const nodes = getNodes();
2818
+ const parent = parentId ? nodes[parentId] : void 0;
2819
+ const shown = visible();
2820
+ const siblings = Object.values(nodes).filter((n) => (n.parentId ?? void 0) === (parent?.id ?? void 0) && (!shown || shown.has(n.id)));
2821
+ const pad = parent ? compoundPadding(parent.type) : { top: 0, side: 0 };
2822
+ batch = siblings.length ? { x: Math.max(...siblings.map((n) => n.x + effectiveWidth(n))) + (parent ? pad.side : BATCH_GAP), y: Math.min(...siblings.map((n) => n.y)), placed: 0 } : { x: pad.side, y: pad.top, placed: 0 };
2823
+ batches.set(key, batch);
2824
+ }
2825
+ const { column, row } = landscapeSlot(batch.placed++);
2826
+ return { x: batch.x + column * BATCH_CELL.width, y: batch.y + row * BATCH_CELL.height };
2827
+ };
2828
+ }
2829
+ function projectToVisibleGraph(nodes, relations) {
2830
+ const visible = {};
2831
+ for (const id of Object.keys(nodes).sort()) {
2832
+ const n = nodes[id];
2833
+ if (!isVisible(n, nodes)) continue;
2834
+ if (isContainerType(n.type) && n.collapsed) {
2835
+ const w = COLLAPSED_WIDTH[n.type];
2836
+ const h = COLLAPSED_HEIGHT[n.type];
2837
+ visible[n.id] = n.width === w && n.height === h ? n : { ...n, width: w, height: h };
2838
+ } else {
2839
+ visible[n.id] = n;
2840
+ }
2841
+ }
2842
+ const visibleAncestor = (id) => {
2843
+ let cur = nodes[id];
2844
+ while (cur && !visible[cur.id]) cur = cur.parentId ? nodes[cur.parentId] : void 0;
2845
+ return cur?.id;
2846
+ };
2847
+ const isAncestor = (a, b) => {
2848
+ for (let cur = nodes[b]?.parentId; cur; cur = nodes[cur]?.parentId) if (cur === a) return true;
2849
+ return false;
2850
+ };
2851
+ const projected = {};
2852
+ const rolledUpLine = /* @__PURE__ */ new Map();
2853
+ for (const id of Object.keys(relations).sort()) {
2854
+ const r = relations[id];
2855
+ const s = visibleAncestor(r.sourceId);
2856
+ const t = visibleAncestor(r.targetId);
2857
+ if (!s || !t || s === t) continue;
2858
+ if (s === r.sourceId && t === r.targetId) {
2859
+ projected[id] = r;
2860
+ continue;
2861
+ }
2862
+ if (isAncestor(s, t) || isAncestor(t, s)) continue;
2863
+ const key = `${s}\0${t}`;
2864
+ const kept = rolledUpLine.get(key);
2865
+ if (kept) {
2866
+ if (r.label) projected[kept] = { ...projected[kept], label: projected[kept].label ? `${projected[kept].label}
2867
+ ${r.label}` : r.label };
2868
+ if (projected[kept].technology !== r.technology) projected[kept] = { ...projected[kept], technology: void 0 };
2869
+ continue;
2870
+ }
2871
+ rolledUpLine.set(key, id);
2872
+ projected[id] = { ...r, sourceId: s, targetId: t };
2873
+ }
2874
+ return { nodes: visible, relations: projected };
2875
+ }
2876
+
2877
+ // ../../packages/layout/src/elkLayout.ts
2878
+ var elk = new ELK();
2879
+ var LAYERED_OPTIONS = {
2880
+ "elk.algorithm": "layered",
2881
+ "elk.direction": "DOWN",
2882
+ // SEPARATE_CHILDREN (default): each compound node is laid out independently.
2883
+ // Cross-boundary crossing minimisation is handled by our geometric post-process
2884
+ // (minimizeCrossings in crossingOpt.ts) — safer than INCLUDE_CHILDREN which
2885
+ // crashes ELK's internal scanline constraint calculator with compound graphs.
2886
+ // ── Connected-component placement ────────────────────────────────────────
2887
+ "elk.separateConnectedComponents": "true",
2888
+ // ── Crossing minimisation ─────────────────────────────────────────────────
2889
+ "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
2890
+ "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
2891
+ "elk.layered.thoroughness": "50",
2892
+ "elk.layered.considerModelOrder.strategy": "NONE",
2893
+ // ── Node placement ────────────────────────────────────────────────────────
2894
+ "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
2895
+ // ── Spacing ───────────────────────────────────────────────────────────────
2896
+ ...ELK_ROOT_SPACING,
2897
+ // ── Post-layout ──────────────────────────────────────────────────────────
2898
+ "elk.layered.unnecessaryBendpoints": "true",
2899
+ "elk.layered.compaction.postCompaction.strategy": "EDGE_LENGTH",
2900
+ "elk.padding": "[top=120, right=30, bottom=30, left=30]"
2901
+ };
2902
+ var CHILD_OPTIONS = {
2903
+ "elk.algorithm": "layered",
2904
+ "elk.direction": "RIGHT",
2905
+ "elk.separateConnectedComponents": "true",
2906
+ "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
2907
+ "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
2908
+ "elk.layered.thoroughness": "50",
2909
+ "elk.layered.considerModelOrder.strategy": "NONE",
2910
+ "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
2911
+ ...ELK_CHILD_SPACING,
2912
+ "elk.layered.unnecessaryBendpoints": "true",
2913
+ "elk.layered.compaction.postCompaction.strategy": "EDGE_LENGTH",
2914
+ "elk.padding": "[top=110, right=20, bottom=20, left=20]"
2915
+ };
2916
+ function ancestorChain(nodeId, nodes) {
2917
+ const chain = [nodeId];
2918
+ let cur = nodes[nodeId];
2919
+ while (cur?.parentId) {
2920
+ chain.push(cur.parentId);
2921
+ cur = nodes[cur.parentId];
2922
+ }
2923
+ return chain;
2924
+ }
2925
+ function lcaContainerId(srcId, tgtId, nodes) {
2926
+ if (srcId === tgtId) return nodes[srcId]?.parentId;
2927
+ const srcSet = new Set(ancestorChain(srcId, nodes));
2928
+ for (const id of ancestorChain(tgtId, nodes)) {
2929
+ if (srcSet.has(id) && id !== srcId && id !== tgtId) return id;
2930
+ }
2931
+ return void 0;
2932
+ }
2933
+ function buildElkNode(n, allNodes, elkNodeMap) {
2934
+ const isCollapsed = n.collapsed && isContainerType(n.type);
2935
+ const width = isCollapsed ? COLLAPSED_WIDTH[n.type] : n.width;
2936
+ const height = isCollapsed ? COLLAPSED_HEIGHT[n.type] : n.height;
2937
+ const childC4 = isCollapsed ? [] : Object.values(allNodes).filter((c) => c.parentId === n.id);
2938
+ const children = childC4.map((c) => buildElkNode(c, allNodes, elkNodeMap));
2939
+ const elkNode = {
2940
+ id: n.id,
2941
+ width,
2942
+ height,
2943
+ layoutOptions: children.length > 0 ? CHILD_OPTIONS : void 0,
2944
+ children,
2945
+ edges: []
2946
+ };
2947
+ elkNodeMap[n.id] = elkNode;
2948
+ return elkNode;
2949
+ }
2950
+ function parseElkResult(node, result) {
2951
+ if (node.id !== "root" && node.x != null && node.y != null) {
2952
+ result[node.id] = { x: node.x, y: node.y, width: node.width, height: node.height };
2953
+ }
2954
+ for (const child of node.children ?? []) {
2955
+ parseElkResult(child, result);
2956
+ }
2957
+ }
2958
+ var PACKED_ASPECT = 1.6;
2959
+ var PACK_MIN_CHILDREN = 8;
2960
+ var PACK_MAX_LINKS_PER_CHILD = 1;
2961
+ var PACKED_OPTIONS = {
2962
+ // Box layout, rows filled in the given order (rectpacking moved elements
2963
+ // between rows to fill them, which split the linked ones apart).
2964
+ "elk.algorithm": "box",
2965
+ "elk.box.packingMode": "SIMPLE",
2966
+ // One block in this order: split into connected components, ELK placed
2967
+ // the components and the lone elements apart, each sorted its own way.
2968
+ "elk.separateConnectedComponents": "false",
2969
+ "elk.spacing.nodeNode": "40",
2970
+ "elk.padding": "[top=110, right=20, bottom=20, left=20]"
2971
+ };
2972
+ function childLinks(group, nodes, relations) {
2973
+ const childIds = new Set((group.children ?? []).map((c) => c.id));
2974
+ const childOf = (id) => {
2975
+ for (let cur = id; cur && nodes[cur]; cur = nodes[cur].parentId) if (childIds.has(cur)) return cur;
2976
+ return void 0;
2977
+ };
2978
+ const links = /* @__PURE__ */ new Map();
2979
+ for (const r of Object.values(relations)) {
2980
+ const a = childOf(r.sourceId);
2981
+ const b = childOf(r.targetId);
2982
+ if (!a || !b || a === b) continue;
2983
+ links.set(a, [...links.get(a) ?? [], b]);
2984
+ links.set(b, [...links.get(b) ?? [], a]);
2985
+ }
2986
+ return links;
2987
+ }
2988
+ function linkedOrder(children, links, nodes) {
2989
+ const name = (id) => (nodes[id]?.label ?? "").toLowerCase();
2990
+ const byName = (a, b) => name(a).localeCompare(name(b)) || (a < b ? -1 : a > b ? 1 : 0);
2991
+ children = [...children].sort((a, b) => byName(a.id, b.id));
2992
+ for (const list of links.values()) list.sort(byName);
2993
+ const byId = new Map(children.map((c) => [c.id, c]));
2994
+ const seen = /* @__PURE__ */ new Set();
2995
+ const order = [];
2996
+ for (const start of children) {
2997
+ if (seen.has(start.id)) continue;
2998
+ const queue = [start.id];
2999
+ seen.add(start.id);
3000
+ while (queue.length) {
3001
+ const id = queue.shift();
3002
+ order.push(byId.get(id));
3003
+ for (const next of links.get(id) ?? []) if (!seen.has(next)) {
3004
+ seen.add(next);
3005
+ queue.push(next);
3006
+ }
3007
+ }
3008
+ }
3009
+ return order;
3010
+ }
3011
+ async function applyElkLayout(inputNodes, inputRelations, opts) {
3012
+ const { nodes: c4Nodes, relations: c4Relations } = projectToVisibleGraph(inputNodes, inputRelations);
3013
+ const elkNodeMap = {};
3014
+ const childOpts = opts?.childOptions ?? CHILD_OPTIONS;
3015
+ const buildWith = (n) => {
3016
+ const built = buildElkNode(n, c4Nodes, elkNodeMap);
3017
+ const apply = (node) => {
3018
+ if (node.children && node.children.length > 0) {
3019
+ node.layoutOptions = childOpts;
3020
+ if (opts?.packSparseGroups && node.children.length >= PACK_MIN_CHILDREN) {
3021
+ const links = childLinks(node, c4Nodes, c4Relations);
3022
+ let count = 0;
3023
+ for (const list of links.values()) count += list.length;
3024
+ if (count / 2 <= node.children.length * PACK_MAX_LINKS_PER_CHILD) {
3025
+ const w = node.children.reduce((sum, c) => sum + (c.width ?? 0), 0);
3026
+ const h = node.children.reduce((sum, c) => sum + (c.height ?? 0), 0);
3027
+ node.layoutOptions = { ...PACKED_OPTIONS, "elk.aspectRatio": String(PACKED_ASPECT * (h > 0 ? w / h : 1)) };
3028
+ node.children = linkedOrder(node.children, links, c4Nodes);
3029
+ const count2 = node.children.length;
3030
+ node.children.forEach((c, i) => {
3031
+ c.layoutOptions = { ...c.layoutOptions, "elk.priority": String(count2 - i) };
3032
+ });
3033
+ }
3034
+ }
3035
+ for (const c of node.children) apply(c);
3036
+ }
3037
+ };
3038
+ apply(built);
3039
+ return built;
3040
+ };
3041
+ const rootChildren = Object.values(c4Nodes).filter((n) => !n.parentId).map(buildWith);
3042
+ const root = {
3043
+ id: "root",
3044
+ layoutOptions: opts?.rootOptions ?? LAYERED_OPTIONS,
3045
+ children: rootChildren,
3046
+ edges: []
3047
+ };
3048
+ elkNodeMap["root"] = root;
3049
+ for (const rel of Object.values(c4Relations)) {
3050
+ if (!c4Nodes[rel.sourceId] || !c4Nodes[rel.targetId]) continue;
3051
+ if (ancestorChain(rel.sourceId, c4Nodes).includes(rel.targetId) || ancestorChain(rel.targetId, c4Nodes).includes(rel.sourceId)) continue;
3052
+ const lca = lcaContainerId(rel.sourceId, rel.targetId, c4Nodes);
3053
+ const container = (lca ? elkNodeMap[lca] : root) ?? root;
3054
+ const edge = { id: rel.id, sources: [rel.sourceId], targets: [rel.targetId] };
3055
+ if (!container.edges) container.edges = [];
3056
+ container.edges.push(edge);
3057
+ }
3058
+ try {
3059
+ const result = await elk.layout(root);
3060
+ const positions = {};
3061
+ parseElkResult(result, positions);
3062
+ return positions;
3063
+ } catch (err) {
3064
+ console.error("[ELK] Layout error:", err);
3065
+ return {};
3066
+ }
3067
+ }
3068
+ var TREE_ROOT_OPTIONS = {
3069
+ "elk.algorithm": "layered",
3070
+ "elk.direction": "DOWN",
3071
+ "elk.separateConnectedComponents": "true",
3072
+ "elk.spacing.componentComponent": "60",
3073
+ "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
3074
+ "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
3075
+ "elk.layered.thoroughness": "50",
3076
+ // Honour input order so siblings stay close to their declared grouping —
3077
+ // the dominant cue users associate with "tree" layouts.
3078
+ "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
3079
+ "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
3080
+ "elk.layered.nodePlacement.bk.fixedAlignment": "BALANCED",
3081
+ "elk.spacing.nodeNode": "50",
3082
+ "elk.layered.spacing.nodeNodeBetweenLayers": "70",
3083
+ "elk.spacing.edgeNode": "20",
3084
+ "elk.spacing.edgeEdge": "10",
3085
+ "elk.layered.compaction.postCompaction.strategy": "LEFT",
3086
+ "elk.layered.unnecessaryBendpoints": "true",
3087
+ "elk.padding": "[top=120, right=30, bottom=30, left=30]"
3088
+ };
3089
+ var TREE_CHILD_OPTIONS = {
3090
+ // Children of every compound container also flow top-down — this is what
3091
+ // produces the visible "nested tree" look (vs. the default ELK config
3092
+ // where compound children flow left-to-right).
3093
+ "elk.algorithm": "layered",
3094
+ "elk.direction": "DOWN",
3095
+ "elk.separateConnectedComponents": "true",
3096
+ "elk.spacing.componentComponent": "30",
3097
+ "elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
3098
+ "elk.layered.crossingMinimization.greedySwitch.type": "TWO_SIDED",
3099
+ "elk.layered.thoroughness": "50",
3100
+ "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
3101
+ "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
3102
+ "elk.layered.nodePlacement.bk.fixedAlignment": "BALANCED",
3103
+ "elk.spacing.nodeNode": "28",
3104
+ "elk.layered.spacing.nodeNodeBetweenLayers": "40",
3105
+ "elk.spacing.edgeNode": "12",
3106
+ "elk.spacing.edgeEdge": "8",
3107
+ "elk.layered.compaction.postCompaction.strategy": "LEFT",
3108
+ "elk.layered.unnecessaryBendpoints": "true",
3109
+ "elk.padding": "[top=110, right=20, bottom=20, left=20]"
3110
+ };
3111
+ async function applyTreeLayout(c4Nodes, c4Relations) {
3112
+ return applyElkLayout(c4Nodes, c4Relations, {
3113
+ rootOptions: TREE_ROOT_OPTIONS,
3114
+ childOptions: TREE_CHILD_OPTIONS
3115
+ });
3116
+ }
3117
+
3118
+ export {
3119
+ __commonJS,
3120
+ __toESM,
3121
+ init_define_RADICAL_BUILD,
3122
+ define_RADICAL_BUILD_default,
3123
+ isRelationAllowed,
3124
+ inferRelationType,
3125
+ isParentAllowed,
3126
+ allowedPlacesText,
3127
+ GROUP_TYPE,
3128
+ placeOf,
3129
+ hasPlaceUnder,
3130
+ isFinalState,
3131
+ isPlacementAllowed,
3132
+ canAddMoreOfType,
3133
+ isReservedPropertyKey,
3134
+ propertyKeyProblem,
3135
+ chainTypeNames,
3136
+ refIds,
3137
+ refValue,
3138
+ refProblem,
3139
+ transitionLabel,
3140
+ requirementStatePhrase,
3141
+ transitionRefusal,
3142
+ lifecycleRefusal,
3143
+ initialPseudostateRefusal,
3144
+ newPseudostateKind,
3145
+ isInitialPseudostate,
3146
+ outgoingTransitionCount,
3147
+ validateModel,
3148
+ relationTypeName,
3149
+ composeEarsSentence,
3150
+ builtInC4Metamodel,
3151
+ RADICAL_METAMODEL_NAME,
3152
+ builtInGovernanceMetamodel,
3153
+ layoutRoleOf,
3154
+ relationLayoutHint,
3155
+ LAYOUT_ROLES,
3156
+ LAYOUT_FLOWS,
3157
+ LAYOUT_AXES,
3158
+ isContainerType,
3159
+ isBackwardStep,
3160
+ trimStepBackward,
3161
+ pinnedNodeIds,
3162
+ defaultGridColumns,
3163
+ landscapeGridColumns,
3164
+ gridCells,
3165
+ constraintLines,
3166
+ slideWithoutMilestone,
3167
+ NODE_SIZES,
3168
+ nodeTypeSize,
3169
+ COLLAPSED_HEIGHT,
3170
+ COLLAPSED_WIDTH,
3171
+ normalizeViewFolder,
3172
+ viewFolderPaths,
3173
+ WIKI_DEPTH_MAX,
3174
+ wikiDepthOf,
3175
+ holderOf,
3176
+ viewShowsEveryNode,
3177
+ viewCanvasPositions,
3178
+ withCanvasPositions,
3179
+ removeFromViewList,
3180
+ addToViewList,
3181
+ effectiveWidth,
3182
+ effectiveHeight,
3183
+ drawnSize,
3184
+ isVisible,
3185
+ compoundPadding,
3186
+ fittedParentSize,
3187
+ placeNewNode,
3188
+ modelCanvas,
3189
+ settleMovedNodes,
3190
+ growWithRoom,
3191
+ growFrameLeftUp,
3192
+ fitShown,
3193
+ makeRoomAround,
3194
+ createBatchPlacer,
3195
+ projectToVisibleGraph,
3196
+ ELK_ROOT_SPACING,
3197
+ ELK_CHILD_SPACING,
3198
+ applyElkLayout,
3199
+ applyTreeLayout
3200
+ };