Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
386 lines (343 loc) · 18.4 KB
/
Copy pathindex.html
File metadata and controls
386 lines (343 loc) · 18.4 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ArchLens - Interactive Repository Map</title>
<!-- Tailwind CSS for modern styling -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Vis-Network for interactive graph visualization -->
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<!-- FontAwesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
#network-container {
height: 600px;
background-color: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 0.5rem;
}
</style>
</head>
<body class="bg-slate-50 text-slate-800 min-h-screen flex flex-col">
<!-- Header -->
<header class="bg-white border-b border-slate-200 py-4 px-6 shadow-sm">
<div class="max-w-7xl mx-auto flex justify-between items-center">
<div class="flex items-center space-x-3">
<div class="bg-indigo-600 text-white p-2 rounded-lg">
<i class="fa-solid fa-diagram-project text-xl"></i>
</div>
<div>
<h1 class="text-xl font-bold tracking-tight text-slate-900">ArchLens</h1>
<p class="text-xs text-slate-500">Static System Architecture Explorer</p>
</div>
</div>
<div class="text-xs text-slate-400">
Powered by GitHub API
</div>
</div>
</header>
<!-- Main Content -->
<main class="flex-grow max-w-7xl w-full mx-auto px-6 py-8 flex flex-col md:flex-row gap-8">
<!-- Left Column: Controls & Details -->
<div class="w-full md:w-1/3 flex flex-col gap-6">
<!-- Repo Input Box -->
<div class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm">
<h2 class="text-lg font-semibold mb-4 flex items-center gap-2">
<i class="fa-solid fa-search text-indigo-500"></i> Analyze Repository
</h2>
<div class="space-y-4">
<div>
<label class="block text-xs font-medium text-slate-500 mb-1">GitHub Repo URL or "owner/repo"</label>
<input id="repo-input" type="text" placeholder="e.g., facebook/react or hexojs/hexo"
class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label class="block text-xs font-medium text-slate-500 mb-1 flex justify-between">
<span>GitHub Token (Optional)</span>
<span class="text-slate-400 italic">Avoids rate limits</span>
</label>
<input id="token-input" type="password" placeholder="ghp_..."
class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<button id="analyze-btn" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200 text-sm flex items-center justify-center gap-2">
<span>Analyze Architecture</span>
<i class="fa-solid fa-arrow-right"></i>
</button>
</div>
</div>
<!-- Details Panel -->
<div id="details-panel" class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm flex-grow">
<h2 class="text-lg font-semibold mb-3 flex items-center gap-2">
<i class="fa-solid fa-circle-info text-indigo-500"></i> Component Details
</h2>
<div id="details-content" class="text-sm text-slate-500 space-y-3">
<p>Select a node in the diagram to view identified directories, inferred technology stack, and mapped file structure.</p>
</div>
</div>
</div>
<!-- Right Column: Interactive Map -->
<div class="w-full md:w-2/3 flex flex-col gap-4">
<div class="bg-white p-4 rounded-xl border border-slate-200 shadow-sm flex-grow flex flex-col">
<div class="flex justify-between items-center mb-4">
<h3 id="map-title" class="font-semibold text-slate-700">System Diagram</h3>
<div id="legend" class="flex gap-4 text-xs">
<span class="flex items-center gap-1"><span class="w-3 h-3 rounded bg-blue-500 inline-block"></span> Frontend</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 rounded bg-emerald-500 inline-block"></span> Backend</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 rounded bg-amber-500 inline-block"></span> Database</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 rounded bg-slate-400 inline-block"></span> Module</span>
</div>
</div>
<!-- Loading State overlay -->
<div id="loading" class="hidden flex-col items-center justify-center h-[500px] text-slate-500">
<i class="fa-solid fa-spinner fa-spin text-3xl text-indigo-600 mb-2"></i>
<p>Querying GitHub file trees and analyzing structure...</p>
</div>
<!-- Network Container -->
<div id="network-container" class="relative">
<div id="network" class="w-full h-full"></div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-white border-t border-slate-200 py-4 text-center text-xs text-slate-400 mt-auto">
<p>ArchLens uses basic directory structures and naming heuristics to map components. Best suited for organized multi-folder architectures.</p>
</footer>
<!-- App JavaScript Logic -->
<script>
const repoInput = document.getElementById('repo-input');
const tokenInput = document.getElementById('token-input');
const analyzeBtn = document.getElementById('analyze-btn');
const loading = document.getElementById('loading');
const networkContainer = document.getElementById('network-container');
const detailsContent = document.getElementById('details-content');
const mapTitle = document.getElementById('map-title');
let network = null;
analyzeBtn.addEventListener('click', startAnalysis);
async function startAnalysis() {
let input = repoInput.value.trim();
// Clean up URLs to extract owner/repo
input = input.replace(/https?:\/\/github\.com\//, '');
const parts = input.split('/');
if (parts.length < 2) {
alert('Please enter a valid "owner/repo" path.');
return;
}
const owner = parts[0];
const repo = parts[1];
toggleLoading(true);
try {
const headers = {};
if (tokenInput.value.trim()) {
headers['Authorization'] = `token ${tokenInput.value.trim()}`;
}
// 1. Get the default branch
const repoResponse = await fetch(`https://api.github.com/repos/${owner}/${repo}`, { headers });
if (!repoResponse.ok) throw new Error('Repository not found or API limit reached.');
const repoData = await repoResponse.json();
const defaultBranch = repoData.default_branch;
// 2. Fetch recursive git tree
const treeResponse = await fetch(`https://api.github.com/repos/${owner}/${repo}/git/trees/${defaultBranch}?recursive=1`, { headers });
if (!treeResponse.ok) throw new Error('Failed to retrieve project file tree.');
const treeData = await treeResponse.json();
mapTitle.textContent = `System Diagram: ${owner}/${repo}`;
processAndRender(treeData.tree);
} catch (err) {
alert(err.message);
} finally {
toggleLoading(false);
}
}
function toggleLoading(isLoading) {
if (isLoading) {
loading.classList.remove('hidden');
loading.classList.add('flex');
networkContainer.classList.add('hidden');
} else {
loading.classList.add('hidden');
loading.classList.remove('flex');
networkContainer.classList.remove('hidden');
}
}
// Heuristic analysis of the codebase structural data
function processAndRender(tree) {
const nodesMap = new Map();
const edges = [];
// 1. Map paths to extract directories
tree.forEach(item => {
const pathParts = item.path.split('/');
const topDir = pathParts[0];
if (item.type === 'tree') {
// Only focus on high-level logical directories to keep diagram simple
if (pathParts.length <= 2) {
nodesMap.set(item.path, {
id: item.path,
label: item.path,
type: 'directory',
files: [],
tech: []
});
}
} else if (item.type === 'blob') {
const fileName = pathParts[pathParts.length - 1];
const extension = fileName.split('.').pop().toLowerCase();
// If file resides in a known top-level directory, aggregate it
if (nodesMap.has(topDir)) {
const dirNode = nodesMap.get(topDir);
dirNode.files.push(item.path);
const detectedTech = detectTechnology(extension, fileName);
if (detectedTech && !dirNode.tech.includes(detectedTech)) {
dirNode.tech.push(detectedTech);
}
} else if (pathParts.length === 1) {
// Key root config files get their own indicator
if (['package.json', 'docker-compose.yml', 'requirements.txt', 'go.mod', 'cargo.toml'].includes(fileName.toLowerCase())) {
nodesMap.set(fileName, {
id: fileName,
label: fileName,
type: 'config',
files: [item.path],
tech: [detectTechnology(extension, fileName)]
});
}
}
}
});
// 2. Categorize components by naming patterns and detected technology
const nodesArray = [];
nodesMap.forEach((node, key) => {
let color = '#94a3b8'; // default gray
let shape = 'box';
let icon = 'fa-folder';
let classification = 'Module';
const lowerKey = key.toLowerCase();
if (node.type === 'config') {
color = '#ec4899';
shape = 'ellipse';
icon = 'fa-gears';
classification = 'Configuration';
} else if (lowerKey.includes('db') || lowerKey.includes('database') || lowerKey.includes('model') || lowerKey.includes('sql') || node.tech.includes('SQL')) {
color = '#f59e0b'; // Amber
shape = 'database';
icon = 'fa-database';
classification = 'Database component';
} else if (lowerKey.includes('api') || lowerKey.includes('server') || lowerKey.includes('backend') || lowerKey.includes('controller') || lowerKey.includes('routes')) {
color = '#10b981'; // Emerald
shape = 'box';
icon = 'fa-server';
classification = 'Backend Service';
} else if (lowerKey.includes('client') || lowerKey.includes('frontend') || lowerKey.includes('web') || lowerKey.includes('ui') || lowerKey.includes('view') || node.tech.includes('React') || node.tech.includes('HTML')) {
color = '#3b82f6'; // Blue
shape = 'ellipse';
icon = 'fa-laptop-code';
classification = 'Frontend App';
}
nodesArray.push({
id: node.id,
label: node.id,
color: { background: color, border: '#1e293b', highlight: { background: '#818cf8', border: '#4f46e5' } },
font: { color: '#0f172a', size: 14, face: 'monospace' },
shape: shape,
margin: 10,
// Store internal metadata
metadata: {
classification,
tech: node.tech,
filesCount: node.files.length,
filesList: node.files.slice(0, 10) // store up to 10 sample files
}
});
});
// 3. Heuristic connections between components
nodesArray.forEach(source => {
nodesArray.forEach(target => {
if (source.id === target.id) return;
const srcClass = source.metadata.classification;
const tgtClass = target.metadata.classification;
// Frontend communicates with backend services
if (srcClass === 'Frontend App' && tgtClass === 'Backend Service') {
edges.push({ from: source.id, to: target.id, label: 'API Calls', arrows: 'to', color: { color: '#cbd5e1' } });
}
// Backend queries database
if (srcClass === 'Backend Service' && tgtClass === 'Database component') {
edges.push({ from: source.id, to: target.id, label: 'Queries', arrows: 'to', color: { color: '#cbd5e1' } });
}
// Configuration links to logical modules
if (srcClass === 'Configuration' && (tgtClass === 'Backend Service' || tgtClass === 'Database component')) {
edges.push({ from: source.id, to: target.id, style: 'dash', color: { color: '#e2e8f0' } });
}
});
});
renderNetwork(nodesArray, edges);
}
function detectTechnology(ext, name) {
if (ext === 'py') return 'Python';
if (ext === 'js' || ext === 'jsx') return 'JavaScript/React';
if (ext === 'ts' || ext === 'tsx') return 'TypeScript';
if (ext === 'sql' || ext === 'prisma') return 'SQL';
if (ext === 'go') return 'Go';
if (ext === 'rs') return 'Rust';
if (ext === 'java') return 'Java';
if (ext === 'rb') return 'Ruby';
if (name === 'Dockerfile') return 'Docker';
return null;
}
// Render the physical graph via vis.js
function renderNetwork(nodes, edges) {
const container = document.getElementById('network');
const data = {
nodes: new vis.DataSet(nodes),
edges: new vis.DataSet(edges)
};
const options = {
physics: {
barnesHut: {
gravitationalConstant: -3000,
springLength: 150
}
},
edges: {
smooth: {
type: 'cubicBezier',
forceDirection: 'none',
roundness: 0.5
}
}
};
network = new vis.Network(container, data, options);
// Handle interactions (Node Selection)
network.on("selectNode", function (params) {
const selectedId = params.nodes[0];
const nodeData = nodes.find(n => n.id === selectedId);
if (nodeData && nodeData.metadata) {
const m = nodeData.metadata;
let techList = m.tech.filter(Boolean).join(', ') || 'None identified';
let filesPreview = m.filesList.map(f => `<li class="truncate text-xs font-mono bg-slate-100 p-1 rounded">${f}</li>`).join('');
detailsContent.innerHTML = `
<div>
<span class="text-xs font-semibold px-2 py-0.5 rounded-full bg-slate-200 text-slate-700">${m.classification}</span>
</div>
<p class="text-lg font-bold text-slate-800">${nodeData.id}</p>
<div>
<span class="block text-xs text-slate-400 font-medium">Technologies:</span>
<span class="text-sm text-slate-700">${techList}</span>
</div>
<div>
<span class="block text-xs text-slate-400 font-medium">Structure (${m.filesCount} files):</span>
<ul class="space-y-1 mt-2">
${filesPreview || '<li class="text-xs italic text-slate-400">No source files grouped directly</li>'}
${m.filesCount > 10 ? '<li class="text-xs text-slate-400 italic">...and more files</li>' : ''}
</ul>
</div>
`;
}
});
// Clear details when deselecting
network.on("deselectNode", function () {
detailsContent.innerHTML = `<p>Select a node in the diagram to view identified directories, inferred technology stack, and mapped file structure.</p>`;
});
}
</script>
</body>
</html>