@radicaltools/mcp 0.0.0-stage → 0.1.1

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 (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +140 -2
  3. package/dist/chunk-KI4NVSTU.js +1763 -0
  4. package/dist/elkLayout-WC6AXWOG.js +185 -0
  5. package/dist/hub-catalogue/adr/adr-api-versioning.radical +53 -0
  6. package/dist/hub-catalogue/adr/adr-auth-strategy.radical +53 -0
  7. package/dist/hub-catalogue/adr/adr-caching-strategy.radical +59 -0
  8. package/dist/hub-catalogue/adr/adr-data-consistency-model.radical +40 -0
  9. package/dist/hub-catalogue/adr/adr-data-store.radical +47 -0
  10. package/dist/hub-catalogue/adr/adr-deployment-strategy.radical +53 -0
  11. package/dist/hub-catalogue/adr/adr-event-schema-evolution.radical +53 -0
  12. package/dist/hub-catalogue/adr/adr-integration-style.radical +50 -0
  13. package/dist/hub-catalogue/adr/adr-ledger-reconciliation-strategy.radical +38 -0
  14. package/dist/hub-catalogue/adr/adr-llm-provider-strategy.radical +40 -0
  15. package/dist/hub-catalogue/adr/adr-marketplace-payments-model.radical +39 -0
  16. package/dist/hub-catalogue/adr/adr-multi-region.radical +60 -0
  17. package/dist/hub-catalogue/adr/adr-multi-tenancy-strategy.radical +41 -0
  18. package/dist/hub-catalogue/adr/adr-observability.radical +59 -0
  19. package/dist/hub-catalogue/adr/adr-realtime-transport.radical +38 -0
  20. package/dist/hub-catalogue/adr/adr-tech-stack.radical +45 -0
  21. package/dist/hub-catalogue/adr/adr-zero-trust-network.radical +40 -0
  22. package/dist/hub-catalogue/blueprint/bp-ai-assistant-platform.radical +1641 -0
  23. package/dist/hub-catalogue/blueprint/bp-analytical-data-platform.radical +1428 -0
  24. package/dist/hub-catalogue/blueprint/bp-ecommerce-platform.radical +1989 -0
  25. package/dist/hub-catalogue/blueprint/bp-fintech-ledger-platform.radical +1701 -0
  26. package/dist/hub-catalogue/blueprint/bp-marketplace-platform.radical +1792 -0
  27. package/dist/hub-catalogue/blueprint/bp-realtime-collaboration.radical +1421 -0
  28. package/dist/hub-catalogue/blueprint/bp-saas-b2b-platform.radical +1713 -0
  29. package/dist/hub-catalogue/fitness-function/ff-accessibility-scan.radical +34 -0
  30. package/dist/hub-catalogue/fitness-function/ff-ai-eval-gate.radical +52 -0
  31. package/dist/hub-catalogue/fitness-function/ff-api-contract.radical +36 -0
  32. package/dist/hub-catalogue/fitness-function/ff-capacity-load-test.radical +67 -0
  33. package/dist/hub-catalogue/fitness-function/ff-carbon-footprint-guard.radical +62 -0
  34. package/dist/hub-catalogue/fitness-function/ff-change-failure-rate.radical +45 -0
  35. package/dist/hub-catalogue/fitness-function/ff-chaos-resilience-test.radical +53 -0
  36. package/dist/hub-catalogue/fitness-function/ff-cost-efficiency-guard.radical +64 -0
  37. package/dist/hub-catalogue/fitness-function/ff-coupling-guard.radical +45 -0
  38. package/dist/hub-catalogue/fitness-function/ff-data-integrity-check.radical +51 -0
  39. package/dist/hub-catalogue/fitness-function/ff-data-residency.radical +43 -0
  40. package/dist/hub-catalogue/fitness-function/ff-dependency-rules.radical +37 -0
  41. package/dist/hub-catalogue/fitness-function/ff-deploy-frequency.radical +46 -0
  42. package/dist/hub-catalogue/fitness-function/ff-dr-drill-success.radical +52 -0
  43. package/dist/hub-catalogue/fitness-function/ff-duplication-guard.radical +53 -0
  44. package/dist/hub-catalogue/fitness-function/ff-error-budget.radical +59 -0
  45. package/dist/hub-catalogue/fitness-function/ff-fail-safe-verification.radical +34 -0
  46. package/dist/hub-catalogue/fitness-function/ff-infra-drift.radical +34 -0
  47. package/dist/hub-catalogue/fitness-function/ff-latency-slo.radical +59 -0
  48. package/dist/hub-catalogue/fitness-function/ff-lead-time.radical +44 -0
  49. package/dist/hub-catalogue/fitness-function/ff-ledger-balance-integrity.radical +45 -0
  50. package/dist/hub-catalogue/fitness-function/ff-license-compliance.radical +43 -0
  51. package/dist/hub-catalogue/fitness-function/ff-mttr.radical +45 -0
  52. package/dist/hub-catalogue/fitness-function/ff-noisy-neighbor-guard.radical +66 -0
  53. package/dist/hub-catalogue/fitness-function/ff-sast-scan.radical +35 -0
  54. package/dist/hub-catalogue/fitness-function/ff-scale-out-verification.radical +66 -0
  55. package/dist/hub-catalogue/fitness-function/ff-security-scan.radical +45 -0
  56. package/dist/hub-catalogue/fitness-function/ff-startup-shutdown-check.radical +66 -0
  57. package/dist/hub-catalogue/fitness-function/ff-sync-convergence-test.radical +45 -0
  58. package/dist/hub-catalogue/fitness-function/ff-test-coverage.radical +43 -0
  59. package/dist/hub-catalogue/fitness-function/ff-web-vitals.radical +57 -0
  60. package/dist/hub-catalogue/pattern/pattern-anti-corruption-layer.radical +88 -0
  61. package/dist/hub-catalogue/pattern/pattern-api-gateway.radical +168 -0
  62. package/dist/hub-catalogue/pattern/pattern-bff.radical +179 -0
  63. package/dist/hub-catalogue/pattern/pattern-bulkhead.radical +114 -0
  64. package/dist/hub-catalogue/pattern/pattern-circuit-breaker.radical +219 -0
  65. package/dist/hub-catalogue/pattern/pattern-cqrs.radical +195 -0
  66. package/dist/hub-catalogue/pattern/pattern-crdt-sync.radical +200 -0
  67. package/dist/hub-catalogue/pattern/pattern-event-driven.radical +210 -0
  68. package/dist/hub-catalogue/pattern/pattern-event-sourced-ledger.radical +211 -0
  69. package/dist/hub-catalogue/pattern/pattern-hexagonal.radical +196 -0
  70. package/dist/hub-catalogue/pattern/pattern-microservices.radical +262 -0
  71. package/dist/hub-catalogue/pattern/pattern-rag-pipeline.radical +213 -0
  72. package/dist/hub-catalogue/pattern/pattern-rate-limiter.radical +114 -0
  73. package/dist/hub-catalogue/pattern/pattern-saga.radical +208 -0
  74. package/dist/hub-catalogue/pattern/pattern-sidecar.radical +123 -0
  75. package/dist/hub-catalogue/pattern/pattern-strangler-fig.radical +227 -0
  76. package/dist/hub-catalogue/pattern/pattern-transactional-outbox.radical +209 -0
  77. package/dist/hub-catalogue/requirement/req-accessibility.radical +48 -0
  78. package/dist/hub-catalogue/requirement/req-ai-autonomous-resolution.radical +51 -0
  79. package/dist/hub-catalogue/requirement/req-ai-groundedness.radical +45 -0
  80. package/dist/hub-catalogue/requirement/req-ai-human-handoff.radical +46 -0
  81. package/dist/hub-catalogue/requirement/req-alerting.radical +52 -0
  82. package/dist/hub-catalogue/requirement/req-api-response-time.radical +51 -0
  83. package/dist/hub-catalogue/requirement/req-api-standard.radical +45 -0
  84. package/dist/hub-catalogue/requirement/req-audit-logging.radical +43 -0
  85. package/dist/hub-catalogue/requirement/req-auth-response-time.radical +45 -0
  86. package/dist/hub-catalogue/requirement/req-auth.radical +43 -0
  87. package/dist/hub-catalogue/requirement/req-autoscaling.radical +62 -0
  88. package/dist/hub-catalogue/requirement/req-availability.radical +50 -0
  89. package/dist/hub-catalogue/requirement/req-backward-compatibility.radical +46 -0
  90. package/dist/hub-catalogue/requirement/req-batch-job-completion.radical +50 -0
  91. package/dist/hub-catalogue/requirement/req-carbon-efficiency.radical +64 -0
  92. package/dist/hub-catalogue/requirement/req-centralised-logging.radical +45 -0
  93. package/dist/hub-catalogue/requirement/req-ci-pipeline-time.radical +43 -0
  94. package/dist/hub-catalogue/requirement/req-code-complexity.radical +43 -0
  95. package/dist/hub-catalogue/requirement/req-config-propagation.radical +45 -0
  96. package/dist/hub-catalogue/requirement/req-data-integrity.radical +35 -0
  97. package/dist/hub-catalogue/requirement/req-data-retention.radical +44 -0
  98. package/dist/hub-catalogue/requirement/req-db-query-response.radical +44 -0
  99. package/dist/hub-catalogue/requirement/req-disaster-recovery.radical +59 -0
  100. package/dist/hub-catalogue/requirement/req-distributed-tracing.radical +45 -0
  101. package/dist/hub-catalogue/requirement/req-encryption.radical +49 -0
  102. package/dist/hub-catalogue/requirement/req-error-rate.radical +45 -0
  103. package/dist/hub-catalogue/requirement/req-error-recovery.radical +34 -0
  104. package/dist/hub-catalogue/requirement/req-event-schema-compatibility.radical +37 -0
  105. package/dist/hub-catalogue/requirement/req-fail-safe-default.radical +55 -0
  106. package/dist/hub-catalogue/requirement/req-fast-startup-graceful-shutdown.radical +69 -0
  107. package/dist/hub-catalogue/requirement/req-gdpr-erasure.radical +44 -0
  108. package/dist/hub-catalogue/requirement/req-graceful-degradation.radical +39 -0
  109. package/dist/hub-catalogue/requirement/req-health-checks.radical +43 -0
  110. package/dist/hub-catalogue/requirement/req-iac.radical +36 -0
  111. package/dist/hub-catalogue/requirement/req-idempotency.radical +47 -0
  112. package/dist/hub-catalogue/requirement/req-input-validation.radical +37 -0
  113. package/dist/hub-catalogue/requirement/req-least-privilege.radical +47 -0
  114. package/dist/hub-catalogue/requirement/req-ledger-immutability.radical +38 -0
  115. package/dist/hub-catalogue/requirement/req-mfa.radical +36 -0
  116. package/dist/hub-catalogue/requirement/req-ml-extraction-accuracy.radical +42 -0
  117. package/dist/hub-catalogue/requirement/req-onboarding-time.radical +42 -0
  118. package/dist/hub-catalogue/requirement/req-page-load-time.radical +59 -0
  119. package/dist/hub-catalogue/requirement/req-payout-latency.radical +46 -0
  120. package/dist/hub-catalogue/requirement/req-presence-latency.radical +46 -0
  121. package/dist/hub-catalogue/requirement/req-rate-limiting.radical +45 -0
  122. package/dist/hub-catalogue/requirement/req-report-generation.radical +44 -0
  123. package/dist/hub-catalogue/requirement/req-resource-efficiency.radical +64 -0
  124. package/dist/hub-catalogue/requirement/req-resource-headroom.radical +53 -0
  125. package/dist/hub-catalogue/requirement/req-resource-isolation.radical +37 -0
  126. package/dist/hub-catalogue/requirement/req-search-response-time.radical +44 -0
  127. package/dist/hub-catalogue/requirement/req-secrets-management.radical +45 -0
  128. package/dist/hub-catalogue/requirement/req-task-success-rate.radical +42 -0
  129. package/dist/hub-catalogue/requirement/req-test-coverage.radical +42 -0
  130. package/dist/hub-catalogue/requirement/req-throughput.radical +55 -0
  131. package/dist/hub-catalogue/requirement/req-vulnerability-scanning.radical +52 -0
  132. package/dist/hub-catalogue/requirement/req-zero-downtime-deploy.radical +39 -0
  133. package/dist/index.js +8382 -0
  134. package/package.json +48 -4
@@ -0,0 +1,1763 @@
1
+ // ../../packages/common/src/metamodel/lookup.ts
2
+ function isRelationAllowed(metamodel, fromType, toType) {
3
+ if (!metamodel) return true;
4
+ const rts = Object.values(metamodel.relationTypes);
5
+ if (rts.length === 0) return true;
6
+ if (rts.some((rt) => rt.allowedPairs.length === 0)) return true;
7
+ return rts.some((rt) => rt.allowedPairs.some((p) => p.from === fromType && p.to === toType));
8
+ }
9
+ function inferRelationType(metamodel, fromType, toType) {
10
+ if (!metamodel) return void 0;
11
+ const matches = Object.values(metamodel.relationTypes).filter(
12
+ (rt) => rt.allowedPairs.length > 0 && rt.allowedPairs.some((p) => p.from === fromType && p.to === toType)
13
+ );
14
+ return matches.length === 1 ? matches[0].id : void 0;
15
+ }
16
+ function isParentAllowed(metamodel, childType, parentType) {
17
+ if (!metamodel) return true;
18
+ const def = metamodel.nodeTypes[childType];
19
+ if (!def) return true;
20
+ const allowed = def.allowedParents;
21
+ if (parentType == null) {
22
+ if (def.allowedAtRoot !== void 0) return def.allowedAtRoot;
23
+ return !allowed || allowed.length === 0;
24
+ }
25
+ return !!allowed && allowed.includes(parentType);
26
+ }
27
+ function canAddMoreOfType(metamodel, typeId, currentCount) {
28
+ if (!metamodel) return true;
29
+ const def = metamodel.nodeTypes[typeId];
30
+ if (!def?.cardinality?.max) return true;
31
+ return currentCount < def.cardinality.max;
32
+ }
33
+
34
+ // ../../packages/common/src/metamodel/refs.ts
35
+ function refIds(value) {
36
+ if (typeof value === "string") return value ? [value] : [];
37
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string" && v !== "");
38
+ return [];
39
+ }
40
+ function refLabels(value, nodes) {
41
+ return refIds(value).map((id) => nodes[id]?.label ?? id);
42
+ }
43
+ function refValue(def, ids) {
44
+ return def.multiple ? ids : ids[0] ?? "";
45
+ }
46
+ function refProblem(def, id, nodes) {
47
+ const node = nodes[id];
48
+ if (!node) return `no node has id "${id}"`;
49
+ if (def.refType && node.type !== def.refType) return `"${node.label}" is of type ${node.type}, not ${def.refType}`;
50
+ return null;
51
+ }
52
+
53
+ // ../../packages/common/src/metamodel/statechart.ts
54
+ var prop = (item, key) => {
55
+ const value = item[key];
56
+ return typeof value === "string" ? value.trim() : "";
57
+ };
58
+ var stateKind = (n) => prop(n, "kind") || "normal";
59
+ var pseudoKind = (n) => prop(n, "kind") || "initial";
60
+ var isState = (n) => n?.type === "state";
61
+ var isPseudo = (n) => n?.type === "pseudostate";
62
+ function transitionLabel(r, nodes) {
63
+ const props = r;
64
+ const event = refLabels(props.event, nodes).join(", ");
65
+ const guard = prop(r, "guard");
66
+ const actions = prop(r, "actions");
67
+ const raises = refLabels(props.raises, nodes).map((label) => `^${label}`).join(" ");
68
+ return [event, guard && `[${guard}]`, actions && `/ ${actions}`, raises].filter(Boolean).join(" ");
69
+ }
70
+ var entityCache = /* @__PURE__ */ new WeakMap();
71
+ function machineEntity(machineId, nodes, relations) {
72
+ let map = entityCache.get(relations);
73
+ if (!map) {
74
+ map = /* @__PURE__ */ new Map();
75
+ for (const r of Object.values(relations)) {
76
+ if (r.relationType === "lifecycle-of" && !map.has(r.sourceId)) map.set(r.sourceId, r.targetId);
77
+ }
78
+ entityCache.set(relations, map);
79
+ }
80
+ const id = map.get(machineId);
81
+ return id ? nodes[id] : void 0;
82
+ }
83
+ function machineOf(node, nodes) {
84
+ let cur = node;
85
+ for (let depth = 0; cur && depth < 64; depth++) {
86
+ if (cur.type === "state-machine") return cur;
87
+ cur = cur.parentId ? nodes[cur.parentId] : void 0;
88
+ }
89
+ return void 0;
90
+ }
91
+ function requirementStatePhrase(requirement, nodes, relations) {
92
+ const state = nodes[refIds(requirement.precondition_state)[0] ?? ""];
93
+ if (!state) return "";
94
+ const machine = machineOf(state, nodes);
95
+ const entity = machine ? machineEntity(machine.id, nodes, relations) : void 0;
96
+ return entity ? `the ${entity.label} is ${state.label}` : `in ${state.label}`;
97
+ }
98
+ function validateStateMachines(nodes, relations) {
99
+ const nodeList = Object.values(nodes);
100
+ if (!nodeList.some((n) => n.type === "state-machine" || n.type === "state" || n.type === "pseudostate")) return [];
101
+ const issues = [];
102
+ const warn = (id, message, at) => {
103
+ issues.push({ id, severity: "warning", message, ...at });
104
+ };
105
+ const children = /* @__PURE__ */ new Map();
106
+ for (const n of nodeList) {
107
+ if (!n.parentId) continue;
108
+ const list = children.get(n.parentId);
109
+ if (list) list.push(n);
110
+ else children.set(n.parentId, [n]);
111
+ }
112
+ const childStates = (id) => (children.get(id) ?? []).filter(isState);
113
+ const initialsOf = (id) => (children.get(id) ?? []).filter((c) => isPseudo(c) && pseudoKind(c) === "initial");
114
+ const transitions = Object.values(relations).filter((r) => r.relationType === "transition" && nodes[r.sourceId] && nodes[r.targetId]);
115
+ const outgoing = /* @__PURE__ */ new Map();
116
+ const incoming = /* @__PURE__ */ new Set();
117
+ for (const t of transitions) {
118
+ const list = outgoing.get(t.sourceId);
119
+ if (list) list.push(t);
120
+ else outgoing.set(t.sourceId, [t]);
121
+ incoming.add(t.targetId);
122
+ }
123
+ const regions = nodeList.filter((n) => n.type === "state-machine" || isState(n) && stateKind(n) === "normal");
124
+ for (const owner of regions) {
125
+ if (childStates(owner.id).length === 0) continue;
126
+ const initials = initialsOf(owner.id);
127
+ const what = owner.type === "state-machine" ? "State machine" : "Compound state";
128
+ if (initials.length === 0) {
129
+ warn(`sm-no-initial:${owner.id}`, `${what} "${owner.label}" has child states but no initial pseudostate to enter them.`, { nodeId: owner.id });
130
+ } else if (initials.length > 1) {
131
+ warn(`sm-many-initials:${owner.id}`, `${what} "${owner.label}" has ${initials.length} initial pseudostates; keep one.`, { nodeId: owner.id });
132
+ }
133
+ }
134
+ for (const n of nodeList) {
135
+ if (isPseudo(n) && pseudoKind(n) === "initial") {
136
+ const out = outgoing.get(n.id) ?? [];
137
+ if (out.length !== 1) {
138
+ 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 });
139
+ }
140
+ if (incoming.has(n.id)) {
141
+ 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 });
142
+ }
143
+ }
144
+ if (!isState(n)) continue;
145
+ const kind = stateKind(n);
146
+ if (kind === "parallel") {
147
+ if (childStates(n.id).length < 2) {
148
+ warn(`sm-parallel-regions:${n.id}`, `Parallel state "${n.label}" needs at least two child states (regions) active at once.`, { nodeId: n.id });
149
+ }
150
+ if (initialsOf(n.id).length > 0) {
151
+ warn(`sm-parallel-initial:${n.id}`, `Parallel state "${n.label}" enters all its regions; it takes no initial pseudostate.`, { nodeId: n.id });
152
+ }
153
+ }
154
+ if (kind === "final") {
155
+ if ((children.get(n.id) ?? []).length > 0) {
156
+ warn(`sm-final-children:${n.id}`, `Final state "${n.label}" cannot contain other states.`, { nodeId: n.id });
157
+ }
158
+ if ((outgoing.get(n.id) ?? []).length > 0) {
159
+ warn(`sm-final-out:${n.id}`, `Final state "${n.label}" cannot have outgoing transitions.`, { nodeId: n.id });
160
+ }
161
+ }
162
+ }
163
+ for (const t of transitions) {
164
+ const src = nodes[t.sourceId];
165
+ const dst = nodes[t.targetId];
166
+ if (machineOf(src, nodes)?.id !== machineOf(dst, nodes)?.id) {
167
+ warn(`sm-cross-machine:${t.id}`, `Transition "${src.label}" \u2192 "${dst.label}" leaves its state machine.`, { relationId: t.id });
168
+ }
169
+ }
170
+ for (const [sourceId, out] of outgoing) {
171
+ const byEvent = /* @__PURE__ */ new Map();
172
+ for (const t of out) {
173
+ if (prop(t, "guard")) continue;
174
+ const key = refIds(t.event)[0] ?? "";
175
+ const list = byEvent.get(key);
176
+ if (list) list.push(t);
177
+ else byEvent.set(key, [t]);
178
+ }
179
+ for (const [event, list] of byEvent) {
180
+ if (list.length < 2) continue;
181
+ const on = event ? `on "${nodes[event]?.label ?? event}"` : "without an event";
182
+ warn(`sm-nondeterministic:${sourceId}:${event}`, `"${nodes[sourceId].label}" has ${list.length} unguarded transitions ${on}; only one can fire.`, { nodeId: sourceId });
183
+ }
184
+ }
185
+ const machinesOfEntity = /* @__PURE__ */ new Map();
186
+ for (const machine of nodeList.filter((n) => n.type === "state-machine")) {
187
+ const entity = machineEntity(machine.id, nodes, relations);
188
+ if (!entity) {
189
+ 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 });
190
+ continue;
191
+ }
192
+ machinesOfEntity.set(entity.id, [...machinesOfEntity.get(entity.id) ?? [], machine]);
193
+ }
194
+ for (const [entityId, machines] of machinesOfEntity) {
195
+ if (machines.length < 2) continue;
196
+ 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 });
197
+ }
198
+ for (const machine of nodeList.filter((n) => n.type === "state-machine")) {
199
+ if (initialsOf(machine.id).length === 0) continue;
200
+ const reached = /* @__PURE__ */ new Set();
201
+ const queue = [machine.id];
202
+ const visit = (id) => {
203
+ if (!reached.has(id)) {
204
+ reached.add(id);
205
+ queue.push(id);
206
+ }
207
+ };
208
+ while (queue.length > 0) {
209
+ const id = queue.shift();
210
+ const n = nodes[id];
211
+ if (!n) continue;
212
+ if (n.parentId && n.parentId !== machine.id && nodes[n.parentId]) visit(n.parentId);
213
+ if (n.type === "state-machine" || isState(n) && stateKind(n) === "normal") {
214
+ for (const init of initialsOf(id)) visit(init.id);
215
+ } else if (isState(n) && stateKind(n) === "parallel") {
216
+ for (const region of childStates(id)) visit(region.id);
217
+ }
218
+ for (const t of outgoing.get(id) ?? []) visit(t.targetId);
219
+ }
220
+ const unreached = (id) => {
221
+ for (const child of children.get(id) ?? []) {
222
+ if (isState(child) && !reached.has(child.id)) {
223
+ warn(`sm-unreachable:${child.id}`, `State "${child.label}" cannot be reached from the initial state of "${machine.label}".`, { nodeId: child.id });
224
+ continue;
225
+ }
226
+ unreached(child.id);
227
+ }
228
+ };
229
+ unreached(machine.id);
230
+ }
231
+ return issues;
232
+ }
233
+
234
+ // ../../packages/common/src/metamodel/domainModel.ts
235
+ var kindOf = (n) => {
236
+ const kind = n.kind;
237
+ return typeof kind === "string" && kind ? kind : "aggregate-root";
238
+ };
239
+ function validateDomainModel(nodes, relations) {
240
+ const entities = Object.values(nodes).filter((n) => n.type === "entity");
241
+ if (entities.length === 0) return [];
242
+ const issues = [];
243
+ const warn = (id, message, at) => {
244
+ issues.push({ id, severity: "warning", message, ...at });
245
+ };
246
+ const rootsOf = /* @__PURE__ */ new Map();
247
+ for (const r of Object.values(relations)) {
248
+ if (r.relationType !== "part-of") continue;
249
+ const part = nodes[r.sourceId];
250
+ const root = nodes[r.targetId];
251
+ if (part?.type !== "entity" || root?.type !== "entity") continue;
252
+ if (kindOf(part) === "aggregate-root") {
253
+ 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 });
254
+ continue;
255
+ }
256
+ if (kindOf(root) !== "aggregate-root") {
257
+ warn(`ddd-part-of-entity:${r.id}`, `"${part.label}" is part of "${root.label}", which is not an aggregate root.`, { relationId: r.id });
258
+ }
259
+ rootsOf.set(part.id, [...rootsOf.get(part.id) ?? [], root.label]);
260
+ }
261
+ for (const entity of entities) {
262
+ if (kindOf(entity) !== "entity") continue;
263
+ const roots = rootsOf.get(entity.id) ?? [];
264
+ if (roots.length === 0) {
265
+ 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 });
266
+ } else if (roots.length > 1) {
267
+ warn(`ddd-many-roots:${entity.id}`, `Entity "${entity.label}" is part of ${roots.length} aggregates (${roots.join(", ")}); it belongs to one.`, { nodeId: entity.id });
268
+ }
269
+ }
270
+ return issues;
271
+ }
272
+
273
+ // ../../packages/common/src/metamodel/validate.ts
274
+ function validateModel(nodes, relations, metamodel) {
275
+ const issues = [];
276
+ const nodeList = Object.values(nodes);
277
+ for (const n of nodeList) {
278
+ const def = metamodel.nodeTypes[n.type];
279
+ if (!def) {
280
+ issues.push({
281
+ id: `unknown-type:${n.id}`,
282
+ severity: "error",
283
+ message: `Node "${n.label}" has unknown type "${n.type}".`,
284
+ nodeId: n.id
285
+ });
286
+ continue;
287
+ }
288
+ const allowed = def.allowedParents;
289
+ if (n.parentId) {
290
+ const parent = nodes[n.parentId];
291
+ if (!parent) {
292
+ issues.push({
293
+ id: `parent-missing:${n.id}`,
294
+ severity: "error",
295
+ message: `Node "${n.label}" references a missing parent.`,
296
+ nodeId: n.id
297
+ });
298
+ } else if (allowed && !allowed.includes(parent.type)) {
299
+ const parentLabel = metamodel.nodeTypes[parent.type]?.label ?? parent.type;
300
+ issues.push({
301
+ id: `bad-parent:${n.id}`,
302
+ severity: "error",
303
+ message: `${def.label} "${n.label}" cannot be inside ${parentLabel}. Allowed parents: ${allowed.length ? allowed.join(", ") : "(none \u2014 must be root)"}.`,
304
+ nodeId: n.id
305
+ });
306
+ }
307
+ } else if (def.allowedAtRoot === false || def.allowedAtRoot === void 0 && allowed && allowed.length > 0) {
308
+ issues.push({
309
+ id: `needs-parent:${n.id}`,
310
+ severity: "error",
311
+ message: `${def.label} "${n.label}" must be inside ${allowed && allowed.length ? allowed.join(" or ") : "a parent"}.`,
312
+ nodeId: n.id
313
+ });
314
+ }
315
+ for (const p of def.properties ?? []) {
316
+ if (!p.required) continue;
317
+ const v = n[p.key];
318
+ if (v == null || v === "") {
319
+ issues.push({
320
+ id: `missing-prop:${n.id}:${p.key}`,
321
+ severity: "warning",
322
+ message: `${def.label} "${n.label}" is missing required property "${p.label}".`,
323
+ nodeId: n.id
324
+ });
325
+ }
326
+ }
327
+ }
328
+ for (const def of Object.values(metamodel.nodeTypes)) {
329
+ const c = def.cardinality;
330
+ if (!c) continue;
331
+ const count = nodeList.filter((n) => n.type === def.id).length;
332
+ if (c.min != null && count < c.min) {
333
+ issues.push({
334
+ id: `cardinality-min:${def.id}`,
335
+ severity: "warning",
336
+ message: `Model has ${count} ${def.label} (minimum ${c.min}).`,
337
+ nodeTypeId: def.id
338
+ });
339
+ }
340
+ if (c.max != null && count > c.max) {
341
+ issues.push({
342
+ id: `cardinality-max:${def.id}`,
343
+ severity: "warning",
344
+ message: `Model has ${count} ${def.label} (maximum ${c.max}).`,
345
+ nodeTypeId: def.id
346
+ });
347
+ }
348
+ }
349
+ const restrictiveTypes = Object.values(metamodel.relationTypes).filter((rt) => rt.allowedPairs.length > 0);
350
+ const anyAllows = Object.values(metamodel.relationTypes).some((rt) => rt.allowedPairs.length === 0);
351
+ if (restrictiveTypes.length > 0 && !anyAllows) {
352
+ for (const r of Object.values(relations)) {
353
+ const src = nodes[r.sourceId];
354
+ const dst = nodes[r.targetId];
355
+ if (!src || !dst) continue;
356
+ const ok = restrictiveTypes.some(
357
+ (rt) => rt.allowedPairs.some((p) => p.from === src.type && p.to === dst.type)
358
+ );
359
+ if (!ok) {
360
+ issues.push({
361
+ id: `bad-rel:${r.id}`,
362
+ severity: "warning",
363
+ message: `Relation "${src.label}" \u2192 "${dst.label}" (${src.type}\u2192${dst.type}) is not allowed by metamodel.`,
364
+ relationId: r.id
365
+ });
366
+ }
367
+ }
368
+ }
369
+ const checkRefs = (item, props, at, what) => {
370
+ for (const p of props ?? []) {
371
+ if (p.type !== "ref") continue;
372
+ for (const id of refIds(item[p.key])) {
373
+ const problem = refProblem(p, id, nodes);
374
+ if (problem) {
375
+ issues.push({
376
+ id: `bad-ref:${at.nodeId ?? at.relationId}:${p.key}:${id}`,
377
+ severity: "warning",
378
+ message: `${what}: "${p.label}" points at nothing valid (${problem}).`,
379
+ ...at
380
+ });
381
+ }
382
+ }
383
+ }
384
+ };
385
+ for (const n of nodeList) {
386
+ const def = metamodel.nodeTypes[n.type];
387
+ if (def) checkRefs(n, def.properties, { nodeId: n.id }, `${def.label} "${n.label}"`);
388
+ }
389
+ for (const r of Object.values(relations)) {
390
+ const def = r.relationType ? metamodel.relationTypes[r.relationType] : void 0;
391
+ if (!def) continue;
392
+ const src = nodes[r.sourceId]?.label ?? r.sourceId;
393
+ const dst = nodes[r.targetId]?.label ?? r.targetId;
394
+ checkRefs(r, def.properties, { relationId: r.id }, `${def.label} "${src}" \u2192 "${dst}"`);
395
+ }
396
+ if (metamodel.nodeTypes.entity && metamodel.relationTypes["part-of"]) {
397
+ issues.push(...validateDomainModel(nodes, relations));
398
+ }
399
+ if (metamodel.nodeTypes.state && metamodel.relationTypes.transition) {
400
+ issues.push(...validateStateMachines(nodes, relations));
401
+ }
402
+ return issues;
403
+ }
404
+
405
+ // ../../packages/common/src/metamodel/ears.ts
406
+ function capitalize(s) {
407
+ return s.charAt(0).toUpperCase() + s.slice(1);
408
+ }
409
+ function composeEarsSentence(node, subject, statePrecondition) {
410
+ const earsType = String(node.ears_type ?? "ubiquitous");
411
+ const subj = (subject || "the system").trim();
412
+ const action = String(node.action ?? "").trim();
413
+ const trigger = String(node.trigger ?? "").trim();
414
+ const precondition = String(node.precondition ?? "").trim() || (statePrecondition ?? "").trim();
415
+ const unwanted = String(node.unwanted_condition ?? "").trim();
416
+ const feature = String(node.feature ?? "").trim();
417
+ const actionPart = action || "\u2039action\u203A";
418
+ const shallClause = `${subj} shall ${actionPart}`;
419
+ let sentence;
420
+ let complete = !!action;
421
+ switch (earsType) {
422
+ case "event-driven":
423
+ sentence = `When ${trigger || "\u2039trigger\u203A"}, ${shallClause}.`;
424
+ complete = complete && !!trigger;
425
+ break;
426
+ case "state-driven":
427
+ sentence = `While ${precondition || "\u2039precondition\u203A"}, ${shallClause}.`;
428
+ complete = complete && !!precondition;
429
+ break;
430
+ case "unwanted-behaviour":
431
+ sentence = `If ${unwanted || "\u2039condition\u203A"}, then ${shallClause}.`;
432
+ complete = complete && !!unwanted;
433
+ break;
434
+ case "optional":
435
+ sentence = `Where ${feature || "\u2039feature\u203A"}, ${shallClause}.`;
436
+ complete = complete && !!feature;
437
+ break;
438
+ case "complex": {
439
+ const parts = [];
440
+ if (precondition) parts.push(`While ${precondition}`);
441
+ if (trigger) parts.push(`when ${trigger}`);
442
+ if (unwanted) parts.push(`if ${unwanted}`);
443
+ if (feature) parts.push(`where ${feature}`);
444
+ const hasCondition = parts.length > 0;
445
+ if (!hasCondition) parts.push("\u2039conditions\u203A");
446
+ else parts[0] = capitalize(parts[0]);
447
+ sentence = `${parts.join(", ")}, ${shallClause}.`;
448
+ complete = complete && hasCondition;
449
+ break;
450
+ }
451
+ default:
452
+ sentence = `${capitalize(subj)} shall ${actionPart}.`;
453
+ break;
454
+ }
455
+ return { sentence, complete };
456
+ }
457
+
458
+ // ../../packages/common/src/metamodel/presets/c4.ts
459
+ var VISUALS = {
460
+ person: {
461
+ label: "Person",
462
+ color: "#08427b",
463
+ fg: "#fff",
464
+ 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",
465
+ width: 150,
466
+ height: 170,
467
+ collapsedWidth: 150,
468
+ collapsedHeight: 170
469
+ },
470
+ system: {
471
+ label: "Software System",
472
+ color: "#1168bd",
473
+ fg: "#fff",
474
+ 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",
475
+ width: 360,
476
+ height: 260,
477
+ collapsedWidth: 280,
478
+ collapsedHeight: 180
479
+ },
480
+ container: {
481
+ label: "Container",
482
+ color: "#438dd5",
483
+ fg: "#fff",
484
+ 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",
485
+ width: 300,
486
+ height: 200,
487
+ collapsedWidth: 240,
488
+ collapsedHeight: 160
489
+ },
490
+ component: {
491
+ label: "Component",
492
+ color: "#85bbf0",
493
+ fg: "#000",
494
+ 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",
495
+ width: 200,
496
+ height: 120,
497
+ collapsedWidth: 200,
498
+ collapsedHeight: 120
499
+ },
500
+ database: {
501
+ label: "Database",
502
+ color: "#438dd5",
503
+ fg: "#fff",
504
+ 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",
505
+ width: 190,
506
+ height: 130,
507
+ collapsedWidth: 190,
508
+ collapsedHeight: 130
509
+ },
510
+ webapp: {
511
+ label: "Web App",
512
+ color: "#438dd5",
513
+ fg: "#fff",
514
+ 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",
515
+ width: 210,
516
+ height: 140,
517
+ collapsedWidth: 210,
518
+ collapsedHeight: 140
519
+ },
520
+ queue: {
521
+ label: "Queue",
522
+ color: "#438dd5",
523
+ fg: "#fff",
524
+ 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",
525
+ width: 220,
526
+ height: 95,
527
+ collapsedWidth: 220,
528
+ collapsedHeight: 95
529
+ },
530
+ group: {
531
+ label: "Group",
532
+ color: "#64748b",
533
+ fg: "#fff",
534
+ // Folder icon.
535
+ 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",
536
+ width: 520,
537
+ height: 360,
538
+ collapsedWidth: 360,
539
+ collapsedHeight: 220
540
+ }
541
+ };
542
+ function builtInC4Metamodel() {
543
+ const nodeTypes = {};
544
+ const allowedParentsMap = {
545
+ person: ["group"],
546
+ system: ["system", "group"],
547
+ container: ["system", "group"],
548
+ component: ["container", "webapp", "group"],
549
+ database: ["system", "group"],
550
+ webapp: ["system", "group"],
551
+ queue: ["system", "group"],
552
+ group: ["group", "system"]
553
+ };
554
+ const techTypes = /* @__PURE__ */ new Set(["container", "component", "database", "webapp", "queue"]);
555
+ const types = [
556
+ "person",
557
+ "system",
558
+ "container",
559
+ "component",
560
+ "database",
561
+ "webapp",
562
+ "queue",
563
+ "group"
564
+ ];
565
+ for (const t of types) {
566
+ const props = [
567
+ { key: "description", label: "Description", type: "textarea" }
568
+ ];
569
+ if (techTypes.has(t)) props.push({ key: "technology", label: "Technology", type: "text" });
570
+ if (t !== "group") props.push({ key: "external", label: "External", type: "boolean" });
571
+ const v = VISUALS[t];
572
+ nodeTypes[t] = {
573
+ id: t,
574
+ label: v.label,
575
+ color: v.color,
576
+ fg: v.fg,
577
+ iconPath: v.iconPath,
578
+ width: v.width,
579
+ height: v.height,
580
+ collapsedWidth: v.collapsedWidth,
581
+ collapsedHeight: v.collapsedHeight,
582
+ allowedParents: allowedParentsMap[t],
583
+ // person, system, and group are top-level concepts and may live at the root.
584
+ allowedAtRoot: t === "person" || t === "system" || t === "group",
585
+ builtin: true,
586
+ properties: props
587
+ };
588
+ }
589
+ const interactsPairs = [
590
+ // Person interacts with the system surface
591
+ { from: "person", to: "system" },
592
+ { from: "person", to: "container" },
593
+ { from: "person", to: "webapp" },
594
+ { from: "person", to: "component" },
595
+ // System-level dependencies
596
+ { from: "system", to: "person" },
597
+ { from: "system", to: "system" },
598
+ { from: "system", to: "container" },
599
+ { from: "system", to: "database" },
600
+ { from: "system", to: "webapp" },
601
+ { from: "system", to: "queue" },
602
+ { from: "system", to: "component" },
603
+ // Container-level calls
604
+ { from: "container", to: "person" },
605
+ { from: "container", to: "system" },
606
+ { from: "container", to: "container" },
607
+ { from: "container", to: "database" },
608
+ { from: "container", to: "webapp" },
609
+ { from: "container", to: "queue" },
610
+ // Web / UI container
611
+ { from: "webapp", to: "person" },
612
+ { from: "webapp", to: "system" },
613
+ { from: "webapp", to: "container" },
614
+ { from: "webapp", to: "database" },
615
+ { from: "webapp", to: "webapp" },
616
+ { from: "webapp", to: "queue" },
617
+ // Queues fan out to consumers
618
+ { from: "queue", to: "container" },
619
+ { from: "queue", to: "webapp" },
620
+ { from: "queue", to: "component" },
621
+ // Component-level calls
622
+ { from: "component", to: "component" },
623
+ { from: "component", to: "container" },
624
+ { from: "component", to: "webapp" },
625
+ { from: "component", to: "database" },
626
+ { from: "component", to: "queue" },
627
+ { from: "component", to: "system" }
628
+ ];
629
+ const relationTypes = {
630
+ interacts: {
631
+ id: "interacts",
632
+ label: "Interacts",
633
+ allowedPairs: interactsPairs,
634
+ properties: [
635
+ { key: "technology", label: "Technology", type: "text" }
636
+ ],
637
+ builtin: true
638
+ }
639
+ };
640
+ return { id: "c4-builtin", name: "C4 (built-in)", nodeTypes, relationTypes };
641
+ }
642
+
643
+ // ../../packages/common/src/metamodel/presets/ddd.ts
644
+ function builtInDddC4Metamodel() {
645
+ const base = builtInC4Metamodel();
646
+ const patchedSystem = {
647
+ ...base.nodeTypes.system,
648
+ allowedParents: ["system", "domain", "group"],
649
+ allowedAtRoot: true
650
+ };
651
+ const domainProps = [
652
+ { key: "description", label: "Description", type: "textarea" },
653
+ { key: "vision", label: "Vision", type: "textarea" },
654
+ {
655
+ key: "kind",
656
+ label: "Kind",
657
+ type: "enum",
658
+ options: ["core", "supporting", "generic"],
659
+ default: "core"
660
+ }
661
+ ];
662
+ const domain = {
663
+ id: "domain",
664
+ label: "Domain",
665
+ color: "#4c1d95",
666
+ fg: "#fff",
667
+ 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",
668
+ width: 520,
669
+ height: 360,
670
+ collapsedWidth: 360,
671
+ collapsedHeight: 220,
672
+ // A domain may be nested inside another domain or a group.
673
+ allowedParents: ["domain", "group"],
674
+ allowedAtRoot: true,
675
+ builtin: true,
676
+ properties: domainProps
677
+ };
678
+ const entity = {
679
+ id: "entity",
680
+ label: "Entity",
681
+ color: "#7e22ce",
682
+ fg: "#fff",
683
+ // A record card with a key
684
+ 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",
685
+ width: 170,
686
+ height: 56,
687
+ allowedParents: ["domain", "group"],
688
+ allowedAtRoot: true,
689
+ builtin: true,
690
+ tableTab: true,
691
+ // The parts of an aggregate list under its root in Table and Wiki views.
692
+ hierarchyRelation: "part-of",
693
+ properties: [
694
+ {
695
+ key: "kind",
696
+ label: "Kind",
697
+ type: "enum",
698
+ options: ["aggregate-root", "entity"],
699
+ default: "aggregate-root"
700
+ },
701
+ { key: "description", label: "Description", type: "textarea" }
702
+ ]
703
+ };
704
+ const realises = {
705
+ id: "realises",
706
+ label: "Realises",
707
+ allowedPairs: [
708
+ { from: "system", to: "domain" },
709
+ { from: "container", to: "domain" },
710
+ ...["system", "container", "component", "webapp"].map((from) => ({ from, to: "entity" }))
711
+ ],
712
+ properties: [],
713
+ builtin: true
714
+ };
715
+ const partOf = {
716
+ id: "part-of",
717
+ label: "Part of",
718
+ allowedPairs: [{ from: "entity", to: "entity" }],
719
+ properties: [],
720
+ color: "#7e22ce",
721
+ builtin: true
722
+ };
723
+ const references = {
724
+ id: "references",
725
+ label: "References",
726
+ allowedPairs: [{ from: "entity", to: "entity" }],
727
+ properties: [
728
+ {
729
+ key: "cardinality",
730
+ label: "Cardinality",
731
+ type: "enum",
732
+ options: ["one", "many"],
733
+ default: "one"
734
+ },
735
+ { key: "description", label: "Description", type: "text" }
736
+ ],
737
+ color: "#a855f7",
738
+ builtin: true
739
+ };
740
+ const ddPairs = [
741
+ { from: "domain", to: "domain" }
742
+ ];
743
+ const dependsOn = {
744
+ id: "depends-on",
745
+ label: "Depends on",
746
+ allowedPairs: ddPairs,
747
+ properties: [
748
+ { key: "description", label: "Description", type: "text" }
749
+ ],
750
+ builtin: true
751
+ };
752
+ const partnership = {
753
+ id: "partnership",
754
+ label: "Partnership",
755
+ allowedPairs: ddPairs,
756
+ properties: [
757
+ {
758
+ key: "pattern",
759
+ label: "Pattern",
760
+ type: "enum",
761
+ options: [
762
+ "partnership",
763
+ "shared-kernel",
764
+ "customer-supplier",
765
+ "conformist",
766
+ "anti-corruption-layer",
767
+ "open-host-service",
768
+ "published-language",
769
+ "separate-ways"
770
+ ],
771
+ default: "partnership"
772
+ },
773
+ { key: "description", label: "Description", type: "text" }
774
+ ],
775
+ builtin: true
776
+ };
777
+ return {
778
+ id: "c4-ddd-builtin",
779
+ name: "C4 + DDD Domains",
780
+ nodeTypes: {
781
+ ...base.nodeTypes,
782
+ system: patchedSystem,
783
+ domain,
784
+ entity
785
+ },
786
+ relationTypes: {
787
+ ...base.relationTypes,
788
+ realises,
789
+ "part-of": partOf,
790
+ references,
791
+ "depends-on": dependsOn,
792
+ partnership
793
+ }
794
+ };
795
+ }
796
+
797
+ // ../../packages/common/src/metamodel/presets/governance.ts
798
+ var RADICAL_METAMODEL_NAME = "Radical";
799
+ function builtInGovernanceMetamodel() {
800
+ const base = builtInDddC4Metamodel();
801
+ const adrProps = [
802
+ {
803
+ key: "status",
804
+ label: "Status",
805
+ type: "enum",
806
+ options: ["proposed", "accepted", "deprecated", "superseded"],
807
+ default: "proposed"
808
+ },
809
+ { key: "date", label: "Date", type: "text" },
810
+ { key: "context", label: "Context", type: "textarea" },
811
+ { key: "decision", label: "Decision", type: "textarea" },
812
+ { key: "consequences", label: "Consequences", type: "textarea" },
813
+ { key: "alternatives", label: "Alternatives considered", type: "textarea" }
814
+ ];
815
+ const adr = {
816
+ id: "adr",
817
+ label: "ADR",
818
+ color: "#92400e",
819
+ fg: "#fff",
820
+ // ADR: document with text lines
821
+ 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",
822
+ width: 180,
823
+ height: 52,
824
+ collapsedWidth: 160,
825
+ collapsedHeight: 52,
826
+ allowedParents: ["system", "domain", "group"],
827
+ allowedAtRoot: true,
828
+ builtin: true,
829
+ tableTab: true,
830
+ properties: adrProps,
831
+ wizard: {
832
+ trigger: "create",
833
+ prefill: { status: "proposed", date: "{{today}}" },
834
+ steps: [
835
+ {
836
+ kind: "fields",
837
+ title: "Title & status",
838
+ fields: ["label", "status", "date"],
839
+ help: 'Name the decision in a few words, e.g. "Use PostgreSQL for order storage".'
840
+ },
841
+ {
842
+ kind: "fields",
843
+ title: "Context",
844
+ fields: ["context"],
845
+ help: "What forces are at play \u2014 the problem, constraints and drivers that make a decision necessary now?"
846
+ },
847
+ {
848
+ kind: "fields",
849
+ title: "Decision",
850
+ fields: ["decision"],
851
+ help: 'What did you decide? State it actively: "We will \u2026".'
852
+ },
853
+ {
854
+ kind: "fields",
855
+ title: "Alternatives",
856
+ fields: ["alternatives"],
857
+ help: "Which other options did you consider, and why were they rejected?"
858
+ },
859
+ {
860
+ kind: "fields",
861
+ title: "Consequences",
862
+ fields: ["consequences"],
863
+ help: "What becomes easier or harder? Include the downsides and the risks you accept."
864
+ },
865
+ {
866
+ kind: "relations",
867
+ title: "Affected elements",
868
+ relationType: "constrains",
869
+ direction: "out",
870
+ help: "Which parts of the architecture must follow this decision?"
871
+ },
872
+ {
873
+ kind: "relations",
874
+ title: "Supersedes",
875
+ relationType: "supersedes",
876
+ direction: "out",
877
+ help: "Does this decision replace an earlier one? Leave empty if not."
878
+ }
879
+ ]
880
+ }
881
+ };
882
+ const fitnessFnProps = [
883
+ { key: "description", label: "Description", type: "textarea" },
884
+ {
885
+ key: "category",
886
+ label: "Category",
887
+ type: "enum",
888
+ options: ["structural", "operational", "process", "holistic"],
889
+ default: "structural"
890
+ },
891
+ { key: "threshold", label: "Threshold / Success criteria", type: "text" }
892
+ ];
893
+ const fitnessFn = {
894
+ id: "fitness-fn",
895
+ label: "Fitness Function",
896
+ color: "#5b21b6",
897
+ fg: "#fff",
898
+ // Concentric circles (target / gauge)
899
+ 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",
900
+ width: 180,
901
+ height: 52,
902
+ collapsedWidth: 160,
903
+ collapsedHeight: 52,
904
+ allowedParents: ["system", "domain", "group"],
905
+ allowedAtRoot: true,
906
+ builtin: true,
907
+ tableTab: true,
908
+ properties: fitnessFnProps,
909
+ wizard: {
910
+ trigger: "create",
911
+ steps: [
912
+ {
913
+ kind: "fields",
914
+ title: "Name & category",
915
+ fields: ["label", "category"],
916
+ help: 'Name the architectural characteristic this function protects, e.g. "Checkout p95 latency".'
917
+ },
918
+ {
919
+ kind: "fields",
920
+ title: "What it measures",
921
+ fields: ["description"],
922
+ help: "How is the characteristic measured \u2014 a test, a metric, a static check?"
923
+ },
924
+ {
925
+ kind: "fields",
926
+ title: "Success criteria",
927
+ fields: ["threshold"],
928
+ help: 'When does it pass? Give a concrete threshold, e.g. "p95 < 300 ms".'
929
+ },
930
+ {
931
+ kind: "relations",
932
+ title: "Verified decisions",
933
+ relationType: "implements",
934
+ direction: "out",
935
+ help: "Which ADRs does this fitness function verify?"
936
+ },
937
+ {
938
+ kind: "relations",
939
+ title: "Guarded elements",
940
+ relationType: "constrains",
941
+ direction: "out",
942
+ help: "Which elements does it check?"
943
+ }
944
+ ]
945
+ }
946
+ };
947
+ const needProps = [
948
+ { key: "description", label: "Text", type: "textarea" },
949
+ {
950
+ key: "kind",
951
+ label: "Kind",
952
+ type: "enum",
953
+ options: ["brief", "user-story", "stakeholder-note", "meeting-notes", "regulation", "other"],
954
+ default: "brief"
955
+ },
956
+ { key: "source", label: "Source (who / where from)", type: "text" }
957
+ ];
958
+ const need = {
959
+ id: "need",
960
+ label: "Need",
961
+ color: "#475569",
962
+ fg: "#fff",
963
+ // Speech bubble with text lines
964
+ 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",
965
+ width: 200,
966
+ height: 80,
967
+ collapsedWidth: 180,
968
+ collapsedHeight: 80,
969
+ allowedParents: ["system", "domain", "group"],
970
+ allowedAtRoot: true,
971
+ builtin: true,
972
+ tableTab: true,
973
+ // A need's wiki page and table tab list what derives from it — sub-needs
974
+ // and requirements — as its children; "add child" creates either.
975
+ hierarchyRelation: "derives",
976
+ properties: needProps,
977
+ wizard: {
978
+ trigger: "create",
979
+ steps: [
980
+ {
981
+ kind: "fields",
982
+ title: "Name & kind",
983
+ fields: ["label", "kind"],
984
+ help: 'A short name, e.g. "Checkout brief from Sales". Pick what kind of input it is.'
985
+ },
986
+ {
987
+ kind: "fields",
988
+ title: "Text",
989
+ fields: ["description"],
990
+ 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."
991
+ },
992
+ {
993
+ kind: "fields",
994
+ title: "Source",
995
+ fields: ["source"],
996
+ help: "Who it came from or where it lives (a person, meeting, ticket or link)."
997
+ },
998
+ {
999
+ kind: "relations",
1000
+ title: "Part of",
1001
+ relationType: "derives",
1002
+ direction: "out",
1003
+ help: "Is this part of a broader need, e.g. one stakeholder's notes within a discovery? Leave empty if not."
1004
+ }
1005
+ ]
1006
+ }
1007
+ };
1008
+ const requirementProps = [
1009
+ {
1010
+ key: "ears_type",
1011
+ label: "EARS type",
1012
+ type: "enum",
1013
+ options: ["ubiquitous", "event-driven", "state-driven", "unwanted-behaviour", "optional", "complex"],
1014
+ default: "ubiquitous"
1015
+ },
1016
+ { key: "trigger", label: "When (trigger)", type: "text", visibleWhen: { key: "ears_type", values: ["event-driven", "complex"] } },
1017
+ { key: "precondition", label: "While (precondition)", type: "text", visibleWhen: { key: "ears_type", values: ["state-driven", "complex"] } },
1018
+ // The state the precondition is, when it is one of a state machine's:
1019
+ // "While the Reservation is Confirmed". Takes the place of the text.
1020
+ { key: "precondition_state", label: "While in state", type: "ref", refType: "state", visibleWhen: { key: "ears_type", values: ["state-driven", "complex"] } },
1021
+ { key: "unwanted_condition", label: "If (unwanted condition)", type: "text", visibleWhen: { key: "ears_type", values: ["unwanted-behaviour", "complex"] } },
1022
+ { key: "feature", label: "Where (feature)", type: "text", visibleWhen: { key: "ears_type", values: ["optional", "complex"] } },
1023
+ { key: "action", label: "The system shall (action)", type: "textarea" },
1024
+ { key: "rationale", label: "Rationale", type: "textarea" }
1025
+ ];
1026
+ const requirement = {
1027
+ id: "requirement",
1028
+ label: "Requirement",
1029
+ color: "#0e7490",
1030
+ fg: "#fff",
1031
+ // Checklist / clipboard with checkmark
1032
+ 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",
1033
+ width: 200,
1034
+ height: 80,
1035
+ collapsedWidth: 180,
1036
+ collapsedHeight: 80,
1037
+ allowedParents: ["system", "domain", "group"],
1038
+ allowedAtRoot: true,
1039
+ builtin: true,
1040
+ tableTab: true,
1041
+ hierarchyRelation: "derives",
1042
+ properties: requirementProps,
1043
+ wizard: {
1044
+ trigger: "create",
1045
+ steps: [
1046
+ {
1047
+ kind: "fields",
1048
+ title: "Name",
1049
+ fields: ["label"],
1050
+ help: 'A short name for the requirement, e.g. "Lock account after failed logins".'
1051
+ },
1052
+ {
1053
+ kind: "custom",
1054
+ title: "Sentence",
1055
+ component: "ears-quick-entry",
1056
+ 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."
1057
+ },
1058
+ {
1059
+ kind: "fields",
1060
+ title: "EARS fields",
1061
+ fields: ["ears_type", "trigger", "precondition", "precondition_state", "unwanted_condition", "feature", "action"],
1062
+ help: "Pick the EARS pattern; only the clauses it uses are shown."
1063
+ },
1064
+ {
1065
+ kind: "fields",
1066
+ title: "Rationale",
1067
+ fields: ["rationale"],
1068
+ help: "Why is this requirement needed? Who asked for it?"
1069
+ },
1070
+ {
1071
+ kind: "relations",
1072
+ title: "Satisfied by",
1073
+ relationType: "satisfies",
1074
+ direction: "in",
1075
+ help: "Which elements must satisfy this requirement?"
1076
+ },
1077
+ {
1078
+ kind: "relations",
1079
+ title: "Derives from",
1080
+ relationType: "derives",
1081
+ direction: "out",
1082
+ help: "Is this a refinement of a broader requirement, or derived from a need?"
1083
+ },
1084
+ {
1085
+ kind: "relations",
1086
+ title: "Traces to",
1087
+ relationType: "traces-to",
1088
+ direction: "out",
1089
+ help: "Which decisions or fitness functions follow from it?"
1090
+ }
1091
+ ]
1092
+ }
1093
+ };
1094
+ const constraintSources = ["adr", "fitness-fn", "requirement"];
1095
+ const constraintTargets = ["person", "system", "domain", "container", "component", "database", "webapp", "queue"];
1096
+ const constrainsPairs = constraintSources.flatMap(
1097
+ (from) => constraintTargets.map((to) => ({ from, to }))
1098
+ );
1099
+ const constrains = {
1100
+ id: "constrains",
1101
+ label: "Constrains",
1102
+ allowedPairs: constrainsPairs,
1103
+ properties: [
1104
+ { key: "description", label: "Note", type: "text" }
1105
+ ],
1106
+ color: "#dc2626",
1107
+ builtin: true
1108
+ };
1109
+ const supersedes = {
1110
+ id: "supersedes",
1111
+ label: "Supersedes",
1112
+ allowedPairs: [{ from: "adr", to: "adr" }],
1113
+ properties: [],
1114
+ color: "#f59e0b",
1115
+ builtin: true
1116
+ };
1117
+ const implements_ = {
1118
+ id: "implements",
1119
+ label: "Implements",
1120
+ allowedPairs: [{ from: "fitness-fn", to: "adr" }],
1121
+ properties: [],
1122
+ color: "#7c3aed",
1123
+ builtin: true
1124
+ };
1125
+ const satisfiesTargets = ["person", "system", "domain", "container", "component", "database", "webapp", "queue"];
1126
+ const satisfies = {
1127
+ id: "satisfies",
1128
+ label: "Satisfies",
1129
+ allowedPairs: satisfiesTargets.map((to) => ({ from: to, to: "requirement" })),
1130
+ properties: [
1131
+ { key: "description", label: "Note", type: "text" }
1132
+ ],
1133
+ color: "#0891b2",
1134
+ builtin: true
1135
+ };
1136
+ const derives = {
1137
+ id: "derives",
1138
+ label: "Derives from",
1139
+ allowedPairs: [
1140
+ { from: "requirement", to: "requirement" },
1141
+ { from: "requirement", to: "need" },
1142
+ { from: "need", to: "need" }
1143
+ ],
1144
+ properties: [],
1145
+ color: "#0d9488",
1146
+ builtin: true
1147
+ };
1148
+ const tracesTo = {
1149
+ id: "traces-to",
1150
+ label: "Traces to",
1151
+ allowedPairs: [
1152
+ { from: "requirement", to: "adr" },
1153
+ { from: "requirement", to: "fitness-fn" }
1154
+ ],
1155
+ properties: [],
1156
+ color: "#06b6d4",
1157
+ builtin: true
1158
+ };
1159
+ const scenarioProps = [
1160
+ { key: "given", label: "Given", type: "textarea" },
1161
+ { key: "when", label: "When", type: "textarea" },
1162
+ { key: "then", label: "Then", type: "textarea" },
1163
+ { key: "gherkin", label: "Extra steps (And/But, raw Gherkin)", type: "textarea" }
1164
+ ];
1165
+ const scenario = {
1166
+ id: "scenario",
1167
+ label: "Scenario",
1168
+ color: "#166534",
1169
+ fg: "#fff",
1170
+ // Play/run triangle in a rounded frame
1171
+ 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",
1172
+ width: 200,
1173
+ height: 80,
1174
+ collapsedWidth: 180,
1175
+ collapsedHeight: 80,
1176
+ allowedParents: ["system", "domain", "group"],
1177
+ allowedAtRoot: true,
1178
+ builtin: true,
1179
+ tableTab: true,
1180
+ properties: scenarioProps,
1181
+ wizard: {
1182
+ trigger: "create",
1183
+ steps: [
1184
+ {
1185
+ kind: "fields",
1186
+ title: "Name",
1187
+ fields: ["label"],
1188
+ help: 'Name the behaviour, e.g. "Card payment declined".'
1189
+ },
1190
+ {
1191
+ kind: "fields",
1192
+ title: "Given",
1193
+ fields: ["given"],
1194
+ help: "The starting state: who is involved and what is already true."
1195
+ },
1196
+ {
1197
+ kind: "fields",
1198
+ title: "When",
1199
+ fields: ["when"],
1200
+ help: "The single action or event under test."
1201
+ },
1202
+ {
1203
+ kind: "fields",
1204
+ title: "Then",
1205
+ fields: ["then", "gherkin"],
1206
+ help: "The observable outcome. Add And/But steps below if needed."
1207
+ },
1208
+ {
1209
+ kind: "relations",
1210
+ title: "Verified requirements",
1211
+ relationType: "verifies",
1212
+ direction: "out",
1213
+ help: "Which requirements does this scenario verify?"
1214
+ }
1215
+ ]
1216
+ }
1217
+ };
1218
+ const verifiesTargets = ["requirement"];
1219
+ const verifies = {
1220
+ id: "verifies",
1221
+ label: "Verifies",
1222
+ allowedPairs: verifiesTargets.map((to) => ({ from: "scenario", to })),
1223
+ properties: [],
1224
+ color: "#16a34a",
1225
+ builtin: true
1226
+ };
1227
+ const blueprintProps = [
1228
+ { key: "description", label: "Description", type: "textarea" },
1229
+ {
1230
+ key: "status",
1231
+ label: "Status",
1232
+ type: "enum",
1233
+ options: ["draft", "reviewed", "approved", "deprecated"],
1234
+ default: "draft"
1235
+ },
1236
+ { key: "domain", label: "Domain / Context", type: "text" },
1237
+ { key: "rationale", label: "Rationale", type: "textarea" }
1238
+ ];
1239
+ const blueprint = {
1240
+ id: "blueprint",
1241
+ label: "Blueprint",
1242
+ color: "#1e3a5f",
1243
+ fg: "#fff",
1244
+ // Blueprint grid / technical drawing
1245
+ 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",
1246
+ width: 520,
1247
+ height: 360,
1248
+ collapsedWidth: 360,
1249
+ collapsedHeight: 220,
1250
+ allowedParents: ["domain", "group"],
1251
+ allowedAtRoot: true,
1252
+ builtin: true,
1253
+ hubOnly: true,
1254
+ tableTab: true,
1255
+ properties: blueprintProps
1256
+ };
1257
+ const mockupProps = [
1258
+ { key: "description", label: "Description", type: "textarea" },
1259
+ { key: "screen", label: "Screen / route", type: "text" },
1260
+ { key: "link", label: "Design link", type: "text" }
1261
+ ];
1262
+ const mockup = {
1263
+ id: "mockup",
1264
+ label: "Mockup",
1265
+ color: "#be185d",
1266
+ fg: "#fff",
1267
+ // Browser window with a header bar and content blocks
1268
+ 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",
1269
+ width: 220,
1270
+ height: 190,
1271
+ collapsedWidth: 220,
1272
+ collapsedHeight: 190,
1273
+ allowedParents: ["system", "domain", "group"],
1274
+ allowedAtRoot: true,
1275
+ builtin: true,
1276
+ tableTab: true,
1277
+ properties: mockupProps,
1278
+ wizard: {
1279
+ trigger: "create",
1280
+ steps: [
1281
+ {
1282
+ kind: "fields",
1283
+ title: "Screen",
1284
+ fields: ["label", "screen", "description"],
1285
+ help: "Which screen is this, and what does the user do on it?"
1286
+ },
1287
+ {
1288
+ kind: "fields",
1289
+ title: "Design link",
1290
+ fields: ["link"],
1291
+ help: "A Figma / Penpot link, if the design exists. You can generate a wireframe from the properties panel later."
1292
+ },
1293
+ {
1294
+ kind: "relations",
1295
+ title: "Illustrates",
1296
+ relationType: "illustrates",
1297
+ direction: "out",
1298
+ help: "Which requirements or scenarios does this screen show?"
1299
+ },
1300
+ {
1301
+ kind: "relations",
1302
+ title: "Presented by",
1303
+ relationType: "presented-by",
1304
+ direction: "out",
1305
+ help: "Which part of the system renders it?"
1306
+ }
1307
+ ]
1308
+ }
1309
+ };
1310
+ const illustrates = {
1311
+ id: "illustrates",
1312
+ label: "Illustrates",
1313
+ allowedPairs: [
1314
+ { from: "mockup", to: "requirement" },
1315
+ { from: "mockup", to: "scenario" }
1316
+ ],
1317
+ properties: [],
1318
+ color: "#db2777",
1319
+ builtin: true
1320
+ };
1321
+ const presentedBy = {
1322
+ id: "presented-by",
1323
+ label: "Presented by",
1324
+ allowedPairs: ["webapp", "container", "component", "system"].map((to) => ({ from: "mockup", to })),
1325
+ properties: [],
1326
+ color: "#be185d",
1327
+ builtin: true
1328
+ };
1329
+ const navigatesTo = {
1330
+ id: "navigates-to",
1331
+ label: "Navigates to",
1332
+ allowedPairs: [{ from: "mockup", to: "mockup" }],
1333
+ properties: [
1334
+ { key: "description", label: "Trigger", type: "text" }
1335
+ ],
1336
+ color: "#f472b6",
1337
+ builtin: true
1338
+ };
1339
+ const stateMachine = {
1340
+ id: "state-machine",
1341
+ label: "State Machine",
1342
+ color: "#3730a3",
1343
+ fg: "#fff",
1344
+ // Two states joined by a transition
1345
+ 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",
1346
+ width: 560,
1347
+ height: 380,
1348
+ collapsedWidth: 200,
1349
+ collapsedHeight: 64,
1350
+ allowedParents: ["system", "domain", "group"],
1351
+ allowedAtRoot: true,
1352
+ builtin: true,
1353
+ tableTab: true,
1354
+ properties: [
1355
+ { key: "description", label: "Description", type: "textarea" }
1356
+ ]
1357
+ };
1358
+ const state = {
1359
+ id: "state",
1360
+ label: "State",
1361
+ color: "#4f46e5",
1362
+ fg: "#fff",
1363
+ // Rounded rectangle
1364
+ 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",
1365
+ width: 320,
1366
+ height: 220,
1367
+ collapsedWidth: 170,
1368
+ collapsedHeight: 72,
1369
+ allowedParents: ["state-machine", "state"],
1370
+ allowedAtRoot: false,
1371
+ builtin: true,
1372
+ tableTab: true,
1373
+ properties: [
1374
+ {
1375
+ key: "kind",
1376
+ label: "Kind",
1377
+ type: "enum",
1378
+ options: ["normal", "parallel", "final"],
1379
+ default: "normal"
1380
+ },
1381
+ { key: "entry", label: "Entry actions", type: "text", visibleWhen: { key: "kind", values: ["normal", "parallel"] } },
1382
+ { key: "exit", label: "Exit actions", type: "text", visibleWhen: { key: "kind", values: ["normal", "parallel"] } },
1383
+ { key: "do", label: "Do (ongoing activity)", type: "text", visibleWhen: { key: "kind", values: ["normal"] } },
1384
+ { key: "description", label: "Description", type: "textarea" }
1385
+ ]
1386
+ };
1387
+ const pseudostate = {
1388
+ id: "pseudostate",
1389
+ label: "Pseudostate",
1390
+ color: "#1e1b4b",
1391
+ fg: "#fff",
1392
+ // Filled dot (initial)
1393
+ iconPath: "M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Z",
1394
+ width: 36,
1395
+ height: 36,
1396
+ allowedParents: ["state-machine", "state"],
1397
+ allowedAtRoot: false,
1398
+ builtin: true,
1399
+ properties: [
1400
+ {
1401
+ key: "kind",
1402
+ label: "Kind",
1403
+ type: "enum",
1404
+ options: ["initial", "shallow-history", "deep-history", "choice"],
1405
+ default: "initial"
1406
+ }
1407
+ ]
1408
+ };
1409
+ const event = {
1410
+ id: "event",
1411
+ label: "Event",
1412
+ color: "#c2410c",
1413
+ fg: "#fff",
1414
+ // Lightning bolt
1415
+ iconPath: "M9.5 1 3 9h4l-1 6 6.5-8h-4l1-6Z",
1416
+ width: 170,
1417
+ height: 52,
1418
+ allowedParents: ["state-machine", "system", "domain", "group"],
1419
+ allowedAtRoot: true,
1420
+ builtin: true,
1421
+ tableTab: true,
1422
+ properties: [
1423
+ {
1424
+ key: "source",
1425
+ label: "Source",
1426
+ type: "enum",
1427
+ options: ["external", "internal", "timer"],
1428
+ default: "external"
1429
+ },
1430
+ { key: "payload", label: "Payload", type: "text" },
1431
+ { key: "description", label: "Description", type: "textarea" }
1432
+ ]
1433
+ };
1434
+ const stateNodeTypes = ["state", "pseudostate"];
1435
+ const transition = {
1436
+ id: "transition",
1437
+ label: "Transition",
1438
+ allowedPairs: stateNodeTypes.flatMap((from) => stateNodeTypes.map((to) => ({ from, to }))),
1439
+ properties: [
1440
+ { key: "event", label: "Event (trigger; none = completion)", type: "ref", refType: "event" },
1441
+ { key: "guard", label: "Guard [condition]", type: "text" },
1442
+ { key: "actions", label: "Actions (/ effect)", type: "text" },
1443
+ { key: "raises", label: "Raises (events it publishes)", type: "ref", refType: "event", multiple: true },
1444
+ {
1445
+ key: "kind",
1446
+ label: "Kind",
1447
+ type: "enum",
1448
+ options: ["external", "internal"],
1449
+ default: "external"
1450
+ }
1451
+ ],
1452
+ color: "#6366f1",
1453
+ builtin: true
1454
+ };
1455
+ const lifecycleOf = {
1456
+ id: "lifecycle-of",
1457
+ label: "Lifecycle of",
1458
+ allowedPairs: [{ from: "state-machine", to: "entity" }],
1459
+ properties: [],
1460
+ color: "#3730a3",
1461
+ builtin: true
1462
+ };
1463
+ const emits = {
1464
+ id: "emits",
1465
+ label: "Emits",
1466
+ allowedPairs: ["person", "system", "container", "component", "webapp", "queue", "state-machine", "state"].map((from) => ({ from, to: "event" })),
1467
+ properties: [
1468
+ {
1469
+ key: "on",
1470
+ label: "On (for a state: entry, exit or do)",
1471
+ type: "enum",
1472
+ options: ["entry", "exit", "do"],
1473
+ default: "entry"
1474
+ }
1475
+ ],
1476
+ color: "#ea580c",
1477
+ builtin: true
1478
+ };
1479
+ implements_.allowedPairs.push(...["system", "container", "component", "webapp"].map((from) => ({ from, to: "state-machine" })));
1480
+ satisfies.allowedPairs.push({ from: "state-machine", to: "requirement" }, { from: "entity", to: "requirement" });
1481
+ verifies.allowedPairs.push({ from: "scenario", to: "state-machine" });
1482
+ illustrates.allowedPairs.push({ from: "mockup", to: "state" });
1483
+ return {
1484
+ id: "c4-ddd-governance-builtin",
1485
+ name: RADICAL_METAMODEL_NAME,
1486
+ nodeTypes: {
1487
+ ...base.nodeTypes,
1488
+ adr,
1489
+ "fitness-fn": fitnessFn,
1490
+ need,
1491
+ requirement,
1492
+ scenario,
1493
+ blueprint,
1494
+ mockup,
1495
+ "state-machine": stateMachine,
1496
+ state,
1497
+ pseudostate,
1498
+ event
1499
+ },
1500
+ relationTypes: {
1501
+ ...base.relationTypes,
1502
+ constrains,
1503
+ supersedes,
1504
+ implements: implements_,
1505
+ satisfies,
1506
+ derives,
1507
+ "traces-to": tracesTo,
1508
+ verifies,
1509
+ illustrates,
1510
+ "presented-by": presentedBy,
1511
+ "navigates-to": navigatesTo,
1512
+ transition,
1513
+ "lifecycle-of": lifecycleOf,
1514
+ emits
1515
+ }
1516
+ };
1517
+ }
1518
+
1519
+ // ../../packages/common/src/c4.ts
1520
+ var CONTAINER_TYPES = /* @__PURE__ */ new Set([
1521
+ "system",
1522
+ "container",
1523
+ "webapp",
1524
+ "domain",
1525
+ "group",
1526
+ "blueprint",
1527
+ "state-machine",
1528
+ "state"
1529
+ ]);
1530
+ function isContainerType(type) {
1531
+ return !!type && CONTAINER_TYPES.has(type);
1532
+ }
1533
+ function pinnedNodeIds(constraints) {
1534
+ return constraints?.find((c) => c.type === "pin")?.nodeIds ?? [];
1535
+ }
1536
+ function defaultGridColumns(count) {
1537
+ return Math.max(1, Math.ceil(Math.sqrt(count)));
1538
+ }
1539
+ var LANDSCAPE_WIDTH = 2;
1540
+ function landscapeSlot(index) {
1541
+ if (index <= 0) return { column: 0, row: 0 };
1542
+ let columns = 1;
1543
+ let rows = 1;
1544
+ let filled = 1;
1545
+ for (; ; ) {
1546
+ if (columns < LANDSCAPE_WIDTH * rows) {
1547
+ if (index < filled + rows) return { column: columns, row: index - filled };
1548
+ filled += rows;
1549
+ columns++;
1550
+ } else {
1551
+ if (index < filled + columns) return { column: index - filled, row: rows };
1552
+ filled += columns;
1553
+ rows++;
1554
+ }
1555
+ }
1556
+ }
1557
+ function landscapeGridColumns(count) {
1558
+ let columns = 1;
1559
+ for (let i = 0; i < count; i++) columns = Math.max(columns, landscapeSlot(i).column + 1);
1560
+ return columns;
1561
+ }
1562
+ function gridCells(c) {
1563
+ const cols = Math.max(1, Math.min(Math.floor(c.columns), c.nodeIds.length));
1564
+ const rows = [];
1565
+ for (let i = 0; i < c.nodeIds.length; i += cols) rows.push(c.nodeIds.slice(i, i + cols));
1566
+ const columns = [];
1567
+ for (let k = 0; k < cols; k++) columns.push(c.nodeIds.filter((_, i) => i % cols === k));
1568
+ return { rows, columns };
1569
+ }
1570
+ function constraintLines(constraints) {
1571
+ return constraints.flatMap((c) => {
1572
+ if (c.type === "align") return [c];
1573
+ if (c.type === "pin") return [];
1574
+ const { rows, columns } = gridCells(c);
1575
+ return [
1576
+ ...rows.map((ids, r) => ({ id: `${c.id}:row${r}`, type: "align", axis: "horizontal", nodeIds: ids, ordered: true })),
1577
+ ...columns.map((ids, k) => ({ id: `${c.id}:col${k}`, type: "align", axis: "vertical", nodeIds: ids, ordered: true }))
1578
+ ];
1579
+ });
1580
+ }
1581
+ var BUILTIN_NODE_TYPES = builtInGovernanceMetamodel().nodeTypes;
1582
+ function pluckPerType(fn) {
1583
+ const out = {};
1584
+ for (const [id, def] of Object.entries(BUILTIN_NODE_TYPES)) {
1585
+ out[id] = fn(def);
1586
+ }
1587
+ return out;
1588
+ }
1589
+ var NODE_SIZES = pluckPerType((def) => ({ width: def.width, height: def.height }));
1590
+ var COLLAPSED_HEIGHT = pluckPerType((def) => def.collapsedHeight ?? def.height);
1591
+ var COLLAPSED_WIDTH = pluckPerType((def) => def.collapsedWidth ?? def.width);
1592
+ var NODE_COLORS = pluckPerType((def) => def.color);
1593
+ var NODE_FG = pluckPerType((def) => def.fg);
1594
+ var TYPE_LABELS = pluckPerType((def) => def.label);
1595
+ var TYPE_ICON_PATHS = pluckPerType((def) => def.iconPath);
1596
+
1597
+ // ../../packages/layout/src/geometry.ts
1598
+ function effectiveWidth(n) {
1599
+ if (isContainerType(n.type) && n.collapsed) return COLLAPSED_WIDTH[n.type];
1600
+ return n.width ?? NODE_SIZES[n.type].width;
1601
+ }
1602
+ function effectiveHeight(n) {
1603
+ if (isContainerType(n.type) && n.collapsed) return COLLAPSED_HEIGHT[n.type];
1604
+ return n.height ?? NODE_SIZES[n.type].height;
1605
+ }
1606
+ var FIXED_SIZE_TYPES = /* @__PURE__ */ new Set(["adr", "fitness-fn", "need", "requirement", "scenario", "mockup", "pseudostate", "event", "entity"]);
1607
+ function drawnSize(n, hasChildren) {
1608
+ if (FIXED_SIZE_TYPES.has(n.type)) return NODE_SIZES[n.type];
1609
+ if (isContainerType(n.type) && (n.collapsed || !hasChildren)) {
1610
+ return { width: COLLAPSED_WIDTH[n.type], height: COLLAPSED_HEIGHT[n.type] };
1611
+ }
1612
+ return { width: n.width, height: n.height };
1613
+ }
1614
+ function isVisible(node, allNodes) {
1615
+ if (!node.parentId) return true;
1616
+ const parent = allNodes[node.parentId];
1617
+ if (!parent) return true;
1618
+ if (parent.collapsed) return false;
1619
+ return isVisible(parent, allNodes);
1620
+ }
1621
+ function compoundPadding(type) {
1622
+ const margin = type === "container" || type === "webapp" ? 20 : 30;
1623
+ return { top: 120, side: margin, bottom: margin };
1624
+ }
1625
+ function fittedParentSize(parent, children) {
1626
+ const pad = compoundPadding(parent.type);
1627
+ let maxRight = 0;
1628
+ let maxBottom = 0;
1629
+ for (const child of children) {
1630
+ maxRight = Math.max(maxRight, child.x + child.width);
1631
+ maxBottom = Math.max(maxBottom, child.y + child.height);
1632
+ }
1633
+ return {
1634
+ width: Math.max(maxRight + pad.side, NODE_SIZES[parent.type].width),
1635
+ height: Math.max(maxBottom + pad.bottom, NODE_SIZES[parent.type].height)
1636
+ };
1637
+ }
1638
+ function fitAncestors(nodes, startId) {
1639
+ const seen = /* @__PURE__ */ new Set();
1640
+ let cur = startId ? nodes[startId] : void 0;
1641
+ while (cur && !seen.has(cur.id)) {
1642
+ seen.add(cur.id);
1643
+ const parentId = cur.id;
1644
+ const children = Object.values(nodes).filter((n) => n.parentId === parentId);
1645
+ if (isContainerType(cur.type) && !cur.collapsed && children.length > 0) {
1646
+ const size = fittedParentSize(cur, children.map((c) => ({ x: c.x, y: c.y, width: effectiveWidth(c), height: effectiveHeight(c) })));
1647
+ cur.width = size.width;
1648
+ cur.height = size.height;
1649
+ }
1650
+ cur = cur.parentId ? nodes[cur.parentId] : void 0;
1651
+ }
1652
+ }
1653
+ function placeNewNode(nodes, parentId) {
1654
+ const parent = parentId ? nodes[parentId] : void 0;
1655
+ const siblings = Object.values(nodes).filter((n) => (n.parentId ?? void 0) === (parent?.id ?? void 0));
1656
+ const right = Math.max(...siblings.map((n) => n.x + effectiveWidth(n)));
1657
+ if (!parent) return { x: siblings.length ? right + 80 : 0, y: 0 };
1658
+ const pad = compoundPadding(parent.type);
1659
+ return { x: siblings.length ? right + 20 : pad.side, y: pad.top };
1660
+ }
1661
+ var BATCH_CELL = { width: 360, height: 280 };
1662
+ var BATCH_GAP = 120;
1663
+ function createBatchPlacer(getNodes, visible = () => void 0) {
1664
+ const batches = /* @__PURE__ */ new Map();
1665
+ return (parentId) => {
1666
+ const key = parentId ?? "";
1667
+ let batch = batches.get(key);
1668
+ if (!batch) {
1669
+ const nodes = getNodes();
1670
+ const parent = parentId ? nodes[parentId] : void 0;
1671
+ const shown = visible();
1672
+ const siblings = Object.values(nodes).filter((n) => (n.parentId ?? void 0) === (parent?.id ?? void 0) && (!shown || shown.has(n.id)));
1673
+ const pad = parent ? compoundPadding(parent.type) : { top: 0, side: 0 };
1674
+ 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 };
1675
+ batches.set(key, batch);
1676
+ }
1677
+ const { column, row } = landscapeSlot(batch.placed++);
1678
+ return { x: batch.x + column * BATCH_CELL.width, y: batch.y + row * BATCH_CELL.height };
1679
+ };
1680
+ }
1681
+ function projectToVisibleGraph(nodes, relations) {
1682
+ const visible = {};
1683
+ for (const n of Object.values(nodes)) {
1684
+ if (!isVisible(n, nodes)) continue;
1685
+ if (isContainerType(n.type) && n.collapsed) {
1686
+ const w = COLLAPSED_WIDTH[n.type];
1687
+ const h = COLLAPSED_HEIGHT[n.type];
1688
+ visible[n.id] = n.width === w && n.height === h ? n : { ...n, width: w, height: h };
1689
+ } else {
1690
+ visible[n.id] = n;
1691
+ }
1692
+ }
1693
+ const visibleAncestor = (id) => {
1694
+ let cur = nodes[id];
1695
+ while (cur && !visible[cur.id]) cur = cur.parentId ? nodes[cur.parentId] : void 0;
1696
+ return cur?.id;
1697
+ };
1698
+ const projected = {};
1699
+ const seen = /* @__PURE__ */ new Set();
1700
+ for (const id of Object.keys(relations).sort()) {
1701
+ const r = relations[id];
1702
+ const s = visibleAncestor(r.sourceId);
1703
+ const t = visibleAncestor(r.targetId);
1704
+ if (!s || !t || s === t) continue;
1705
+ const key = `${s}\0${t}`;
1706
+ if (seen.has(key)) continue;
1707
+ seen.add(key);
1708
+ projected[id] = s === r.sourceId && t === r.targetId ? r : { ...r, sourceId: s, targetId: t };
1709
+ }
1710
+ return { nodes: visible, relations: projected };
1711
+ }
1712
+
1713
+ // ../../packages/layout/src/elkSpacingBase.ts
1714
+ var ELK_ROOT_SPACING = {
1715
+ "elk.spacing.nodeNode": "60",
1716
+ "elk.layered.spacing.nodeNodeBetweenLayers": "80",
1717
+ "elk.spacing.edgeNode": "20",
1718
+ "elk.spacing.edgeEdge": "10",
1719
+ "elk.spacing.componentComponent": "80"
1720
+ };
1721
+ var ELK_CHILD_SPACING = {
1722
+ "elk.spacing.nodeNode": "30",
1723
+ "elk.layered.spacing.nodeNodeBetweenLayers": "50",
1724
+ "elk.spacing.edgeNode": "12",
1725
+ "elk.spacing.edgeEdge": "8",
1726
+ "elk.spacing.componentComponent": "40"
1727
+ };
1728
+
1729
+ export {
1730
+ isRelationAllowed,
1731
+ inferRelationType,
1732
+ isParentAllowed,
1733
+ canAddMoreOfType,
1734
+ refValue,
1735
+ refProblem,
1736
+ transitionLabel,
1737
+ requirementStatePhrase,
1738
+ validateModel,
1739
+ composeEarsSentence,
1740
+ builtInC4Metamodel,
1741
+ builtInGovernanceMetamodel,
1742
+ isContainerType,
1743
+ pinnedNodeIds,
1744
+ defaultGridColumns,
1745
+ landscapeGridColumns,
1746
+ gridCells,
1747
+ constraintLines,
1748
+ NODE_SIZES,
1749
+ COLLAPSED_HEIGHT,
1750
+ COLLAPSED_WIDTH,
1751
+ effectiveWidth,
1752
+ effectiveHeight,
1753
+ drawnSize,
1754
+ isVisible,
1755
+ compoundPadding,
1756
+ fittedParentSize,
1757
+ fitAncestors,
1758
+ placeNewNode,
1759
+ createBatchPlacer,
1760
+ projectToVisibleGraph,
1761
+ ELK_ROOT_SPACING,
1762
+ ELK_CHILD_SPACING
1763
+ };