Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

refactor(kg): stop computing a layout the canvas never reads (#1827)

Raghav Chamadiyaac34b6860a78
diff --git a/packages/server/src/repowise/server/routers/c4.py b/packages/server/src/repowise/server/routers/c4.py
index 039a4efe6..f3bd0f3b6 100644
--- a/packages/server/src/repowise/server/routers/c4.py
+++ b/packages/server/src/repowise/server/routers/c4.py
@@ -30,7 +30,6 @@ from repowise.server.schemas import (
ZoomMapResponse,
ZoomMetricsResponse,
ZoomNodeResponse,
- ZoomRectResponse,
ZoomRelationResponse,
)
from repowise.server.services import c4_builder
@@ -297,16 +296,6 @@ def _zoom_response(zoom: ZoomMap) -> ZoomMapResponse:
entry_point_count=n.metrics.entry_point_count,
on_flow_count=n.metrics.on_flow_count,
),
- layout=(
- ZoomRectResponse(
- x=round(n.layout.x, 6),
- y=round(n.layout.y, 6),
- w=round(n.layout.w, 6),
- h=round(n.layout.h, 6),
- )
- if n.layout is not None
- else None
- ),
summary=n.summary,
language=n.language,
health_score=(round(n.health_score, 2) if n.health_score is not None else None),
diff --git a/packages/server/src/repowise/server/schemas/__init__.py b/packages/server/src/repowise/server/schemas/__init__.py
index 4a64e017a..2d714e80b 100644
--- a/packages/server/src/repowise/server/schemas/__init__.py
+++ b/packages/server/src/repowise/server/schemas/__init__.py
@@ -219,7 +219,6 @@ from .zoom import (
ZoomMapResponse,
ZoomMetricsResponse,
ZoomNodeResponse,
- ZoomRectResponse,
ZoomRelationResponse,
)
@@ -393,6 +392,5 @@ __all__ = [
"ZoomMapResponse",
"ZoomMetricsResponse",
"ZoomNodeResponse",
- "ZoomRectResponse",
"ZoomRelationResponse",
]
diff --git a/packages/server/src/repowise/server/schemas/zoom.py b/packages/server/src/repowise/server/schemas/zoom.py
index 4c7130bd3..4d5dd2bb1 100644
--- a/packages/server/src/repowise/server/schemas/zoom.py
+++ b/packages/server/src/repowise/server/schemas/zoom.py
@@ -3,9 +3,9 @@
One nested containment tree (system -> layer -> group -> folder -> file) served
as a flat list of nodes (each carrying its own id), plus parent-relative
relations. The canvas renderer indexes the list by id and reconstructs the tree
-from ``parent_id`` / ``children``, then uses ``layout`` (parent ``[0,1]`` space)
-for clip-and-scale and ``importance`` / ``sibling_rank`` for density caps. The
-list is emitted in a stable order (sorted by id).
+from ``parent_id`` / ``children``, lays the children out itself, and uses
+``importance`` / ``sibling_rank`` for density caps. The list is emitted in a
+stable order (sorted by id).
"""
from __future__ import annotations
@@ -13,13 +13,6 @@ from __future__ import annotations
from pydantic import BaseModel, Field
-class ZoomRectResponse(BaseModel):
- x: float
- y: float
- w: float
- h: float
-
-
class ZoomMetricsResponse(BaseModel):
file_count: int = 0
descendant_count: int = 0
@@ -40,7 +33,6 @@ class ZoomNodeResponse(BaseModel):
importance: float = 0.0
sibling_rank: int = 0
metrics: ZoomMetricsResponse = Field(default_factory=ZoomMetricsResponse)
- layout: ZoomRectResponse | None = None
summary: str = ""
language: str | None = None
# Code-health score (0..10, higher = healthier), matching the /files treemap.
diff --git a/packages/server/src/repowise/server/services/zoom_builder/__init__.py b/packages/server/src/repowise/server/services/zoom_builder/__init__.py
index bda92f839..d944558d8 100644
--- a/packages/server/src/repowise/server/services/zoom_builder/__init__.py
+++ b/packages/server/src/repowise/server/services/zoom_builder/__init__.py
@@ -4,13 +4,13 @@ Public API
----------
``build_zoom_map(session, repo, *, max_depth=None, focus=None)`` returns the
nested containment tree (system -> layer -> group -> folder -> file) with
-execution-aware importance, rolled-up metrics, parent-relative relations, and a
-deterministic treemap layout.
+execution-aware importance, rolled-up metrics and parent-relative relations.
+Placement is the canvas's job, not this service's.
Like :mod:`c4_builder`, the map is derived ON DEMAND from the persisted graph
(it reuses ``c4_builder.build_architecture_view`` for the heavy load), so it
works on hosted backends with no checkout and never goes stale. Everything below
-the load is pure functions (tree / scoring / metrics / relations / layout) that
+the load is pure functions (tree / scoring / metrics / relations) that
unit-test without a session.
"""
@@ -21,7 +21,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
from repowise.server.services.c4_builder.architecture import build_architecture_view
from repowise.server.services.c4_builder.models import ArchitectureView
-from .layout import lay_out
from .metrics import rollup_health, rollup_metrics
from .models import ZoomMap, ZoomNode, ZoomRelation
from .relations import aggregate_relations
@@ -133,7 +132,6 @@ def assemble_zoom_map(
nodes = rollup_metrics(root_id, nodes)
nodes = rollup_health(root_id, nodes)
nodes = score_tree(root_id, nodes, signals)
- nodes = lay_out(root_id, nodes)
relations = aggregate_relations(nodes, edges)
# Honest count of files actually placed in the tree (a file the view knows
diff --git a/packages/server/src/repowise/server/services/zoom_builder/layout.py b/packages/server/src/repowise/server/services/zoom_builder/layout.py
deleted file mode 100644
index ef936f553..000000000
--- a/packages/server/src/repowise/server/services/zoom_builder/layout.py
+++ /dev/null
@@ -1,111 +0,0 @@
-"""Deterministic squarified-treemap layout for the zoom map.
-
-Each parent's children are packed into the parent's unit ``[0,1]`` rectangle,
-with area proportional to ``importance`` (so the execution-relevant nodes the
-scorer surfaced are also the biggest boxes). Rectangles are emitted in parent
-space; the renderer maps a child straight to screen by scaling content by
-``(w, h)`` and translating by ``(x, y)`` (clip-and-scale recursion).
-
-Squarified treemap (Bruls, Huizing, van Wijk) keeps boxes close to square so
-labels stay readable. The squarify pass itself is iterative so a single flat
-folder with thousands of files cannot blow the recursion limit; the tree walk
-(``place_children``) recurses one frame per *level*, which the single-child
-chain compression in ``tree.py`` keeps shallow. Pure, deterministic, no DB.
-"""
-
-from __future__ import annotations
-
-from dataclasses import replace
-
-from .models import ZoomNode, ZoomRect
-
-_EPS = 1e-9
-
-
-def _worst(row: list[float], length: float) -> float:
- """Worst aspect ratio of a row of areas laid along a side of ``length``."""
- if length <= 0:
- return float("inf")
- total = sum(row)
- if total <= 0:
- return float("inf")
- side = total / length
- worst = 0.0
- for area in row:
- other = area / side if side > 0 else 0.0
- if other <= 0:
- return float("inf")
- ratio = max(side / other, other / side)
- worst = max(worst, ratio)
- return worst
-
-
-def _emit_row(
- row: list[float], x: float, y: float, dx: float, dy: float
-) -> tuple[list[tuple[float, float, float, float]], tuple[float, float, float, float]]:
- """Place ``row`` along the shorter side; return its rects + the leftover."""
- total = sum(row)
- rects: list[tuple[float, float, float, float]] = []
- if dx >= dy: # lay the row as a vertical column of fixed width
- width = total / dy if dy > 0 else 0.0
- yy = y
- for area in row:
- h = area / width if width > 0 else 0.0
- rects.append((x, yy, width, h))
- yy += h
- return rects, (x + width, y, dx - width, dy)
- # lay the row as a horizontal strip of fixed height
- height = total / dx if dx > 0 else 0.0
- xx = x
- for area in row:
- w = area / height if height > 0 else 0.0
- rects.append((xx, y, w, height))
- xx += w
- return rects, (x, y + height, dx, dy - height)
-
-
-def _squarify(areas: list[float], x: float, y: float, dx: float, dy: float) -> list[tuple]:
- """Lay out ``areas`` (summing to ``dx*dy``, sorted desc) into rectangles."""
- rects: list[tuple] = []
- remaining = list(areas)
- while remaining:
- if dx <= 0 or dy <= 0:
- # Degenerate strip: stack the rest with zero area (keeps positions).
- for _ in remaining:
- rects.append((x, y, 0.0, 0.0))
- break
- shorter = min(dx, dy)
- row: list[float] = [remaining[0]]
- i = 1
- while i < len(remaining):
- if _worst(row, shorter) < _worst([*row, remaining[i]], shorter):
- break
- row.append(remaining[i])
- i += 1
- placed, (x, y, dx, dy) = _emit_row(row, x, y, dx, dy)
- rects.extend(placed)
- remaining = remaining[i:]
- return rects
-
-
-def lay_out(root_id: str, nodes: dict[str, ZoomNode]) -> dict[str, ZoomNode]:
- """Return ``nodes`` with a ``layout`` rect on every node (parent space)."""
- updated: dict[str, ZoomNode] = dict(nodes)
- updated[root_id] = replace(updated[root_id], layout=ZoomRect(0.0, 0.0, 1.0, 1.0))
-
- def place_children(node_id: str) -> None:
- node = updated[node_id]
- children = list(node.children)
- if children:
- ordered = sorted(children, key=lambda c: (-updated[c].importance, updated[c].name))
- weights = [updated[c].importance + _EPS for c in ordered]
- total = sum(weights)
- areas = [w / total for w in weights] # sum to 1 == unit-square area
- rects = _squarify(areas, 0.0, 0.0, 1.0, 1.0)
- for cid, (rx, ry, rw, rh) in zip(ordered, rects, strict=True):
- updated[cid] = replace(updated[cid], layout=ZoomRect(rx, ry, rw, rh))
- for cid in children:
- place_children(cid)
-
- place_children(root_id)
- return updated
diff --git a/packages/server/src/repowise/server/services/zoom_builder/models.py b/packages/server/src/repowise/server/services/zoom_builder/models.py
index da68d30a0..5eb4fa6bb 100644
--- a/packages/server/src/repowise/server/services/zoom_builder/models.py
+++ b/packages/server/src/repowise/server/services/zoom_builder/models.py
@@ -1,7 +1,7 @@
"""Plain dataclasses produced by the zoom-map builder.
Framework-agnostic (no Pydantic, no SQLAlchemy) so the pure tree / scoring /
-layout / relation functions unit-test without a session, mirroring
+metric / relation functions unit-test without a session, mirroring
``c4_builder.models``. The router wraps these into Pydantic response models.
The zoom map is one nested containment tree:
@@ -10,8 +10,8 @@ The zoom map is one nested containment tree:
Every node carries an execution-aware ``importance`` (0..1) and a
``sibling_rank`` so the renderer can cap how many children it draws at each
-zoom depth, plus a deterministic ``layout`` rect (parent ``[0,1]`` space) for
-the clip-and-scale canvas.
+zoom depth. Placement is not here: the canvas packs each parent's children
+itself, from those two fields.
"""
from __future__ import annotations
@@ -22,20 +22,6 @@ from dataclasses import dataclass, field
NODE_KINDS = ("system", "layer", "group", "folder", "file")
-@dataclass(frozen=True)
-class ZoomRect:
- """A child's allocation inside its parent, in parent ``[0,1]`` space.
-
- The renderer maps this straight to screen space: scale child content by
- ``(w, h)`` and translate by ``(x, y)`` (clip-and-scale recursion).
- """
-
- x: float
- y: float
- w: float
- h: float
-
-
@dataclass(frozen=True)
class ZoomMetrics:
"""Counts rolled up over a node's subtree (a file is its own subtree)."""
@@ -62,7 +48,6 @@ class ZoomNode:
importance: float = 0.0 # 0..1, execution-aware, normalized within siblings
sibling_rank: int = 0 # 1 = most important among siblings
metrics: ZoomMetrics = field(default_factory=ZoomMetrics)
- layout: ZoomRect | None = None
summary: str = ""
language: str | None = None
# Code-health score on the 0..10 scale (higher = healthier), matching the
diff --git a/packages/server/src/repowise/server/services/zoom_builder/tree.py b/packages/server/src/repowise/server/services/zoom_builder/tree.py
index 325ecaca8..519bcbb9f 100644
--- a/packages/server/src/repowise/server/services/zoom_builder/tree.py
+++ b/packages/server/src/repowise/server/services/zoom_builder/tree.py
@@ -12,7 +12,7 @@ This is deliberately NOT ``derive_modules`` (which right-sizes wiki modules to
zoom folder by folder.
Pure and framework-agnostic: inputs are plain specs, output is a dict of frozen
-``ZoomNode``. Importance, metrics, and layout are filled by later passes.
+``ZoomNode``. Importance and metrics are filled by later passes.
"""
from __future__ import annotations
diff --git a/packages/ui/__tests__/zoom/cull.test.ts b/packages/ui/__tests__/zoom/cull.test.ts
index 1c0deea3d..1196bb9fa 100644
--- a/packages/ui/__tests__/zoom/cull.test.ts
+++ b/packages/ui/__tests__/zoom/cull.test.ts
@@ -39,7 +39,6 @@ function leaf(id: string, rank: number): ZoomNode {
entry_point_count: 0,
on_flow_count: 0,
},
- layout: { x: 0, y: 0, w: 1, h: 1 },
summary: "",
language: null,
is_entry_point: false,
diff --git a/packages/ui/__tests__/zoom/focus-path.test.ts b/packages/ui/__tests__/zoom/focus-path.test.ts
index 9429b687f..7f5a933a2 100644
--- a/packages/ui/__tests__/zoom/focus-path.test.ts
+++ b/packages/ui/__tests__/zoom/focus-path.test.ts
@@ -23,7 +23,6 @@ function node(id: string, children: string[]): ZoomNode {
entry_point_count: 0,
on_flow_count: 0,
},
- layout: null,
summary: "",
language: null,
is_entry_point: false,
diff --git a/packages/ui/__tests__/zoom/geometry.test.ts b/packages/ui/__tests__/zoom/geometry.test.ts
index 957dff796..a6e5ecbfb 100644
--- a/packages/ui/__tests__/zoom/geometry.test.ts
+++ b/packages/ui/__tests__/zoom/geometry.test.ts
@@ -7,7 +7,7 @@ import {
} from "../../src/zoom/geometry";
import type { ZoomNode } from "../../src/zoom/types";
-function node(id: string, parent: string | null, children: string[], layout: ZoomNode["layout"]): ZoomNode {
+function node(id: string, parent: string | null, children: string[]): ZoomNode {
return {
id,
parent_id: parent,
@@ -26,7 +26,6 @@ function node(id: string, parent: string | null, children: string[], layout: Zoo
entry_point_count: 0,
on_flow_count: 0,
},
- layout,
summary: "",
language: null,
is_entry_point: false,
@@ -49,10 +48,10 @@ describe("composeRect", () => {
describe("computeWorldRects", () => {
it("lays children out within their parent's rect, recursively", () => {
const nodes = new Map<string, ZoomNode>([
- ["root", node("root", null, ["a", "b"], null)],
- ["a", node("a", "root", ["a1"], null)],
- ["b", node("b", "root", [], null)],
- ["a1", node("a1", "a", [], null)],
+ ["root", node("root", null, ["a", "b"])],
+ ["a", node("a", "root", ["a1"])],
+ ["b", node("b", "root", [])],
+ ["a1", node("a1", "a", [])],
]);
const rects = computeWorldRects(nodes, "root");
expect(rects.get("root")).toEqual({ x: 0, y: 0, w: 1, h: 1 });
@@ -69,17 +68,17 @@ describe("computeWorldRects", () => {
};
within("a", "root");
within("b", "root");
- within("a1", "a"); // grid layout composes through every depth
+ within("a1", "a"); // the pack composes through every depth
});
- it("lays out a node even when the backend gave it no layout rect", () => {
+ it("places only the children it can reach from the root", () => {
const nodes = new Map<string, ZoomNode>([
- ["root", node("root", null, ["a", "ghost"], null)],
- ["a", node("a", "root", [], null)], // null backend layout -> still placed
- ["orphan", node("orphan", "nope", [], null)],
+ ["root", node("root", null, ["a", "ghost"])],
+ ["a", node("a", "root", [])],
+ ["orphan", node("orphan", "nope", [])],
]);
const rects = computeWorldRects(nodes, "root");
- expect(rects.has("a")).toBe(true); // layout is computed client-side now
+ expect(rects.has("a")).toBe(true);
expect(rects.has("ghost")).toBe(false); // referenced but absent
expect(rects.has("orphan")).toBe(false); // not reachable from root
});
diff --git a/packages/ui/__tests__/zoom/node-signals.test.ts b/packages/ui/__tests__/zoom/node-signals.test.ts
index dfffc4ab3..54692a126 100644
--- a/packages/ui/__tests__/zoom/node-signals.test.ts
+++ b/packages/ui/__tests__/zoom/node-signals.test.ts
@@ -20,9 +20,9 @@ const METRICS: ZoomMetrics = {
* The return is not cast. The `as ZoomNode` that used to sit here accepted an
* object that did not describe a `ZoomNode` at all: `metrics` was missing
* `descendant_count`, `summary` was null against a `string`, `importance` and
- * `sibling_rank` were absent, and `rect` is not a field (the node's box is
- * `layout`). Only the one override call site ever errored, and only in the
- * type-check job, which does not run on pull requests.
+ * `sibling_rank` were absent, and `rect` is not a field (a node carries no box
+ * at all; the pack computes one). Only the one override call site ever errored,
+ * and only in the type-check job, which does not run on pull requests.
*/
function node(
over: Omit<Partial<ZoomNode>, "metrics"> & { metrics?: Partial<ZoomMetrics> } = {},
@@ -38,7 +38,6 @@ function node(
children: [],
importance: 0,
sibling_rank: 0,
- layout: null,
summary: "",
language: null,
health_score: null,
diff --git a/packages/ui/src/zoom/ZoomCanvas.tsx b/packages/ui/src/zoom/ZoomCanvas.tsx
index a6b690232..c84789c7f 100644
--- a/packages/ui/src/zoom/ZoomCanvas.tsx
+++ b/packages/ui/src/zoom/ZoomCanvas.tsx
@@ -24,7 +24,7 @@ import { buildScene } from "./scene";
import { resolveZoomPalette } from "./theme";
import type { ZoomMap, ZoomNode, ZoomRelation } from "./types";
import { describeRelations, summarizeRelations } from "./relation-summary";
-import { healthBandLabel, nodeRoles } from "./node-signals";
+import { healthBandLabel, KIND_LABEL, nodeRoles } from "./node-signals";
import { useThemeVersion } from "../shared/use-theme-tokens";
export interface ZoomCanvasHandle {
@@ -370,14 +370,6 @@ export const ZoomCanvas = forwardRef<ZoomCanvasHandle, ZoomCanvasProps>(function
);
});
-const HOVER_KIND_LABEL: Record<ZoomNode["kind"], string> = {
- system: "System",
- layer: "Layer",
- group: "Group",
- folder: "Folder",
- file: "File",
-};
-
/**
* A deliberately light tooltip: kind, name, path, a one-line summary and, when
* the host supplies the index, what this box's arrows mean. The full metric
@@ -413,7 +405,7 @@ function HoverCard({
style={{ left: hover.sx, top: hover.sy, transform: `translate(${tx}, ${ty})` }}
>
<div className="font-mono text-[10px] uppercase tracking-[0.12em] text-[var(--color-text-tertiary)]">
- {HOVER_KIND_LABEL[node.kind]}
+ {KIND_LABEL[node.kind]}
</div>
<div className="mt-0.5 font-semibold text-[var(--color-text-primary)]">{node.name}</div>
{node.path && node.path !== node.name && (
diff --git a/packages/ui/src/zoom/cull.ts b/packages/ui/src/zoom/cull.ts
index 5a43e1765..2491262ff 100644
--- a/packages/ui/src/zoom/cull.ts
+++ b/packages/ui/src/zoom/cull.ts
@@ -26,7 +26,7 @@ export function isOnScreen(screenRect: Rect, vp: Viewport, margin = CULL_MARGIN_
* Choose which children to draw: the top `cap` by `sibling_rank` (1 = most
* important). Pure and deterministic; ties break by id so the selection is
* stable frame-to-frame. Returns the ids in their original child order so the
- * treemap layout (which the renderer reads from each node) still lines up.
+ * pack layout, which places children in that order, still lines up.
*/
export function selectChildren(
children: readonly ZoomNode[],
diff --git a/packages/ui/src/zoom/geometry.ts b/packages/ui/src/zoom/geometry.ts
index f53bbeda4..1e9a9ddcb 100644
--- a/packages/ui/src/zoom/geometry.ts
+++ b/packages/ui/src/zoom/geometry.ts
@@ -1,8 +1,8 @@
/**
* Pure containment-tree geometry. Browser-free and unit-testable.
*
- * The backend gives every node a `layout` rect in its parent's `[0,1]` space.
- * Composed down the tree this yields each node's **absolute world rect** inside
+ * `layout.ts` packs each parent's children into rects in that parent's `[0,1]`
+ * space. Composed down the tree this yields each node's **absolute world rect** inside
* the root unit square. We precompute those once per scene; culling, the fade
* `t`, hit-testing and "zoom to node" all read them, while the draw pass uses
* the same rects to set each node's clip-and-scale transform.
@@ -30,8 +30,7 @@ const ROOT_RECT: Rect = { x: 0, y: 0, w: 1, h: 1 };
* Each node's children are laid out client-side as an importance-weighted
* masonry pack (see `layout.ts`) keyed off the parent's world aspect, then
* composed into world space, so card size encodes importance and the rows
- * stagger. The backend treemap rects are intentionally ignored; unreachable
- * nodes are skipped.
+ * stagger. Nodes unreachable from the root are skipped.
*/
export function computeWorldRects(
nodes: Map<string, ZoomNode>,
diff --git a/packages/ui/src/zoom/index.ts b/packages/ui/src/zoom/index.ts
index 080b04083..0a7b5b5f7 100644
--- a/packages/ui/src/zoom/index.ts
+++ b/packages/ui/src/zoom/index.ts
@@ -29,7 +29,7 @@ export {
} from "./relation-summary";
export type { RelationSummary, VerbCount } from "./relation-summary";
-export { hasRole, healthBandLabel, nodeRoles } from "./node-signals";
+export { hasRole, healthBandLabel, KIND_LABEL, nodeRoles } from "./node-signals";
export { drawScene, pickNode } from "./draw-tree";
export type { DrawOptions, DrawStats, PickEntry } from "./draw-tree";
@@ -87,7 +87,6 @@ export { isOnScreen, selectChildren } from "./cull";
export type {
ZoomKind,
- ZoomRect,
ZoomMetrics,
ZoomNode,
ZoomRelation,
diff --git a/packages/ui/src/zoom/layout.ts b/packages/ui/src/zoom/layout.ts
index eea97158e..303ec4a12 100644
--- a/packages/ui/src/zoom/layout.ts
+++ b/packages/ui/src/zoom/layout.ts
@@ -1,16 +1,14 @@
/**
* Per-parent masonry pack layout. Pure, browser-free and unit-testable.
*
- * The backend ships a containment tree but its layout rects are a squarified
- * treemap (space-filling, extreme aspect ratios). We ignore those and lay each
- * parent's children out client-side instead: every card is sized by importance
- * (more central = bigger, within bounds so nothing is unreadably small) and the
- * cards are row-packed into centred, variable-width rows. The staggered row
- * edges and the size variation give an organic architecture-map feel rather than
- * a rigid grid, while the whole cluster is uniform-fit (aspect-preserving) into
- * the parent so cards keep a single landscape shape. The rect emitted is still in
- * parent `[0,1]` space, so the clip-and-scale composition in `geometry.ts` is
- * unchanged.
+ * The backend ships a containment tree and no placement. Every card is sized by
+ * importance (more central = bigger, within bounds so nothing is unreadably
+ * small) and the cards are row-packed into centred, variable-width rows. The
+ * staggered row edges and the size variation give an organic architecture-map
+ * feel rather than a rigid grid, while the whole cluster is uniform-fit
+ * (aspect-preserving) into the parent so cards keep a single landscape shape.
+ * The rect emitted is in parent `[0,1]` space, which is what the clip-and-scale
+ * composition in `geometry.ts` consumes.
*/
import type { Rect } from "./camera";
diff --git a/packages/ui/src/zoom/node-signals.ts b/packages/ui/src/zoom/node-signals.ts
index 8c3abbdd3..1325e2cd2 100644
--- a/packages/ui/src/zoom/node-signals.ts
+++ b/packages/ui/src/zoom/node-signals.ts
@@ -1,5 +1,5 @@
/**
- * What a card's two dots mean, in words. Pure, browser-free.
+ * What a card says about itself, in words. Pure, browser-free.
*
* A card carries two dots and nothing on the surface named either. Worse, they
* shared a palette: the role dot painted `--color-success` for "has an entry
@@ -15,7 +15,23 @@
*/
import { bandForScore, HEALTH_BAND_LABEL } from "@repowise-dev/types/health";
-import type { ZoomNode } from "./types";
+import type { ZoomKind, ZoomNode } from "./types";
+
+/**
+ * Human label per node kind.
+ *
+ * One record, because three surfaces name the same five kinds: the card footer
+ * the canvas draws, the hover tooltip over it, and the detail rail beside it. A
+ * reader moving between them is looking at one node, so a divergence here would
+ * read as three different things.
+ */
+export const KIND_LABEL: Record<ZoomKind, string> = {
+ system: "System",
+ layer: "Layer",
+ group: "Group",
+ folder: "Folder",
+ file: "File",
+};
/**
* Every role that applies to a node, most notable first. Empty when the node
diff --git a/packages/ui/src/zoom/nodes.ts b/packages/ui/src/zoom/nodes.ts
index 4cd9490fc..813fe7b14 100644
--- a/packages/ui/src/zoom/nodes.ts
+++ b/packages/ui/src/zoom/nodes.ts
@@ -17,7 +17,7 @@
import { ALERT_MAX, HEALTHY_MIN } from "@repowise-dev/types/health";
import type { Rect } from "./camera";
-import { hasRole } from "./node-signals";
+import { hasRole, KIND_LABEL } from "./node-signals";
import { ARROW_SIZE_PX, EDGE_LINE_PX } from "./constants";
import type { EdgeRoute } from "./edges";
import type { ZoomPalette } from "./theme";
@@ -32,15 +32,6 @@ const GLYPH_MIN_PX = 52; // draw the kind glyph beside the title once there is r
const FOOTER_MIN_W_PX = 132; // draw the bottom signal row on cards at least this wide
const FOOTER_MIN_H_PX = 104; // ...and at least this tall
-/** Human label per node kind, shown small in the card footer. */
-const KIND_LABEL: Record<ZoomKind, string> = {
- system: "System",
- layer: "Layer",
- group: "Group",
- folder: "Folder",
- file: "File",
-};
-
/**
* A minimal monoline glyph per node kind, drawn into the `[x, y, s, s]` box in the
* caller's current stroke style. Canvas-native rather than the KG cards' Lucide
diff --git a/packages/ui/src/zoom/types.ts b/packages/ui/src/zoom/types.ts
index 5ea27ecef..85017f011 100644
--- a/packages/ui/src/zoom/types.ts
+++ b/packages/ui/src/zoom/types.ts
@@ -3,10 +3,10 @@
*
* The backend serves one nested containment tree (system -> layer -> group ->
* folder -> file) as a flat list of nodes, each carrying its own `id`, plus
- * parent-relative `relations`. The renderer indexes the list by id and rebuilds
- * the tree from `parent_id` / `children`. Every node's `layout` rect is in its
- * parent's `[0,1]` space, which composes multiplicatively down the tree into an
- * absolute world rect for clip-and-scale drawing.
+ * parent-relative `relations`. The renderer indexes the list by id, rebuilds
+ * the tree from `parent_id` / `children`, and packs each parent's children
+ * itself (see `layout.ts`) into rects that compose multiplicatively down the
+ * tree into an absolute world rect for clip-and-scale drawing.
*
* Source of truth: `packages/server/src/repowise/server/schemas/zoom.py`.
*/
@@ -14,14 +14,6 @@
/** Node kinds, coarsest to finest. A leaf is always `file`. */
export type ZoomKind = "system" | "layer" | "group" | "folder" | "file";
-/** A child's allocation inside its parent, in parent `[0,1]` space. */
-export interface ZoomRect {
- x: number;
- y: number;
- w: number;
- h: number;
-}
-
/** Counts rolled up over a node's subtree (a file is its own subtree). */
export interface ZoomMetrics {
file_count: number;
@@ -43,7 +35,6 @@ export interface ZoomNode {
importance: number;
sibling_rank: number;
metrics: ZoomMetrics;
- layout: ZoomRect | null;
summary: string;
language: string | null;
/** Code-health score (0-10, higher = healthier), matching the /files treemap.
diff --git a/packages/web/src/components/zoom/zoom-detail-panel.tsx b/packages/web/src/components/zoom/zoom-detail-panel.tsx
index fb6854078..7b7280e55 100644
--- a/packages/web/src/components/zoom/zoom-detail-panel.tsx
+++ b/packages/web/src/components/zoom/zoom-detail-panel.tsx
@@ -24,6 +24,7 @@ import {
describeCap,
describeRelations,
healthBandLabel,
+ KIND_LABEL,
nodeRoles,
summarizeRelations,
} from "@repowise-dev/ui/zoom";
@@ -47,14 +48,6 @@ function fileHref(repoId: string, path: string): string {
return fileEntityPath(`/repos/${repoId}`, path);
}
-const KIND_LABEL: Record<ZoomNode["kind"], string> = {
- system: "System",
- layer: "Layer",
- group: "Group",
- folder: "Folder",
- file: "File",
-};
-
/** A micro-label: mono, because it labels something a machine produced. */
function Micro({ children }: { children: React.ReactNode }) {
return (
diff --git a/tests/unit/server/services/test_zoom_builder.py b/tests/unit/server/services/test_zoom_builder.py
index 115a855de..8dec61632 100644
--- a/tests/unit/server/services/test_zoom_builder.py
+++ b/tests/unit/server/services/test_zoom_builder.py
@@ -11,7 +11,6 @@ from repowise.server.services.c4_builder.models import (
ArchTourStep,
)
from repowise.server.services.zoom_builder import assemble_zoom_map
-from repowise.server.services.zoom_builder.layout import lay_out
from repowise.server.services.zoom_builder.metrics import rollup_health, rollup_metrics
from repowise.server.services.zoom_builder.models import ZoomNode
from repowise.server.services.zoom_builder.relations import aggregate_relations
@@ -284,43 +283,6 @@ def test_rollup_health_none_when_no_scored_descendant():
assert nodes[root_id].health_score is None
-# ---------------------------------------------------------------------------
-# layout
-# ---------------------------------------------------------------------------
-
-
-def test_layout_is_deterministic_and_within_unit_box():
- layers = [
- LayerSpec(
- id="layer:service",
- name="Service",
- display_order=0,
- node_ids=[f"pkg/f{i}.py" for i in range(6)],
- ),
- ]
- leaf_info = {f"pkg/f{i}.py": LeafInfo() for i in range(6)}
- root_id, nodes = build_tree("proj", layers, leaf_info)
- nodes = score_tree(root_id, nodes, compute_file_signals(
- [FileStat(path=f"pkg/f{i}.py", degree=i) for i in range(6)], [], [], set()
- ))
- a = lay_out(root_id, nodes)
- b = lay_out(root_id, nodes)
-
- for nid, node in a.items():
- assert node.layout == b[nid].layout # deterministic
- rect = node.layout
- assert rect is not None
- assert -1e-6 <= rect.x <= 1.0 + 1e-6
- assert -1e-6 <= rect.y <= 1.0 + 1e-6
- assert rect.x + rect.w <= 1.0 + 1e-6
- assert rect.y + rect.h <= 1.0 + 1e-6
-
- # children of a parent tile its unit box (areas sum ~ 1)
- folder = next(n for n in a.values() if n.children and n.kind != "system")
- total = sum(a[c].layout.w * a[c].layout.h for c in folder.children)
- assert abs(total - 1.0) < 1e-3
-
-
# ---------------------------------------------------------------------------
# relations
# ---------------------------------------------------------------------------
@@ -478,8 +440,6 @@ def test_assemble_zoom_map_full():
# the entry-point file is the top-ranked sibling under its parent
main = zoom.nodes[file_id("pkg/main.py")]
assert main.is_entry_point and main.sibling_rank == 1
- # layout assigned everywhere
- assert all(n.layout is not None for n in zoom.nodes.values())
assert not zoom.truncated