archscribe 0.2.2-rc.1 → 0.2.3

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 (312) hide show
  1. package/README.md +96 -30
  2. package/dashboard-server/client-dist/assets/index-BK3iMzXX.css +1 -0
  3. package/dashboard-server/client-dist/assets/index-CvlC6kTE.js +23 -0
  4. package/dashboard-server/client-dist/brand/favicon.png +0 -0
  5. package/dashboard-server/client-dist/brand/logo-full.png +0 -0
  6. package/dashboard-server/client-dist/icons.svg +24 -0
  7. package/dashboard-server/client-dist/index.html +14 -0
  8. package/dashboard-server/dist/core-bridge.js +26 -0
  9. package/dashboard-server/dist/files-route.js +34 -0
  10. package/dashboard-server/dist/index.js +292 -0
  11. package/dashboard-server/dist/license-routes.js +39 -0
  12. package/dashboard-server/dist/outputs-route.js +208 -0
  13. package/dashboard-server/dist/run-route.js +89 -0
  14. package/dashboard-server/dist/security.js +115 -0
  15. package/dist/cli/archscribe.js +111 -30
  16. package/dist/cli/archscribe.js.map +1 -1
  17. package/dist/cli/commands.js +6 -0
  18. package/dist/cli/commands.js.map +1 -1
  19. package/dist/cli/context.d.ts +1 -0
  20. package/dist/cli/context.js +34 -0
  21. package/dist/cli/context.js.map +1 -0
  22. package/dist/cli/doctor.js +2 -2
  23. package/dist/cli/doctor.js.map +1 -1
  24. package/dist/cli/history.js +58 -0
  25. package/dist/cli/history.js.map +1 -1
  26. package/dist/cli/login.js +4 -6
  27. package/dist/cli/login.js.map +1 -1
  28. package/dist/cli/logout.js +1 -1
  29. package/dist/cli/logout.js.map +1 -1
  30. package/dist/cli/rag.d.ts +1 -4
  31. package/dist/cli/rag.js +7 -29
  32. package/dist/cli/rag.js.map +1 -1
  33. package/dist/cli/review.d.ts +1 -0
  34. package/dist/cli/review.js +144 -0
  35. package/dist/cli/review.js.map +1 -0
  36. package/dist/cli/run.d.ts +4 -1
  37. package/dist/cli/run.js +10 -20
  38. package/dist/cli/run.js.map +1 -1
  39. package/dist/cli/shell.js +8 -19
  40. package/dist/cli/shell.js.map +1 -1
  41. package/dist/cli/ui/animations.js +1 -1
  42. package/dist/cli/ui/document-frame.d.ts +17 -0
  43. package/dist/cli/ui/document-frame.js +65 -0
  44. package/dist/cli/ui/document-frame.js.map +1 -0
  45. package/dist/cli/ui/document-tui.d.ts +5 -0
  46. package/dist/cli/ui/document-tui.js +224 -0
  47. package/dist/cli/ui/document-tui.js.map +1 -0
  48. package/dist/cli/ui/keys.d.ts +1 -0
  49. package/dist/cli/ui/keys.js +30 -6
  50. package/dist/cli/ui/keys.js.map +1 -1
  51. package/dist/cli/ui/little-scribe.d.ts +3 -0
  52. package/dist/cli/ui/little-scribe.js +67 -0
  53. package/dist/cli/ui/little-scribe.js.map +1 -0
  54. package/dist/cli/ui/mascot.d.ts +4 -2
  55. package/dist/cli/ui/mascot.js +19 -46
  56. package/dist/cli/ui/mascot.js.map +1 -1
  57. package/dist/cli/ui/menu.d.ts +1 -1
  58. package/dist/cli/ui/menu.js +1 -1
  59. package/dist/cli/ui/menu.js.map +1 -1
  60. package/dist/cli/ui/stage.js +12 -7
  61. package/dist/cli/ui/stage.js.map +1 -1
  62. package/dist/cli/ui/term.js +3 -1
  63. package/dist/cli/ui/term.js.map +1 -1
  64. package/dist/core/actor-inference.d.ts +1 -0
  65. package/dist/core/actor-inference.js +2 -1
  66. package/dist/core/actor-inference.js.map +1 -1
  67. package/dist/core/approval-ledger.d.ts +57 -0
  68. package/dist/core/approval-ledger.js +95 -0
  69. package/dist/core/approval-ledger.js.map +1 -0
  70. package/dist/core/component-groups.d.ts +2 -0
  71. package/dist/core/component-groups.js +4 -0
  72. package/dist/core/component-groups.js.map +1 -1
  73. package/dist/core/docx-export.d.ts +4 -0
  74. package/dist/core/docx-export.js +25 -0
  75. package/dist/core/docx-export.js.map +1 -0
  76. package/dist/core/docx-lists.d.ts +8 -0
  77. package/dist/core/docx-lists.js +75 -0
  78. package/dist/core/docx-lists.js.map +1 -0
  79. package/dist/core/docx-styles.d.ts +2 -1
  80. package/dist/core/docx-styles.js +2 -1
  81. package/dist/core/docx-styles.js.map +1 -1
  82. package/dist/core/docx-table.d.ts +5 -0
  83. package/dist/core/docx-table.js +71 -0
  84. package/dist/core/docx-table.js.map +1 -0
  85. package/dist/core/docx-update.js +72 -8
  86. package/dist/core/docx-update.js.map +1 -1
  87. package/dist/core/docx.js +83 -31
  88. package/dist/core/docx.js.map +1 -1
  89. package/dist/core/flow-steps.d.ts +1 -4
  90. package/dist/core/flow-steps.js +61 -115
  91. package/dist/core/flow-steps.js.map +1 -1
  92. package/dist/core/flow-trace.d.ts +9 -2
  93. package/dist/core/flow-trace.js +57 -58
  94. package/dist/core/flow-trace.js.map +1 -1
  95. package/dist/core/flow.js +10 -14
  96. package/dist/core/flow.js.map +1 -1
  97. package/dist/core/ledger-reconcile.d.ts +40 -0
  98. package/dist/core/ledger-reconcile.js +296 -0
  99. package/dist/core/ledger-reconcile.js.map +1 -0
  100. package/dist/core/markdown.d.ts +18 -1
  101. package/dist/core/markdown.js +98 -41
  102. package/dist/core/markdown.js.map +1 -1
  103. package/dist/core/materialize-report.d.ts +10 -0
  104. package/dist/core/materialize-report.js +72 -0
  105. package/dist/core/materialize-report.js.map +1 -0
  106. package/dist/core/output-history.d.ts +29 -0
  107. package/dist/core/output-history.js +204 -0
  108. package/dist/core/output-history.js.map +1 -0
  109. package/dist/core/output-mutation.d.ts +1 -0
  110. package/dist/core/output-mutation.js +15 -0
  111. package/dist/core/output-mutation.js.map +1 -0
  112. package/dist/core/parser.js +1 -3
  113. package/dist/core/parser.js.map +1 -1
  114. package/dist/core/review-feedback.d.ts +7 -0
  115. package/dist/core/review-feedback.js +46 -0
  116. package/dist/core/review-feedback.js.map +1 -0
  117. package/dist/core/uc-context-builder.d.ts +1 -0
  118. package/dist/core/uc-context-builder.js +11 -0
  119. package/dist/core/uc-context-builder.js.map +1 -1
  120. package/dist/core/uc-grouping-candidates.d.ts +9 -0
  121. package/dist/core/uc-grouping-candidates.js +35 -0
  122. package/dist/core/uc-grouping-candidates.js.map +1 -0
  123. package/dist/core/uc-grouping-evidence.d.ts +5 -0
  124. package/dist/core/uc-grouping-evidence.js +95 -0
  125. package/dist/core/uc-grouping-evidence.js.map +1 -0
  126. package/dist/core/uc-proposal.d.ts +19 -2
  127. package/dist/core/uc-proposal.js +127 -0
  128. package/dist/core/uc-proposal.js.map +1 -1
  129. package/dist/diagrams/activity.js +58 -14
  130. package/dist/diagrams/activity.js.map +1 -1
  131. package/dist/diagrams/arch/c4/build.d.ts +4 -0
  132. package/dist/diagrams/arch/c4/build.js +98 -0
  133. package/dist/diagrams/arch/c4/build.js.map +1 -0
  134. package/dist/diagrams/arch/c4/components.d.ts +4 -0
  135. package/dist/diagrams/arch/c4/components.js +92 -0
  136. package/dist/diagrams/arch/c4/components.js.map +1 -0
  137. package/dist/diagrams/arch/c4/context.d.ts +3 -0
  138. package/dist/diagrams/arch/c4/context.js +135 -0
  139. package/dist/diagrams/arch/c4/context.js.map +1 -0
  140. package/dist/diagrams/arch/c4/embedded.d.ts +7 -0
  141. package/dist/diagrams/arch/c4/embedded.js +43 -0
  142. package/dist/diagrams/arch/c4/embedded.js.map +1 -0
  143. package/dist/diagrams/arch/c4/identity.d.ts +6 -0
  144. package/dist/diagrams/arch/c4/identity.js +25 -0
  145. package/dist/diagrams/arch/c4/identity.js.map +1 -0
  146. package/dist/diagrams/arch/c4/messages.d.ts +2 -0
  147. package/dist/diagrams/arch/c4/messages.js +6 -0
  148. package/dist/diagrams/arch/c4/messages.js.map +1 -0
  149. package/dist/diagrams/arch/c4/render.d.ts +3 -0
  150. package/dist/diagrams/arch/c4/render.js +150 -0
  151. package/dist/diagrams/arch/c4/render.js.map +1 -0
  152. package/dist/diagrams/arch/c4/topology-layout.d.ts +24 -0
  153. package/dist/diagrams/arch/c4/topology-layout.js +98 -0
  154. package/dist/diagrams/arch/c4/topology-layout.js.map +1 -0
  155. package/dist/diagrams/arch/c4/types.d.ts +123 -0
  156. package/dist/diagrams/arch/c4/types.js +2 -0
  157. package/dist/diagrams/arch/c4/types.js.map +1 -0
  158. package/dist/diagrams/arch/c4/views.d.ts +3 -0
  159. package/dist/diagrams/arch/c4/views.js +48 -0
  160. package/dist/diagrams/arch/c4/views.js.map +1 -0
  161. package/dist/diagrams/arch/classify.d.ts +27 -0
  162. package/dist/diagrams/arch/classify.js +136 -0
  163. package/dist/diagrams/arch/classify.js.map +1 -0
  164. package/dist/diagrams/arch/layered.d.ts +11 -0
  165. package/dist/diagrams/arch/layered.js +35 -0
  166. package/dist/diagrams/arch/layered.js.map +1 -0
  167. package/dist/diagrams/arch/layout-clean.d.ts +10 -0
  168. package/dist/diagrams/arch/layout-clean.js +74 -0
  169. package/dist/diagrams/arch/layout-clean.js.map +1 -0
  170. package/dist/diagrams/arch/layout-component.d.ts +13 -0
  171. package/dist/diagrams/arch/layout-component.js +221 -0
  172. package/dist/diagrams/arch/layout-component.js.map +1 -0
  173. package/dist/diagrams/arch/layout-hexagonal.d.ts +11 -0
  174. package/dist/diagrams/arch/layout-hexagonal.js +142 -0
  175. package/dist/diagrams/arch/layout-hexagonal.js.map +1 -0
  176. package/dist/diagrams/arch/layout-layered.d.ts +17 -0
  177. package/dist/diagrams/arch/layout-layered.js +89 -0
  178. package/dist/diagrams/arch/layout-layered.js.map +1 -0
  179. package/dist/diagrams/arch/messages.generated.d.ts +119 -0
  180. package/dist/diagrams/arch/messages.generated.js +120 -0
  181. package/dist/diagrams/arch/messages.generated.js.map +1 -0
  182. package/dist/diagrams/arch/model.d.ts +60 -0
  183. package/dist/diagrams/arch/model.js +271 -0
  184. package/dist/diagrams/arch/model.js.map +1 -0
  185. package/dist/diagrams/arch/xml.d.ts +23 -0
  186. package/dist/diagrams/arch/xml.js +42 -0
  187. package/dist/diagrams/arch/xml.js.map +1 -0
  188. package/dist/diagrams/architecture.d.ts +29 -36
  189. package/dist/diagrams/architecture.js +52 -152
  190. package/dist/diagrams/architecture.js.map +1 -1
  191. package/dist/diagrams/layout/radial.d.ts +1 -1
  192. package/dist/diagrams/layout/radial.js +318 -2
  193. package/dist/diagrams/layout/radial.js.map +1 -1
  194. package/dist/diagrams/sequence-model.js +6 -8
  195. package/dist/diagrams/sequence-model.js.map +1 -1
  196. package/dist/diagrams/sequence.js +34 -4
  197. package/dist/diagrams/sequence.js.map +1 -1
  198. package/dist/diagrams/usecase.d.ts +2 -1
  199. package/dist/diagrams/usecase.js +44 -20
  200. package/dist/diagrams/usecase.js.map +1 -1
  201. package/dist/diagrams/usecase_layout.d.ts +7 -12
  202. package/dist/diagrams/usecase_layout.js +25 -84
  203. package/dist/diagrams/usecase_layout.js.map +1 -1
  204. package/dist/evaluation/dashboard-review.js +0 -66
  205. package/dist/evaluation/dashboard-review.js.map +1 -1
  206. package/dist/knowledge/evidence.d.ts +48 -0
  207. package/dist/knowledge/evidence.js +253 -0
  208. package/dist/knowledge/evidence.js.map +1 -0
  209. package/dist/knowledge/hub-grouping.d.ts +7 -3
  210. package/dist/knowledge/hub-grouping.js +74 -55
  211. package/dist/knowledge/hub-grouping.js.map +1 -1
  212. package/dist/knowledge/local-kb.d.ts +4 -0
  213. package/dist/knowledge/local-kb.js +84 -0
  214. package/dist/knowledge/local-kb.js.map +1 -0
  215. package/dist/knowledge/rag-augment.d.ts +31 -6
  216. package/dist/knowledge/rag-augment.js +77 -37
  217. package/dist/knowledge/rag-augment.js.map +1 -1
  218. package/dist/knowledge/rag-client.d.ts +11 -0
  219. package/dist/knowledge/rag-client.js +60 -0
  220. package/dist/knowledge/rag-client.js.map +1 -0
  221. package/dist/knowledge/retriever.d.ts +7 -2
  222. package/dist/knowledge/retriever.js +29 -14
  223. package/dist/knowledge/retriever.js.map +1 -1
  224. package/dist/knowledge/rules.d.ts +2 -0
  225. package/dist/knowledge/rules.js +10 -0
  226. package/dist/knowledge/rules.js.map +1 -0
  227. package/dist/knowledge/store-lock.d.ts +2 -0
  228. package/dist/knowledge/store-lock.js +35 -0
  229. package/dist/knowledge/store-lock.js.map +1 -0
  230. package/dist/knowledge/types.d.ts +6 -1
  231. package/dist/license/banner.d.ts +1 -3
  232. package/dist/license/banner.js +2 -6
  233. package/dist/license/banner.js.map +1 -1
  234. package/dist/license/client.d.ts +4 -7
  235. package/dist/license/client.js +6 -16
  236. package/dist/license/client.js.map +1 -1
  237. package/dist/license/gate.d.ts +1 -3
  238. package/dist/license/gate.js +3 -3
  239. package/dist/license/gate.js.map +1 -1
  240. package/dist/license/verify.js +19 -14
  241. package/dist/license/verify.js.map +1 -1
  242. package/dist/parser.jar +0 -0
  243. package/dist/server.js +145 -11
  244. package/dist/server.js.map +1 -1
  245. package/dist/theory/context.d.ts +52 -0
  246. package/dist/theory/context.js +144 -0
  247. package/dist/theory/context.js.map +1 -0
  248. package/dist/theory/fill.d.ts +13 -1
  249. package/dist/theory/fill.js +122 -71
  250. package/dist/theory/fill.js.map +1 -1
  251. package/dist/theory/references.d.ts +9 -34
  252. package/dist/theory/references.js +9 -135
  253. package/dist/theory/references.js.map +1 -1
  254. package/dist/theory/scaffold.js +41 -26
  255. package/dist/theory/scaffold.js.map +1 -1
  256. package/dist/tools/environment.js +1 -1
  257. package/dist/tools/environment.js.map +1 -1
  258. package/dist/tools/generate_report.d.ts +8 -1
  259. package/dist/tools/generate_report.js +186 -89
  260. package/dist/tools/generate_report.js.map +1 -1
  261. package/dist/tools/learn_usecase.d.ts +2 -6
  262. package/dist/tools/learn_usecase.js +50 -34
  263. package/dist/tools/learn_usecase.js.map +1 -1
  264. package/dist/tools/propose_uc_groupings.d.ts +1 -10
  265. package/dist/tools/propose_uc_groupings.js +23 -79
  266. package/dist/tools/propose_uc_groupings.js.map +1 -1
  267. package/dist/tools/review_tools.d.ts +26 -0
  268. package/dist/tools/review_tools.js +55 -0
  269. package/dist/tools/review_tools.js.map +1 -0
  270. package/dist/tools/scaffold.d.ts +3 -1
  271. package/dist/tools/scaffold.js +99 -58
  272. package/dist/tools/scaffold.js.map +1 -1
  273. package/dist/tools/scan_repo.js +1 -1
  274. package/dist/tools/scan_repo.js.map +1 -1
  275. package/dist/types/ir.d.ts +4 -0
  276. package/dist/types/license.d.ts +4 -3
  277. package/dist/types/report.d.ts +17 -1
  278. package/dist/types/theory.d.ts +3 -2
  279. package/dist/types/uc-grouping.d.ts +57 -7
  280. package/dist/utils/dashboard-launcher.js +1 -1
  281. package/dist/utils/dashboard-launcher.js.map +1 -1
  282. package/dist/utils/mcp-launch.d.ts +26 -0
  283. package/dist/utils/mcp-launch.js +48 -0
  284. package/dist/utils/mcp-launch.js.map +1 -0
  285. package/dist/utils/run-history.d.ts +1 -2
  286. package/dist/utils/run-history.js +2 -11
  287. package/dist/utils/run-history.js.map +1 -1
  288. package/package.json +35 -10
  289. package/dist/knowledge/embedding.d.ts +0 -11
  290. package/dist/knowledge/embedding.js +0 -31
  291. package/dist/knowledge/embedding.js.map +0 -1
  292. package/dist/knowledge/qdrant-client.d.ts +0 -20
  293. package/dist/knowledge/qdrant-client.js +0 -95
  294. package/dist/knowledge/qdrant-client.js.map +0 -1
  295. package/dist/knowledge/seed-data-extended.d.ts +0 -7
  296. package/dist/knowledge/seed-data-extended.js +0 -183
  297. package/dist/knowledge/seed-data-extended.js.map +0 -1
  298. package/dist/knowledge/seed-data-extra.d.ts +0 -6
  299. package/dist/knowledge/seed-data-extra.js +0 -178
  300. package/dist/knowledge/seed-data-extra.js.map +0 -1
  301. package/dist/knowledge/seed-data.d.ts +0 -3
  302. package/dist/knowledge/seed-data.js +0 -333
  303. package/dist/knowledge/seed-data.js.map +0 -1
  304. package/dist/knowledge/seed.d.ts +0 -22
  305. package/dist/knowledge/seed.js +0 -44
  306. package/dist/knowledge/seed.js.map +0 -1
  307. package/dist/utils/approval.d.ts +0 -65
  308. package/dist/utils/approval.js +0 -324
  309. package/dist/utils/approval.js.map +0 -1
  310. package/dist/utils/keep-regions.d.ts +0 -44
  311. package/dist/utils/keep-regions.js +0 -153
  312. package/dist/utils/keep-regions.js.map +0 -1
