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.
- package/README.md +96 -30
- package/dashboard-server/client-dist/assets/index-BK3iMzXX.css +1 -0
- package/dashboard-server/client-dist/assets/index-CvlC6kTE.js +23 -0
- package/dashboard-server/client-dist/brand/favicon.png +0 -0
- package/dashboard-server/client-dist/brand/logo-full.png +0 -0
- package/dashboard-server/client-dist/icons.svg +24 -0
- package/dashboard-server/client-dist/index.html +14 -0
- package/dashboard-server/dist/core-bridge.js +26 -0
- package/dashboard-server/dist/files-route.js +34 -0
- package/dashboard-server/dist/index.js +292 -0
- package/dashboard-server/dist/license-routes.js +39 -0
- package/dashboard-server/dist/outputs-route.js +208 -0
- package/dashboard-server/dist/run-route.js +89 -0
- package/dashboard-server/dist/security.js +115 -0
- package/dist/cli/archscribe.js +111 -30
- package/dist/cli/archscribe.js.map +1 -1
- package/dist/cli/commands.js +6 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/context.d.ts +1 -0
- package/dist/cli/context.js +34 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/doctor.js +2 -2
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/history.js +58 -0
- package/dist/cli/history.js.map +1 -1
- package/dist/cli/login.js +4 -6
- package/dist/cli/login.js.map +1 -1
- package/dist/cli/logout.js +1 -1
- package/dist/cli/logout.js.map +1 -1
- package/dist/cli/rag.d.ts +1 -4
- package/dist/cli/rag.js +7 -29
- package/dist/cli/rag.js.map +1 -1
- package/dist/cli/review.d.ts +1 -0
- package/dist/cli/review.js +144 -0
- package/dist/cli/review.js.map +1 -0
- package/dist/cli/run.d.ts +4 -1
- package/dist/cli/run.js +10 -20
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/shell.js +8 -19
- package/dist/cli/shell.js.map +1 -1
- package/dist/cli/ui/animations.js +1 -1
- package/dist/cli/ui/document-frame.d.ts +17 -0
- package/dist/cli/ui/document-frame.js +65 -0
- package/dist/cli/ui/document-frame.js.map +1 -0
- package/dist/cli/ui/document-tui.d.ts +5 -0
- package/dist/cli/ui/document-tui.js +224 -0
- package/dist/cli/ui/document-tui.js.map +1 -0
- package/dist/cli/ui/keys.d.ts +1 -0
- package/dist/cli/ui/keys.js +30 -6
- package/dist/cli/ui/keys.js.map +1 -1
- package/dist/cli/ui/little-scribe.d.ts +3 -0
- package/dist/cli/ui/little-scribe.js +67 -0
- package/dist/cli/ui/little-scribe.js.map +1 -0
- package/dist/cli/ui/mascot.d.ts +4 -2
- package/dist/cli/ui/mascot.js +19 -46
- package/dist/cli/ui/mascot.js.map +1 -1
- package/dist/cli/ui/menu.d.ts +1 -1
- package/dist/cli/ui/menu.js +1 -1
- package/dist/cli/ui/menu.js.map +1 -1
- package/dist/cli/ui/stage.js +12 -7
- package/dist/cli/ui/stage.js.map +1 -1
- package/dist/cli/ui/term.js +3 -1
- package/dist/cli/ui/term.js.map +1 -1
- package/dist/core/actor-inference.d.ts +1 -0
- package/dist/core/actor-inference.js +2 -1
- package/dist/core/actor-inference.js.map +1 -1
- package/dist/core/approval-ledger.d.ts +57 -0
- package/dist/core/approval-ledger.js +95 -0
- package/dist/core/approval-ledger.js.map +1 -0
- package/dist/core/component-groups.d.ts +2 -0
- package/dist/core/component-groups.js +4 -0
- package/dist/core/component-groups.js.map +1 -1
- package/dist/core/docx-export.d.ts +4 -0
- package/dist/core/docx-export.js +25 -0
- package/dist/core/docx-export.js.map +1 -0
- package/dist/core/docx-lists.d.ts +8 -0
- package/dist/core/docx-lists.js +75 -0
- package/dist/core/docx-lists.js.map +1 -0
- package/dist/core/docx-styles.d.ts +2 -1
- package/dist/core/docx-styles.js +2 -1
- package/dist/core/docx-styles.js.map +1 -1
- package/dist/core/docx-table.d.ts +5 -0
- package/dist/core/docx-table.js +71 -0
- package/dist/core/docx-table.js.map +1 -0
- package/dist/core/docx-update.js +72 -8
- package/dist/core/docx-update.js.map +1 -1
- package/dist/core/docx.js +83 -31
- package/dist/core/docx.js.map +1 -1
- package/dist/core/flow-steps.d.ts +1 -4
- package/dist/core/flow-steps.js +61 -115
- package/dist/core/flow-steps.js.map +1 -1
- package/dist/core/flow-trace.d.ts +9 -2
- package/dist/core/flow-trace.js +57 -58
- package/dist/core/flow-trace.js.map +1 -1
- package/dist/core/flow.js +10 -14
- package/dist/core/flow.js.map +1 -1
- package/dist/core/ledger-reconcile.d.ts +40 -0
- package/dist/core/ledger-reconcile.js +296 -0
- package/dist/core/ledger-reconcile.js.map +1 -0
- package/dist/core/markdown.d.ts +18 -1
- package/dist/core/markdown.js +98 -41
- package/dist/core/markdown.js.map +1 -1
- package/dist/core/materialize-report.d.ts +10 -0
- package/dist/core/materialize-report.js +72 -0
- package/dist/core/materialize-report.js.map +1 -0
- package/dist/core/output-history.d.ts +29 -0
- package/dist/core/output-history.js +204 -0
- package/dist/core/output-history.js.map +1 -0
- package/dist/core/output-mutation.d.ts +1 -0
- package/dist/core/output-mutation.js +15 -0
- package/dist/core/output-mutation.js.map +1 -0
- package/dist/core/parser.js +1 -3
- package/dist/core/parser.js.map +1 -1
- package/dist/core/review-feedback.d.ts +7 -0
- package/dist/core/review-feedback.js +46 -0
- package/dist/core/review-feedback.js.map +1 -0
- package/dist/core/uc-context-builder.d.ts +1 -0
- package/dist/core/uc-context-builder.js +11 -0
- package/dist/core/uc-context-builder.js.map +1 -1
- package/dist/core/uc-grouping-candidates.d.ts +9 -0
- package/dist/core/uc-grouping-candidates.js +35 -0
- package/dist/core/uc-grouping-candidates.js.map +1 -0
- package/dist/core/uc-grouping-evidence.d.ts +5 -0
- package/dist/core/uc-grouping-evidence.js +95 -0
- package/dist/core/uc-grouping-evidence.js.map +1 -0
- package/dist/core/uc-proposal.d.ts +19 -2
- package/dist/core/uc-proposal.js +127 -0
- package/dist/core/uc-proposal.js.map +1 -1
- package/dist/diagrams/activity.js +58 -14
- package/dist/diagrams/activity.js.map +1 -1
- package/dist/diagrams/arch/c4/build.d.ts +4 -0
- package/dist/diagrams/arch/c4/build.js +98 -0
- package/dist/diagrams/arch/c4/build.js.map +1 -0
- package/dist/diagrams/arch/c4/components.d.ts +4 -0
- package/dist/diagrams/arch/c4/components.js +92 -0
- package/dist/diagrams/arch/c4/components.js.map +1 -0
- package/dist/diagrams/arch/c4/context.d.ts +3 -0
- package/dist/diagrams/arch/c4/context.js +135 -0
- package/dist/diagrams/arch/c4/context.js.map +1 -0
- package/dist/diagrams/arch/c4/embedded.d.ts +7 -0
- package/dist/diagrams/arch/c4/embedded.js +43 -0
- package/dist/diagrams/arch/c4/embedded.js.map +1 -0
- package/dist/diagrams/arch/c4/identity.d.ts +6 -0
- package/dist/diagrams/arch/c4/identity.js +25 -0
- package/dist/diagrams/arch/c4/identity.js.map +1 -0
- package/dist/diagrams/arch/c4/messages.d.ts +2 -0
- package/dist/diagrams/arch/c4/messages.js +6 -0
- package/dist/diagrams/arch/c4/messages.js.map +1 -0
- package/dist/diagrams/arch/c4/render.d.ts +3 -0
- package/dist/diagrams/arch/c4/render.js +150 -0
- package/dist/diagrams/arch/c4/render.js.map +1 -0
- package/dist/diagrams/arch/c4/topology-layout.d.ts +24 -0
- package/dist/diagrams/arch/c4/topology-layout.js +98 -0
- package/dist/diagrams/arch/c4/topology-layout.js.map +1 -0
- package/dist/diagrams/arch/c4/types.d.ts +123 -0
- package/dist/diagrams/arch/c4/types.js +2 -0
- package/dist/diagrams/arch/c4/types.js.map +1 -0
- package/dist/diagrams/arch/c4/views.d.ts +3 -0
- package/dist/diagrams/arch/c4/views.js +48 -0
- package/dist/diagrams/arch/c4/views.js.map +1 -0
- package/dist/diagrams/arch/classify.d.ts +27 -0
- package/dist/diagrams/arch/classify.js +136 -0
- package/dist/diagrams/arch/classify.js.map +1 -0
- package/dist/diagrams/arch/layered.d.ts +11 -0
- package/dist/diagrams/arch/layered.js +35 -0
- package/dist/diagrams/arch/layered.js.map +1 -0
- package/dist/diagrams/arch/layout-clean.d.ts +10 -0
- package/dist/diagrams/arch/layout-clean.js +74 -0
- package/dist/diagrams/arch/layout-clean.js.map +1 -0
- package/dist/diagrams/arch/layout-component.d.ts +13 -0
- package/dist/diagrams/arch/layout-component.js +221 -0
- package/dist/diagrams/arch/layout-component.js.map +1 -0
- package/dist/diagrams/arch/layout-hexagonal.d.ts +11 -0
- package/dist/diagrams/arch/layout-hexagonal.js +142 -0
- package/dist/diagrams/arch/layout-hexagonal.js.map +1 -0
- package/dist/diagrams/arch/layout-layered.d.ts +17 -0
- package/dist/diagrams/arch/layout-layered.js +89 -0
- package/dist/diagrams/arch/layout-layered.js.map +1 -0
- package/dist/diagrams/arch/messages.generated.d.ts +119 -0
- package/dist/diagrams/arch/messages.generated.js +120 -0
- package/dist/diagrams/arch/messages.generated.js.map +1 -0
- package/dist/diagrams/arch/model.d.ts +60 -0
- package/dist/diagrams/arch/model.js +271 -0
- package/dist/diagrams/arch/model.js.map +1 -0
- package/dist/diagrams/arch/xml.d.ts +23 -0
- package/dist/diagrams/arch/xml.js +42 -0
- package/dist/diagrams/arch/xml.js.map +1 -0
- package/dist/diagrams/architecture.d.ts +29 -36
- package/dist/diagrams/architecture.js +52 -152
- package/dist/diagrams/architecture.js.map +1 -1
- package/dist/diagrams/layout/radial.d.ts +1 -1
- package/dist/diagrams/layout/radial.js +318 -2
- package/dist/diagrams/layout/radial.js.map +1 -1
- package/dist/diagrams/sequence-model.js +6 -8
- package/dist/diagrams/sequence-model.js.map +1 -1
- package/dist/diagrams/sequence.js +34 -4
- package/dist/diagrams/sequence.js.map +1 -1
- package/dist/diagrams/usecase.d.ts +2 -1
- package/dist/diagrams/usecase.js +44 -20
- package/dist/diagrams/usecase.js.map +1 -1
- package/dist/diagrams/usecase_layout.d.ts +7 -12
- package/dist/diagrams/usecase_layout.js +25 -84
- package/dist/diagrams/usecase_layout.js.map +1 -1
- package/dist/evaluation/dashboard-review.js +0 -66
- package/dist/evaluation/dashboard-review.js.map +1 -1
- package/dist/knowledge/evidence.d.ts +48 -0
- package/dist/knowledge/evidence.js +253 -0
- package/dist/knowledge/evidence.js.map +1 -0
- package/dist/knowledge/hub-grouping.d.ts +7 -3
- package/dist/knowledge/hub-grouping.js +74 -55
- package/dist/knowledge/hub-grouping.js.map +1 -1
- package/dist/knowledge/local-kb.d.ts +4 -0
- package/dist/knowledge/local-kb.js +84 -0
- package/dist/knowledge/local-kb.js.map +1 -0
- package/dist/knowledge/rag-augment.d.ts +31 -6
- package/dist/knowledge/rag-augment.js +77 -37
- package/dist/knowledge/rag-augment.js.map +1 -1
- package/dist/knowledge/rag-client.d.ts +11 -0
- package/dist/knowledge/rag-client.js +60 -0
- package/dist/knowledge/rag-client.js.map +1 -0
- package/dist/knowledge/retriever.d.ts +7 -2
- package/dist/knowledge/retriever.js +29 -14
- package/dist/knowledge/retriever.js.map +1 -1
- package/dist/knowledge/rules.d.ts +2 -0
- package/dist/knowledge/rules.js +10 -0
- package/dist/knowledge/rules.js.map +1 -0
- package/dist/knowledge/store-lock.d.ts +2 -0
- package/dist/knowledge/store-lock.js +35 -0
- package/dist/knowledge/store-lock.js.map +1 -0
- package/dist/knowledge/types.d.ts +6 -1
- package/dist/license/banner.d.ts +1 -3
- package/dist/license/banner.js +2 -6
- package/dist/license/banner.js.map +1 -1
- package/dist/license/client.d.ts +4 -7
- package/dist/license/client.js +6 -16
- package/dist/license/client.js.map +1 -1
- package/dist/license/gate.d.ts +1 -3
- package/dist/license/gate.js +3 -3
- package/dist/license/gate.js.map +1 -1
- package/dist/license/verify.js +19 -14
- package/dist/license/verify.js.map +1 -1
- package/dist/parser.jar +0 -0
- package/dist/server.js +145 -11
- package/dist/server.js.map +1 -1
- package/dist/theory/context.d.ts +52 -0
- package/dist/theory/context.js +144 -0
- package/dist/theory/context.js.map +1 -0
- package/dist/theory/fill.d.ts +13 -1
- package/dist/theory/fill.js +122 -71
- package/dist/theory/fill.js.map +1 -1
- package/dist/theory/references.d.ts +9 -34
- package/dist/theory/references.js +9 -135
- package/dist/theory/references.js.map +1 -1
- package/dist/theory/scaffold.js +41 -26
- package/dist/theory/scaffold.js.map +1 -1
- package/dist/tools/environment.js +1 -1
- package/dist/tools/environment.js.map +1 -1
- package/dist/tools/generate_report.d.ts +8 -1
- package/dist/tools/generate_report.js +186 -89
- package/dist/tools/generate_report.js.map +1 -1
- package/dist/tools/learn_usecase.d.ts +2 -6
- package/dist/tools/learn_usecase.js +50 -34
- package/dist/tools/learn_usecase.js.map +1 -1
- package/dist/tools/propose_uc_groupings.d.ts +1 -10
- package/dist/tools/propose_uc_groupings.js +23 -79
- package/dist/tools/propose_uc_groupings.js.map +1 -1
- package/dist/tools/review_tools.d.ts +26 -0
- package/dist/tools/review_tools.js +55 -0
- package/dist/tools/review_tools.js.map +1 -0
- package/dist/tools/scaffold.d.ts +3 -1
- package/dist/tools/scaffold.js +99 -58
- package/dist/tools/scaffold.js.map +1 -1
- package/dist/tools/scan_repo.js +1 -1
- package/dist/tools/scan_repo.js.map +1 -1
- package/dist/types/ir.d.ts +4 -0
- package/dist/types/license.d.ts +4 -3
- package/dist/types/report.d.ts +17 -1
- package/dist/types/theory.d.ts +3 -2
- package/dist/types/uc-grouping.d.ts +57 -7
- package/dist/utils/dashboard-launcher.js +1 -1
- package/dist/utils/dashboard-launcher.js.map +1 -1
- package/dist/utils/mcp-launch.d.ts +26 -0
- package/dist/utils/mcp-launch.js +48 -0
- package/dist/utils/mcp-launch.js.map +1 -0
- package/dist/utils/run-history.d.ts +1 -2
- package/dist/utils/run-history.js +2 -11
- package/dist/utils/run-history.js.map +1 -1
- package/package.json +35 -10
- package/dist/knowledge/embedding.d.ts +0 -11
- package/dist/knowledge/embedding.js +0 -31
- package/dist/knowledge/embedding.js.map +0 -1
- package/dist/knowledge/qdrant-client.d.ts +0 -20
- package/dist/knowledge/qdrant-client.js +0 -95
- package/dist/knowledge/qdrant-client.js.map +0 -1
- package/dist/knowledge/seed-data-extended.d.ts +0 -7
- package/dist/knowledge/seed-data-extended.js +0 -183
- package/dist/knowledge/seed-data-extended.js.map +0 -1
- package/dist/knowledge/seed-data-extra.d.ts +0 -6
- package/dist/knowledge/seed-data-extra.js +0 -178
- package/dist/knowledge/seed-data-extra.js.map +0 -1
- package/dist/knowledge/seed-data.d.ts +0 -3
- package/dist/knowledge/seed-data.js +0 -333
- package/dist/knowledge/seed-data.js.map +0 -1
- package/dist/knowledge/seed.d.ts +0 -22
- package/dist/knowledge/seed.js +0 -44
- package/dist/knowledge/seed.js.map +0 -1
- package/dist/utils/approval.d.ts +0 -65
- package/dist/utils/approval.js +0 -324
- package/dist/utils/approval.js.map +0 -1
- package/dist/utils/keep-regions.d.ts +0 -44
- package/dist/utils/keep-regions.js +0 -153
- package/dist/utils/keep-regions.js.map +0 -1
|
@@ -1,165 +1,65 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
*
|
|
30
|
-
*
|
|
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
|
|
33
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
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
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"architecture.js","sourceRoot":"","sources":["../../src/diagrams/architecture.ts"],"names":[],"mappings":"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"}
|
|
@@ -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
|
-
|
|
160
|
-
|
|
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));
|