Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Interactive module graph viewers (#82375)

Chris Trutera632ed179920
diff --git a/.clj-kondo/src/hooks/common/modules.clj b/.clj-kondo/src/hooks/common/modules.clj
index d21ed8ae4bf..13166af48a0 100644
--- a/.clj-kondo/src/hooks/common/modules.clj
+++ b/.clj-kondo/src/hooks/common/modules.clj
@@ -89,6 +89,12 @@
[modules module ancestor]
(boolean (some #{ancestor} (take-while some? (iterate #(parent-module modules %) module)))))
+(defn module-team
+ "Team owning `module`: its own `:team`, else its nearest ancestor's."
+ [modules module]
+ (some #(get-in modules [% :team])
+ (take-while some? (iterate #(parent-module modules %) module))))
+
(defn- rest-module? [module]
(re-find #"[.-]rest$" (str module)))
@@ -145,11 +151,11 @@
[config ns-symb]
(resolve-module (prefix->module config) ns-symb))
-(defn- module-api-namespaces
+(defn module-api-namespaces
"Set of API namespace symbols for a given module. `:any` means you can use anything, there are no API namespaces for
- this module (yet). If unspecified, the default is just the `<module>.core` namespace."
- [config module]
- (let [module-config (get-in config [:metabase/modules module :api])]
+ this module (yet). If unspecified, the defaults are `<prefix>.api`, `<prefix>.core`, and `<prefix>.init`."
+ [modules module]
+ (let [module-config (get-in modules [module :api])]
(cond
(= module-config :any)
nil
@@ -158,7 +164,7 @@
module-config
:else
- (let [ns-prefix (module-ns-prefix (:metabase/modules config) module)]
+ (let [ns-prefix (module-ns-prefix modules module)]
#{(symbol (str ns-prefix ".api"))
(symbol (str ns-prefix ".core"))
(symbol (str ns-prefix ".init"))}))))
@@ -181,7 +187,7 @@
(defn- allowed-module-namespace? [config current-module ns-symb]
(let [module (module config ns-symb)
- module-api-namespaces (module-api-namespaces config module)
+ module-api-namespaces (module-api-namespaces (:metabase/modules config) module)
module-friends (module-friends config module)]
(or (nil? module-api-namespaces)
(contains? module-api-namespaces ns-symb)
diff --git a/.gitignore b/.gitignore
index 2464e6665ef..edb5a391f0c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -210,3 +210,6 @@ __pycache__/
# dependency-cruiser output
dependency-graph.json
.playwright-cli/
+
+# mage modules-tree --html output
+/modules.html
diff --git a/CLAUDE.md b/CLAUDE.md
index ab2d80fa982..63c85510a8e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -87,7 +87,8 @@ Run all repository-level checks, or one named suite:
### Nested modules
Module names form a tree: `lib.schema` is a child of `lib`. When OSS module `search` exists,
-`enterprise/search` is its child. Run `./bin/mage modules-tree` to inspect the hierarchy.
+`enterprise/search` is its child. Run `./bin/mage modules-tree` to inspect the hierarchy, or add `--html` for an
+interactive explorer with a dependency graph.
- Namespace ownership uses the most specific matching prefix. Declaring `lib.schema` assigns
`metabase.lib.schema.*` to it without moving files. Use `:ns-prefix` when namespaces do not match the
diff --git a/bb.edn b/bb.edn
index a66bbb61012..181515d3876 100644
--- a/bb.edn
+++ b/bb.edn
@@ -265,9 +265,13 @@
{:doc "Print the module hierarchy, nesting enterprise extensions under their OSS module"
:examples [["./bin/mage modules-tree" "Print the full tree; * marks a custom :ns-prefix"]
["./bin/mage modules-tree --nested-only" "Print only roots with nested modules"]
- ["./bin/mage modules-tree --prefixes" "Show custom prefixes instead of *"]]
+ ["./bin/mage modules-tree --prefixes" "Show custom prefixes instead of *"]
+ ["./bin/mage modules-tree --html --output modules.html" "Write the interactive explorer"]]
:options [["-n" "--nested-only" "Only print modules that have nested children"]
- ["-p" "--prefixes" "Print the :ns-prefix instead of the star"]]
+ ["-p" "--prefixes" "Print the :ns-prefix instead of the star"]
+ ["-H" "--html" "Emit the interactive HTML explorer instead of the text tree"]
+ ["-o" "--output FILE" "With --html, write to FILE instead of stdout"]
+ ["-S" "--no-stats" "With --html, skip the slower per-module source metrics"]]
:requires [[mage.modules]]
:task (task! (mage.modules/cli-print-module-tree parsed))}
diff --git a/dev/resources/dev/module_explorer.html b/dev/resources/dev/module_explorer.html
new file mode 100644
index 00000000000..a39e1a7c358
--- /dev/null
+++ b/dev/resources/dev/module_explorer.html
@@ -0,0 +1,948 @@
+<!doctype html><html lang="en"><head><meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Metabase modules</title>
+<!-- Built by dev.module-explorer; the module data is embedded below as DATA. -->
+<style>
+:root{
+ color-scheme:light dark;
+ --bg:#f7f8fa; --panel:#ffffff; --panel-2:#fbfcfd; --ink:#1a1f27; --ink-soft:#5b6572;
+ --line:#e4e8ee; --line-strong:#d2d8e0; --accent:#4a6fe8; --accent-soft:#e8eeff;
+ --group:#8a94a3; --chip:#eef1f6; --chip-ink:#3a4350; --shadow:0 1px 2px rgba(20,30,50,.06),0 8px 24px rgba(20,30,50,.06);
+ --uses:#e8892b; --usedby:#2fa36b;
+}
+/* explicit color-scheme per theme keeps native controls matched and opts out of Chrome auto-darkening */
+:root[data-theme=light],:root[data-theme=solarized-light]{color-scheme:only light}
+:root[data-theme=dark],:root[data-theme=solarized-dark],:root[data-theme=gruvbox],:root[data-theme=nord]{color-scheme:dark}
+@media (prefers-color-scheme:dark){:root{
+ --bg:#0f1319; --panel:#161b23; --panel-2:#12161d; --ink:#e6eaf0; --ink-soft:#8b96a6;
+ --line:#252c37; --line-strong:#323a48; --accent:#6d8bff; --accent-soft:#1c2740;
+ --group:#5a6472; --chip:#1c222c; --chip-ink:#b9c3d1; --shadow:0 1px 2px rgba(0,0,0,.3),0 12px 32px rgba(0,0,0,.35);
+ --uses:#e89a4d; --usedby:#4cc98a;
+}}
+:root[data-theme=light]{
+ --bg:#f7f8fa; --panel:#ffffff; --panel-2:#fbfcfd; --ink:#1a1f27; --ink-soft:#5b6572;
+ --line:#e4e8ee; --line-strong:#d2d8e0; --accent:#4a6fe8; --accent-soft:#e8eeff;
+ --group:#8a94a3; --chip:#eef1f6; --chip-ink:#3a4350; --shadow:0 1px 2px rgba(20,30,50,.06),0 8px 24px rgba(20,30,50,.06);
+ --uses:#e8892b; --usedby:#2fa36b;
+}
+:root[data-theme=dark]{
+ --bg:#0f1319; --panel:#161b23; --panel-2:#12161d; --ink:#e6eaf0; --ink-soft:#8b96a6;
+ --line:#252c37; --line-strong:#323a48; --accent:#6d8bff; --accent-soft:#1c2740;
+ --group:#5a6472; --chip:#1c222c; --chip-ink:#b9c3d1; --shadow:0 1px 2px rgba(0,0,0,.3),0 12px 32px rgba(0,0,0,.35);
+ --uses:#e89a4d; --usedby:#4cc98a;
+}
+:root[data-theme=solarized-light]{
+ --bg:#eee8d5; --panel:#fdf6e3; --panel-2:#f4eeda; --ink:#586e75; --ink-soft:#93a1a1;
+ --line:#e3ddc8; --line-strong:#d3ccb4; --accent:#268bd2; --accent-soft:#dceaf4;
+ --group:#93a1a1; --chip:#e7e0cc; --chip-ink:#586e75; --shadow:0 1px 2px rgba(88,110,117,.12),0 10px 26px rgba(88,110,117,.14);
+ --uses:#cb4b16; --usedby:#859900;
+}
+:root[data-theme=solarized-dark]{
+ --bg:#002b36; --panel:#073642; --panel-2:#053039; --ink:#93a1a1; --ink-soft:#657b83;
+ --line:#0a3f4c; --line-strong:#164955; --accent:#2aa7d8; --accent-soft:#0f4657;
+ --group:#586e75; --chip:#08313c; --chip-ink:#93a1a1; --shadow:0 1px 2px rgba(0,0,0,.3),0 12px 32px rgba(0,0,0,.4);
+ --uses:#cb4b16; --usedby:#859900;
+}
+:root[data-theme=gruvbox]{
+ --bg:#282828; --panel:#32302f; --panel-2:#3c3836; --ink:#ebdbb2; --ink-soft:#a89984;
+ --line:#3c3836; --line-strong:#504945; --accent:#83a598; --accent-soft:#374446;
+ --group:#928374; --chip:#3c3836; --chip-ink:#d5c4a1; --shadow:0 1px 2px rgba(0,0,0,.3),0 12px 32px rgba(0,0,0,.4);
+ --uses:#fe8019; --usedby:#b8bb26;
+}
+:root[data-theme=nord]{
+ --bg:#2e3440; --panel:#3b4252; --panel-2:#353c4a; --ink:#e5e9f0; --ink-soft:#94a0b8;
+ --line:#434c5e; --line-strong:#4c566a; --accent:#88c0d0; --accent-soft:#3d4a5c;
+ --group:#7b88a1; --chip:#434c5e; --chip-ink:#d8dee9; --shadow:0 1px 2px rgba(0,0,0,.3),0 12px 32px rgba(0,0,0,.4);
+ --uses:#d08770; --usedby:#a3be8c;
+}
+*{box-sizing:border-box}
+[hidden]{display:none!important}
+html,body{margin:0;height:100%}
+body{background:var(--bg);color:var(--ink);
+ font:14px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
+ -webkit-font-smoothing:antialiased;display:flex;flex-direction:column;height:100vh;overflow:hidden}
+.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
+header{display:flex;align-items:center;gap:16px;padding:12px 20px;border-bottom:1px solid var(--line);
+ background:var(--panel);flex-wrap:wrap}
+header h1{font-size:15px;font-weight:650;margin:0;letter-spacing:-.01em;white-space:nowrap}
+header h1 .dim{color:var(--ink-soft);font-weight:400}
+.stats{color:var(--ink-soft);font-size:12.5px;display:flex;gap:14px;flex-wrap:wrap}
+.stats b{color:var(--ink);font-weight:600}
+.grow{flex:1}
+.search{position:relative}
+.search input{width:230px;padding:7px 11px 7px 30px;border:1px solid var(--line-strong);border-radius:8px;
+ background:var(--panel-2);color:var(--ink);font-size:13px;outline:none}
+.search input:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
+.search svg{position:absolute;left:9px;top:8px;width:15px;height:15px;color:var(--ink-soft)}
+.ghost{border:1px solid var(--line-strong);background:var(--panel-2);color:var(--ink-soft);
+ border-radius:8px;padding:6px 11px;font-size:12.5px;cursor:pointer}
+.ghost:hover{color:var(--ink);border-color:var(--accent)}
+.ghost:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
+.seg{display:inline-flex;border:1px solid var(--line-strong);border-radius:8px;overflow:hidden;background:var(--panel-2)}
+.seg button{border:none;background:transparent;color:var(--ink-soft);font:inherit;font-size:12.5px;
+ padding:6px 12px;cursor:pointer}
+.seg button+button{border-left:1px solid var(--line)}
+.seg button:hover{color:var(--ink)}
+.seg button.on{background:var(--accent-soft);color:var(--accent);font-weight:600}
+.seg button:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
+.themepick:focus-within{color:var(--ink);border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
+.themepick{display:inline-flex;align-items:center;gap:6px;padding:0 9px}
+.themepick .ticon{color:var(--ink-soft);flex-shrink:0}
+.themepick:hover .ticon,.themepick:hover .tchev{color:var(--ink)}
+.themepick select{border:none;background:transparent;color:inherit;font:inherit;font-size:12.5px;
+ padding:6px 0;cursor:pointer;-webkit-appearance:none;appearance:none;outline:none}
+.themepick .tchev{color:var(--ink-soft);font-size:10px;pointer-events:none}
+.legend{display:flex;gap:6px;flex-wrap:wrap;padding:10px 20px;border-bottom:1px solid var(--line);
+ background:var(--panel-2);align-items:center}
+.legend .lbl{color:var(--ink-soft);font-size:11.5px;text-transform:uppercase;letter-spacing:.04em;margin-right:2px}
+.tchip{display:inline-flex;align-items:center;gap:6px;padding:3px 9px;border-radius:20px;font-size:12px;
+ border:1px solid var(--line-strong);background:var(--panel);cursor:pointer;user-select:none;color:var(--ink)}
+.tchip .dot{width:9px;height:9px;border-radius:50%}
+.tchip.off{opacity:.4}
+.tchip .ct{color:var(--ink-soft);font-size:11px}
+main{flex:1;display:flex;min-height:0}
+.tree{flex:1;overflow:auto;padding:10px 8px 40px;min-width:0;overflow-anchor:none}
+.detail{width:380px;flex-shrink:0;border-left:1px solid var(--line);background:var(--panel);
+ overflow:auto;padding:0}
+.row{display:flex;align-items:center;gap:7px;padding:3px 6px;border-radius:7px;cursor:pointer;
+ white-space:nowrap;position:relative}
+.row:hover{background:var(--panel-2)}
+.row.sel{background:var(--accent-soft)}
+.row.dim{opacity:.32}
+.caret{width:14px;height:14px;flex-shrink:0;display:inline-flex;align-items:center;justify-content:center;
+ color:var(--ink-soft);transition:transform .12s;font-size:10px}
+.caret.none{visibility:hidden}
+.row.open>.caret{transform:rotate(90deg)}
+.dot{width:9px;height:9px;border-radius:50%;flex-shrink:0}
+.dot.group{background:transparent;border:1.5px solid var(--group)}
+.name{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px}
+.name.group{color:var(--group)}
+.name.nsmoved{text-decoration:underline dotted var(--group);text-underline-offset:3px;text-decoration-thickness:1px}
+.badge{font-size:9px;font-weight:700;padding:1px 4px;border-radius:4px;letter-spacing:.03em}
+.badge.ent{background:var(--accent-soft);color:var(--accent);opacity:.85}
+.badge.debt{background:transparent;border:1px solid var(--uses);color:var(--uses);padding:0 4px}
+.badge.bypass{background:transparent;border:1px dashed var(--group);color:var(--group);padding:0 4px}
+.submini{font-size:10px;color:var(--group);margin-left:5px}
+.row.flat{padding-left:8px}
+.ghost.on{color:var(--accent);border-color:var(--accent);background:var(--accent-soft)}
+.mini{font-size:10.5px;color:var(--ink-soft);margin-left:4px;opacity:.55;font-variant-numeric:tabular-nums}
+.row:hover .mini,.row.sel .mini{opacity:1}
+.cnt-in{color:var(--usedby);font-weight:600}
+.cnt-out{color:var(--uses);font-weight:600}
+/* hotspots and graph toolbars */
+.viewbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:4px 8px 10px;padding:9px 14px;
+ border:1px solid var(--line);border-radius:10px;background:var(--panel)}
+.viewbar b{font-size:12.5px;font-weight:650}
+.viewbar .desc{color:var(--ink-soft);font-size:12px;flex:1;min-width:260px}
+.viewbar .desc code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px;color:var(--uses)}
+.viewbar .swatch{display:inline-block;width:8px;height:8px;border-radius:2px;vertical-align:baseline;margin:0 3px 0 1px}
+.viewbar select,.viewbar input{border:1px solid var(--line-strong);background:var(--panel-2);color:var(--ink);
+ border-radius:7px;padding:4px 7px;font:inherit;font-size:12px;outline:none}
+.viewbar select{cursor:pointer}
+.rank{width:26px;text-align:right;color:var(--group);font-size:10.5px;flex-shrink:0;font-variant-numeric:tabular-nums}
+.hname{display:inline-flex;align-items:center;gap:7px;width:300px;flex-shrink:0;overflow:hidden}
+.hname .name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.hname .badge{flex-shrink:0}
+.track{flex:1;max-width:360px;height:7px;border-radius:4px;background:var(--chip);overflow:hidden;display:flex}
+.track .in{background:var(--usedby)}
+.track .out{background:var(--uses)}
+.hcounts{margin-left:12px;font-size:11px;color:var(--ink-soft);font-variant-numeric:tabular-nums;flex-shrink:0}
+.dep-mark{display:inline-block;width:7px;height:7px;border-radius:50%;flex-shrink:0;margin-left:3px;vertical-align:middle}
+.dep-mark.uses{background:var(--uses)}
+.dep-mark.usedby{background:var(--usedby)}
+.kids{margin-left:15px;border-left:1px solid var(--line);padding-left:2px}
+.kids.hidden{display:none}
+/* graph view */
+.graph{flex:1;display:flex;flex-direction:column;min-width:0;padding-top:6px}
+.graph .viewbar{margin-bottom:0}
+#cy{flex:1;min-height:0}
+.graph .note{color:var(--ink-soft);font-size:12px;padding:40px;text-align:center}
+.fchip{display:inline-flex;align-items:center;gap:4px;padding:2px 4px 2px 8px;border-radius:20px;font-size:11.5px;
+ background:var(--accent-soft);color:var(--accent);border:1px solid var(--accent)}
+.fchip button{border:none;background:transparent;color:inherit;cursor:pointer;padding:0 3px;font-size:13px;line-height:1}
+.ctxmenu{position:fixed;z-index:10;background:var(--panel);border:1px solid var(--line-strong);border-radius:8px;
+ box-shadow:var(--shadow);padding:4px 0;font-size:12.5px;min-width:190px}
+.ctxmenu div{padding:6px 12px;cursor:pointer}
+.ctxmenu div:hover{background:var(--accent-soft)}
+/* detail panel */
+.d-empty{padding:60px 26px;color:var(--ink-soft);text-align:center;font-size:13px;line-height:1.7}
+.d-empty .keys{margin-top:24px;font-size:11.5px;color:var(--group);line-height:2.2}
+kbd{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:10.5px;color:var(--ink-soft);
+ background:var(--chip);border:1px solid var(--line-strong);border-bottom-width:2px;border-radius:5px;
+ padding:1px 5px;margin:0 3px}
+.d-head{padding:18px 20px 14px;border-bottom:1px solid var(--line);position:sticky;top:0;background:var(--panel);z-index:2}
+.d-title{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:16px;font-weight:600;
+ word-break:break-all;display:flex;align-items:center;gap:8px}
+.d-title .dot{width:11px;height:11px}
+.d-sub{margin-top:8px;display:flex;gap:6px;flex-wrap:wrap;align-items:center}
+.d-sub a{color:var(--accent);font-size:12px;text-decoration:none}
+.d-sub a:hover{text-decoration:underline}
+.d-body{padding:6px 20px 40px}
+.d-stats{display:grid;grid-template-columns:repeat(4,1fr);gap:7px;margin-top:16px}
+.stat{background:var(--panel-2);border:1px solid var(--line);border-radius:8px;padding:9px 5px;text-align:center}
+.stat b{display:block;font-size:16px;font-weight:650;font-variant-numeric:tabular-nums;line-height:1.2}
+.stat span{font-size:9px;color:var(--ink-soft);text-transform:uppercase;letter-spacing:.03em}
+.sec{margin-top:18px}
+.sec h3{font-size:11px;text-transform:uppercase;letter-spacing:.05em;color:var(--ink-soft);margin:0 0 8px;
+ display:flex;align-items:center;gap:7px}
+.sec h3 .n{background:var(--chip);color:var(--chip-ink);border-radius:20px;padding:0 7px;font-size:10.5px;
+ letter-spacing:0;font-weight:600}
+.sec h3 .swatch{width:8px;height:8px;border-radius:50%}
+.chips{display:flex;flex-wrap:wrap;gap:5px}
+.chip{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11.5px;padding:3px 8px;
+ border-radius:6px;background:var(--chip);color:var(--chip-ink);border:1px solid transparent}
+.chip.link{cursor:pointer}
+.chip.link:hover{border-color:var(--accent);color:var(--accent)}
+.nsuse{margin-bottom:9px}
+.nsuse .nsname{font-size:11.5px;color:var(--ink-soft);margin-bottom:4px;word-break:break-all}
+.empty-note{color:var(--ink-soft);font-size:12px;font-style:italic}
+.d-team{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;color:var(--ink)}
+.nsnote{margin-top:10px;font-size:12px;color:var(--ink-soft);background:var(--panel-2);
+ border:1px solid var(--line);border-radius:8px;padding:8px 10px;line-height:1.45}
+.nsnote code{color:var(--uses)}
+@media (max-width:820px){.detail{position:fixed;right:0;top:0;bottom:0;box-shadow:var(--shadow);width:min(380px,90vw);
+ transform:translateX(100%);transition:transform .2s}.detail.show{transform:none}}
+</style></head><body>
+<header>
+ <h1>Metabase <span class=dim>modules</span></h1>
+ <div class=stats id=stats></div>
+ <div class=grow></div>
+ <div class=search>
+ <svg viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>
+ <input id=q type=search list=modlist placeholder='Filter modules…' autocomplete=off spellcheck=false title='Enter selects the first match'>
+ <datalist id=modlist></datalist>
+ </div>
+ <div class=seg role=group aria-label='View'>
+ <button id=view-tree class=on>Tree</button>
+ <button id=view-hotspots title='Rank modules by coupling'>Hotspots</button>
+ <button id=view-graph title='Dependency graph around the focused modules'>Graph</button>
+ </div>
+ <button class=ghost id=debt title='Show only modules with an unfilled boundary (:api :any, :uses :any, or :model-imports :bypass)'>Unfilled only</button>
+ <div class=seg id=foldctl role=group aria-label='Folding'>
+ <button id=expand title='Expand all groups'>Expand</button>
+ <button id=collapse title='Collapse all groups'>Collapse</button>
+ </div>
+ <label class='themepick ghost' title='Theme'>
+ <svg class=ticon viewBox='0 0 24 24' width='15' height='15' fill='none' stroke='currentColor' stroke-width='2'><circle cx='12' cy='12' r='9'/><path d='M12 3a9 9 0 0 0 0 18' fill='currentColor' stroke='none'/></svg>
+ <select id=theme>
+ <option value=''>System</option>
+ <option value='light'>Light</option>
+ <option value='dark'>Dark</option>
+ <option value='solarized-light'>Solarized Light</option>
+ <option value='solarized-dark'>Solarized Dark</option>
+ <option value='gruvbox'>Gruvbox</option>
+ <option value='nord'>Nord</option>
+ </select>
+ <span class=tchev>▾</span>
+ </label>
+</header>
+<div class=legend id=legend></div>
+<main>
+ <div class=tree id=tree></div>
+ <div class=graph id=graph hidden>
+ <div class=viewbar id=graphbar></div>
+ <div id=cy></div>
+ </div>
+ <aside class=detail id=detail></aside>
+</main>
+<script>const DATA = /*DATA*/null;</script>
+<script>
+'use strict';
+/*STATE-CODEC*/
+const MODULES = DATA.modules;
+const byId = Object.fromEntries(MODULES.map(m => [m.id, m]));
+const GITHUB = 'https://github.com/metabase/metabase/';
+// team -> color (stable palette, assigned in first-seen order over sorted teams)
+const TEAMS = [...new Set(MODULES.map(m => m.team).filter(Boolean))].sort();
+const VALID_IDS = new Set(MODULES.map(m => m.id));
+const VALID_TEAMS = new Set(TEAMS);
+const PALETTE = ['#4a6fe8','#e8892b','#2fa36b','#c0468a','#7d5fe0','#2fa8c0','#d0443b','#b0952f','#5a7a3a','#8a5a3a','#607080'];
+const teamColor = {}; TEAMS.forEach((t,i)=>teamColor[t]=PALETTE[i%PALETTE.length]);
+const teamCount = {}; MODULES.forEach(m=>{ if(m.team) teamCount[m.team]=(teamCount[m.team]||0)+1; });
+const NS_EDGES = DATA['ns-edges'];
+const NS_FILES = DATA['ns-files'] || {};
+const HAS_ACTUAL_EDGES = Array.isArray(NS_EDGES);
+
+// ---- build the display tree from each module's `path` --------------------
+function makeNode(seg){ return {seg, children:new Map(), module:null}; }
+const root = makeNode('');
+for(const m of MODULES){
+ let cur = root;
+ m.path.forEach((seg,i)=>{
+ if(!cur.children.has(seg)) cur.children.set(seg, makeNode(seg));
+ cur = cur.children.get(seg);
+ if(i===m.path.length-1) cur.module = m;
+ });
+}
+// number of modules under each node (shown as a count on group/parent rows)
+(function countSub(node){ let n=0; for(const k of node.children.values()){ n += (k.module?1:0)+countSub(k); } node.sub=n; return n; })(root);
+function sortedKids(node){
+ return [...node.children.values()].sort((a,b)=>{
+ const ax=a.seg==='enterprise'?1:0, bx=b.seg==='enterprise'?1:0; // enterprise sorts last
+ return ax-bx || a.seg.localeCompare(b.seg);
+ });
+}
+
+// ---- state ---------------------------------------------------------------
+const open = new Set(); // node dom-path keys currently expanded
+// team focus: empty = passive (every team shown); non-empty = show only these.
+// toggling a team in/out; emptying the set returns to passive.
+const focusTeams = new Set();
+function teamActive(t){ return focusTeams.size===0 || focusTeams.has(t); }
+function refreshTeamChips(){
+ for(const el of legend.querySelectorAll('.tchip'))
+ el.classList.toggle('off', focusTeams.size>0 && !focusTeams.has(el.dataset.team));
+}
+let selected = null; // module id
+let query = '';
+let debtOnly = false, view = 'tree', sortBy = 'used-by';
+// graph view: modules whose neighbourhood is drawn, how far out, which show their API namespaces, and what to leave out
+let focus = new Set(), degree = 1, expanded = new Set(), hidden = new Set(), hideRe = '';
+function isDebt(m){ return !!(m && (m['uses-any'] || m['api-any'] || m['model-imports-bypass'])); }
+function teamOk(m){ return !m || !m.team || teamActive(m.team); }
+
+// ---- header stats + legend ----------------------------------------------
+const ent = MODULES.filter(m=>m.enterprise).length;
+const starred = MODULES.filter(m=>m['ns-prefix']).length;
+const debtN = MODULES.filter(isDebt).length;
+document.getElementById('stats').innerHTML =
+ `<span><b>${MODULES.length}</b> modules</span><span><b>${ent}</b> enterprise</span>`+
+ `<span title='namespaces not yet moved to match the module name'><b>${starred}</b> ns-prefixed</span>`+
+ `<span title='modules with an unfilled boundary (:api :any, :uses :any, or :model-imports :bypass)'><b>${debtN}</b> unfilled</span>`+
+ `<span><b>${TEAMS.length}</b> teams</span>`;
+document.getElementById('modlist').append(...MODULES.map(m=>{ const o=document.createElement('option'); o.value=m.id; return o; }));
+
+const legend = document.getElementById('legend');
+legend.innerHTML = '<span class=lbl>Teams</span>';
+for(const t of TEAMS){
+ const el = document.createElement('span');
+ el.className='tchip'; el.dataset.team=t; el.title='Show only this team';
+ el.innerHTML=`<span class=dot style='background:${teamColor[t]}'></span>${t}<span class=ct>${teamCount[t]}</span>`;
+ el.onclick=()=>{ focusTeams.has(t)?focusTeams.delete(t):focusTeams.add(t); refreshTeamChips(); render(); syncHash(true); };
+ legend.appendChild(el);
+}
+
+// ---- tree rendering ------------------------------------------------------
+const treeEl = document.getElementById('tree');
+const graphEl = document.getElementById('graph');
+
+// which module ids match the current query (module + its ancestors stay visible)
+function matches(m){
+ if(debtOnly && !isDebt(m)) return false;
+ if(!query) return true;
+ return m.id.toLowerCase().includes(query) || (m.team||'').toLowerCase().includes(query);
+}
+function outCount(m){ return m['uses-any'] && !HAS_ACTUAL_EDGES ? null : m.uses.length; }
+function totalCount(m){ const out=outCount(m); return out===null ? null : m['used-by'].length+out; }
+// precompute, for an active filter, the set of node-keys that must remain visible
+function visibleKeys(){
+ if(!query && !debtOnly) return null;
+ const keep = new Set();
+ (function walk(node, path){
+ let any=false;
+ for(const kid of sortedKids(node)){
+ const kpath = path.concat(kid.seg);
+ const key = kpath.join('/');
+ const self = kid.module && matches(kid.module);
+ const below = walk(kid, kpath);
+ if(self||below){ keep.add(key); any=true; }
+ }
+ return any;
+ })(root, []);
+ return keep;
+}
+
+// Append dependency dots directly to the row as flex children (7px each). Wrapping them in a span
+// would make that span a flex item whose line box inherits line-height:1.5 (~21px), taller than the
+// row text — so related rows would grow/shrink by ~1px as selection moves. Direct children don't.
+function appendDepMarks(row, m){
+ if(!selected || !m) return;
+ const s = byId[selected];
+ const mark=(cls,title)=>{ const d=document.createElement('span'); d.className='dep-mark '+cls; d.title=title; row.appendChild(d); };
+ if(s.uses.includes(m.id)) mark('uses', 'used by '+selected);
+ if(s['used-by'].includes(m.id)) mark('usedby', 'uses '+selected);
+}
+
+let visibleIds = []; // module ids currently rendered, in visual order (for keyboard nav)
+
+function appendBadges(row, m){
+ if(m.enterprise){ const b=document.createElement('span'); b.className='badge ent'; b.textContent='EE'; row.appendChild(b); }
+ if(m['api-any']||m['uses-any']){ const b=document.createElement('span'); b.className='badge debt'; b.textContent='any';
+ b.title=[m['api-any']?'no API namespace (:api :any)':'', m['uses-any']?'unrestricted deps (:uses :any)':''].filter(Boolean).join(' · '); row.appendChild(b); }
+ if(m['model-imports-bypass']){ const b=document.createElement('span'); b.className='badge bypass'; b.textContent='bypass'; b.title='imports any model (:model-imports :bypass)'; row.appendChild(b); }
+}
+// ns-prefixed modules get a dotted underline instead of a badge — quieter at 70+ occurrences
+function makeName(m, label, extraClass){
+ const name=document.createElement('span'); name.className='name'+(extraClass||''); name.textContent=label;
+ if(m&&m['ns-prefix']){ name.classList.add('nsmoved'); name.title='namespaces still at '+m['ns-prefix']+' — not yet moved to match the module name'; }
+ return name;
+}
+function appendCounts(row, m){
+ const c=document.createElement('span'); c.className='mini';
+ const inN=document.createElement('span'); inN.className='cnt-in'; inN.textContent=m['used-by'].length;
+ const out=outCount(m);
+ const outN=document.createElement('span'); outN.className='cnt-out'; outN.textContent=out===null?'any':out;
+ c.append(inN, ' used by · ', outN, ' uses');
+ c.title=`${m['used-by'].length} known modules depend on it · `+
+ (out===null?'its unrestricted dependencies are unknown':`it depends on ${out}`);
+ row.appendChild(c);
+}
+// Build a row's shared content (caret slot, team dot, name, badges, counts, dep-marks).
+function buildRow(m, label, hasKids){
+ const row=document.createElement('div');
+ row.className='row'+(m&&m.id===selected?' sel':'')+((m&&!teamOk(m))?' dim':'');
+ if(m) row.dataset.id=m.id;
+ const caret=document.createElement('span'); caret.className='caret'+(hasKids?'':' none'); caret.textContent='▶'; row.appendChild(caret);
+ const dot=document.createElement('span'); dot.className='dot'+(m?'':' group');
+ if(m&&m.team) dot.style.background=teamColor[m.team]; else if(m) dot.style.background='var(--group)';
+ row.appendChild(dot);
+ row.appendChild(makeName(m, label, m?'':' group'));
+ if(m){ appendBadges(row,m); appendCounts(row,m); }
+ appendDepMarks(row,m);
+ return {row, caret};
+}
+
+// Shown while the unfilled-boundaries filter is active, so the lens explains itself.
+function debtNotice(){
+ const d=document.createElement('div'); d.className='viewbar';
+ d.innerHTML=`<b>Unfilled boundaries</b><span class=desc>the ${debtN} modules whose config still has an `+
+ `escape hatch instead of a real boundary: <code>:api :any</code> (no API namespace — every namespace is `+
+ `public), <code>:uses :any</code> (may depend on any module), or <code>:model-imports :bypass</code> `+
+ `(may use any module&#39;s models). The badge on each row says which.</span>`;
+ return d;
+}
+
+function render(){
+ visibleIds=[];
+ treeEl.hidden = view==='graph';
+ graphEl.hidden = view!=='graph';
+ if(view==='graph') return renderGraph();
+ if(view==='hotspots') return renderHotspots();
+ const scroll = treeEl.scrollTop; // full rebuild resets scroll; restore it so selecting a node doesn't jump
+ const keep = visibleKeys();
+ treeEl.innerHTML='';
+ if(debtOnly) treeEl.appendChild(debtNotice());
+ const frag = document.createDocumentFragment();
+ (function walk(node, path, container, visible){
+ for(const kid of sortedKids(node)){
+ const kpath = path.concat(kid.seg);
+ const key = kpath.join('/');
+ if(keep && !keep.has(key)) continue;
+ const m = kid.module;
+ const hasKids = kid.children.size>0;
+ const {row, caret} = buildRow(m, kid.seg, hasKids);
+ const isOpen = open.has(key) || (keep && keep.has(key));
+ if(hasKids && isOpen) row.classList.add('open');
+ if(hasKids){ const sc=document.createElement('span'); sc.className='submini'; sc.textContent=kid.sub; sc.title=kid.sub+' modules below'; row.appendChild(sc); }
+ if(m && visible) visibleIds.push(m.id); // only rows whose ancestors are all open are keyboard-reachable
+ const kidsBox=document.createElement('div');
+ kidsBox.className='kids'+(hasKids&&isOpen?'':' hidden');
+ const toggle=()=>{ if(open.has(key)) open.delete(key); else open.add(key); render(); };
+ if(hasKids) caret.onclick=(e)=>{ e.stopPropagation(); toggle(); };
+ row.onclick=(e)=>{ e.stopPropagation(); if(m) select(m.id); else if(hasKids) toggle(); };
+ container.appendChild(row);
+ container.appendChild(kidsBox);
+ if(hasKids) walk(kid, kpath, kidsBox, visible && isOpen);
+ }
+ })(root, [], frag, true);
+ treeEl.appendChild(frag);
+ treeEl.scrollTop = scroll;
+}
+
+// Flat coupling view: rank modules by known dependency counts. A hotspot is a graph-coupling fact,
+// not a code-quality judgement. Config-only data cannot resolve the dependencies behind `:uses :any`.
+const SORTS = {
+ 'used-by': {label:'dependents (fan-in)',
+ metric:m=>m['used-by'].length,
+ desc:HAS_ACTUAL_EDGES
+ ? 'how many modules depend on it in the source scan — a change here has the widest blast radius'
+ : 'how many modules declare it directly — unrestricted consumers are not inferred'},
+ 'uses': {label:'dependencies (fan-out)',
+ metric:outCount,
+ desc:HAS_ACTUAL_EDGES
+ ? 'how many modules it depends on in the source scan — the most entangled consumers in the graph'
+ : 'how many modules it declares directly — unrestricted modules sort after known counts'},
+ 'coupling':{label:'total coupling (in + out)',
+ metric:totalCount,
+ desc:'known dependents plus dependencies — modules that are both load-bearing and entangled'},
+};
+function renderHotspots(){
+ const scroll = treeEl.scrollTop;
+ treeEl.innerHTML='';
+ const s = SORTS[sortBy];
+ const list = MODULES.filter(m => matches(m) && teamOk(m))
+ .sort((a,b) => (s.metric(b)??-1)-(s.metric(a)??-1) || a.id.localeCompare(b.id));
+
+ const bar=document.createElement('div'); bar.className='viewbar';
+ const ttl=document.createElement('b'); ttl.textContent='Ranked by'; bar.appendChild(ttl);
+ const sel=document.createElement('select');
+ for(const [k,v] of Object.entries(SORTS)){
+ const o=document.createElement('option'); o.value=k; o.textContent=v.label; sel.appendChild(o);
+ }
+ sel.value=sortBy; sel.onchange=()=>{ sortBy=sel.value; render(); };
+ bar.appendChild(sel);
+ const d=document.createElement('span'); d.className='desc';
+ d.innerHTML=`${s.desc}. Bars share one scale: <span class=swatch style='background:var(--usedby)'></span>dependents + <span class=swatch style='background:var(--uses)'></span>dependencies.`;
+ bar.appendChild(d);
+ treeEl.appendChild(bar);
+ if(debtOnly) treeEl.appendChild(debtNotice());
+
+ const maxTotal = Math.max(1, ...list.map(m=>m['used-by'].length+(outCount(m)??0)));
+ const frag = document.createDocumentFragment();
+ list.forEach((m,i)=>{
+ const row=document.createElement('div');
+ row.className='row flat'+(m.id===selected?' sel':'');
+ row.dataset.id=m.id;
+ const rank=document.createElement('span'); rank.className='rank'; rank.textContent=i+1; row.appendChild(rank);
+ const nm=document.createElement('span'); nm.className='hname';
+ const dot=document.createElement('span'); dot.className='dot';
+ dot.style.background=m.team?teamColor[m.team]:'var(--group)'; nm.appendChild(dot);
+ const name=makeName(m, m.id, '');
+ name.title=m.id+(m['ns-prefix']?' · namespaces still at '+m['ns-prefix']: '');
+ nm.appendChild(name);
+ appendBadges(nm,m); row.appendChild(nm);
+ const track=document.createElement('span'); track.className='track';
+ const inSeg=document.createElement('span'); inSeg.className='in';
+ inSeg.style.width=(m['used-by'].length/maxTotal*100)+'%'; track.appendChild(inSeg);
+ const out=outCount(m);
+ const outSeg=document.createElement('span'); outSeg.className='out';
+ outSeg.style.width=((out??0)/maxTotal*100)+'%'; track.appendChild(outSeg);
+ track.title=`${m['used-by'].length} known dependents · ${out===null?'unrestricted dependencies':out+' dependencies'}`;
+ row.appendChild(track);
+ const c=document.createElement('span'); c.className='hcounts';
+ const inN=document.createElement('span'); inN.className='cnt-in'; inN.textContent=m['used-by'].length;
+ const outN=document.createElement('span'); outN.className='cnt-out'; outN.textContent=out===null?'any':out;
+ c.append(inN, ' used by · ', outN, ' uses'); row.appendChild(c);
+ appendDepMarks(row,m);
+ row.onclick=(e)=>{ e.stopPropagation(); select(m.id); };
+ visibleIds.push(m.id);
+ frag.appendChild(row);
+ });
+ treeEl.appendChild(frag);
+ treeEl.scrollTop = scroll;
+}
+
+// ---- graph view ------------------------------------------------------------
+// Edges are [consumer, producer, namespace]. With namespace data (dev.module-explorer/open!) they come from the
+// source scan; otherwise from each module's :uses, and a `:uses :any` module draws none rather than one to everything.
+const EDGES = HAS_ACTUAL_EDGES ? NS_EDGES : MODULES.flatMap(m => m.uses.map(u => [m.id, u, null]));
+const edgesByMod = {};
+for(const e of EDGES){ (edgesByMod[e[0]] ||= []).push(e); if(e[1]!==e[0]) (edgesByMod[e[1]] ||= []).push(e); }
+const GRAPH_LIBS = ['https://unpkg.com/[email protected]/dist/cytoscape.min.js',
+ 'https://unpkg.com/[email protected]/WebCola/cola.min.js',
+ 'https://unpkg.com/[email protected]/cytoscape-cola.js'];
+let graphLibs = null, cy = null, layout = null, locked = [];
+function loadGraphLibs(){
+ const load = src => new Promise((ok, fail) => {
+ const s=document.createElement('script'); s.src=src; s.onload=ok; s.onerror=()=>fail(new Error('could not load '+src));
+ document.head.appendChild(s);
+ });
+ graphLibs ||= GRAPH_LIBS.reduce((p, src) => p.then(() => load(src)), Promise.resolve())
+ .then(() => cytoscape.use(cytoscapeCola))
+ .catch(e => { graphLibs = null; throw e; });
+ return graphLibs;
+}
+function hiddenFromGraph(id){
+ if(focus.has(id)) return false; // a focused module stays even when a hide rule matches it
+ let re=null; try{ re = hideRe && new RegExp(hideRe); }catch(e){}
+ return hidden.has(id) || !!(re && re.test(id)) || !teamOk(byId[id]);
+}
+// union of each focused module's `degree`-hop neighbourhood, ignoring edge direction
+function neighbourhood(){
+ const visible = new Set();
+ for(const start of focus){
+ const seen = new Set([start]);
+ let frontier = [start];
+ for(let hop=0; hop<degree && frontier.length; hop++){
+ const next = [];
+ for(const m of frontier) for(const [c,p] of edgesByMod[m]||[])
+ for(const n of [c,p]) if(!seen.has(n) && byId[n] && !hiddenFromGraph(n)){ seen.add(n); next.push(n); }
+ frontier = next;
+ }
+ seen.forEach(n => visible.add(n));
+ }
+ return visible;
+}
+const nsNodeId = (m, ns) => 'ns:'+m+'/'+ns;
+// Edges into an expanded module point at the API namespace they use; all others collapse to one weighted
+// edge per module pair.
+function graphElements(visible){
+ const nodes = [], edges = [], pairs = new Map();
+ for(const id of visible){
+ const m = byId[id];
+ nodes.push({data:{id:'mod:'+id, label:id, type:'module', module:id, team:m.team||'', loc:m.stats?m.stats.loc:0}});
+ if(expanded.has(id) && !m['api-any'])
+ for(const ns of m.api) nodes.push({data:{id:nsNodeId(id,ns), label:ns, type:'ns', parent:'mod:'+id, module:id}});
+ }
+ for(const [c,p,ns] of EDGES){
+ if(c===p || !visible.has(c) || !visible.has(p)) continue;
+ if(ns && expanded.has(p) && byId[p].api.includes(ns)){
+ edges.push({data:{id:'e:'+c+'->'+ns, source:'mod:'+c, target:nsNodeId(p,ns), sourceModule:c, targetModule:p}});
+ } else {
+ const k = c+'->'+p;
+ if(!pairs.has(k)) pairs.set(k, {c, p, n:0});
+ pairs.get(k).n++;
+ }
+ }
+ for(const {c,p,n} of pairs.values())
+ edges.push({data:{id:'agg:'+c+'->'+p, source:'mod:'+c, target:'mod:'+p, sourceModule:c, targetModule:p,
+ aggregate:true, weight:NS_EDGES?n:1}});
+ return {nodes, edges};
+}
+function graphStyle(){
+ const v = n => getComputedStyle(document.documentElement).getPropertyValue(n).trim();
+ const ink=v('--ink'), soft=v('--ink-soft'), panel=v('--panel'), accent=v('--accent'), line=v('--line-strong'), group=v('--group');
+ const color = n => teamColor[n.data('team')] || group;
+ const size = n => Math.max(36, Math.min(180, Math.sqrt(n.data('loc')||0)*1.4));
+ return [
+ {selector:'node[type="module"]', style:{'background-color':color, 'background-opacity':.22, 'border-width':1, 'border-color':color,
+ label:'data(label)', 'font-size':16, 'font-weight':600, color:ink, 'text-outline-width':3, 'text-outline-color':panel,
+ 'text-valign':'top', 'text-halign':'center', 'text-margin-y':-6, padding:'12px', shape:'round-rectangle'}},
+ {selector:'node[type="module"]:childless', style:{'background-opacity':.85, width:size, height:size}},
+ {selector:'node[type="ns"]', style:{'background-color':panel, 'border-width':1, 'border-color':soft, label:'data(label)',
+ 'font-size':9, color:ink, 'text-valign':'center', 'text-halign':'center', shape:'round-rectangle', width:160, height:18}},
+ {selector:'edge', style:{'curve-style':'bezier', width:1, 'line-color':line, 'target-arrow-color':line,
+ 'target-arrow-shape':'triangle', 'arrow-scale':1.4, opacity:.8}},
+ {selector:'edge[?aggregate]', style:{width:e=>Math.min(10, 1+Math.log2(e.data('weight')+1)*1.6),
+ label:e=>e.data('weight')>1?String(e.data('weight')):'', 'font-size':9, color:soft,
+ 'text-background-color':panel, 'text-background-opacity':.85, 'text-background-padding':2}},
+ {selector:'.focused', style:{'border-color':accent, 'border-width':3}},
+ {selector:'edge.focused', style:{'line-color':accent, 'target-arrow-color':accent, width:2, opacity:1}},
+ {selector:'.sel', style:{'overlay-color':accent, 'overlay-opacity':.15, 'overlay-padding':6}},
+ ];
+}
+function initCy(){
+ cy = cytoscape({container:document.getElementById('cy'), style:graphStyle(), wheelSensitivity:.2});
+ cy.on('tap', 'node', e => {
+ const id = e.target.data('module'), ev = e.originalEvent;
+ if(ev && ev.shiftKey) return setFocus(id, focus.has(id) ? 'remove' : 'add');
+ if(selected!==id) select(id);
+ });
+ cy.on('dbltap', 'node[type="module"]', e => setFocus(e.target.data('module'), 'replace'));
+ // The native event, because cytoscape's cxttap can stop firing after a drag.
+ document.getElementById('cy').addEventListener('contextmenu', ev => {
+ ev.preventDefault();
+ const box = ev.currentTarget.getBoundingClientRect(), pan = cy.pan(), zoom = cy.zoom();
+ const x = (ev.clientX-box.left-pan.x)/zoom, y = (ev.clientY-box.top-pan.y)/zoom;
+ const hit = cy.nodes().filter(n => { const b=n.boundingBox(); return x>=b.x1 && x<=b.x2 && y>=b.y1 && y<=b.y2; }).last();
+ if(hit.nonempty()) showNodeMenu(hit, ev.clientX, ev.clientY);
+ });
+}
+const menuEl = document.createElement('div'); menuEl.className='ctxmenu'; menuEl.hidden=true; document.body.appendChild(menuEl);
+document.addEventListener('click', () => { menuEl.hidden = true; });
+function showNodeMenu(node, x, y){
+ const id = node.data('module'), m = byId[id];
+ const items = [];
+ if(node.data('type')==='ns'){
+ const file = NS_FILES[node.data('label')];
+ items.push(['Select '+id, () => select(id)]);
+ if(file) items.push(['Open source ↗', () => window.open(GITHUB+'blob/master/'+file, '_blank', 'noopener')]);
+ } else {
+ items.push(['Focus only this', () => setFocus(id, 'replace')],
+ focus.has(id) ? ['Remove from focus', () => setFocus(id, 'remove')] : ['Add to focus', () => setFocus(id, 'add')]);
+ if(NS_EDGES && !m['api-any'])
+ items.push([expanded.has(id) ? 'Collapse API namespaces' : 'Expand API namespaces', () => {
+ expanded.has(id) ? expanded.delete(id) : expanded.add(id); syncHash(true); renderGraph(); }]);
+ if(!focus.has(id)) items.push(['Hide', () => { hidden.add(id); syncHash(true); renderGraph(); }]);
+ if(m.source) items.push(['Open source ↗', () => window.open(GITHUB+'tree/master/'+m.source, '_blank', 'noopener')]);
+ }
+ menuEl.innerHTML = '';
+ for(const [label, fn] of items){ const d=document.createElement('div'); d.textContent=label; d.onclick=fn; menuEl.appendChild(d); }
+ menuEl.style.left = x+'px'; menuEl.style.top = y+'px'; menuEl.hidden = false;
+}
+function setFocus(id, mode){
+ if(mode==='replace') focus = new Set([id]);
+ else if(mode==='add') focus.add(id);
+ else focus.delete(id);
+ syncHash(true);
+ renderGraph();
+}
+function renderGraphBar(visible){
+ const bar = document.getElementById('graphbar');
+ bar.innerHTML = '';
+ const btn = (label, title, fn) => { const x=document.createElement('button'); x.className='ghost'; x.textContent=label; x.title=title; x.onclick=fn; bar.appendChild(x); };
+ const b = document.createElement('b'); b.textContent = 'Focus'; bar.appendChild(b);
+ for(const id of [...focus].sort()){
+ const c=document.createElement('span'); c.className='fchip mono'; c.textContent=id;
+ const x=document.createElement('button'); x.textContent='×'; x.title='Remove from focus'; x.onclick=()=>setFocus(id,'remove');
+ c.appendChild(x); bar.appendChild(c);
+ }
+ const pick = document.createElement('input'); pick.className = 'mono'; pick.setAttribute('list', 'modlist');
+ pick.placeholder = focus.size ? 'add a module…' : 'pick a module…';
+ pick.title = 'Type a module name, or pick one from the list';
+ const commit = () => {
+ const id = pick.value.trim();
+ if(!byId[id]) return;
+ pick.value = '';
+ focus.size ? setFocus(id, 'add') : navigate(id);
+ };
+ pick.addEventListener('change', commit);
+ // picking from the datalist doesn't fire `change` until the box loses focus
+ pick.addEventListener('input', e => { if(e.inputType==='insertReplacementText' || !e.inputType) commit(); });
+ bar.appendChild(pick);
+ if(!focus.size){
+ if(selected) btn('Focus '+selected, 'Draw the selected module’s neighbourhood', () => setFocus(selected, 'replace'));
+ requestAnimationFrame(() => pick.focus());
+ }
+ const deg = document.createElement('select'); deg.title = 'Hops out from the focused modules';
+ for(const n of [1,2,3]){ const o=document.createElement('option'); o.value=n; o.textContent=n+(n===1?' hop':' hops'); deg.appendChild(o); }
+ deg.value = degree; deg.onchange = () => { degree = +deg.value; syncHash(true); renderGraph(); };
+ bar.appendChild(deg);
+ const hre = document.createElement('input'); hre.placeholder = 'hide regex'; hre.value = hideRe; hre.className = 'mono';
+ hre.title = 'Leave matching modules out of the graph';
+ hre.onchange = () => { hideRe = hre.value.trim(); syncHash(false); renderGraph(); };
+ bar.appendChild(hre);
+ if(hidden.size) btn('Show '+hidden.size+' hidden', [...hidden].sort().join(', '), () => { hidden.clear(); syncHash(true); renderGraph(); });
+ if(expanded.size) btn('Collapse all', 'Hide every API namespace', () => { expanded.clear(); syncHash(true); renderGraph(); });
+ if(cy && focus.size) btn('Re-layout', 'Run the layout again', runLayout);
+ const d = document.createElement('span'); d.className = 'desc';
+ d.textContent = (visible ? visible.size+' modules · '+cy.edges().length+' edges · ' : '') +
+ 'click selects · shift-click adds to focus · double-click focuses · right-click for more' +
+ (NS_EDGES ? '' : ' · run (dev.module-explorer/open!) in a dev REPL for namespace-level edges');
+ bar.appendChild(d);
+}
+function runLayout(){
+ if(layout) layout.stop();
+ layout = cy.layout({name:'cola', animate:true, maxSimulationTime:3000, randomize:true, fit:true, padding:60,
+ avoidOverlap:true, handleDisconnected:true,
+ nodeSpacing: n => n.data('type')==='module' ? 80 : 20,
+ // heavily used pairs sit closer together
+ edgeLength: e => Math.max(220, 500 - Math.log2((e.data('weight')||1)+1)*50)});
+ layout.one('layoutstop', () => { locked.forEach(n => n.unlock()); locked = []; });
+ layout.run();
+}
+function markGraph(){
+ if(!cy) return;
+ cy.elements().removeClass('focused sel');
+ focus.forEach(id => cy.getElementById('mod:'+id).addClass('focused'));
+ cy.edges().filter(e => focus.has(e.data('sourceModule')) || focus.has(e.data('targetModule'))).addClass('focused');
+ if(selected) cy.getElementById('mod:'+selected).addClass('sel');
+}
+async function renderGraph(){
+ renderGraphBar(null);
+ if(!focus.size){ if(cy) cy.elements().remove(); return; }
+ try{ await loadGraphLibs(); }
+ catch(e){ document.getElementById('cy').innerHTML = `<div class=note>The graph needs cytoscape from unpkg.com: ${e.message}</div>`; return; }
+ if(!cy) initCy();
+ cy.resize();
+ const visible = neighbourhood();
+ const {nodes, edges} = graphElements(visible);
+ // modules that stay on screen keep their place while the new ones settle around them
+ const old = {}; cy.nodes().forEach(n => { old[n.id()] = {...n.position()}; });
+ locked.forEach(n => n.unlock()); locked = [];
+ cy.batch(() => { cy.elements().remove(); cy.add(nodes); cy.add(edges); });
+ for(const id in old){ const n=cy.getElementById(id); if(n.nonempty()){ n.position(old[id]); n.lock(); locked.push(n); } }
+ markGraph();
+ renderGraphBar(visible);
+ runLayout();
+}
+
+// ---- detail panel --------------------------------------------------------
+const detailEl=document.getElementById('detail');
+function chip(text, link){
+ const c=document.createElement('span');
+ c.className='chip'+(link?' link':'');
+ c.textContent=text;
+ if(link&&byId[text]) c.onclick=()=>navigate(text);
+ return c;
+}
+function section(title, items, opts={}){
+ if(!items||!items.length) return null;
+ const s=document.createElement('div'); s.className='sec';
+ const h=document.createElement('h3');
+ if(opts.swatch){ h.innerHTML=`<span class=swatch style='background:${opts.swatch}'></span>`; }
+ h.append(title);
+ const n=document.createElement('span'); n.className='n'; n.textContent=items.length; h.appendChild(n);
+ s.appendChild(h);
+ const box=document.createElement('div'); box.className='chips';
+ for(const it of items) box.appendChild(chip(it, opts.link));
+ s.appendChild(box);
+ return s;
+}
+// with namespace data: for each namespace of `m` another module requires, the modules that require it
+function nsUsage(m){
+ const byNs = {};
+ for(const [c,p,ns] of NS_EDGES) if(p===m.id) (byNs[ns] ||= new Set()).add(c);
+ const names = Object.keys(byNs).sort();
+ if(!names.length) return null;
+ const s=document.createElement('div'); s.className='sec';
+ const h=document.createElement('h3'); h.append('Used through');
+ const n=document.createElement('span'); n.className='n'; n.textContent=names.length; h.appendChild(n);
+ s.appendChild(h);
+ for(const ns of names){
+ const row=document.createElement('div'); row.className='nsuse';
+ const nm=document.createElement('div'); nm.className='nsname mono'; nm.textContent=ns; row.appendChild(nm);
+ const box=document.createElement('div'); box.className='chips';
+ for(const c of [...byNs[ns]].sort()) box.appendChild(chip(c, true));
+ row.appendChild(box); s.appendChild(row);
+ }
+ return s;
+}
+function expandAncestors(id){ const p=byId[id]&&byId[id].path; if(!p) return; for(let i=1;i<p.length;i++) open.add(p.slice(0,i).join('/')); }
+function scrollToSelected(){ if(!selected) return; const el=treeEl.querySelector('[data-id='+JSON.stringify(selected)+']'); if(el) el.scrollIntoView({block:'center'}); }
+// The hash holds selection, filters, and graph state, so reloads and deep links restore the same view.
+function stateHash(){
+ const s=encodeExplorerState({selected, view, focus, degree, expanded, hidden, hideRe, teams:focusTeams});
+ return s ? '#'+s : location.pathname+location.search;
+}
+function syncHash(push){ (push ? history.pushState : history.replaceState).call(history, null, '', stateHash()); }
+function applyHash(){
+ const state=decodeExplorerState(location.hash, VALID_IDS, VALID_TEAMS);
+ view=state.view; focus=state.focus; degree=state.degree; expanded=state.expanded; hidden=state.hidden; hideRe=state.hideRe;
+ focusTeams.clear(); state.teams.forEach(team=>focusTeams.add(team));
+ if(view==='graph' && !state.focusSpecified && state.selected) focus.add(state.selected);
+ refreshTeamChips();
+ syncView();
+ endKbRun();
+ if(view==='graph') render();
+ applySelected(state.selected);
+}
+function applySelected(id){ // id may be null; updates the view + detail, never touches history
+ selected = id;
+ if(view==='graph'){ markGraph(); renderDetail(); return; }
+ if(selected && view==='tree') expandAncestors(selected); // reveal: open the path down to it
+ render();
+ if(selected) scrollToSelected();
+ renderDetail();
+}
+function select(id){ // user selection → push a history entry
+ endKbRun(); // a committed (click/chip/Escape) selection ends any in-flight arrow run
+ applySelected(selected===id ? null : id);
+ syncHash(true);
+}
+function navigate(id){ // go to a module from a link: selects it, and in the graph also focuses it
+ endKbRun();
+ if(view==='graph') focus = new Set([id]);
+ applySelected(id);
+ syncHash(true);
+ if(view==='graph') renderGraph();
+}
+let kbRunTimer=null;
+function endKbRun(){ clearTimeout(kbRunTimer); kbRunTimer=null; }
+function keyboardSelect(id){ // coalesce a run of arrow moves into one history entry ending at the resting selection
+ const startOfRun = kbRunTimer===null;
+ applySelected(id);
+ syncHash(startOfRun); // push on the first move of a run, replace as it continues
+ clearTimeout(kbRunTimer);
+ kbRunTimer=setTimeout(endKbRun, 500);
+}
+const EMPTY_DETAIL='<div class=d-empty>Select a module to see its team, API surface, and dependencies.'+
+ '<br>Its relatives light up in the tree: <span class="dep-mark uses"></span> ones it uses, <span class="dep-mark usedby"></span> ones that use it.'+
+ '<div class=keys><kbd>/</kbd> search &nbsp; <kbd>↵</kbd> go to match &nbsp; <kbd>↑</kbd><kbd>↓</kbd> move selection &nbsp; <kbd>Esc</kbd> clear</div></div>';
+function renderDetail(){
+ if(!selected){ detailEl.classList.remove('show'); detailEl.innerHTML=EMPTY_DETAIL; return; }
+ const m=byId[selected];
+ detailEl.classList.add('show');
+ detailEl.innerHTML='';
+ const head=document.createElement('div'); head.className='d-head';
+ const t=document.createElement('div'); t.className='d-title';
+ const dot=document.createElement('span'); dot.className='dot'; dot.style.background=m.team?teamColor[m.team]:'var(--group)';
+ t.appendChild(dot); t.append(m.id); head.appendChild(t);
+ const sub=document.createElement('div'); sub.className='d-sub';
+ if(m.team){ const tm=document.createElement('span'); tm.className='d-team';
+ tm.innerHTML=`<span class=dot style='width:9px;height:9px;background:${teamColor[m.team]}'></span>${m.team}`; sub.appendChild(tm); }
+ if(m.enterprise){ const b=document.createElement('span'); b.className='badge ent'; b.textContent='ENTERPRISE'; sub.appendChild(b); }
+ if(m.source){ const a=document.createElement('a'); a.href=GITHUB+'tree/master/'+m.source; a.target='_blank'; a.rel='noopener';
+ a.textContent='source ↗'; a.title=m.source; sub.appendChild(a); }
+ head.appendChild(sub);
+ if(m['ns-prefix']){ const n=document.createElement('div'); n.className='nsnote';
+ n.innerHTML=`Namespaces not yet moved to match the module name — still at <code>${m['ns-prefix']}</code>`; head.appendChild(n); }
+ detailEl.appendChild(head);
+
+ const body=document.createElement('div'); body.className='d-body';
+ if(m.stats){
+ const st=document.createElement('div'); st.className='d-stats';
+ for(const [k,v] of [['namespaces',m.stats.namespaces],['lines',m.stats.loc],['tests',m.stats.tests],['commits',m.stats.commits]]){
+ const d=document.createElement('div'); d.className='stat';
+ d.innerHTML=`<b>${(v||0).toLocaleString()}</b><span>${k}</span>`;
+ if(k==='tests'&&m.stats['test-files']) d.title=`${m.stats.tests} deftest across ${m.stats['test-files']} files`;
+ st.appendChild(d);
+ }
+ body.appendChild(st);
+ }
+ const api = m['api-any']?['(any — no API namespace yet)']:m.api;
+ const uses = m['uses-any']
+ ? (HAS_ACTUAL_EDGES ? (m.uses.length ? m.uses : ['(none observed)']) : ['(any — actual dependencies require a dev REPL)'])
+ : m.uses;
+ const secs=[
+ section('API namespaces', api),
+ section(m['uses-any']?'Uses (unrestricted)':'Uses', uses, {link:true, swatch:'var(--uses)'}),
+ section('Used by', m['used-by'], {link:true, swatch:'var(--usedby)'}),
+ NS_EDGES && nsUsage(m),
+ section('Friends', m.friends, {link:true}),
+ section('Module exports', m['module-exports'], {link:true}),
+ section('Model exports', m['model-exports']),
+ section(m['model-imports-bypass']?'Model imports (bypass)':'Model imports',
+ m['model-imports-bypass']?['(bypass — imports any model)']:m['model-imports']),
+ ].filter(Boolean);
+ if(secs.length) secs.forEach(s=>body.appendChild(s));
+ else { const e=document.createElement('div'); e.className='empty-note'; e.textContent='No declared dependencies or surface.'; body.appendChild(e); }
+ detailEl.appendChild(body);
+}
+
+// ---- controls ------------------------------------------------------------
+const qInput=document.getElementById('q');
+qInput.addEventListener('input', e=>{ query=e.target.value.trim().toLowerCase(); if(view!=='graph') render(); });
+qInput.addEventListener('keydown', e=>{
+ if(e.key!=='Enter') return;
+ const q=qInput.value.trim(), lower=q.toLowerCase();
+ const id = byId[q] ? q : (MODULES.find(m => m.id.toLowerCase().includes(lower)) || {}).id;
+ if(id) navigate(id);
+});
+function expandAll(){ (function all(node,path){ for(const kid of node.children.values()){ const kp=path.concat(kid.seg);
+ if(kid.children.size) open.add(kp.join('/')); all(kid,kp); } })(root,[]); }
+document.getElementById('expand').onclick=()=>{ expandAll(); render(); };
+document.getElementById('collapse').onclick=()=>{ open.clear(); render(); };
+const rootEl=document.documentElement;
+const themeSel=document.getElementById('theme');
+function applyTheme(v){ v ? rootEl.setAttribute('data-theme',v) : rootEl.removeAttribute('data-theme'); if(cy) cy.style(graphStyle()); }
+try{ const saved=localStorage.getItem('mb-modtree-theme'); if(saved!==null){ themeSel.value=saved; applyTheme(saved); } }catch(e){}
+themeSel.onchange=()=>{ applyTheme(themeSel.value); try{ localStorage.setItem('mb-modtree-theme', themeSel.value); }catch(e){} };
+
+// unfilled-boundaries lens + tree/hotspots/graph view
+const debtBtn=document.getElementById('debt');
+debtBtn.onclick=()=>{ debtOnly=!debtOnly; debtBtn.classList.toggle('on',debtOnly); render(); };
+function syncView(){
+ for(const v of ['tree','hotspots','graph']) document.getElementById('view-'+v).classList.toggle('on', view===v);
+ document.getElementById('foldctl').style.display = view==='tree' ? '' : 'none';
+ debtBtn.style.display = view==='graph' ? 'none' : '';
+}
+function setView(v){
+ if(view===v) return;
+ view=v; syncView();
+ if(view==='graph' && !focus.size && selected) focus.add(selected);
+ if(view==='tree'&&selected) expandAncestors(selected);
+ render();
+ if(view==='tree'&&selected) scrollToSelected();
+ syncHash(true);
+}
+for(const v of ['tree','hotspots','graph']) document.getElementById('view-'+v).onclick=()=>setView(v);
+syncView();
+
+// keyboard: / focuses search, Esc clears/deselects, ↑/↓ move selection through visible rows
+document.addEventListener('keydown', e=>{
+ if(e.key==='/' && document.activeElement!==qInput){ e.preventDefault(); qInput.focus(); qInput.select(); return; }
+ if(e.key==='Escape'){
+ menuEl.hidden=true;
+ if(document.activeElement===qInput && qInput.value){ qInput.value=''; query=''; if(view!=='graph') render(); qInput.blur(); }
+ else if(selected){ select(selected); }
+ return;
+ }
+ if((e.key==='ArrowDown'||e.key==='ArrowUp') && visibleIds.length){
+ const ae=document.activeElement, tag=ae&&ae.tagName;
+ if(tag==='INPUT'||tag==='SELECT'||tag==='TEXTAREA'||(ae&&ae.isContentEditable)) return; // don't hijack native controls
+ e.preventDefault();
+ let i=visibleIds.indexOf(selected);
+ if(e.key==='ArrowDown') i = i<0 ? 0 : Math.min(i+1, visibleIds.length-1);
+ else i = i<0 ? visibleIds.length-1 : Math.max(i-1, 0);
+ if(visibleIds[i] && visibleIds[i]!==selected) keyboardSelect(visibleIds[i]);
+ }
+});
+// back/forward restores the whole view
+window.addEventListener('popstate', applyHash);
+
+// fully expanded by default
+expandAll();
+applyHash();
+</script>
+</body></html>
diff --git a/dev/resources/dev/module_explorer_state.js b/dev/resources/dev/module_explorer_state.js
new file mode 100644
index 00000000000..e076e91cf9e
--- /dev/null
+++ b/dev/resources/dev/module_explorer_state.js
@@ -0,0 +1,37 @@
+function encodeExplorerState(state) {
+ const params = new URLSearchParams();
+ if (state.selected) params.set('m', state.selected);
+ if (state.view !== 'tree') params.set('view', state.view);
+ if (state.focus.size) params.set('focus', [...state.focus].sort().join(','));
+ else if (state.view === 'graph') params.set('focus', '');
+ if (state.degree !== 1) params.set('deg', state.degree);
+ if (state.expanded.size) params.set('exp', [...state.expanded].sort().join(','));
+ if (state.hidden.size) params.set('hide', [...state.hidden].sort().join(','));
+ if (state.hideRe) params.set('hre', state.hideRe);
+ for (const team of [...state.teams].sort()) params.append('team', team);
+ return params.toString();
+}
+
+function decodeExplorerState(hash, validIds, validTeams) {
+ const raw = hash.replace(/^#/, '');
+ const params = new URLSearchParams(raw.includes('=') ? raw : (raw ? 'm=' + raw : ''));
+ const ids = key => (params.get(key) || '').split(',').filter(id => validIds.has(id));
+ const requestedView = params.get('view');
+ const requestedDegree = Number.parseInt(params.get('deg'), 10);
+ const selected = validIds.has(params.get('m')) ? params.get('m') : null;
+ return {
+ selected,
+ view: ['hotspots', 'graph'].includes(requestedView) ? requestedView : 'tree',
+ focus: new Set(ids('focus')),
+ focusSpecified: params.has('focus'),
+ degree: Math.min(3, Math.max(1, requestedDegree || 1)),
+ expanded: new Set(ids('exp')),
+ hidden: new Set(ids('hide')),
+ hideRe: params.get('hre') || '',
+ teams: new Set(params.getAll('team').filter(team => validTeams.has(team))),
+ };
+}
+
+if (typeof module === 'object' && module.exports) {
+ module.exports = {decodeExplorerState, encodeExplorerState};
+}
diff --git a/dev/resources/dev/module_viz.html b/dev/resources/dev/module_viz.html
deleted file mode 100644
index 921134650b7..00000000000
--- a/dev/resources/dev/module_viz.html
+++ /dev/null
@@ -1,834 +0,0 @@
-<!doctype html>
-<html lang="en">
-<head>
-<meta charset="utf-8"/>
-<title>Metabase Modules Graph</title>
-<style>
-html, body { margin:0; padding:0; height:100%; overflow:hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
-#app { display:flex; height:100vh; overflow:hidden; }
-#cy { flex:1 1 auto; min-height:0; min-width:0; background:#fafafa; }
-#side { width:340px; height:100vh; box-sizing:border-box; border-left:1px solid #ddd; background:#fff; padding:12px; overflow:auto; font-size:13px; }
-#side h2 { margin:8px 0 4px; font-size:14px; }
-#side h3 { margin:10px 0 4px; font-size:12px; color:#666; text-transform:uppercase; letter-spacing:.04em; }
-#side .pill { display:inline-block; padding:2px 6px; background:#eef; border-radius:4px; margin-right:4px; font-size:11px; }
-#toolbar { padding:8px; border-bottom:1px solid #ddd; background:#fff; display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
-#toolbar input[type=text] { padding:4px 8px; border:1px solid #ccc; border-radius:4px; min-width:240px; }
-#toolbar button { padding:4px 10px; border:1px solid #ccc; background:#f7f7f7; border-radius:4px; cursor:pointer; }
-#toolbar button:hover { background:#eee; }
-#wrap { display:flex; flex-direction:column; flex:1 1 auto; min-height:0; min-width:0; overflow:hidden; }
-.muted { color:#888; font-size:11px; }
-ul { margin:4px 0; padding-left:18px; }
-li { margin:2px 0; cursor:pointer; }
-li:hover { background:#f4f4f4; }
-code { background:#f4f4f4; padding:1px 4px; border-radius:3px; font-size:12px; }
-</style>
-<script src="https://unpkg.com/[email protected]/dist/cytoscape.min.js"></script>
-<script src="https://unpkg.com/[email protected]/WebCola/cola.min.js"></script>
-<script src="https://unpkg.com/[email protected]/cytoscape-cola.js"></script>
-</head>
-<body>
-<div id="app">
-<div id="wrap">
-<div id="toolbar">
-<input id="focus" type="text" list="modlist" placeholder="focus module…"/>
-<datalist id="modlist"></datalist>
-<div id="focusChips" style="display:flex; gap:4px; flex-wrap:wrap;"></div>
-<label class="muted">degree
-<select id="degree">
-<option value="1" selected>1</option>
-<option value="2">2</option>
-</select>
-</label>
-<button id="clear-focus">clear focus</button>
-<button id="reset-state" title="clear localStorage + URL hash">reset</button>
-<button id="collapse-all">collapse all</button>
-<button id="expand-all">expand all</button>
-<button id="relayout">re-layout (cola)</button>
-<span class="muted" id="stats"></span>
-<span class="muted" id="debug" style="color:#c33"></span>
-<span class="muted">shift-click a module to refocus · right-click for menu · double-click to expand api ns</span>
-</div>
-<div id="cy"></div>
-</div>
-<div id="side">
-<h2>Metabase Modules</h2>
-<div class="muted">Select a module to focus its 1-degree neighborhood.</div>
-<details id="hiddenWrap" style="margin:8px 0;">
-<summary class="muted" style="cursor:pointer">hidden modules (<span id="hiddenCount">0</span>)</summary>
-<div style="margin-top:6px;"><strong class="muted">hide by team</strong></div>
-<div id="teamChips" style="display:flex; gap:4px; flex-wrap:wrap; margin:4px 0;"></div>
-<div style="margin-top:6px;"><strong class="muted">hide by name/regex</strong></div>
-<div id="hiddenPanel" style="margin-top:4px;"></div>
-<div class="muted" style="margin-top:4px">one entry per line. <code>re:</code> prefix = regex, <code>team:</code> prefix = team. example: <code>re:^enterprise/</code></div>
-<textarea id="hiddenEditor" rows="5" style="width:100%; box-sizing:border-box; font:12px/1.4 monospace;"></textarea>
-<button id="hiddenSave" style="margin-top:4px">save</button>
-<button id="hiddenClear">clear all</button>
-</details>
-<div id="detail"></div>
-</div>
-</div>
-<script>
-try { cytoscape.use(cytoscapeCola); } catch (e) {}
-const teamColors = {};
-const palette = ['#6aa7e8','#e8a06a','#7bcf8a','#cf7bba','#cfc27b','#7bcfc6','#cf7b7b','#a07bcf','#9ccf7b','#cfb37b'];
-function colorFor(team) {
-if (!teamColors[team]) teamColors[team] = palette[Object.keys(teamColors).length % palette.length];
-return teamColors[team];
-}
-const cy = cytoscape({
-container: document.getElementById('cy'),
-elements: { nodes: [], edges: [] },
-wheelSensitivity: 0.2,
-style: [
-{ selector: 'node[type="module"]',
-style: {
-'background-color': (ele) => colorFor(ele.data('team')),
-'background-opacity': 0.22,
-'border-width': 1,
-'border-color': (ele) => colorFor(ele.data('team')),
-'label': 'data(label)',
-'font-size': 18,
-'font-weight': 700,
-'color': '#111',
-'text-outline-width': 3,
-'text-outline-color': '#fff',
-'text-outline-opacity': 1,
-'text-valign': 'top',
-'text-halign': 'center',
-'text-margin-y': -6,
-'padding': '12px',
-'shape': 'round-rectangle',
-'min-width': 30,
-'min-height': 30,
-} },
-{ selector: 'node[type="module"]:childless',
-style: {
-'background-opacity': 0.85,
-'width': (ele) => Math.max(36, Math.min(180, Math.sqrt(ele.data('loc') || 0) * 1.4)),
-'height': (ele) => Math.max(36, Math.min(180, Math.sqrt(ele.data('loc') || 0) * 1.4)),
-} },
-{ selector: 'node[type="ns"]',
-style: {
-'background-color': '#fff', 'border-width': 1, 'border-color': '#888',
-'label': 'data(label)', 'font-size': 9, 'text-valign': 'center', 'text-halign': 'center',
-'shape': 'round-rectangle', 'padding': '4px', 'width': 160, 'height': 18,
-} },
-{ selector: 'edge',
-style: {
-'curve-style': 'unbundled-bezier',
-// single control point offset ~tan(20°)/2 of chord length; use a constant proxy that
-// looks like ~20° bend at typical edge lengths.
-'control-point-distances': [50],
-'control-point-weights': [0.5],
-'width': 1,
-'line-color': '#aaa',
-'target-arrow-color': '#aaa',
-'target-arrow-shape': 'triangle',
-'arrow-scale': 1.8,
-'opacity': 0.7,
-} },
-{ selector: 'edge[?aggregate]',
-style: {
-'width': (ele) => Math.min(10, 1 + Math.log2((ele.data('weight') || 1) + 1) * 1.6),
-'line-color': '#666',
-'target-arrow-color': '#666',
-'opacity': 0.85,
-'label': (ele) => (ele.data('weight') > 1 ? String(ele.data('weight')) : ''),
-'font-size': 9,
-'color': '#444',
-'text-background-color': '#fff',
-'text-background-opacity': 0.85,
-'text-background-padding': 2,
-} },
-{ selector: '.focused', style: { 'border-color': '#e25', 'border-width': 3 } },
-{ selector: 'edge.focused',
-style: { 'line-color': '#e25', 'target-arrow-color': '#e25', 'width': 2, 'opacity': 1 } },
-],
-});
-// Expand/collapse is fully server-side now (focusOn refetches based on `expandedModules`).
-// Skipping the expand-collapse plugin removes the +/- cue + the cxttap interceptor it installs.
-// DIY right-click context menu. Lighter than cytoscape-context-menus plugin and avoids the
-// double-register noise across hot reloads.
-const ctxMenu = document.createElement('div');
-ctxMenu.id = 'ctxmenu';
-ctxMenu.style.cssText = 'position:fixed;display:none;background:#fff;border:1px solid #ccc;' +
-'box-shadow:0 2px 8px rgba(0,0,0,.15);font-size:13px;z-index:9999;min-width:180px;';
-document.body.appendChild(ctxMenu);
-function showCtxMenu(x, y, items) {
-clear(ctxMenu);
-items.forEach(([label, fn]) => {
-const item = mk('div', null, label);
-item.style.cssText = 'padding:6px 12px;cursor:pointer;';
-item.onmouseenter = () => item.style.background = '#eef';
-item.onmouseleave = () => item.style.background = '';
-item.onclick = () => { hideCtxMenu(); fn(); };
-ctxMenu.appendChild(item);
-});
-ctxMenu.style.left = x + 'px';
-ctxMenu.style.top = y + 'px';
-ctxMenu.style.display = 'block';
-}
-function hideCtxMenu() { ctxMenu.style.display = 'none'; }
-document.addEventListener('click', hideCtxMenu);
-function focusOnAt(label, deg) {
-document.getElementById('degree').value = String(deg);
-focusOn(label);
-}
-function toggleExpanded(label) {
-if (expandedModules.has(label)) expandedModules.delete(label);
-else expandedModules.add(label);
-writeUrlState();
-refetch();
-}
-function openGithub(url) { if (url) window.open(url, '_blank', 'noopener'); }
-function hideLabel(label) {
-hiddenLabels.add(label);
-saveHidden();
-writeUrlState();
-renderHiddenPanel();
-refetch();
-}
-function handleModuleCxt(evt) {
-const n = evt.target;
-const label = n.data('label');
-const pos = evt.originalEvent;
-console.log('cxt module', label);
-const expanded = expandedModules.has(label);
-const isFocused = focusedLabels.has(label);
-const items = [
-['focus only this (1°)', () => { document.getElementById('degree').value = '1'; focusOn(label, 'replace'); }],
-['focus only this (2°)', () => { document.getElementById('degree').value = '2'; focusOn(label, 'replace'); }],
-];
-if (isFocused) items.push(['remove from focus', () => focusOn(label, 'remove')]);
-else items.push(['add to focus', () => focusOn(label, 'add')]);
-items.push(
-[expanded ? 'collapse api namespaces' : 'expand api namespaces',
-() => toggleExpanded(label)],
-['hide this module', () => hideLabel(label)],
-['show details', () => renderDetail(n)],
-['open on github ↗', () => openGithub(n.data('githubUrl'))],
-);
-showCtxMenu(pos.clientX, pos.clientY, items);
-}
-cy.on('cxttapstart', 'node[type="module"]', (e) => console.log('cxttapstart', e.target.data('label')));
-cy.on('cxttap', 'node[type="module"]', (e) => console.log('cxttap', e.target.data('label')));
-cy.on('cxttapend', 'node[type="module"]', handleModuleCxt);
-// Fallback: native contextmenu on the canvas. Cytoscape's cxttap detection sometimes wedges after
-// a drag (the renderer keeps a stale grab state). The native event always fires.
-document.getElementById('cy').addEventListener('contextmenu', (ev) => {
-ev.preventDefault();
-const rect = ev.currentTarget.getBoundingClientRect();
-const pos = { x: ev.clientX - rect.left, y: ev.clientY - rect.top };
-// Convert page coords to cytoscape model coords via pan/zoom.
-const pan = cy.pan(), zoom = cy.zoom();
-const model = { x: (pos.x - pan.x) / zoom, y: (pos.y - pan.y) / zoom };
-// Walk nodes from top to find the one under the cursor (small N, cheap).
-const hit = cy.nodes().filter(n => {
-const bb = n.boundingBox();
-return model.x >= bb.x1 && model.x <= bb.x2 && model.y >= bb.y1 && model.y <= bb.y2;
-}).last();
-if (hit && !hit.empty()) {
-console.log('native ctx -> ', hit.data('label'));
-if (hit.data('type') === 'module') {
-handleModuleCxt({target: hit, originalEvent: ev});
-} else if (hit.data('type') === 'ns') {
-handleNsCxt({target: hit, originalEvent: ev});
-}
-} else {
-hideCtxMenu();
-}
-});
-function handleNsCxt(evt) {
-const n = evt.target;
-const parentLabel = n.data('module');
-const pos = evt.originalEvent;
-console.log('cxt ns', n.data('label'));
-showCtxMenu(pos.clientX, pos.clientY, [
-['focus parent module (1°)', () => focusOnAt(parentLabel, 1)],
-['focus parent module (2°)', () => focusOnAt(parentLabel, 2)],
-['show details', () => renderDetail(n)],
-['open on github ↗', () => openGithub(n.data('githubUrl'))],
-]);
-}
-cy.on('cxttapend', 'node[type="ns"]', handleNsCxt);
-function runLayout() {
-const rect = document.getElementById('cy').getBoundingClientRect();
-const dbg = document.getElementById('debug');
-dbg.textContent = '[cy ' + Math.round(rect.width) + 'x' + Math.round(rect.height) + ', ' +
-cy.nodes().length + 'n ' + cy.edges().length + 'e]';
-if (rect.width < 10 || rect.height < 10) {
-dbg.textContent += ' container too small';
-return;
-}
-try {
-if (currentLayout) { try { currentLayout.stop(); } catch (_) {} }
-currentLayout = cy.layout({
-name: 'cola',
-animate: true,
-maxSimulationTime: 4000,
-refresh: 1,
-// bigger nodeSpacing = more repulsion / breathing room between nodes
-nodeSpacing: (node) => (node.data('type') === 'module' ? 80 : 20),
-// Heavily-used pairs sit closer (shorter spring); rare pairs sit farther apart.
-edgeLength: (edge) => {
-const w = edge.data('weight') || 1;
-return Math.max(220, 500 - Math.log2(w + 1) * 50);
-},
-randomize: true,
-fit: true,
-padding: 80,
-avoidOverlap: true,
-handleDisconnected: true,
-});
-currentLayout.one('layoutstop', () => {
-pendingSurvivors.forEach(n => { try { n.unlock(); } catch (_) {} });
-pendingSurvivors = [];
-});
-currentLayout.run();
-} catch (e) {
-console.error('layout failed', e);
-dbg.textContent = 'layout failed: ' + e.message + ' — falling back to grid';
-try { cy.layout({name: 'grid', fit: true, padding: 30}).run(); } catch (e2) { console.error(e2); }
-}
-}
-let currentLayout = null;
-function clear(el) { while (el.firstChild) el.removeChild(el.firstChild); }
-function mk(tag, attrs, ...kids) {
-const el = document.createElement(tag);
-for (const k in (attrs || {})) {
-if (k === 'class') el.className = attrs[k];
-else if (k.startsWith('on')) el[k] = attrs[k];
-else el.setAttribute(k, attrs[k]);
-}
-for (const kid of kids) {
-if (kid == null) continue;
-el.appendChild(typeof kid === 'string' ? document.createTextNode(kid) : kid);
-}
-return el;
-}
-// Focus is now a SET. Single-focus is just |focusedLabels| == 1.
-let focusedLabels = new Set();
-let expandedModules = new Set(); // module labels w/ api-ns children visible
-let modulesIndex = {}; // label -> {label, team, apiCount}
-function loadFocus() {
-try {
-const raw = JSON.parse(localStorage.getItem('moduleVizFocus') || '[]');
-if (Array.isArray(raw)) focusedLabels = new Set(raw);
-} catch (e) {}
-}
-function saveFocus() {
-localStorage.setItem('moduleVizFocus', JSON.stringify([...focusedLabels]));
-}
-loadFocus();
-// --- URL state -------------------------------------------------------------
-// The URL hash mirrors focusedLabels/degree/expandedModules/hiddenLabels so:
-// * back/forward buttons replay focus changes
-// * deep links work (paste URL, get same view)
-// localStorage stays the stickiness-across-sessions fallback when no hash is present.
-function readUrlState() {
-const hash = (location.hash || '').replace(/^#/, '');
-if (!hash) return null;
-const params = new URLSearchParams(hash);
-return {
-focus: (params.get('focus') || '').split(',').filter(Boolean),
-degree: parseInt(params.get('degree') || '1', 10) || 1,
-expanded: (params.get('expanded') || '').split(',').filter(Boolean),
-hidden: (params.get('hidden') || '').split(',').filter(Boolean),
-};
-}
-let suppressHistoryWrite = false;
-function writeUrlState() {
-if (suppressHistoryWrite) return;
-const params = new URLSearchParams();
-if (focusedLabels.size) params.set('focus', [...focusedLabels].join(','));
-const deg = document.getElementById('degree') && document.getElementById('degree').value;
-if (deg && deg !== '1') params.set('degree', deg);
-if (expandedModules.size) params.set('expanded', [...expandedModules].join(','));
-const hid = hiddenQueryParam();
-if (hid) params.set('hidden', hid);
-const next = '#' + params.toString();
-if (next === location.hash) return;
-history.pushState(null, '', next);
-}
-function applyUrlState(s) {
-if (!s) return false;
-suppressHistoryWrite = true;
-try {
-focusedLabels = new Set(s.focus);
-expandedModules = new Set(s.expanded);
-// Hidden: each token is either a literal label or `re:<pattern>`.
-hiddenLabels = new Set();
-hiddenPatterns = [];
-hiddenTeams = new Set();
-s.hidden.forEach(tok => {
-if (tok.startsWith('re:')) {
-const pat = tok.slice(3);
-try { hiddenPatterns.push({pattern: pat, re: new RegExp(pat)}); } catch (e) {}
-} else if (tok.startsWith('team:')) {
-hiddenTeams.add(tok.slice(5));
-} else hiddenLabels.add(tok);
-});
-saveFocus(); saveHidden();
-const degEl = document.getElementById('degree');
-if (degEl) degEl.value = String(s.degree || 1);
-} finally {
-suppressHistoryWrite = false;
-}
-return true;
-}
-window.addEventListener('popstate', () => {
-applyUrlState(readUrlState());
-renderFocusChips();
-renderHiddenPanel();
-if (focusedLabels.size) refetch();
-else clearFocus();
-});
-let pendingSurvivors = []; // nodes locked for the current layout run
-let inflightFocus = null; // AbortController for the current /api/focus fetch
-// Hidden modules: exact-match labels + regex strings. Persisted to localStorage so it survives
-// reloads. The server applies these as a pre-BFS filter so 2-degree views don't sprout via a
-// module the user explicitly hid.
-let hiddenLabels = new Set();
-let hiddenPatterns = []; // array of {pattern: string, re: RegExp}
-let hiddenTeams = new Set(); // exact team names
-function loadHidden() {
-try {
-const raw = JSON.parse(localStorage.getItem('moduleVizHidden') || '{}');
-hiddenLabels = new Set(raw.labels || []);
-hiddenPatterns = (raw.patterns || []).map(p => ({pattern: p, re: new RegExp(p)}));
-hiddenTeams = new Set(raw.teams || []);
-} catch (e) { console.warn('loadHidden failed', e); }
-}
-function saveHidden() {
-localStorage.setItem('moduleVizHidden', JSON.stringify({
-labels: [...hiddenLabels],
-patterns: hiddenPatterns.map(p => p.pattern),
-teams: [...hiddenTeams],
-}));
-}
-function hiddenQueryParam() {
-// Comma-joined: bare labels, re:<pat> for regex, team:<name> for teams.
-return [
-...[...hiddenLabels],
-...hiddenPatterns.map(p => 're:' + p.pattern),
-...[...hiddenTeams].map(t => 'team:' + t),
-].join(',');
-}
-loadHidden();
-function hiddenLines() {
-return [
-...[...hiddenLabels],
-...hiddenPatterns.map(p => 're:' + p.pattern),
-...[...hiddenTeams].map(t => 'team:' + t),
-];
-}
-function renderTeamChips() {
-const wrap = document.getElementById('teamChips');
-if (!wrap) return;
-clear(wrap);
-const teams = [...new Set(Object.values(modulesIndex).map(m => m.team).filter(Boolean))].sort();
-teams.forEach(team => {
-const on = hiddenTeams.has(team);
-const chip = mk('button',
-{style:
-'cursor:pointer; padding:2px 6px; border-radius:10px; font-size:11px; ' +
-'border:1px solid ' + (on ? '#e25' : '#aaa') + '; ' +
-'background:' + (on ? '#fce4e4' : '#fff') + '; ' +
-'color:' + (on ? '#a00' : '#333') + '; ' +
-'text-decoration:' + (on ? 'line-through' : 'none') + ';'},
-team);
-chip.onclick = () => {
-if (hiddenTeams.has(team)) hiddenTeams.delete(team);
-else hiddenTeams.add(team);
-saveHidden();
-writeUrlState();
-renderTeamChips();
-renderHiddenPanel();
-refetch();
-};
-wrap.appendChild(chip);
-});
-}
-function renderHiddenPanel() {
-const panel = document.getElementById('hiddenPanel');
-const editor = document.getElementById('hiddenEditor');
-const count = document.getElementById('hiddenCount');
-if (!panel) return;
-clear(panel);
-const lines = hiddenLines();
-count.textContent = String(lines.length);
-editor.value = lines.join('\n');
-if (lines.length === 0) {
-panel.appendChild(mk('div', {class: 'muted'}, 'nothing hidden'));
-return;
-}
-const ul = mk('ul', {style: 'list-style:none; padding-left:0; margin:0;'});
-lines.forEach(line => {
-const li = mk('li', {style: 'display:flex; gap:6px; align-items:center; padding:2px 0;'});
-const btn = mk('button', {style: 'font-size:11px; padding:0 4px; cursor:pointer;'}, '×');
-btn.onclick = () => {
-if (line.startsWith('re:')) {
-const pat = line.slice(3);
-hiddenPatterns = hiddenPatterns.filter(p => p.pattern !== pat);
-} else if (line.startsWith('team:')) {
-hiddenTeams.delete(line.slice(5));
-} else {
-hiddenLabels.delete(line);
-}
-saveHidden();
-writeUrlState();
-renderHiddenPanel();
-renderTeamChips();
-refetch();
-};
-li.appendChild(btn);
-li.appendChild(mk('code', null, line));
-ul.appendChild(li);
-});
-panel.appendChild(ul);
-}
-function applyHiddenEditor() {
-const editor = document.getElementById('hiddenEditor');
-const lines = editor.value.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
-hiddenLabels = new Set();
-hiddenPatterns = [];
-hiddenTeams = new Set();
-lines.forEach(line => {
-if (line.startsWith('re:')) {
-const pat = line.slice(3);
-try { hiddenPatterns.push({pattern: pat, re: new RegExp(pat)}); }
-catch (e) { console.warn('bad regex', pat, e); }
-} else if (line.startsWith('team:')) {
-hiddenTeams.add(line.slice(5));
-} else {
-hiddenLabels.add(line);
-}
-});
-saveHidden();
-writeUrlState();
-renderHiddenPanel();
-refetch();
-}
-async function fetchModules() {
-console.log('fetchModules start');
-try {
-const r = await fetch('/api/modules');
-console.log('fetchModules response status', r.status);
-const list = await r.json();
-console.log('fetchModules got', list.length, 'modules');
-modulesIndex = Object.fromEntries(list.map(m => [m.label, m]));
-const dl = document.getElementById('modlist');
-clear(dl);
-list.forEach(m => dl.appendChild(mk('option', {value: m.label})));
-renderModuleList(list);
-renderTeamChips();
-console.log('fetchModules done');
-// URL hash beats localStorage on first paint. applyUrlState was called pre-fetch but we
-// re-validate now that modulesIndex is populated.
-const urlState = readUrlState();
-if (urlState) applyUrlState(urlState);
-if (focusedLabels.size === 0) {
-// Auto-focus: pick the module w/ the LARGEST edgeCount that is still <= 50.
-const candidates = list.filter(m => (m.edgeCount || 0) <= 50);
-const pick = candidates.sort((a, b) => (b.edgeCount || 0) - (a.edgeCount || 0))[0];
-if (pick) {
-console.log('auto-focus', pick.label, 'edgeCount', pick.edgeCount);
-focusOn(pick.label);
-}
-} else {
-renderFocusChips();
-renderHiddenPanel();
-refetch();
-}
-} catch (e) {
-console.error('fetchModules failed', e);
-}
-}
-function renderModuleList(list) {
-const el = document.getElementById('detail');
-clear(el);
-el.appendChild(mk('h3', null, 'all modules (' + list.length + ')'));
-const ul = mk('ul');
-list.forEach(m => {
-ul.appendChild(mk('li', {onclick: () => focusOn(m.label)},
-m.label + ' ', mk('span', {class:'muted'}, m.team)));
-});
-el.appendChild(ul);
-}
-function currentDegree() {
-return parseInt(document.getElementById('degree').value, 10) || 1;
-}
-function updateFocusSet(labels, mode) {
-const arr = Array.isArray(labels) ? labels : [labels];
-switch (mode) {
-case 'add':
-arr.forEach(l => modulesIndex[l] && focusedLabels.add(l));
-break;
-case 'remove':
-arr.forEach(l => focusedLabels.delete(l));
-break;
-case 'toggle':
-arr.forEach(l => {
-if (!modulesIndex[l]) return;
-if (focusedLabels.has(l)) focusedLabels.delete(l);
-else focusedLabels.add(l);
-});
-break;
-case 'replace':
-default:
-focusedLabels = new Set(arr.filter(l => modulesIndex[l]));
-break;
-}
-saveFocus();
-writeUrlState();
-}
-// Backward-compatible single-arg form ('focusOn(label)' = replace w/ that label) + optional mode.
-async function focusOn(labelOrLabels, mode) {
-updateFocusSet(labelOrLabels, mode || 'replace');
-if (focusedLabels.size === 0) {
-cy.elements().remove();
-document.getElementById('stats').textContent = '';
-renderFocusChips();
-renderModuleListIfNeeded();
-return;
-}
-// Snapshot positions of every node currently in cy so survivors stay put across the refetch.
-const oldPositions = {};
-cy.nodes().forEach(n => {
-const p = n.position();
-oldPositions[n.data('id')] = { x: p.x, y: p.y };
-});
-document.getElementById('focus').value = [...focusedLabels].join(', ');
-renderFocusChips();
-try {
-const deg = currentDegree();
-const exp = [...expandedModules].join(',');
-const hid = hiddenQueryParam();
-const fs = [...focusedLabels].join(',');
-const url = '/api/focus?m=' + encodeURIComponent(fs) + '&degree=' + deg +
-(exp ? '&expanded=' + encodeURIComponent(exp) : '') +
-(hid ? '&hidden=' + encodeURIComponent(hid) : '');
-if (inflightFocus) inflightFocus.abort();
-inflightFocus = new AbortController();
-const r = await fetch(url, {signal: inflightFocus.signal});
-inflightFocus = null;
-const sub = await r.json();
-console.log('focus', fs, 'degree', deg, 'expanded=', exp, 'nodes=', sub.nodes.length, 'edges=', sub.edges.length);
-cy.batch(() => {
-cy.elements().remove();
-const modNodes = sub.nodes.filter(n => n.data.type === 'module');
-const nsNodes = sub.nodes.filter(n => n.data.type === 'ns');
-cy.add(modNodes);
-cy.add(nsNodes);
-cy.add(sub.edges);
-});
-// Unlock any leftover survivors from a prior interrupted layout before we lock the new set.
-pendingSurvivors.forEach(n => { try { if (n && n.unlock) n.unlock(); } catch (_) {} });
-pendingSurvivors = [];
-// Restore positions for survivors; new nodes get whatever cola decides. Re-query by id since
-// cy.elements().remove() + cy.add() produces fresh node refs.
-const survivors = [];
-Object.keys(oldPositions).forEach(id => {
-const n = cy.getElementById(id);
-if (!n.empty()) {
-n.position(oldPositions[id]);
-n.lock();
-survivors.push(n);
-}
-});
-pendingSurvivors = survivors;
-document.getElementById('debug').textContent =
-'cy: ' + cy.nodes().length + ' nodes · ' + cy.edges().length + ' edges';
-console.log('cy now has', cy.nodes().length, 'nodes', cy.edges().length, 'edges');
-// Mark every focused module + the edges that touch any focused module.
-focusedLabels.forEach(label => {
-const node = cy.getElementById('mod:' + label);
-if (!node.empty()) node.addClass('focused');
-});
-cy.edges().forEach(e => {
-if (focusedLabels.has(e.data('sourceModule')) || focusedLabels.has(e.data('targetModule'))) {
-e.addClass('focused');
-}
-});
-runLayout();
-// Sidebar detail: if exactly one focused, show it; otherwise show a summary.
-if (focusedLabels.size === 1) {
-const only = cy.getElementById('mod:' + [...focusedLabels][0]);
-if (!only.empty()) renderDetail(only);
-} else {
-renderFocusSummary();
-}
-document.getElementById('stats').textContent =
-sub.stats.moduleCount + ' modules · ' + sub.stats.edgeCount + ' edges' +
-(sub.stats.rawEdges ? ' (raw ' + sub.stats.rawEdges + ')' : '') +
-' · ' + sub.degree + '-deg · expanded: ' + (sub.expanded.length || 0);
-} catch (e) {
-if (e.name === 'AbortError') return; // user clicked again before we finished
-console.error('focusOn failed', e);
-}
-}
-function clearFocus() {
-focusedLabels = new Set();
-saveFocus();
-document.getElementById('focus').value = '';
-document.getElementById('stats').textContent = '';
-cy.elements().remove();
-renderFocusChips();
-// Don't auto-load the full graph — it's the hairball we're trying to avoid.
-fetchModules();
-}
-function refetch() {
-if (focusedLabels.size > 0) focusOn([...focusedLabels], 'replace');
-}
-function renderFocusSummary() {
-const el = document.getElementById('detail');
-if (!el) return;
-clear(el);
-el.appendChild(mk('h2', null, focusedLabels.size + ' focused modules'));
-const ul = mk('ul');
-[...focusedLabels].sort().forEach(label => {
-const li = mk('li', {style: 'display:flex; gap:6px; align-items:center;'});
-const link = mk('a', {href: '#'}, label);
-link.onclick = (e) => { e.preventDefault(); focusOn(label, 'replace'); };
-const x = mk('button', {style: 'font-size:11px; cursor:pointer'}, 'remove');
-x.onclick = () => focusOn(label, 'remove');
-li.appendChild(link);
-li.appendChild(x);
-ul.appendChild(li);
-});
-el.appendChild(ul);
-}
-function renderFocusChips() {
-const wrap = document.getElementById('focusChips');
-if (!wrap) return;
-clear(wrap);
-[...focusedLabels].sort().forEach(label => {
-const chip = mk('span', {style:
-'display:inline-flex; align-items:center; gap:4px; padding:2px 6px; ' +
-'background:#fce4e4; border:1px solid #e25; border-radius:10px; font-size:12px;'},
-label);
-const x = mk('button', {style: 'border:0; background:transparent; cursor:pointer; padding:0;'}, '×');
-x.onclick = () => focusOn(label, 'remove');
-chip.appendChild(x);
-wrap.appendChild(chip);
-});
-}
-function renderModuleListIfNeeded() {
-// After clearing focus we want the sidebar to fall back to the module list.
-fetch('/api/modules').then(r => r.json()).then(renderModuleList);
-}
-function renderDetail(node) {
-const el = document.getElementById('detail');
-clear(el);
-const d = node.data();
-if (d.type === 'module') {
-const consumers = cy.edges('[targetModule="' + d.module + '"]');
-const producers = cy.edges('[sourceModule="' + d.module + '"]');
-const byNs = {};
-consumers.forEach(e => {
-const ns = e.data('targetNs') || '(module)';
-(byNs[ns] ||= new Set()).add(e.data('sourceModule'));
-});
-const usesBy = {};
-producers.forEach(e => {
-const m = e.data('targetModule');
-(usesBy[m] ||= new Set()).add(e.data('targetNs') || '(any)');
-});
-el.appendChild(mk('h2', null, d.label));
-el.appendChild(mk('div', null,
-mk('span', {class:'pill'}, 'team: ' + d.team),
-mk('span', {class:'pill'}, 'api: ' + d.apiCount)));
-el.appendChild(mk('h3', null, 'used by → which api ns'));
-if (Object.keys(byNs).length === 0) {
-el.appendChild(mk('p', {class:'muted'}, 'no external consumers'));
-} else {
-Object.entries(byNs).sort().forEach(([ns, set]) => {
-el.appendChild(mk('div', null, mk('code', null, ns)));
-const ul = mk('ul');
-[...set].sort().forEach(m => {
-ul.appendChild(mk('li', {onclick: () => focusOn(m)}, m));
-});
-el.appendChild(ul);
-});
-}
-el.appendChild(mk('h3', null, 'uses → others'));
-if (Object.keys(usesBy).length === 0) {
-el.appendChild(mk('p', {class:'muted'}, 'depends on nothing external'));
-} else {
-Object.entries(usesBy).sort().forEach(([m, set]) => {
-el.appendChild(mk('div', null, mk('strong', {onclick: () => focusOn(m)}, m)));
-const ul = mk('ul');
-[...set].sort().forEach(ns => ul.appendChild(mk('li', null, mk('code', null, ns))));
-el.appendChild(ul);
-});
-}
-if (d.friends && d.friends.length) {
-el.appendChild(mk('h3', null, 'friends'));
-const ul = mk('ul');
-d.friends.forEach(f => ul.appendChild(mk('li', null, f)));
-el.appendChild(ul);
-}
-} else if (d.type === 'ns') {
-const consumers = cy.edges('[targetNs="' + d.label + '"][targetModule="' + d.module + '"]');
-const set = new Set();
-consumers.forEach(e => set.add(e.data('sourceModule')));
-el.appendChild(mk('h2', null, mk('code', null, d.label)));
-el.appendChild(mk('div', {class:'muted'}, 'API namespace of ', mk('strong', null, d.module)));
-el.appendChild(mk('h3', null, 'used by'));
-if (set.size === 0) {
-el.appendChild(mk('p', {class:'muted'}, 'no external consumers'));
-} else {
-const ul = mk('ul');
-[...set].sort().forEach(m => ul.appendChild(mk('li', {onclick: () => focusOn(m)}, m)));
-el.appendChild(ul);
-}
-}
-}
-cy.on('tap', 'node', (evt) => {
-const n = evt.target;
-if (n.data('type') === 'module' && evt.originalEvent) {
-const ev = evt.originalEvent;
-// Shift = toggle in focus set; Cmd/Ctrl = remove; otherwise just show details.
-if (ev.shiftKey) return focusOn(n.data('label'), 'toggle');
-if (ev.metaKey || ev.ctrlKey) return focusOn(n.data('label'), 'remove');
-}
-renderDetail(n);
-});
-cy.on('dbltap', 'node[type="module"]', (evt) => {
-toggleExpanded(evt.target.data('label'));
-});
-document.getElementById('focus').addEventListener('change', (e) => {
-const v = e.target.value.trim();
-if (!v) clearFocus(); else focusOn(v);
-});
-document.getElementById('clear-focus').onclick = clearFocus;
-document.getElementById('reset-state').onclick = () => {
-try { localStorage.clear(); } catch (_) {}
-history.replaceState(null, '', location.pathname);
-location.reload();
-};
-document.getElementById('degree').addEventListener('change', () => {
-writeUrlState();
-refetch();
-});
-document.getElementById('collapse-all').onclick = () => {
-expandedModules.clear();
-refetch();
-};
-document.getElementById('expand-all').onclick = () => {
-// Expand every currently visible module.
-cy.nodes('[type="module"]').forEach(n => expandedModules.add(n.data('label')));
-refetch();
-};
-document.getElementById('relayout').onclick = () => runLayout();
-document.getElementById('hiddenSave').onclick = applyHiddenEditor;
-document.getElementById('hiddenClear').onclick = () => {
-hiddenLabels = new Set(); hiddenPatterns = []; hiddenTeams = new Set();
-saveHidden(); writeUrlState(); renderHiddenPanel(); renderTeamChips();
-refetch();
-};
-renderHiddenPanel();
-fetchModules();
-</script>
-</body>
-</html>
\ No newline at end of file
diff --git a/dev/src/dev/deps_graph.clj b/dev/src/dev/deps_graph.clj
index 94b70bf8b65..fb45469a12f 100644
--- a/dev/src/dev/deps_graph.clj
+++ b/dev/src/dev/deps_graph.clj
@@ -436,12 +436,6 @@
;; ignore the config for [[metabase.connection-pool]] which comes from one of our libraries.
(dissoc 'connection-pool)))
-(defn module-team
- "Team owning `module`: its own `:team`, else its nearest ancestor's."
- [config module]
- (some #(get-in config [% :team])
- (take-while some? (iterate #(modules/parent-module config %) module))))
-
(defn- kondo-config-diff-ignore-any
"Ignore entries in the config that use `:any`."
[diff]
diff --git a/dev/src/dev/module_explorer.clj b/dev/src/dev/module_explorer.clj
new file mode 100644
index 00000000000..4df3b7a04fd
--- /dev/null
+++ b/dev/src/dev/module_explorer.clj
@@ -0,0 +1,256 @@
+(ns dev.module-explorer
+ "Interactive HTML explorer for the module tree and dependency graph.
+
+ `./bin/mage modules-tree --html` builds it from the module config under Babashka.
+ [[open!]] builds it in a dev REPL and adds namespace-level edges from `dev.deps-graph`, so the graph can show
+ which API namespaces each consumer uses.
+ Babashka loads this namespace too, which is why it resolves `dev.deps-graph` only inside [[open!]]."
+ (:require
+ [clojure.edn :as edn]
+ [clojure.java.browse :as browse]
+ [clojure.java.io :as io]
+ [clojure.java.shell :as shell]
+ [clojure.string :as str]
+ [hooks.common.modules :as modules]))
+
+(set! *warn-on-reflection* true)
+
+(defn module->tree-path
+ "The path segments used to display `module` in the tree.
+
+ An enterprise module appears under its OSS counterpart when one exists.
+ Otherwise its full `enterprise/` name appears at the root."
+ [modules-config module]
+ (let [segments (str/split (name module) #"\.")]
+ (if (= (namespace module) "enterprise")
+ (if (contains? modules-config (symbol (first segments)))
+ ;; Keep an enterprise subtree together under its OSS module.
+ (into [(first segments) "enterprise"] (rest segments))
+ (into [(str "enterprise/" (first segments))] (rest segments)))
+ segments)))
+
+(defn explicit-ns-prefix
+ "Return a module's custom `:ns-prefix`, or `nil` when it uses the default."
+ [modules-config module]
+ (let [prefix (get-in modules-config [module :ns-prefix])]
+ (when (and prefix (not= prefix (modules/default-ns-prefix module)))
+ prefix)))
+
+(defn- ns-prefix->source-dir
+ "Repo-relative source directory for a namespace prefix: `metabase.lib-be` -> `src/metabase/lib_be`."
+ [ns-prefix]
+ (str (when (str/starts-with? ns-prefix "metabase-enterprise.") "enterprise/backend/")
+ "src/"
+ (-> ns-prefix (str/replace "." "/") (str/replace "-" "_"))))
+
+(defn- set->strings
+ "Sort and stringify a set-valued config field."
+ [x]
+ (if (set? x)
+ (vec (sort (map str x)))
+ []))
+
+(defn- build-module->uses
+ "Known module dependencies.
+
+ Namespace edges provide observed dependencies. Without them, use the declared sets and leave `:uses :any`
+ unresolved instead of treating it as a dependency on every module."
+ [modules-config ns-edges]
+ (if (some? ns-edges)
+ (let [known-modules (set (keys modules-config))]
+ (reduce (fn [acc [consumer producer _namespace]]
+ (let [consumer (symbol (str consumer))
+ producer (symbol (str producer))]
+ (if (and (not= consumer producer)
+ (contains? known-modules consumer)
+ (contains? known-modules producer))
+ (update acc consumer conj producer)
+ acc)))
+ (zipmap known-modules (repeat #{}))
+ ns-edges))
+ (into {}
+ (map (fn [[module {:keys [uses]}]]
+ [module (if (set? uses) uses #{})]))
+ modules-config)))
+
+(defn- used-by-index
+ "Reverse `module -> #{dependencies}` into `module -> #{dependents}`."
+ [module->uses]
+ (reduce-kv (fn [acc module uses]
+ (reduce (fn [index used]
+ (update index used (fnil conj #{}) module))
+ acc
+ uses))
+ {}
+ module->uses))
+
+(defn- module-node
+ "One module's config as the plain data the page consumes."
+ [modules-config module->uses used-by module]
+ (let [{:keys [api uses friends] :as entry} (get modules-config module)
+ source-dir (ns-prefix->source-dir (modules/module-ns-prefix modules-config module))]
+ {:id (str module)
+ :enterprise (= (namespace module) "enterprise")
+ :team (modules/module-team modules-config module)
+ :path (module->tree-path modules-config module)
+ :ns-prefix (explicit-ns-prefix modules-config module)
+ :source (when (.isDirectory (io/file source-dir)) source-dir)
+ :api-any (= api :any)
+ :api (set->strings (modules/module-api-namespaces modules-config module))
+ :uses-any (= uses :any)
+ :uses (set->strings (get module->uses module))
+ :used-by (set->strings (get used-by module))
+ :friends (set->strings friends)
+ :module-exports (set->strings (:module-exports entry))
+ :model-exports (set->strings (:model-exports entry))
+ :model-imports-bypass (= (:model-imports entry) :bypass)
+ :model-imports (set->strings (:model-imports entry))}))
+
+;;; Per-module source metrics, from tracked files and git history.
+
+(def ^:private source-dirs ["src" "enterprise/backend/src" "test" "enterprise/backend/test" "modules/drivers"])
+
+(defn- git-output!
+ "Run Git and return stdout, or throw with its stderr when it fails."
+ [& args]
+ (let [{:keys [exit out err]} (apply shell/sh "git" args)]
+ (when-not (zero? exit)
+ (throw (ex-info (str "Git failed: " err) {:args args, :exit exit, :stderr err})))
+ out))
+
+(defn- tracked-source-files []
+ (->> (apply git-output! "ls-files" "--" source-dirs)
+ str/split-lines
+ (filter #(re-find #"\.clj[cs]?$" %))))
+
+(def ^:private source-root #"^(?:enterprise/backend/)?(?:src|test)/|^modules/drivers/[^/]+/(?:src|test)/")
+
+(defn- file->ns
+ "The namespace a source or test file declares, going by its path."
+ [filename]
+ (when-let [root (re-find source-root filename)]
+ (-> (subs filename (count root))
+ (str/replace #"\.[^./]+$" "")
+ (str/replace "/" ".")
+ (str/replace "_" "-")
+ symbol)))
+
+(defn- file->module [prefix->module filename]
+ (if (str/starts-with? filename "modules/drivers/")
+ ;; driver plugins, including test-data helpers whose namespaces sit outside `metabase.driver`
+ 'driver
+ (some->> (file->ns filename) (modules/declared-module prefix->module))))
+
+(defn- test-file? [filename]
+ (or (str/starts-with? filename "test/")
+ (str/starts-with? filename "enterprise/backend/test/")
+ (str/includes? filename "/test/")))
+
+(defn- count-lines [filename]
+ (with-open [r (io/reader filename)]
+ (count (line-seq r))))
+
+(defn- count-deftests [filename]
+ (with-open [r (io/reader filename)]
+ (count (filter #(re-find #"\(\s*deftest\b" %) (line-seq r)))))
+
+(defn- module->commit-count
+ "Distinct commits that touched each module's files, from one `git log` pass."
+ [file->module*]
+ (let [log (apply git-output! "log" "--format=%H" "--name-only" "--" source-dirs)]
+ (loop [[line & more :as lines] (str/split-lines log)
+ commit nil
+ acc {}]
+ (cond
+ (empty? lines) (update-vals acc count)
+ (re-matches #"[0-9a-f]{40}" line) (recur more line acc)
+ :else (recur more commit (if-let [m (file->module* line)]
+ (update acc m (fnil conj #{}) commit)
+ acc))))))
+
+(defn- module-stats
+ "`module -> {:namespaces :loc :test-files :tests :commits}`."
+ [modules-config files]
+ (let [prefix->module (modules/build-prefix->module modules-config)
+ file->module* (into {} (keep (fn [f] (some->> (file->module prefix->module f) (vector f)))) files)
+ by-module (reduce (fn [acc [f m]]
+ (if (test-file? f)
+ (-> acc
+ (update-in [m :test-files] (fnil inc 0))
+ (update-in [m :tests] (fnil + 0) (count-deftests f)))
+ (-> acc
+ (update-in [m :namespaces] (fnil inc 0))
+ (update-in [m :loc] (fnil + 0) (count-lines f)))))
+ {}
+ file->module*)
+ commits (module->commit-count file->module*)]
+ (into {}
+ (for [m (keys modules-config)]
+ [m (merge {:namespaces 0, :loc 0, :test-files 0, :tests 0}
+ (get by-module m)
+ {:commits (get commits m 0)})]))))
+
+(defn explorer-data
+ "The data embedded in the page.
+
+ `:stats?` adds per-module source metrics, which take a few seconds.
+ `:ns-edges` is a seq of `[consumer producer namespace]` string triples."
+ [modules-config {:keys [stats? ns-edges]}]
+ (let [module->uses (build-module->uses modules-config ns-edges)
+ used-by (used-by-index module->uses)
+ files (when (or stats? ns-edges) (tracked-source-files))
+ stats (when stats? (module-stats modules-config files))]
+ {:modules (mapv (fn [m]
+ (cond-> (module-node modules-config module->uses used-by m)
+ stats? (assoc :stats (get stats m))))
+ (sort (keys modules-config)))
+ :ns-edges (some-> ns-edges vec)
+ :ns-files (when ns-edges
+ (let [used (into #{} (map #(nth % 2)) ns-edges)]
+ (into {}
+ (keep (fn [f]
+ (let [ns-str (str (file->ns f))]
+ (when (and (used ns-str) (not (test-file? f)))
+ [ns-str f]))))
+ files)))}))
+
+(defn- explorer-resource [filename]
+ (slurp (or (io/resource (str "dev/" filename))
+ (io/file "dev/resources/dev" filename))))
+
+(defn- generate-json [data]
+ ;; Mage runs under Babashka, where Cheshire is bundled and metabase.util.json is not on the classpath.
+ ((requiring-resolve 'cheshire.core/generate-string) data))
+
+(defn page
+ "The explorer as one HTML document with `data` embedded."
+ [data]
+ (-> (explorer-resource "module_explorer.html")
+ (str/replace "/*STATE-CODEC*/" (explorer-resource "module_explorer_state.js"))
+ (str/replace "/*DATA*/null"
+ ;; a `</` in the JSON would close the script element early
+ (str/replace (generate-json data) "</" "<\\/"))))
+
+(defn- ns-edges
+ "Distinct `[consumer producer namespace]` triples from the source scan."
+ [modules-config]
+ (let [dependencies (requiring-resolve 'dev.deps-graph/dependencies)
+ external-usages (requiring-resolve 'dev.deps-graph/external-usages)
+ deps (dependencies)]
+ (into []
+ (comp (mapcat #(external-usages deps %))
+ (keep (fn [{:keys [module depends-on-module depends-on-namespace]}]
+ (when (and module depends-on-module (not= module depends-on-module))
+ [(str module) (str depends-on-module) (str depends-on-namespace)])))
+ (distinct))
+ (keys modules-config))))
+
+(defn open!
+ "Build the explorer with namespace-level edges, write it to a temp file, and open it in a browser.
+ Needs a dev REPL. Returns the file path."
+ []
+ (let [modules-config (-> (slurp ".clj-kondo/config/modules/config.edn") edn/read-string :metabase/modules)
+ file (java.io.File/createTempFile "module-explorer" ".html")]
+ (spit file (page (explorer-data modules-config {:stats? true, :ns-edges (ns-edges modules-config)})))
+ (browse/browse-url (str (.toURI file)))
+ (str file)))
diff --git a/dev/src/dev/module_viz.clj b/dev/src/dev/module_viz.clj
deleted file mode 100644
index 0cab5b84c86..00000000000
--- a/dev/src/dev/module_viz.clj
+++ /dev/null
@@ -1,427 +0,0 @@
-(ns dev.module-viz
- "Interactive Cytoscape.js visualization of the Metabase modules graph.
-
- Backed by a small Ring/Jetty server so the browser only fetches the *pruned* subgraph for the
- module(s) currently in focus instead of the full 600+ node hairball. Multi-focus unions and
- configurable hop degree (1-3) are supported. Endpoints:
-
- GET / -> HTML shell
- GET /api/modules -> [{:label :team :apiCount :edgeCount}] for the picker
- GET /api/focus?m=LABEL1,LABEL2,... {:focus [...] :nodes [...] :edges [...] :stats {...}}
- &degree=N
- &expanded=MOD1,MOD2,...
- &hidden=re:pat1,team:T1,LABEL3,...
- GET /api/full -> full graph (escape hatch / debugging)
-
- Usage:
-
- (require '[dev.module-viz :as v])
- (v/start!) ;; default port 4321, opens browser
- (v/stop!)"
- (:require
- [cheshire.core :as json]
- [clojure.java.io :as io]
- [clojure.java.shell :as sh]
- [clojure.string :as str]
- [dev.deps-graph :as deps-graph]
- [ring.adapter.jetty :as jetty]))
-
-(set! *warn-on-reflection* true)
-
-(defn- module-id [m] (str "mod:" m))
-(defn- ns-id [m ns-symb] (str "ns:" m "/" ns-symb))
-
-(def ^:private github-base "https://github.com/metabase/metabase/blob/master/")
-
-(defn- ns->github-path
- "Translate a Clojure namespace symbol into the most likely repo-relative path."
- [ns-symb]
- (let [s (str ns-symb)
- path (-> s (str/replace "-" "_") (str/replace "." "/"))]
- (cond
- (str/starts-with? s "metabase-enterprise.")
- (str "enterprise/backend/src/" path ".clj")
-
- ;; driver namespaces live under modules/drivers/<driver>/src/...
- (re-find #"^metabase\.driver\.([^.]+)" s)
- (let [drv (second (re-find #"^metabase\.driver\.([^.]+)" s))]
- (str "modules/drivers/" drv "/src/" path ".clj"))
-
- :else
- (str "src/" path ".clj"))))
-
-;; TODO (Chris 2026-09-11) -- Not aware of nested modules: paths come from the module name rather than its
-;; `:ns-prefix`, a parent's LOC includes its children's files, and teams ignore inheritance. Consolidate with
-;; `hooks.common.modules/module-ns-prefix` and `dev.deps-graph/module-team`.
-(defn- module->github-path
- "Best-effort repo-relative source path for a module symbol."
- [module-symb]
- (let [s (str module-symb)]
- (cond
- (str/starts-with? s "enterprise/")
- (str "enterprise/backend/src/metabase_enterprise/" (subs s (count "enterprise/")))
-
- :else
- (str "src/metabase/" s))))
-
-(defn- module-source-dir
- "`java.io.File` for the module's source directory (relative to project root), or nil if it doesn't exist."
- [module-symb]
- (let [rel (module->github-path module-symb)
- f (io/file rel)]
- (when (.isDirectory f) f)))
-
-(defn- module-loc
- "Sum of non-blank lines across `.clj`, `.cljc`, `.cljs` files under the module's source dir."
- [module-symb]
- (if-let [dir (module-source-dir module-symb)]
- (->> (file-seq dir)
- (filter (fn [^java.io.File f]
- (and (.isFile f)
- (let [n (.getName f)]
- (or (.endsWith n ".clj")
- (.endsWith n ".cljc")
- (.endsWith n ".cljs"))))))
- (map (fn [^java.io.File f]
- (with-open [r (io/reader f)]
- (count (remove str/blank? (line-seq r))))))
- (reduce + 0))
- 0))
-
-;; --- data ---------------------------------------------------------------------------------------
-
-(def ^:private cache
- "Cache the expensive `deps-graph/dependencies` + `kondo-config` results across requests so refocus
- is near-instant. Reset with `(reset-cache!)` if you edit the kondo config."
- (atom nil))
-
-(defn reset-cache! [] (reset! cache nil))
-
-(defn- build-cache
- "Build the full modules cache — a map with keys :kondo, :module-nodes, :api-children, :all-edges,
- :edges-by-mod. Called once on first request and memoized via the `cache` atom."
- []
- (let [kondo (deps-graph/kondo-config)
- deps (deps-graph/dependencies)
- ;; Build module node + child api-ns node list once.
- module-nodes (into {}
- (map (fn [[m {:keys [team api friends]}]]
- [m {:data {:id (module-id m)
- :label (str m)
- :type "module"
- :module (str m)
- :team (or team "?")
- :apiCount (cond
- (= api :any) 0
- (set? api) (count api)
- :else 0)
- :loc (module-loc m)
- :friends (mapv str (or friends []))
- :githubUrl (str github-base (module->github-path m))}}]))
- kondo)
- api-children (into {}
- (map (fn [[m {:keys [api]}]]
- [m (when (set? api)
- (mapv (fn [ns-symb]
- {:data {:id (ns-id m ns-symb)
- :label (str ns-symb)
- :type "ns"
- :parent (module-id m)
- :module (str m)
- :githubUrl (str github-base (ns->github-path ns-symb))}})
- api))]))
- kondo)
- ;; Collapse all external usages into distinct (consumer, producer, producer-ns) triples
- ;; once. Indexed by both consumer and producer for fast 1-degree lookup.
- all-edges (into []
- (comp
- (mapcat (fn [m] (deps-graph/external-usages deps m)))
- (map (fn [{:keys [module depends-on-module depends-on-namespace]}]
- [module depends-on-module depends-on-namespace]))
- (distinct)
- (keep (fn [[consumer producer producer-ns]]
- (when (and consumer producer (not= consumer producer))
- (let [producer-api (get-in kondo [producer :api])
- target (if (and (set? producer-api)
- (contains? producer-api producer-ns))
- (ns-id producer producer-ns)
- (module-id producer))]
- {:data {:id (str "e:" consumer "->" producer "/" producer-ns)
- :source (module-id consumer)
- :target target
- :sourceModule (str consumer)
- :targetModule (str producer)
- :targetNs (str producer-ns)}})))))
- (keys kondo))
- ;; Index for 1-degree lookups: module-symbol -> edges touching it.
- edges-by-mod (reduce
- (fn [m e]
- (let [s (symbol (get-in e [:data :sourceModule]))
- t (symbol (get-in e [:data :targetModule]))]
- (-> m
- (update s (fnil conj []) e)
- (cond-> (not= s t) (update t (fnil conj []) e)))))
- {}
- all-edges)]
- {:kondo kondo
- :module-nodes module-nodes
- :api-children api-children
- :all-edges all-edges
- :edges-by-mod edges-by-mod}))
-
-(defn- ensure-cache! []
- (or @cache (reset! cache (build-cache))))
-
-(defn modules-list
- "[{:label :team :apiCount :edgeCount}] for the picker dropdown. `edgeCount` = number of distinct
- edges touching this module (in or out), used by the client to pick a sensible default focus."
- []
- (let [{:keys [module-nodes edges-by-mod]} (ensure-cache!)]
- (->> (vals module-nodes)
- (map (fn [n]
- (let [label (get-in n [:data :label])]
- {:label label
- :team (get-in n [:data :team])
- :apiCount (get-in n [:data :apiCount])
- :edgeCount (count (get edges-by-mod (symbol label) []))})))
- (sort-by :label))))
-
-(defn- bfs-neighbors
- "Return modules within `degree` hops of `start` over the undirected module-edge graph, skipping
- any module that fails the optional `keep?` predicate."
- ([edges-by-mod start degree]
- (bfs-neighbors edges-by-mod start degree (constantly true)))
- ([edges-by-mod start degree keep?]
- (loop [frontier #{start}
- visited #{start}
- hops 0]
- (if (or (zero? (count frontier)) (>= hops degree))
- visited
- (let [next-frontier (into #{}
- (comp
- (mapcat (fn [m] (get edges-by-mod m [])))
- (mapcat (fn [e]
- [(symbol (get-in e [:data :sourceModule]))
- (symbol (get-in e [:data :targetModule]))]))
- (remove visited)
- (filter keep?))
- frontier)]
- (recur next-frontier (into visited next-frontier) (inc hops)))))))
-
-(defn- parse-hidden
- "Parse the `hidden` query string into a predicate `(fn [module-symbol] -> hide?)`. Tokens:
- * plain string -> exact label match
- * `re:<pattern>` -> regex match against the label
- * `team:<team>` -> match every module whose `:team` equals `<team>`
- The team match needs the kondo config to resolve label -> team, so the returned predicate is a
- closure over `module-nodes`."
- [hidden-str module-nodes]
- (if (str/blank? hidden-str)
- (constantly false)
- (let [tokens (remove str/blank? (str/split hidden-str #","))
- literals (into #{}
- (remove #(or (str/starts-with? % "re:")
- (str/starts-with? % "team:")))
- tokens)
- regexes (into []
- (keep (fn [tok]
- (when (str/starts-with? tok "re:")
- (try (re-pattern (subs tok 3))
- (catch Exception _ nil)))))
- tokens)
- teams (into #{}
- (keep (fn [tok]
- (when (str/starts-with? tok "team:")
- (subs tok 5))))
- tokens)
- team-of (fn [m] (get-in module-nodes [m :data :team]))]
- (fn [m]
- (let [s (str m)]
- (or (contains? literals s)
- (contains? teams (team-of m))
- (some #(re-find % s) regexes)))))))
-
-(defn- aggregate-edges
- "Collapse per-ns edges between `expanded-set` complement modules into one edge per (consumer,
- producer) pair. Edges where the *producer* (target side) is expanded keep their api-ns target so
- the user can see which exact namespace the consumer is pulling in. Otherwise we fall back to the
- producer module id so the edge never references a node we didn't ship."
- [edges expanded-set]
- (let [{disag true aggregable false}
- (group-by (fn [e]
- (let [s (symbol (get-in e [:data :sourceModule]))
- t (symbol (get-in e [:data :targetModule]))]
- (boolean (or (contains? expanded-set s)
- (contains? expanded-set t)))))
- edges)
- ;; Rewrite disaggregated edges so endpoints only reference nodes the client actually has.
- keep-as-is (mapv (fn [e]
- (let [s-mod (symbol (get-in e [:data :sourceModule]))
- t-mod (symbol (get-in e [:data :targetModule]))
- ;; Always start with the safe module-id target; only point to the
- ;; ns child when the producer module is expanded.
- t-id (if (contains? expanded-set t-mod)
- (get-in e [:data :target])
- (str "mod:" t-mod))
- s-id (if (contains? expanded-set s-mod)
- (get-in e [:data :source])
- (str "mod:" s-mod))]
- (-> e
- (assoc-in [:data :source] s-id)
- (assoc-in [:data :target] t-id))))
- disag)
- pair->edges (group-by (fn [e]
- [(get-in e [:data :sourceModule])
- (get-in e [:data :targetModule])])
- aggregable)
- agg (for [[[s t] es] pair->edges
- :let [target-nss (into (sorted-set) (map #(get-in % [:data :targetNs])) es)]]
- {:data {:id (str "agg:" s "->" t)
- :source (str "mod:" s)
- :target (str "mod:" t)
- :sourceModule s
- :targetModule t
- :weight (count es)
- :aggregate true
- :nsList (vec target-nss)}})]
- (into (vec agg) keep-as-is)))
-
-(defn focus-subgraph
- "Subgraph for one or more focused modules.
-
- `focus-labels` is a non-empty seq of module label strings; the visible set is the union of each
- label's `degree`-hop BFS neighborhood, minus anything matched by `hide?`. `expanded` is the set of
- module symbols whose api-ns children should render (and whose edges stay disaggregated)."
- [focus-labels degree expanded hide?]
- (let [{:keys [module-nodes api-children edges-by-mod all-edges]} (ensure-cache!)
- degree (max 1 (min 3 (or degree 1)))
- expanded (set (map symbol (or expanded #{})))
- hide? (or hide? (constantly false))
- focus-syms (into [] (comp (remove str/blank?) (map symbol)) (or focus-labels []))
- unknown (remove #(contains? module-nodes %) focus-syms)
- known (filter #(contains? module-nodes %) focus-syms)]
- (if (empty? known)
- {:error (str "no known focus modules in " (pr-str focus-labels))
- :nodes [] :edges [] :focus [] :unknown (mapv str unknown)}
- (let [focus-set (set known)
- ;; Focused modules stay visible even if they match a hide rule.
- keep? (fn [m] (or (contains? focus-set m) (not (hide? m))))
- visible (reduce (fn [acc start]
- (into acc (bfs-neighbors edges-by-mod start degree keep?)))
- #{}
- known)
- nodes (vec
- (mapcat (fn [label]
- (when-let [mn (get module-nodes label)]
- (if (contains? expanded label)
- (cons mn (get api-children label []))
- [mn])))
- visible))
- raw-edges (filterv (fn [e]
- (let [s (symbol (get-in e [:data :sourceModule]))
- t (symbol (get-in e [:data :targetModule]))]
- (and (contains? visible s) (contains? visible t))))
- all-edges)
- edges (aggregate-edges raw-edges expanded)]
- {:focus (mapv str known)
- :unknown (mapv str unknown)
- :degree degree
- :expanded (mapv str expanded)
- :nodes nodes
- :edges edges
- :stats {:moduleCount (count visible)
- :edgeCount (count edges)
- :rawEdges (count raw-edges)}}))))
-
-(defn full-graph
- "Return the full module graph with all nodes (modules + api namespaces) and all edges, unfiltered.
- Escape hatch for debugging; the normal interactive path is `focus-subgraph`."
- []
- (let [{:keys [module-nodes api-children all-edges]} (ensure-cache!)
- nodes (vec
- (mapcat (fn [[m mn]]
- (cons mn (get api-children m [])))
- module-nodes))]
- {:nodes nodes :edges all-edges}))
-
-;; --- HTML ---------------------------------------------------------------------------------------
-
-;; served from dev/resources/dev/module_viz.html — see that file for the full HTML/JS/CSS
-(def ^:private html-page
- (slurp (io/resource "dev/module_viz.html")))
-
-;; --- ring handler -------------------------------------------------------------------------------
-
-(defn- json-response [body]
- {:status 200
- :headers {"Content-Type" "application/json"
- "Cache-Control" "no-store"}
- :body (json/generate-string body)})
-
-(defn- html-response [body]
- {:status 200
- :headers {"Content-Type" "text/html; charset=utf-8"
- "Cache-Control" "no-store"}
- :body body})
-
-(defn- parse-query [qs]
- (when qs
- (into {}
- (for [pair (str/split qs #"&")
- :let [[k v] (str/split pair #"=" 2)]
- :when k]
- [k (try (java.net.URLDecoder/decode v)
- (catch IllegalArgumentException _
- v))]))))
-
-(defn handler
- "Ring handler. See ns-level docstring for endpoint contracts."
- [req]
- (try
- (let [uri (:uri req)
- q (parse-query (:query-string req))]
- (case uri
- "/" (html-response html-page)
- "/api/modules" (json-response (modules-list))
- "/api/focus" (json-response
- (focus-subgraph (some-> (get q "m") (str/split #","))
- (try (Integer/parseInt (or (get q "degree") "1"))
- (catch Exception _ 1))
- (when-let [exp (get q "expanded")]
- (set (remove str/blank? (str/split exp #","))))
- (parse-hidden (get q "hidden")
- (:module-nodes (ensure-cache!)))))
- "/api/full" (json-response (full-graph))
- {:status 404 :body "not found"}))
- (catch Exception e
- {:status 500
- :headers {"Content-Type" "application/json"}
- :body (json/generate-string {:error (.getMessage e)})})))
-
-;; --- server lifecycle ---------------------------------------------------------------------------
-
-(defonce ^:private server (atom nil))
-
-(defn stop! []
- (when-let [s @server]
- (.stop s)
- (reset! server nil)
- (println "module-viz server stopped"))
- nil)
-
-(defn start!
- "Start the visualization server. `:port` defaults to 4321. Opens browser unless `:open?` is false."
- [& {:keys [port open?] :or {port 4321 open? true}}]
- (stop!)
- (reset-cache!)
- (let [s (jetty/run-jetty #'handler {:port port :join? false})]
- (reset! server s)
- (let [url (str "http://localhost:" port "/")]
- (println "module-viz running at" url)
- (when open? (sh/sh "open" url))
- url)))
-
-(comment
- (start!)
- (stop!)
- (reset-cache!))
diff --git a/dev/test/metabase/core/modules_test.clj b/dev/test/metabase/core/modules_test.clj
index bd2b3c0414f..6ad7576c0f2 100644
--- a/dev/test/metabase/core/modules_test.clj
+++ b/dev/test/metabase/core/modules_test.clj
@@ -42,7 +42,7 @@
(let [teams (teams)
config (modules-config)]
(doseq [module (keys config)
- :let [team (dev.deps-graph/module-team config module)]]
+ :let [team (modules/module-team config module)]]
(testing (format "\n'%s' module" module)
(is (or (contains? teams team)
(contains? teams-to-reassign team))
@@ -54,7 +54,7 @@
parent.child.leaf {:team "Leaf"}
enterprise/parent {}
enterprise/standalone {:team "Enterprise"}}]
- (are [module team] (= team (dev.deps-graph/module-team config module))
+ (are [module team] (= team (modules/module-team config module))
'parent.child "Parent" ; inherited from the nearest configured ancestor
'parent.child.leaf "Leaf" ; an explicit team overrides its ancestors
'enterprise/parent "Parent" ; an EE companion inherits from its OSS parent
diff --git a/mage/src/mage/modules.clj b/mage/src/mage/modules.clj
index f7fe38fa3dc..3e2c7dffcd3 100644
--- a/mage/src/mage/modules.clj
+++ b/mage/src/mage/modules.clj
@@ -4,6 +4,7 @@
[clojure.java.io :as io]
[clojure.set :as set]
[clojure.string :as str]
+ [dev.module-explorer :as module-explorer]
[hooks.common.modules :as modules]
[mage.be-dev :as be-dev]
[mage.color :as c]
@@ -264,27 +265,6 @@
;;;; Module tree
;;;; =============================================================================
-(defn- module->tree-path
- "The path segments used to display `module` in the tree.
-
- An enterprise module appears under its OSS counterpart when one exists.
- Otherwise its full `enterprise/` name appears at the root."
- [modules-config module]
- (let [segments (str/split (name module) #"\.")]
- (if (= (namespace module) "enterprise")
- (if (contains? modules-config (symbol (first segments)))
- ;; Keep an enterprise subtree together under its OSS module.
- (into [(first segments) "enterprise"] (rest segments))
- (into [(str "enterprise/" (first segments))] (rest segments)))
- segments)))
-
-(defn- explicit-ns-prefix
- "Return a module's custom `:ns-prefix`, or `nil` when it uses the default."
- [modules-config module]
- (let [prefix (get-in modules-config [module :ns-prefix])]
- (when (and prefix (not= prefix (modules/default-ns-prefix module)))
- prefix)))
-
(defn- module-display-tree
"Build the nested map consumed by [[tree-node-lines]].
@@ -292,7 +272,9 @@
[modules-config]
(reduce (fn [tree module]
(update-in tree
- (into [] (mapcat (fn [segment] [:children segment])) (module->tree-path modules-config module))
+ (into []
+ (mapcat (fn [segment] [:children segment]))
+ (module-explorer/module->tree-path modules-config module))
assoc :module module))
{}
(keys modules-config)))
@@ -319,7 +301,7 @@
line (str (when (pos? depth)
(str (apply str (repeat depth "-")) " "))
(if module display (c/dark display))
- (when-let [prefix (and module (explicit-ns-prefix modules-config module))]
+ (when-let [prefix (and module (module-explorer/explicit-ns-prefix modules-config module))]
(if show-prefixes?
(str " " (c/yellow (str "(" prefix ")")))
(str " " (c/yellow "*")))))]
@@ -328,16 +310,31 @@
(tree-node-lines modules-config show-prefixes? (conj path segment) child)))
(sorted-children node))))
+(defn- write-explorer!
+ "Write the HTML explorer to `output`, or to stdout, and exit."
+ [modules-config {:keys [output no-stats]}]
+ (let [html (module-explorer/page (module-explorer/explorer-data modules-config {:stats? (not no-stats)}))]
+ (if output
+ (do (spit output html)
+ (println (c/green (str "Wrote " output))))
+ (do (print html)
+ ;; u/exit throws for bb to catch, which skips the flush at shutdown
+ (flush)))
+ (u/exit 0)))
+
(defn cli-print-module-tree
"Print the module tree, nesting enterprise extensions under their OSS module.
- Marks modules whose namespace prefix differs from their name."
+ Marks modules whose namespace prefix differs from their name.
+ With `--html`, writes the interactive explorer instead."
[{:keys [options] :as _parsed}]
+ (when (:html options)
+ (write-explorer! (read-modules-config) options))
(let [modules-config (read-modules-config)
tree (module-display-tree modules-config)
roots (cond->> (sorted-children tree)
(:nested-only options) (filter (fn [[_ node]] (seq (:children node)))))
- starred (count (keep #(explicit-ns-prefix modules-config %) (keys modules-config)))]
+ starred (count (keep #(module-explorer/explicit-ns-prefix modules-config %) (keys modules-config)))]
(doseq [[segment node] roots
line (tree-node-lines modules-config (:prefixes options) [segment] node)]
(println line))
diff --git a/mage/test/mage/module_explorer_state_test.js b/mage/test/mage/module_explorer_state_test.js
new file mode 100644
index 00000000000..8d9d0230dde
--- /dev/null
+++ b/mage/test/mage/module_explorer_state_test.js
@@ -0,0 +1,40 @@
+'use strict';
+
+const assert = require('node:assert/strict');
+const {
+ decodeExplorerState,
+ encodeExplorerState,
+} = require('../../../dev/resources/dev/module_explorer_state.js');
+
+const validIds = new Set(['core', 'lib']);
+const validTeams = new Set(['DevEx', 'Querying']);
+
+const encoded = encodeExplorerState({
+ selected: 'core',
+ view: 'graph',
+ focus: new Set(),
+ degree: 2,
+ expanded: new Set(['core']),
+ hidden: new Set(['lib']),
+ hideRe: 'enterprise/',
+ teams: new Set(['Querying', 'DevEx']),
+});
+const decoded = decodeExplorerState('#' + encoded, validIds, validTeams);
+
+assert.equal(decoded.selected, 'core');
+assert.equal(decoded.view, 'graph');
+assert.deepEqual(decoded.focus, new Set());
+assert.equal(decoded.focusSpecified, true);
+assert.equal(decoded.degree, 2);
+assert.deepEqual(decoded.expanded, new Set(['core']));
+assert.deepEqual(decoded.hidden, new Set(['lib']));
+assert.equal(decoded.hideRe, 'enterprise/');
+assert.deepEqual(decoded.teams, new Set(['DevEx', 'Querying']));
+
+const legacy = decodeExplorerState('#m=core&view=graph', validIds, validTeams);
+assert.equal(legacy.focusSpecified, false);
+
+const invalid = decodeExplorerState('#m=unknown&focus=core,unknown&team=Unknown', validIds, validTeams);
+assert.equal(invalid.selected, null);
+assert.deepEqual(invalid.focus, new Set(['core']));
+assert.deepEqual(invalid.teams, new Set());
diff --git a/mage/test/mage/modules_test.clj b/mage/test/mage/modules_test.clj
index 4bca4879b3e..8c2a6dba39c 100644
--- a/mage/test/mage/modules_test.clj
+++ b/mage/test/mage/modules_test.clj
@@ -2,7 +2,10 @@
"Tests for driver decision logic.
Run `mage -driver-decisions -h` to see the priority order."
(:require
+ [clojure.java.shell :as shell]
+ [clojure.string :as str]
[clojure.test :refer [deftest is testing]]
+ [dev.module-explorer :as module-explorer]
[hooks.common.modules :as modules]
[mage.color]
[mage.modules]))
@@ -361,11 +364,76 @@
(deftest module-tree-enterprise-default-prefix-not-starred-test
(testing "default enterprise prefixes are not marked as custom"
- (is (nil? (#'mage.modules/explicit-ns-prefix '{enterprise/billing {}} 'enterprise/billing)))
- (is (nil? (#'mage.modules/explicit-ns-prefix '{enterprise/billing {:ns-prefix "metabase-enterprise.billing"}}
- 'enterprise/billing)))
+ (is (nil? (module-explorer/explicit-ns-prefix '{enterprise/billing {}} 'enterprise/billing)))
+ (is (nil? (module-explorer/explicit-ns-prefix '{enterprise/billing {:ns-prefix "metabase-enterprise.billing"}}
+ 'enterprise/billing)))
(is (= "metabase.lib-be"
- (#'mage.modules/explicit-ns-prefix '{lib.be {:ns-prefix "metabase.lib-be"}} 'lib.be)))))
+ (module-explorer/explicit-ns-prefix '{lib.be {:ns-prefix "metabase.lib-be"}} 'lib.be)))))
+
+(deftest explorer-data-test
+ (let [config '{core {:uses :any, :team "Core"}
+ widget {:uses #{gadget}, :api #{metabase.widget.core}}
+ gadget {:uses #{}, :team "Gadgets", :ns-prefix "metabase.gizmo"}
+ gadget.part {:uses #{gadget}}
+ enterprise/gadget {:uses #{gadget}}
+ enterprise/cloud {:uses #{}}}
+ modules (into {} (map (juxt :id identity)) (:modules (module-explorer/explorer-data config {})))]
+ (testing ":uses :any remains unresolved without source data"
+ (is (empty? (get-in modules ["core" :uses])))
+ (is (= ["enterprise/gadget" "gadget.part" "widget"]
+ (get-in modules ["gadget" :used-by]))))
+ (testing "teams are inherited from the nearest ancestor"
+ (is (= "Gadgets" (get-in modules ["gadget.part" :team])))
+ (is (= "Gadgets" (get-in modules ["enterprise/gadget" :team]))))
+ (testing "tree paths nest children and keep enterprise companions under their OSS module"
+ (is (= ["gadget" "part"] (get-in modules ["gadget.part" :path])))
+ (is (= ["gadget" "enterprise"] (get-in modules ["enterprise/gadget" :path])))
+ (is (= ["enterprise/cloud"] (get-in modules ["enterprise/cloud" :path]))))
+ (testing "only custom prefixes are reported"
+ (is (= "metabase.gizmo" (get-in modules ["gadget" :ns-prefix])))
+ (is (nil? (get-in modules ["widget" :ns-prefix]))))
+ (testing "an omitted :api uses the same defaults as the module linter"
+ (is (= ["metabase.gizmo.api" "metabase.gizmo.core" "metabase.gizmo.init"]
+ (get-in modules ["gadget" :api]))))))
+
+(deftest explorer-data-with-namespace-edges-test
+ (let [config '{core {:uses :any}
+ widget {:uses #{gadget}}
+ gadget {:uses #{}}}
+ edges [["core" "gadget" "metabase.gadget.core"]
+ ["widget" "gadget" "metabase.gadget.core"]]
+ modules (into {}
+ (map (juxt :id identity))
+ (:modules (module-explorer/explorer-data config {:ns-edges edges})))]
+ (testing "observed namespace edges resolve unrestricted and reverse dependencies"
+ (is (= ["gadget"] (get-in modules ["core" :uses])))
+ (is (= ["core" "widget"] (get-in modules ["gadget" :used-by]))))))
+
+(deftest explorer-file->module-test
+ (let [file->module #'module-explorer/file->module
+ prefix->module (modules/build-prefix->module '{lib {} lib.schema {} driver {}})]
+ (testing "files resolve through the declared prefixes, tests included"
+ (is (= 'lib.schema (file->module prefix->module "src/metabase/lib/schema/join.cljc")))
+ (is (= 'lib.schema (file->module prefix->module "test/metabase/lib/schema_test.cljc")))
+ (is (= 'lib (file->module prefix->module "src/metabase/lib/core.cljc"))))
+ (testing "driver-plugin files belong to the driver module regardless of namespace"
+ (is (= 'driver (file->module prefix->module "modules/drivers/mysql/src/metabase/driver/mysql.clj")))
+ (is (= 'driver (file->module prefix->module "modules/drivers/mysql/test/metabase/test/data/mysql.clj"))))))
+
+(deftest explorer-page-test
+ (let [html (module-explorer/page {:modules [{:id "</script>"}]})]
+ (testing "the data and state codec replace their placeholders"
+ (is (not (str/includes? html "/*DATA*/null")))
+ (is (not (str/includes? html "/*STATE-CODEC*/")))
+ (is (str/includes? html "<\\/script>")))))
+
+(deftest explorer-git-failure-test
+ (is (thrown-with-msg? Exception #"Git failed:"
+ (#'module-explorer/git-output! "not-a-real-git-subcommand"))))
+
+(deftest explorer-state-codec-test
+ (let [{:keys [exit out err]} (shell/sh "node" "mage/test/mage/module_explorer_state_test.js")]
+ (is (zero? exit) (str out err))))
(deftest dotted-module-files-mark-correct-module-changes
(testing "dotted module files resolve to the dotted module when its prefix exists"
diff --git a/test/metabase/core/modules_consistency_test.clj b/test/metabase/core/modules_consistency_test.clj
index 06870ed649d..c73c41546ee 100644
--- a/test/metabase/core/modules_consistency_test.clj
+++ b/test/metabase/core/modules_consistency_test.clj
@@ -175,12 +175,12 @@
{"metabase.lib.schema" 'lib.schema}
["test/metabase/lib/schema_test.cljc"])))))))
-(deftest ^:parallel log-team-attribution-agrees-with-deps-graph-test
- (testing "logging and dev tooling assign the same team to every module"
+(deftest ^:parallel log-team-attribution-agrees-with-hook-test
+ (testing "logging and the shared resolver assign the same team to every module"
(let [config (dev.deps-graph/kondo-config)]
(is (< 100 (count config)) "expected the full module config")
(doseq [module (sort (keys config))
:let [ns-symb (symbol (modules/module-ns-prefix config module))]]
(testing (str "\n" ns-symb)
- (is (= (dev.deps-graph/module-team config module)
+ (is (= (modules/module-team config module)
(log/ns->team* ns-symb))))))))
diff --git a/test/metabase/core/modules_nesting_test.clj b/test/metabase/core/modules_nesting_test.clj
index ac006c9eea5..747e70dd07b 100644
--- a/test/metabase/core/modules_nesting_test.clj
+++ b/test/metabase/core/modules_nesting_test.clj
@@ -69,6 +69,20 @@
(is (= "metabase.lib-be" (modules/module-ns-prefix modules 'lib.be)))
(is (= "metabase.lib.schema" (modules/module-ns-prefix modules 'lib.schema)))))
+(deftest ^:parallel module-api-namespaces-test
+ (let [modules '{default {}
+ custom {:ns-prefix "metabase.renamed"}
+ explicit {:api #{metabase.explicit.core}}
+ open {:api :any}}]
+ (testing "an omitted API uses the module namespace prefix defaults"
+ (is (= '#{metabase.default.api metabase.default.core metabase.default.init}
+ (modules/module-api-namespaces modules 'default)))
+ (is (= '#{metabase.renamed.api metabase.renamed.core metabase.renamed.init}
+ (modules/module-api-namespaces modules 'custom))))
+ (testing "explicit and unrestricted APIs retain their configured meaning"
+ (is (= '#{metabase.explicit.core} (modules/module-api-namespaces modules 'explicit)))
+ (is (nil? (modules/module-api-namespaces modules 'open))))))
+
(deftest ^:parallel module-resolution-explicit-ns-prefix-test
(let [config {:metabase/modules {'lib {}
'lib.schema {}