-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
241 lines (217 loc) · 6.59 KB
/
types.ts
File metadata and controls
241 lines (217 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
export interface Node {
id: string;
type: string;
label?: string; // Optional, inferred from ID if missing
file?: string;
// API Normalization fields
method?: string;
method_inferred?: boolean;
operation_id?: string;
path?: string;
raw_method?: string;
raw_path?: string;
summary?: string;
// D3 simulation properties (added at runtime)
x?: number;
y?: number;
z?: number;
fx?: number | null;
fy?: number | null;
fz?: number | null;
vx?: number;
vy?: number;
vz?: number;
index?: number;
// Calculated properties
degree?: number; // Number of VISIBLE connections (for physics/charge)
totalDegree?: number; // Number of TOTAL connections in raw graph (for visual sizing)
module?: string; // The architectural cluster this node belongs to
modulePath?: string[]; // Hierarchical path for drill-down (e.g. ['Frontend', 'Features', 'Maketplace'])
details?: { // For external dependencies
version?: string;
deptype?: string;
};
}
export interface Edge {
from: string;
to: string;
type: string;
// D3 simulation properties (added at runtime)
source?: Node | string;
target?: Node | string;
}
export interface GraphData {
nodes: Node[];
edges: Edge[];
generated_at?: string;
schema_version?: string;
source?: string;
source_commit?: string;
}
export interface GroupSet {
id: string;
label: string;
source: string;
multi_membership: boolean;
metadata: Record<string, any>;
}
export interface Group {
group_set: string;
id: string;
label: string;
nodes: string[];
metadata: Record<string, any>;
}
export interface GroupingData {
generated_at?: string;
source_commit?: string;
group_sets: GroupSet[];
groups: Group[];
}
export type ViewMode = 'force' | 'structured' | 'hierarchical';
export type GraphViewMode = 'unified' | 'frontend' | 'backend';
export interface NodeDetail {
docstring?: string;
doc_summary?: string;
signature?: string;
imports?: string[];
params?: string[];
returns?: string;
decorators?: string[] | null;
}
export interface EdgeDetail {
callsite?: {
file: string;
line: number;
};
notes?: string;
}
export interface DetailsData {
nodes: Record<string, NodeDetail>;
edges: Record<string, EdgeDetail>;
generated_at?: string;
source_commit?: string;
}
export interface GraphContextType {
data: GraphData; // The filtered data shown on canvas
details: DetailsData | null; // The rich details loaded asynchronously
isDetailsLoading: boolean;
totalNodeCounts: Record<string, number>; // Stats based on raw data (for sidebar)
moduleCounts: Record<string, number>; // Stats for modules
selectedNode: Node | null;
setSelectedNode: (node: Node | null) => void;
filters: Record<string, boolean>;
setFilters: (filters: Record<string, boolean>) => void;
hoveredNode: Node | null;
setHoveredNode: (node: Node | null) => void;
focusMode: boolean;
setFocusMode: (focus: boolean) => void;
viewMode: ViewMode;
setViewMode: (mode: ViewMode) => void;
graphView: GraphViewMode;
setGraphView: (mode: GraphViewMode) => void;
activeModule: string | null;
setActiveModule: (module: string | null) => void;
// Grouping Support
groupingData: GroupingData | null;
activeGroupingMode: string; // ID of the active GroupSet
setActiveGroupingMode: (mode: string) => void;
// Visualization Support
activeColorMode: string;
setActiveColorMode: (mode: string) => void;
enableMotionOptimizations: boolean;
setEnableMotionOptimizations: (enabled: boolean) => void;
enablePerformanceMode: boolean;
setEnablePerformanceMode: (enabled: boolean) => void;
zoomSpeed: number;
setZoomSpeed: (value: number) => void;
panSpeed: number;
setPanSpeed: (value: number) => void;
rotateSpeed: number;
setRotateSpeed: (value: number) => void;
// Metadata Support
gitMetadata: GitMetadata | null;
dependencyData: DependencyGraph | null;
}
export interface GitMetadata {
[filePath: string]: {
last_modified: number;
change_count: number;
unique_authors: number;
}
}
export interface DependencyGraph {
nodes: Node[]; // Re-using Node type, but with type='external_dependency'
edges: Edge[];
}
// Configuration for Node Sizing based on Total Degree
// Radius = base + (log(totalDegree + 1) * factor)
export const NODE_SIZE_CONFIG = {
baseRadius: 5,
scaleFactor: 2.8,
maxRadius: 25,
};
export const NODE_COLORS: Record<string, string> = {
route: '#a855f7', // purple-500
page: '#3b82f6', // blue-500
component: '#22d3ee', // cyan-400
hook: '#10b981', // emerald-500
api_endpoint: '#f97316', // orange-500
endpoint: '#f97316', // orange-500 alias
handler: '#ef4444', // red-500
service: '#eab308', // yellow-500
model: '#ec4899', // pink-500
repository: '#6366f1', // indigo-500
schema: '#8b5cf6', // violet-500
migration: '#64748b', // slate-500
router: '#d946ef', // fuchsia-500
api_client: '#14b8a6', // teal-500
type: '#94a3b8', // slate-400
query_key: '#84cc16', // lime-500
};
export const EDGE_STYLES: Record<string, { stroke: string; width: number; dash?: string }> = {
// Navigation
route_to_page: { stroke: '#a855f7', width: 2, dash: '5,5' }, // Purple dashed
router_exposes: { stroke: '#d946ef', width: 2 },
// React
uses_hook: { stroke: '#10b981', width: 1.5 },
page_uses_component: { stroke: '#3b82f6', width: 1.5 },
component_uses_component: { stroke: '#22d3ee', width: 1.5 },
component_uses_hook: { stroke: '#10b981', width: 1.5 },
// API
calls_api: { stroke: '#f97316', width: 3 }, // Thick orange
api_client_calls_endpoint: { stroke: '#14b8a6', width: 2 },
hook_calls_api_client: { stroke: '#14b8a6', width: 1.5, dash: '3,3' },
// Backend
handled_by: { stroke: '#ef4444', width: 2.5 }, // Red
handler_calls_service: { stroke: '#eab308', width: 2 },
// Data
service_uses_model: { stroke: '#ec4899', width: 2 },
repository_uses_model: { stroke: '#6366f1', width: 2 },
service_calls_repository: { stroke: '#8b5cf6', width: 2 },
// Misc
default: { stroke: '#475569', width: 1 }
};
export interface GraphRendererViewState {
viewMode: ViewMode;
focusMode: boolean;
selectedNode: Node | null;
activeColorMode: string;
groupingData: GroupingData | null;
gitMetadata: GitMetadata | null;
enableMotionOptimizations: boolean;
enablePerformanceMode: boolean;
zoomSpeed: number;
panSpeed: number;
rotateSpeed: number;
}
export interface GraphRendererHandlers {
onNodeSelect: (node: Node | null) => void;
onNodeHover: (node: Node | null) => void;
onBackgroundClick?: () => void;
}
export interface GraphRendererProps {
data: GraphData;
viewState: GraphRendererViewState;
handlers: GraphRendererHandlers;
}