Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
feat(dashboard): add layer visualization with grouping and legend
Lum11049f16c2c0e550
diff --git a/packages/dashboard/public/knowledge-graph.json b/packages/dashboard/public/knowledge-graph.jsonindex 6587753c..7051021b 100644--- a/packages/dashboard/public/knowledge-graph.json+++ b/packages/dashboard/public/knowledge-graph.json@@ -22,6 +22,25 @@{"source": "func:src/auth/login.ts:handleLogin", "target": "func:src/auth/login.ts:validateEmail", "type": "calls", "direction": "forward", "description": "handleLogin calls validateEmail to check the email format", "weight": 0.8},{"source": "file:src/auth/login.ts", "target": "file:src/db/connection.ts", "type": "imports", "direction": "forward", "weight": 0.7}],- "layers": [],+ "layers": [+ {+ "id": "layer:api",+ "name": "API Layer",+ "description": "Entry points and route handlers for the Express API",+ "nodeIds": ["file:src/index.ts", "file:src/auth/login.ts"]+ },+ {+ "id": "layer:auth",+ "name": "Auth Logic",+ "description": "Authentication and validation business logic",+ "nodeIds": ["func:src/auth/login.ts:handleLogin", "func:src/auth/login.ts:validateEmail"]+ },+ {+ "id": "layer:data",+ "name": "Data Layer",+ "description": "Database connections and data access",+ "nodeIds": ["file:src/db/connection.ts"]+ }+ ],"tour": []}diff --git a/packages/dashboard/src/App.tsx b/packages/dashboard/src/App.tsxindex 6ff1b216..13c4142b 100644--- a/packages/dashboard/src/App.tsx+++ b/packages/dashboard/src/App.tsx@@ -6,6 +6,7 @@ import CodeViewer from "./components/CodeViewer";import SearchBar from "./components/SearchBar";import NodeInfo from "./components/NodeInfo";import ChatPanel from "./components/ChatPanel";+import LayerLegend from "./components/LayerLegend";function App() {const graph = useDashboardStore((s) => s.graph);@@ -36,6 +37,8 @@ function App() {<span>{nodeCount} nodes</span><span className="text-gray-600">|</span><span>{edgeCount} edges</span>+ <span className="text-gray-600">|</span>+ <LayerLegend /></>)}</div>diff --git a/packages/dashboard/src/components/GraphView.tsx b/packages/dashboard/src/components/GraphView.tsxindex fab23d20..fd360423 100644--- a/packages/dashboard/src/components/GraphView.tsx+++ b/packages/dashboard/src/components/GraphView.tsx@@ -7,13 +7,18 @@ import {Controls,MiniMap,} from "@xyflow/react";-import type { Edge } from "@xyflow/react";+import type { Edge, Node } from "@xyflow/react";import "@xyflow/react/dist/style.css";import CustomNode from "./CustomNode";import type { CustomFlowNode } from "./CustomNode";import { useDashboardStore } from "../store";import { applyDagreLayout } from "../utils/layout";+import { getLayerColor, getLayerBorderColor } from "./LayerLegend";++const NODE_WIDTH = 280;+const NODE_HEIGHT = 120;+const LAYER_PADDING = 40;const nodeTypes = { custom: CustomNode };@@ -22,9 +27,14 @@ export default function GraphView() {const selectedNodeId = useDashboardStore((s) => s.selectedNodeId);const searchResults = useDashboardStore((s) => s.searchResults);const selectNode = useDashboardStore((s) => s.selectNode);+ const showLayers = useDashboardStore((s) => s.showLayers);const { initialNodes, initialEdges } = useMemo(() => {- if (!graph) return { initialNodes: [] as CustomFlowNode[], initialEdges: [] as Edge[] };+ if (!graph)+ return {+ initialNodes: [] as (CustomFlowNode | Node)[],+ initialEdges: [] as Edge[],+ };const flowNodes: CustomFlowNode[] = graph.nodes.map((node) => {const matchResult = searchResults.find((r) => r.nodeId === node.id);@@ -54,12 +64,107 @@ export default function GraphView() {labelStyle: { fill: "#9ca3af", fontSize: 10 },}));+ // Run dagre layout on all nodes (without groups)const laid = applyDagreLayout(flowNodes, flowEdges);- return {- initialNodes: laid.nodes as CustomFlowNode[],- initialEdges: laid.edges,- };- }, [graph, searchResults, selectedNodeId]);+ const laidNodes = laid.nodes as CustomFlowNode[];++ const layers = graph.layers ?? [];+ if (!showLayers || layers.length === 0) {+ return { initialNodes: laidNodes, initialEdges: laid.edges };+ }++ // Build a map of nodeId -> layer for quick lookup+ const nodeToLayer = new Map<string, string>();+ for (const layer of layers) {+ for (const nodeId of layer.nodeIds) {+ nodeToLayer.set(nodeId, layer.id);+ }+ }++ // Create group nodes and adjust member positions+ const groupNodes: Node[] = [];+ const adjustedNodes: (CustomFlowNode | Node)[] = [];++ for (let layerIdx = 0; layerIdx < layers.length; layerIdx++) {+ const layer = layers[layerIdx];+ const memberNodes = laidNodes.filter((n) =>+ layer.nodeIds.includes(n.id),+ );++ if (memberNodes.length === 0) continue;++ // Compute bounding box around member nodes+ let minX = Infinity;+ let minY = Infinity;+ let maxX = -Infinity;+ let maxY = -Infinity;++ for (const node of memberNodes) {+ const x = node.position.x;+ const y = node.position.y;+ minX = Math.min(minX, x);+ minY = Math.min(minY, y);+ maxX = Math.max(maxX, x + NODE_WIDTH);+ maxY = Math.max(maxY, y + NODE_HEIGHT);+ }++ // Group node position = top-left with padding+ const groupX = minX - LAYER_PADDING;+ const groupY = minY - LAYER_PADDING - 24; // extra space for label+ const groupWidth = maxX - minX + LAYER_PADDING * 2;+ const groupHeight = maxY - minY + LAYER_PADDING * 2 + 24;++ const bgColor = getLayerColor(layerIdx);+ const borderColor = getLayerBorderColor(layerIdx);++ // Create the group node+ groupNodes.push({+ id: layer.id,+ type: "group",+ position: { x: groupX, y: groupY },+ data: { label: layer.name },+ style: {+ width: groupWidth,+ height: groupHeight,+ backgroundColor: bgColor,+ borderRadius: 12,+ border: `2px dashed ${borderColor}`,+ padding: 8,+ fontSize: 13,+ fontWeight: 600,+ color: borderColor,+ },+ });++ // Adjust member node positions to be relative to the group+ for (const node of memberNodes) {+ adjustedNodes.push({+ ...node,+ parentId: layer.id,+ extent: "parent" as const,+ position: {+ x: node.position.x - groupX,+ y: node.position.y - groupY,+ },+ });+ }+ }++ // Add nodes that are not in any layer (keep original positions)+ for (const node of laidNodes) {+ if (!nodeToLayer.has(node.id)) {+ adjustedNodes.push(node);+ }+ }++ // Group nodes must come before their children in the array+ const allNodes: (CustomFlowNode | Node)[] = [+ ...groupNodes,+ ...adjustedNodes,+ ];++ return { initialNodes: allNodes, initialEdges: laid.edges };+ }, [graph, searchResults, selectedNodeId, showLayers]);const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);@@ -73,10 +178,13 @@ export default function GraphView() {}, [initialEdges, setEdges]);const onNodeClick = useCallback(- (_: React.MouseEvent, node: CustomFlowNode) => {+ (_: React.MouseEvent, node: { id: string }) => {+ // Ignore clicks on group nodes+ const isGroupNode = graph?.layers?.some((l) => l.id === node.id);+ if (isGroupNode) return;selectNode(node.id);},- [selectNode],+ [selectNode, graph],);const onPaneClick = useCallback(() => {diff --git a/packages/dashboard/src/components/LayerLegend.tsx b/packages/dashboard/src/components/LayerLegend.tsxnew file mode 100644index 00000000..3245d067--- /dev/null+++ b/packages/dashboard/src/components/LayerLegend.tsx@@ -0,0 +1,86 @@+import { useDashboardStore } from "../store";++const LAYER_COLORS = [+ "rgba(59, 130, 246, 0.08)", // blue+ "rgba(16, 185, 129, 0.08)", // green+ "rgba(245, 158, 11, 0.08)", // amber+ "rgba(139, 92, 246, 0.08)", // violet+ "rgba(236, 72, 153, 0.08)", // pink+ "rgba(6, 182, 212, 0.08)", // cyan+ "rgba(249, 115, 22, 0.08)", // orange+ "rgba(168, 162, 158, 0.08)", // stone+];++export const LAYER_BORDER_COLORS = [+ "rgba(59, 130, 246, 0.5)", // blue+ "rgba(16, 185, 129, 0.5)", // green+ "rgba(245, 158, 11, 0.5)", // amber+ "rgba(139, 92, 246, 0.5)", // violet+ "rgba(236, 72, 153, 0.5)", // pink+ "rgba(6, 182, 212, 0.5)", // cyan+ "rgba(249, 115, 22, 0.5)", // orange+ "rgba(168, 162, 158, 0.5)", // stone+];++export { LAYER_COLORS };++export function getLayerColor(index: number): string {+ return LAYER_COLORS[index % LAYER_COLORS.length];+}++export function getLayerBorderColor(index: number): string {+ return LAYER_BORDER_COLORS[index % LAYER_BORDER_COLORS.length];+}++export default function LayerLegend() {+ const graph = useDashboardStore((s) => s.graph);+ const showLayers = useDashboardStore((s) => s.showLayers);+ const toggleLayers = useDashboardStore((s) => s.toggleLayers);++ const layers = graph?.layers ?? [];+ const hasLayers = layers.length > 0;++ return (+ <div className="flex items-center gap-2">+ <button+ onClick={toggleLayers}+ disabled={!hasLayers}+ className={`px-2 py-0.5 rounded text-[11px] font-medium transition-colors ${+ showLayers && hasLayers+ ? "bg-blue-600 text-white"+ : hasLayers+ ? "bg-gray-700 text-gray-300 hover:bg-gray-600"+ : "bg-gray-800 text-gray-600 cursor-not-allowed"+ }`}+ title={+ hasLayers+ ? showLayers+ ? "Hide layer grouping"+ : "Show layer grouping"+ : "No layers in graph"+ }+ >+ Layers {showLayers && hasLayers ? "ON" : "OFF"}+ </button>++ {showLayers && hasLayers && (+ <div className="flex items-center gap-3">+ {layers.map((layer, i) => (+ <div key={layer.id} className="flex items-center gap-1">+ <span+ className="inline-block w-2 h-2 rounded-full"+ style={{ backgroundColor: getLayerBorderColor(i) }}+ />+ <span className="text-gray-400 text-[11px]">+ {layer.name}+ <span className="text-gray-600 ml-0.5">+ ({layer.nodeIds.length})+ </span>+ </span>+ </div>+ ))}+ </div>+ )}+ </div>+ );+}diff --git a/packages/dashboard/src/store.ts b/packages/dashboard/src/store.tsindex 5dcdf92d..e65f67d4 100644--- a/packages/dashboard/src/store.ts+++ b/packages/dashboard/src/store.ts@@ -20,12 +20,15 @@ interface DashboardStore {chatMessages: ChatMessage[];chatLoading: boolean;+ showLayers: boolean;+setGraph: (graph: KnowledgeGraph) => void;selectNode: (nodeId: string | null) => void;setSearchQuery: (query: string) => void;setApiKey: (key: string) => void;sendChatMessage: (message: string) => Promise<void>;clearChat: () => void;+ toggleLayers: () => void;}function buildSystemPrompt(@@ -110,6 +113,8 @@ export const useDashboardStore = create<DashboardStore>()((set, get) => ({chatMessages: [],chatLoading: false,+ showLayers: false,+setGraph: (graph) => {const searchEngine = new SearchEngine(graph.nodes);const query = get().searchQuery;@@ -187,4 +192,6 @@ export const useDashboardStore = create<DashboardStore>()((set, get) => ({},clearChat: () => set({ chatMessages: [] }),++ toggleLayers: () => set((state) => ({ showLayers: !state.showLayers })),}));