@@ -1,165 +1,65 @@
1
- import { escapeXml, safeXmlId } from "../utils/xml.js";
1
+ import { detectPattern } from "./arch/classify.js";
2
+ import { buildArchModel } from "./arch/model.js";
3
+ import { layoutHexagonal } from "./arch/layout-hexagonal.js";
4
+ import { layoutClean } from "./arch/layout-clean.js";
5
+ import { layoutLayered } from "./arch/layout-layered.js";
6
+ import { layoutComponent } from "./arch/layout-component.js";
7
+ import { cell, wrapMxFile } from "./arch/xml.js";
2
8
  import { writeTextFile } from "../utils/file.js";
3
- // ── XML primitives ────────────────────────────────────────────────────────────
4
- function cell(id, attrs = {}) {
5
- const a = Object.entries(attrs).map(([k, v]) => ` ${k}="${escapeXml(v)}"`).join("");
6
- return `<mxCell id="${escapeXml(id)}"${a}/>`;
9
+ import { buildC4Model } from './arch/c4/build.js';
10
+ import { projectC4Views } from './arch/c4/views.js';
11
+ import { renderC4Drawio } from './arch/c4/render.js';
12
+ // Detection lives in ./arch/classify.ts; re-exported so existing importers keep working.
13
+ export { detectPattern };
14
+ function layoutFor(style) {
15
+ if (style === "hexagonal")
16
+ return layoutHexagonal;
17
+ if (style === "clean")
18
+ return layoutClean;
19
+ return layoutLayered;
7
20
  }
8
- function vertex(id, value, style, parent, x, y, w, h) {
9
- return `<mxCell id="${escapeXml(id)}" value="${escapeXml(value)}" style="${escapeXml(style)}" parent="${escapeXml(parent)}" vertex="1"><mxGeometry x="${x}" y="${y}" width="${w}" height="${h}" as="geometry"/></mxCell>`;
10
- }
11
- function edge(id, value, style, source, target) {
12
- return `<mxCell id="${escapeXml(id)}" value="${escapeXml(value)}" style="${style}" parent="1" source="${escapeXml(source)}" target="${escapeXml(target)}" edge="1"><mxGeometry relative="1" as="geometry"/></mxCell>`;
13
- }
14
- function wrapMxFile(id, name, cells, width, height) {
15
- return ['<mxfile host="archscribe">',
16
- ` <diagram id="${escapeXml(id)}" name="${escapeXml(name)}">`,
17
- ` <mxGraphModel dx="${width}" dy="${height}" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="${width}" pageHeight="${height}" math="0" shadow="0">`,
18
- " <root>", ...cells.map((c) => ` ${c}`), " </root>", " </mxGraphModel>", " </diagram>", "</mxfile>"].join("\n");
19
- }
20
- const STAGE_PALETTE = [
21
- { header: "#dae8fc", body: "#eaf4fb", stroke: "#6c8ebf" },
22
- { header: "#d5e8d4", body: "#ecf8e8", stroke: "#82b366" },
23
- { header: "#d9d2e9", body: "#f0eaf4", stroke: "#9673a6" },
24
- { header: "#fff2cc", body: "#fffaed", stroke: "#d6b656" },
25
- { header: "#f8cecc", body: "#fde8e8", stroke: "#b85450" },
26
- { header: "#fce4d6", body: "#fef3ee", stroke: "#c55a11" },
27
- ];
28
21
  /**
29
- * Detects Hexagonal vs Layered architecture by scanning package names.
30
- * Hexagonal: packages contain `adapter.(inbound|outbound)` or `port(s)`.
22
+ * Build a Draw.io architecture diagram from an IR.
23
+ *
24
+ * The detected style (hexagonal | clean | layered) picks the layout; the model
25
+ * always comes from `buildArchModel`, so a wrong heuristic can be corrected by
26
+ * the caller's group override rather than by editing the drawing.
31
27
  */
32
- export function detectPattern(ir) {
33
- const pkgs = (ir.classes ?? []).map((c) => c.packageName.toLowerCase()).join(" ");
34
- return /\badapter\b.*\b(inbound|outbound)\b|\b(inbound|outbound)\b.*\badapter\b|\bport(s)?\b|\badapter\.[a-z]/.test(pkgs) ? "hexagonal" : "layered";
35
- }
36
- // ── External resource detection ───────────────────────────────────────────────
37
- function depList(ir) { return (ir.project.dependencies ?? []).map((d) => (d.artifactId ?? "").toLowerCase()); }
38
- function detectDatabases(ir) {
39
- const deps = depList(ir);
40
- const result = [];
41
- if (deps.some((d) => d.includes("postgres")))
42
- result.push("PostgreSQL");
43
- if (deps.some((d) => d.includes("mysql")))
44
- result.push("MySQL");
45
- if (deps.some((d) => d.includes("mongodb")))
46
- result.push("MongoDB");
47
- if (deps.some((d) => d.includes("dynamodb")))
48
- result.push("DynamoDB");
49
- if (deps.some((d) => d.includes("redis")))
50
- result.push("Redis");
51
- return result.length ? result : ["Database"];
52
- }
53
- function detectExternals(ir) {
54
- const deps = depList(ir);
55
- const result = [];
56
- if (deps.some((d) => d.includes("firebase")))
57
- result.push("Firebase (FCM)");
58
- if (deps.some((d) => d.includes("agora")))
59
- result.push("Agora (Video)");
60
- if (deps.some((d) => /s3|aws-sdk/.test(d)))
61
- result.push("Amazon S3");
62
- if (deps.some((d) => d.includes("kafka")))
63
- result.push("Apache Kafka");
64
- if (deps.some((d) => d.includes("rabbitmq")))
65
- result.push("RabbitMQ");
66
- if (deps.some((d) => d.includes("twilio")))
67
- result.push("Twilio");
68
- if (deps.some((d) => /sendgrid|mailgun/.test(d)))
69
- result.push("Email Service");
70
- return result;
71
- }
72
- // ── Class display name ────────────────────────────────────────────────────────
73
- function cardName(name) {
74
- return name.replace(/([a-z])([A-Z])/g, "$1 $2");
75
- }
76
- function byStereotype(classes, stereo) {
77
- return classes.filter((c) => c.stereotype === stereo).map((c) => cardName(c.name));
28
+ export async function buildArchitectureDrawio(ir, override, options) {
29
+ return renderC4Drawio(projectC4Views(buildC4Model(ir, options)), options?.locale);
78
30
  }
79
- // ── Pattern → Stage mapping ───────────────────────────────────────────────────
80
- /**
81
- * Maps a detected architecture pattern to an ordered array of stages.
82
- * Each stage has a title, subtitle, color, and list of component cards.
83
- */
84
- export function patternToStages(pattern, ir) {
31
+ /** Complementary source-role view; overrides never imply C4 boundaries. */
32
+ export async function buildSourceArchitectureDrawio(ir, override, _options) {
33
+ const style = detectPattern(ir);
34
+ const model = buildArchModel(style, ir, override);
85
35
  const classes = ir.classes ?? [];
86
- const dbs = detectDatabases(ir);
87
- const ext = detectExternals(ir);
88
- const [c0, c1, c2, c3, c4, c5] = STAGE_PALETTE;
89
- if (pattern === "hexagonal") {
90
- return [
91
- { index: 1, title: "CLIENT", subtitle: "HTTP / WebSocket", ...c0, cards: ["Web App", "Mobile App"] },
92
- { index: 2, title: "INBOUND ADAPTERS", subtitle: "REST Controllers", ...c1, cards: byStereotype(classes, "controller") },
93
- { index: 3, title: "APPLICATION", subtitle: "Use Cases / Services", ...c2, cards: byStereotype(classes, "service") },
94
- { index: 4, title: "DOMAIN", subtitle: "Entities / Value Objects", ...c3, cards: byStereotype(classes, "entity") },
95
- { index: 5, title: "OUTBOUND ADAPTERS", subtitle: "Repositories / DAOs", ...c4, cards: byStereotype(classes, "repository") },
96
- { index: 6, title: "INFRASTRUCTURE", subtitle: "Databases & Externals", ...c5, cards: [...dbs, ...ext] },
97
- ].filter((s) => s.cards.length > 0 || s.index === 1);
98
- }
99
- // Layered pattern — 6 standard stages
100
- return [
101
- { index: 1, title: "CLIENT LAYER", subtitle: "Client Applications", ...c0, cards: ["Web App", "Mobile App"] },
102
- { index: 2, title: "PRESENTATION LAYER", subtitle: "UI / API Controllers", ...c1, cards: byStereotype(classes, "controller") },
103
- { index: 3, title: "APPLICATION LAYER", subtitle: "Business Logic Services", ...c2, cards: byStereotype(classes, "service") },
104
- { index: 4, title: "PERSISTENCE LAYER", subtitle: "Data Access Objects", ...c3, cards: byStereotype(classes, "repository") },
105
- { index: 5, title: "DATABASES", subtitle: "Data Storage", ...c4, cards: dbs },
106
- { index: 6, title: "EXTERNAL SERVICES", subtitle: "Integrations", ...c5, cards: ext },
107
- ].filter((s) => s.cards.length > 0 || s.index <= 2);
36
+ const subtitle = `${classes.length} lớp · ${new Set(classes.map((c) => c.packageName)).size} package · ` +
37
+ `kiểu nhận diện: ${style} · ${model.edges.length} phụ thuộc`;
38
+ const { cells, width, height } = await layoutComponent(model, ir.project.name ?? "project", subtitle);
39
+ const root = [cell("0"), cell("1", { parent: "0" })];
40
+ return wrapMxFile("architecture", "System Architecture Diagram", [...root, ...cells], width, height);
108
41
  }
109
- // ── Stage renderer ────────────────────────────────────────────────────────────
110
- const COL_W = 170, COL_GAP = 24, CARD_H = 34, CARD_GAP = 8, HDR_H = 88, COL_PAD = 10, MAX_CARDS = 7, TOP = 60;
111
42
  /**
112
- * Renders an ordered list of stages as Draw.io cells.
113
- * Each stage = numbered column swimlane + stacked component cards.
114
- * Flow arrows link consecutive stages left-to-right.
43
+ * The style-specific pattern view (hexagonal / clean / layered) of the same model.
44
+ * Complementary to the component view: it explains the *style*, the component view
45
+ * explains the *wiring*.
115
46
  */
116
- export function renderStages(stages) {
117
- const maxCards = Math.min(MAX_CARDS, Math.max(2, ...stages.map((s) => s.cards.length)));
118
- const colH = HDR_H + maxCards * (CARD_H + CARD_GAP) + COL_PAD * 2 + 20;
119
- const cells = [];
120
- const colIds = [];
121
- let ox = 40;
122
- for (const stage of stages) {
123
- const colId = safeXmlId(`stage_${stage.index}`, `st_${stage.index}`);
124
- colIds.push(colId);
125
- const swimStyle = `swimlane;startSize=${HDR_H};html=1;rounded=1;arcSize=5;fillColor=${stage.body};swimlaneFillColor=${stage.header};strokeColor=${stage.stroke};fontColor=#1a1a1a;fontStyle=1;whiteSpace=wrap;`;
126
- const hdrVal = `<font style="font-size:22px;font-weight:900;color:#1a1a1a;">${stage.index}</font><br><b style="font-size:10px;">${stage.title}</b><br><span style="font-size:9px;font-weight:normal;">${stage.subtitle}</span>`;
127
- cells.push(vertex(colId, hdrVal, swimStyle, "1", ox, TOP, COL_W, colH));
128
- // Draw.io swimlane children: y is relative to container top-left, so start after the header band
129
- let cy = HDR_H + COL_PAD;
130
- const cards = stage.cards.slice(0, MAX_CARDS);
131
- for (const name of cards) {
132
- const cardStyle = `rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=${stage.stroke};fontColor=#1a1a1a;fontSize=10;align=center;`;
133
- cells.push(vertex(safeXmlId(`card_${stage.index}_${name}`, `c${stage.index}_${cy}`), name, cardStyle, colId, COL_PAD, cy, COL_W - 2 * COL_PAD, CARD_H));
134
- cy += CARD_H + CARD_GAP;
135
- }
136
- if (stage.cards.length > MAX_CARDS) {
137
- cells.push(vertex(`more_${stage.index}`, `+${stage.cards.length - MAX_CARDS} more`, `text;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#888888;strokeColor=none;fillColor=none;`, colId, COL_PAD, cy, COL_W - 2 * COL_PAD, 20));
138
- }
139
- ox += COL_W + COL_GAP;
140
- }
141
- const flowStyle = "endArrow=block;endFill=1;html=1;rounded=0;strokeColor=#555555;strokeWidth=2;";
142
- for (let i = 0; i + 1 < colIds.length; i++)
143
- cells.push(edge(`flow_${i}`, "", flowStyle, colIds[i], colIds[i + 1]));
144
- return { cells, totalW: ox + 40, totalH: colH + TOP + 60 };
47
+ export function buildPatternDrawio(ir, override) {
48
+ const style = detectPattern(ir);
49
+ const { cells, width, height } = layoutFor(style)(buildArchModel(style, ir, override));
50
+ const root = [cell("0"), cell("1", { parent: "0" })];
51
+ return wrapMxFile("architecture", `Architecture (${style})`, [...root, ...cells], width, height);
145
52
  }
146
- // ── Public API ────────────────────────────────────────────────────────────────
147
- /**
148
- * Build a Draw.io architecture diagram XML string from an IR.
149
- * Detects Hexagonal vs Layered pattern; maps to Stage[]; renders as numbered column swimlanes.
150
- * Database and External stages derived from pom.xml dependencies.
151
- */
152
- export function buildArchitectureDrawio(ir) {
153
- const pattern = detectPattern(ir);
154
- const stages = patternToStages(pattern, ir);
155
- const { cells, totalW, totalH } = renderStages(stages);
156
- const allCells = [cell("0"), cell("1", { parent: "0" }), ...cells];
157
- return wrapMxFile("architecture", "System Architecture Diagram", allCells, totalW, totalH);
53
+ /** Write the architecture diagram to `outputPath`. */
54
+ export async function writeArchitectureDiagram(ir, outputPath, override, options) {
55
+ writeTextFile(outputPath, await buildArchitectureDrawio(ir, override, options));
158
56
  }
159
- /**
160
- * Write the architecture diagram to `outputPath`.
161
- */
162
- export function writeArchitectureDiagram(ir, outputPath) {
163
- writeTextFile(outputPath, buildArchitectureDrawio(ir));
57
+ /** Write the style-specific pattern view next to the component view. */
58
+ export function writePatternDiagram(ir, outputPath, override) {
59
+ writeTextFile(outputPath, buildPatternDrawio(ir, override));
60
+ }
61
+ /** The detected style, for naming the pattern file. */
62
+ export function architectureStyle(ir) {
63
+ return detectPattern(ir);
164
64
  }
165
65
  //# sourceMappingURL=architecture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"architecture.js","sourceRoot":"","sources":["../../src/diagrams/architecture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,iFAAiF;AAEjF,SAAS,IAAI,CAAC,EAAU,EAAE,QAAgC,EAAE;IAC1D,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpF,OAAO,eAAe,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,SAAS,MAAM,CAAC,EAAU,EAAE,KAAa,EAAE,KAAa,EAAE,MAAc,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IAClH,OAAO,eAAe,SAAS,CAAC,EAAE,CAAC,YAAY,SAAS,CAAC,KAAK,CAAC,YAAY,SAAS,CAAC,KAAK,CAAC,aAAa,SAAS,CAAC,MAAM,CAAC,+BAA+B,CAAC,QAAQ,CAAC,YAAY,CAAC,aAAa,CAAC,4BAA4B,CAAC;AAC5N,CAAC;AAED,SAAS,IAAI,CAAC,EAAU,EAAE,KAAa,EAAE,KAAa,EAAE,MAAc,EAAE,MAAc;IACpF,OAAO,eAAe,SAAS,CAAC,EAAE,CAAC,YAAY,SAAS,CAAC,KAAK,CAAC,YAAY,KAAK,wBAAwB,SAAS,CAAC,MAAM,CAAC,aAAa,SAAS,CAAC,MAAM,CAAC,8DAA8D,CAAC;AACxN,CAAC;AAED,SAAS,UAAU,CAAC,EAAU,EAAE,IAAY,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K,EAAE,MAAM,CAAC,CAAC;AACvG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAM,EAAE,QAAuB;IAChE,MAAM,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvF,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IACrD,OAAO,UAAU,CAAC,cAAc,EAAE,iBAAiB,KAAK,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACnG,CAAC;AAED,sDAAsD;AACtD,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAAM,EAAE,UAAkB,EAAE,QAAuB,EAAE,OAA6B;IAC/H,aAAa,CAAC,UAAU,EAAE,MAAM,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,mBAAmB,CAAC,EAAM,EAAE,UAAkB,EAAE,QAAuB;IACrF,aAAa,CAAC,UAAU,EAAE,kBAAkB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,iBAAiB,CAAC,EAAM;IACtC,OAAO,aAAa,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
@@ -41,7 +41,7 @@ interface Placed {
41
41
  h: number;
42
42
  }
43
43
  /** Which side of the hub satellites may occupy. */
44
- export type RingSide = "both" | "top" | "bottom";
44
+ export type RingSide = "both" | "top" | "bottom" | "tb";
45
45
  /**
46
46
  * Lay a cluster out as a ring: hub at the local origin, satellites on two side arcs
47
47
  * of an ellipse (right arc −arc/2..+arc/2, left arc π±arc/2) so a clear vertical
@@ -61,6 +61,15 @@ export function ringLayout(c, side = "both") {
61
61
  for (let i = 0; i < nL; i++)
62
62
  angles.push(nL === 1 ? Math.PI : Math.PI - arc / 2 + (arc * i) / (nL - 1));
63
63
  }
64
+ else if (side === "tb") {
65
+ // top/bottom arcs leave the hub's left/right sides clear for horizontal edges
66
+ const a = Math.min(arc, (2 * Math.PI) / 3);
67
+ const nT = Math.ceil(n / 2), nB = n - nT;
68
+ for (let i = 0; i < nT; i++)
69
+ angles.push(-Math.PI / 2 + (nT === 1 ? 0 : -a / 2 + (a * i) / (nT - 1)));
70
+ for (let i = 0; i < nB; i++)
71
+ angles.push(Math.PI / 2 + (nB === 1 ? 0 : -a / 2 + (a * i) / (nB - 1)));
72
+ }
64
73
  else {
65
74
  // half-ring fan: diagonals off the vertical (±30°..±60°) keep the corridor clear
66
75
  const base = side === "top" ? -Math.PI / 2 : Math.PI / 2;
@@ -82,6 +91,8 @@ export function ringLayout(c, side = "both") {
82
91
  ok = false;
83
92
  break;
84
93
  }
94
+ if (side === "tb" && placed.some((p) => p.y < c.hubH / 2 + g && p.y + p.height > -c.hubH / 2 - g))
95
+ ok = false;
85
96
  if (ok) {
86
97
  nodes.push(...placed);
87
98
  break;
@@ -97,6 +108,62 @@ export function ringLayout(c, side = "both") {
97
108
  }
98
109
  return { hubId: c.hubId, nodes, w: maxX - minX, h: maxY - minY };
99
110
  }
111
+ const APPROACH_CLEARANCE = 5;
112
+ function clusterCandidates(c, approachYs) {
113
+ const baseline = ringLayout(c, "tb");
114
+ if (!c.satellites.length || c.satellites.length === 4)
115
+ return [baseline];
116
+ const result = [baseline];
117
+ for (const mirror of [1, -1])
118
+ for (const bias of [0, 1, -1]) {
119
+ const hub = { id: c.hubId, x: -c.hubW / 2, y: -c.hubH / 2, width: c.hubW, height: c.hubH };
120
+ const nodes = [hub];
121
+ const bank = new Map();
122
+ c.satellites.forEach((s, i) => {
123
+ const side = (i % 2 === 0 ? 1 : -1) * mirror;
124
+ const top = (Math.floor(i / 2) % 2 === 0 ? -1 : 1) * (bias < 0 ? -1 : 1);
125
+ const key = `${side}:${top}`;
126
+ const used = bank.get(key) ?? 0;
127
+ const edge = top < 0 ? Math.min(...approachYs) - APPROACH_CLEARANCE : Math.max(...approachYs) + APPROACH_CLEARANCE;
128
+ const y = top < 0 ? edge - used - s.height : edge + used;
129
+ nodes.push({ ...s, x: side > 0 ? c.hubW / 2 + 55 : -c.hubW / 2 - 55 - s.width,
130
+ y: y + (bias === 1 ? top * 12 : 0) });
131
+ bank.set(key, used + s.height + GAP);
132
+ });
133
+ if (nodes.some((a, i) => nodes.slice(i + 1).some(b => boxesOverlap(a, b, 8))))
134
+ continue;
135
+ // Straight Extend edges must not pass through another child in the same bank.
136
+ const blocked = nodes.slice(1).some(n => nodes.slice(1).some(other => {
137
+ if (n === other)
138
+ return false;
139
+ let lo = 0, hi = 1;
140
+ for (const [end, min, max] of [
141
+ [n.x + n.width / 2, other.x - 5, other.x + other.width + 5],
142
+ [n.y + n.height / 2, other.y - 5, other.y + other.height + 5],
143
+ ]) {
144
+ if (Math.abs(end) < 0.000001) {
145
+ if (min > 0 || max < 0)
146
+ return false;
147
+ }
148
+ else {
149
+ lo = Math.max(lo, Math.min(min / end, max / end));
150
+ hi = Math.min(hi, Math.max(min / end, max / end));
151
+ }
152
+ }
153
+ return lo < hi;
154
+ }));
155
+ if (blocked)
156
+ continue;
157
+ const minX = Math.min(...nodes.map(n => n.x)) - CLUSTER_PAD;
158
+ const minY = Math.min(...nodes.map(n => n.y)) - CLUSTER_PAD;
159
+ const w = Math.max(...nodes.map(n => n.x + n.width)) + CLUSTER_PAD - minX;
160
+ const h = Math.max(...nodes.map(n => n.y + n.height)) + CLUSTER_PAD - minY;
161
+ if (w > Math.max(baseline.w, 600))
162
+ continue;
163
+ result.push({ hubId: c.hubId, w, h, nodes: nodes.map(n => ({ ...n, x: n.x - minX, y: n.y - minY })) });
164
+ }
165
+ return result;
166
+ }
100
167
  /**
101
168
  * Barycenter zone ordering for N actors: each actor's position in the sorted
102
169
  * `actorNames` list is its index (0..N-1); a cluster's zone is the rounded
@@ -156,8 +223,9 @@ function balanceRows(rows, zoneOfHub) {
156
223
  * Login: one straight horizontal line). Deterministic, no ELK.
157
224
  */
158
225
  export function layoutUsecaseRadial(input) {
159
- if (input.clusters.length > 8)
160
- return layoutWrapped(input);
226
+ const login = input.login;
227
+ if (login || input.clusters.length > 8)
228
+ return layoutVertical(input, login);
161
229
  const actorNames = [...new Set(input.clusters.flatMap((c) => c.actors))].sort();
162
230
  const clusterByHub = new Map(input.clusters.map((c) => [c.hubId, c]));
163
231
  const zoneOfHub = new Map(input.clusters.map((c) => [c.hubId, zoneOf(c, actorNames)]));
@@ -274,6 +342,254 @@ export function layoutUsecaseRadial(input) {
274
342
  });
275
343
  return { nodes, edges: [...edges, ...specialEdges] };
276
344
  }
345
+ /**
346
+ * Two height-balanced columns with Login in a clear central corridor.
347
+ * Actor preferences break ties, but do not leave a long, mostly empty column.
348
+ */
349
+ function layoutVertical(input, login) {
350
+ const mixed = layoutVerticalCandidate(input, login, true);
351
+ const baseline = layoutVerticalCandidate(input, login, false);
352
+ const bounds = (g) => ({
353
+ w: Math.max(...g.nodes.map(n => n.x + n.width), 0) - Math.min(...g.nodes.map(n => n.x), 0),
354
+ h: Math.max(...g.nodes.map(n => n.y + n.height), 0) - Math.min(...g.nodes.map(n => n.y), 0),
355
+ });
356
+ const a = bounds(mixed), b = bounds(baseline);
357
+ // A lone group follows the explicitly requested near-horizontal preference.
358
+ // Catalog alternatives must beat the complete fallback, not just local shapes.
359
+ return input.clusters.length === 1 || (a.w * a.h < b.w * b.h && a.w <= b.w * 1.05) ? mixed : baseline;
360
+ }
361
+ function layoutVerticalCandidate(input, login, mixed) {
362
+ const GUTTER = 70, ROW_GAP = 30;
363
+ const actorNames = [...new Set(input.clusters.flatMap((c) => c.actors))].sort();
364
+ const mid = actorNames.length - 1;
365
+ const cols = [[], [], []];
366
+ const approaches = (id) => {
367
+ const c = input.clusters.find(c => c.hubId === id);
368
+ const actors = input.actors.filter(a => a.hubIds.includes(id));
369
+ return [0, ...actors.map((_, i) => actors.length <= 1 ? 0 :
370
+ ((i + 1) / (actors.length + 1) - 0.5) * (c.hubH - 16))];
371
+ };
372
+ const candidates = new Map(input.clusters.map(c => [c.hubId, mixed ? clusterCandidates(c, approaches(c.hubId)) : [ringLayout(c, "tb")]]));
373
+ const placed = new Map(input.clusters.map(c => [c.hubId, [...candidates.get(c.hubId)].sort((a, b) => a.h - b.h || a.w - b.w)[0]]));
374
+ const weight = (c) => placed.get(c.hubId).h + ROW_GAP;
375
+ const load = [0, 0, 0];
376
+ const shared = [];
377
+ for (const c of input.clusters) {
378
+ // Only Login/Register occupy the centre; every group goes to one of the two columns.
379
+ const z = zoneOf(c, actorNames);
380
+ const col = z < mid ? 0 : z > mid ? 2 : -1;
381
+ if (col < 0) {
382
+ shared.push(c);
383
+ continue;
384
+ }
385
+ cols[col].push(c);
386
+ load[col] += weight(c);
387
+ }
388
+ for (const c of shared) {
389
+ const col = load[0] <= load[2] ? 0 : 2;
390
+ cols[col].push(c);
391
+ load[col] += weight(c);
392
+ }
393
+ // Move the group that most reduces the height difference, preserving actor
394
+ // locality whenever moving it would not actually improve the balance.
395
+ for (;;) {
396
+ const [from, to] = load[0] > load[2] ? [0, 2] : [2, 0];
397
+ const diff = Math.abs(load[from] - load[to]);
398
+ const candidates = cols[from].map(c => ({ c, diff: Math.abs(diff - 2 * weight(c)) }))
399
+ .filter(v => v.diff < diff - 1).sort((a, b) => a.diff - b.diff);
400
+ if (!candidates.length || cols[from].length < 2)
401
+ break;
402
+ const c = candidates[0].c;
403
+ cols[from].splice(cols[from].indexOf(c), 1);
404
+ cols[to].push(c);
405
+ load[from] -= weight(c);
406
+ load[to] += weight(c);
407
+ }
408
+ const split = cols.map(list => {
409
+ const ps = list.map(c => placed.get(c.hubId));
410
+ const total = ps.reduce((sum, p) => sum + p.h + ROW_GAP, 0);
411
+ let height = 0, cut = 0, best = Infinity;
412
+ for (let i = 0; i <= ps.length; i++) {
413
+ const diff = Math.abs(total - 2 * height);
414
+ if (diff < best) {
415
+ best = diff;
416
+ cut = i;
417
+ }
418
+ if (ps[i])
419
+ height += ps[i].h + ROW_GAP;
420
+ }
421
+ return { above: ps.slice(0, cut), below: ps.slice(cut) };
422
+ });
423
+ const hubCx = (p) => { const h = p.nodes.find((n) => n.id === p.hubId); return h.x + h.width / 2; };
424
+ const approachWidth = Math.max(...[...candidates.values()].flat().map(p => p.w), 0);
425
+ const contour = (p) => {
426
+ const h = p.nodes.find(n => n.id === p.hubId);
427
+ const cx = h.x + h.width / 2, cy = h.y + h.height / 2;
428
+ return [...p.nodes, ...approaches(p.hubId).map(y => ({ ...h, x: cx - approachWidth,
429
+ y: cy + y, width: approachWidth * 2, height: 0, approach: true })),
430
+ ...p.nodes.filter(n => n !== h).map(n => {
431
+ const nx = n.x + n.width / 2, ny = n.y + n.height / 2;
432
+ return { id: n.id, x: Math.min(cx, nx), y: Math.min(cy, ny), width: Math.abs(cx - nx), height: Math.abs(cy - ny) };
433
+ })];
434
+ };
435
+ const pack = (ps) => {
436
+ let states = [{ entries: [], occupied: [], height: 0, floor: 0, width: 0 }];
437
+ for (const original of ps) {
438
+ const next = [];
439
+ for (const state of states)
440
+ for (const p of candidates.get(original.hubId)) {
441
+ const h = p.nodes.find(n => n.id === p.hubId);
442
+ const shapes = contour(p).map(n => ({ ...n, x: n.x - hubCx(p) }));
443
+ const forbidden = [];
444
+ for (const a of state.occupied)
445
+ for (const b of shapes) {
446
+ if (a.approach && b.approach)
447
+ continue;
448
+ const gap = (a.approach || b.approach ? APPROACH_CLEARANCE : 8) + 0.00001;
449
+ if (a.x < b.x + b.width + gap && b.x < a.x + a.width + gap)
450
+ forbidden.push([a.y - b.y - b.height - gap, a.y + a.height - b.y + gap]);
451
+ }
452
+ forbidden.sort((a, b) => a[0] - b[0]);
453
+ let y = Math.max(0, state.floor - h.y);
454
+ for (const [lo, hi] of forbidden)
455
+ if (y > lo + 0.000001 && y < hi - 0.000001)
456
+ y = hi;
457
+ next.push({ entries: [...state.entries, { p, y }], occupied: [...state.occupied, ...shapes.map(n => ({ ...n, y: n.y + y }))],
458
+ height: Math.max(state.height, y + p.h), floor: y + h.y + h.height + 8, width: Math.max(state.width, p.w) });
459
+ }
460
+ next.sort((a, b) => (a.height + a.width * 0.25) - (b.height + b.width * 0.25));
461
+ states = next.slice(0, 12);
462
+ }
463
+ return states[0];
464
+ };
465
+ const packed = split.map(s => ({ above: pack(s.above), below: pack(s.below) }));
466
+ const halfW = packed.map(({ above, below }) => Math.max(0, ...[...above.entries, ...below.entries].map(({ p }) => Math.max(hubCx(p), p.w - hubCx(p)))));
467
+ const reg = input.register;
468
+ if (login)
469
+ halfW[1] = Math.max(halfW[1], login.width / 2 + (reg ? 40 + reg.width : 0));
470
+ // Each include route to Login gets its own lane in the half of the gutter nearest Login.
471
+ const LANE_STEP = 14;
472
+ const lanes = Math.max(...[0, 2].map((ci) => Math.max(split[ci].above.length, split[ci].below.length)));
473
+ // Actor associations use the outer walls, leaving the middle gutters to includes.
474
+ const actorLaneCount = input.actors.reduce((sum, a) => sum + a.hubIds.length, 0);
475
+ const actorLaneWidth = (actorLaneCount + 1) * 10;
476
+ const gutter = Math.max(GUTTER, 2 * (lanes + 1) * LANE_STEP);
477
+ const colCx = [halfW[0], 0, 0];
478
+ colCx[1] = colCx[0] + halfW[0] + gutter + halfW[1];
479
+ colCx[2] = colCx[1] + halfW[1] + gutter + halfW[2];
480
+ const gutterX = [colCx[0] + halfW[0] + gutter / 2, colCx[1] + halfW[1] + gutter / 2];
481
+ const nodes = [];
482
+ const hubs = [];
483
+ const place = (p, col, y, rowTop, above) => {
484
+ const dx = colCx[col] - hubCx(p);
485
+ for (const nd of p.nodes) {
486
+ const abs = { ...nd, x: nd.x + dx, y: nd.y + y };
487
+ nodes.push(abs);
488
+ if (nd.id === p.hubId)
489
+ hubs.push({ node: abs, col, rowTop, above });
490
+ }
491
+ };
492
+ const topHeight = Math.max(...packed.map(s => s.above.height));
493
+ packed.forEach((s, col) => {
494
+ const dy = topHeight - s.above.height;
495
+ for (const { p, y } of s.above.entries)
496
+ place(p, col, y + dy, y + dy, true);
497
+ });
498
+ const loginTop = topHeight + BAND_PAD;
499
+ // Without Login the corridor stays an empty band so actors keep a clear latitude.
500
+ const loginNode = login && { id: login.id, x: colCx[1] - login.width / 2, y: loginTop, width: login.width, height: login.height };
501
+ if (loginNode)
502
+ nodes.push(loginNode);
503
+ const loginCY = loginTop + (login?.height ?? 0) / 2;
504
+ let registerNode;
505
+ if (reg && loginNode) {
506
+ registerNode = { id: reg.id, x: loginNode.x - 40 - reg.width, y: loginNode.y + loginNode.height + 20, width: reg.width, height: reg.height };
507
+ nodes.push(registerNode);
508
+ }
509
+ const bottomTop = (registerNode ? registerNode.y + registerNode.height : loginTop + (login?.height ?? 0)) + BAND_PAD;
510
+ packed.forEach((s, col) => {
511
+ for (const { p, y } of s.below.entries)
512
+ place(p, col, y + bottomTop, y + bottomTop, false);
513
+ });
514
+ const edges = [];
515
+ const hubById = new Map(hubs.map((h) => [h.node.id, h]));
516
+ // Vertical layout: every hub edge leaves/enters the hub's left or right side at its centre latitude.
517
+ // Farther hubs take lanes nearer Login and enter it farther from its centre, so no two routes cross or overlap.
518
+ const groups = new Map();
519
+ for (const hb of hubs) {
520
+ const k = `${hb.col}${hb.above}`;
521
+ groups.set(k, [...(groups.get(k) ?? []), hb]);
522
+ }
523
+ const rank = new Map();
524
+ for (const g of groups.values()) {
525
+ g.sort((a, b) => Math.abs(a.node.y - loginCY) - Math.abs(b.node.y - loginCY));
526
+ g.forEach((hb, idx) => rank.set(hb.node.id, { idx, n: g.length }));
527
+ }
528
+ for (const { node: h, col, above } of loginNode ? hubs : []) {
529
+ const hcy = h.y + h.height / 2;
530
+ const right = col === 2;
531
+ const { idx, n } = rank.get(h.id);
532
+ const gx = right ? gutterX[1] - (idx + 1) * LANE_STEP : gutterX[0] + (idx + 1) * LANE_STEP;
533
+ const hx = right ? h.x : col === 0 ? h.x + h.width : h.x;
534
+ const side = right ? loginNode.x + loginNode.width : loginNode.x;
535
+ const step = Math.min(10, (loginNode.height / 2 - 4) / n);
536
+ const ey = loginCY + (above ? -1 : 1) * (idx + 1) * step;
537
+ edges.push({ id: `${h.id}~${loginNode.id}`, source: h.id, target: loginNode.id,
538
+ points: [{ x: hx, y: hcy }, { x: gx, y: hcy }, { x: gx, y: ey }, { x: side, y: ey }] });
539
+ }
540
+ const minX = Math.min(...nodes.map((n) => n.x)), maxX = Math.max(...nodes.map((n) => n.x + n.width));
541
+ const half = Math.ceil(input.actors.length / 2);
542
+ const catalogBottom = Math.max(...nodes.map(n => n.y + n.height));
543
+ let associationIndex = 0;
544
+ // Unique outer lanes also separate associations shared by multiple actors.
545
+ const outerMargin = Math.max(ACTOR_MARGIN, actorLaneWidth + 40);
546
+ input.actors.forEach((act, i) => {
547
+ const left = i < half;
548
+ const groupIdx = left ? i : i - half;
549
+ const groupCount = left ? half : input.actors.length - half;
550
+ const an = {
551
+ id: act.id, x: left ? minX - outerMargin - act.width : maxX + outerMargin,
552
+ y: loginCY - act.height / 2 + (groupIdx - (groupCount - 1) / 2) * (act.height + 24),
553
+ width: act.width, height: act.height,
554
+ };
555
+ nodes.push(an);
556
+ const ax = an.x + an.width / 2, ay = an.y + an.height / 2;
557
+ for (const hubId of act.hubIds) {
558
+ const hub = hubById.get(hubId);
559
+ if (!hub)
560
+ continue;
561
+ const offset = (++associationIndex) * 10;
562
+ const portY = ay + ((act.hubIds.indexOf(hubId) + 1) / (act.hubIds.length + 1) - 0.5) * (act.height - 16);
563
+ const linkedActors = input.actors.filter(a => a.hubIds.includes(hubId));
564
+ const entryOffset = linkedActors.length <= 1 ? 0 :
565
+ ((linkedActors.findIndex(a => a.id === act.id) + 1) / (linkedActors.length + 1) - 0.5) * (hub.node.height - 16);
566
+ const hcy = hub.node.y + hub.node.height / 2 + entryOffset;
567
+ const hubOnRight = hub.col === 2;
568
+ const hx = hubOnRight ? hub.node.x + hub.node.width : hub.node.x;
569
+ const outerX = left ? minX - 20 - offset : maxX + 20 + offset;
570
+ const crossesCentre = left ? hub.col === 2 : hub.col === 0;
571
+ // Cross-column associations wrap around the opposite outer wall;
572
+ // the middle gutters remain clear for includes.
573
+ const lx = crossesCentre ? (left ? maxX + 25 + offset : minX - 25 - offset) : outerX;
574
+ const topY = hub.above ? -20 - offset : catalogBottom + 20 + offset;
575
+ edges.push({ id: `${act.id}~${hubId}`, source: act.id, target: hubId,
576
+ points: crossesCentre
577
+ ? [{ x: ax, y: portY }, { x: outerX, y: portY }, { x: outerX, y: topY }, { x: lx, y: topY }, { x: lx, y: hcy }, { x: hx, y: hcy }]
578
+ : [{ x: ax, y: portY }, { x: lx, y: portY }, { x: lx, y: hcy }, { x: hx, y: hcy }] });
579
+ }
580
+ if (loginNode) {
581
+ const lx = left ? loginNode.x : loginNode.x + loginNode.width;
582
+ edges.push({ id: `${act.id}~${loginNode.id}`, source: act.id, target: loginNode.id,
583
+ points: ay === loginCY ? [{ x: ax, y: ay }, { x: lx, y: loginCY }] : [{ x: ax, y: ay }, { x: ax, y: loginCY }, { x: lx, y: loginCY }] });
584
+ }
585
+ if (registerNode && left) {
586
+ const ry = registerNode.y + registerNode.height / 2;
587
+ edges.push({ id: `${act.id}~${registerNode.id}`, source: act.id, target: registerNode.id,
588
+ points: [{ x: ax, y: ay }, { x: ax, y: ry }, { x: registerNode.x, y: ry }] });
589
+ }
590
+ });
591
+ return { nodes, edges };
592
+ }
277
593
  /** Large catalogs use shelves; the small hand-drawn two-row layout stays unchanged. */
278
594
  function layoutWrapped(input) {
279
595
  const clusters = input.clusters.map(c => ringLayout(c));