refactor(admin): split architecture page.tsx into colocated components

Extract DetailPanel, ArchHeader, Toolbar, ArchCanvas and ServiceTable into
_components/, the ReactFlow node/edge builder into _hooks/useArchGraph, and
layout constants/helpers into _layout.ts. page.tsx drops from 950 to 91 LOC,
well below the 300 soft target.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sharang Parnerkar
2026-04-14 22:57:28 +02:00
parent 4921d1c052
commit 76962a2831
8 changed files with 1028 additions and 894 deletions

View File

@@ -0,0 +1,164 @@
'use client'
import React, { useCallback, useEffect } from 'react'
import ReactFlow, {
Node,
Controls,
Background,
MiniMap,
useNodesState,
useEdgesState,
BackgroundVariant,
Panel,
} from 'reactflow'
import 'reactflow/dist/style.css'
import { ARCH_SERVICES, LAYERS, type ArchService } from '../architecture-data'
import { LAYER_ORDER, type LayerFilter } from '../_layout'
import { useArchGraph } from '../_hooks/useArchGraph'
import DetailPanel from './DetailPanel'
export default function ArchCanvas({
layerFilter,
showDb,
showRag,
showApis,
selectedService,
setSelectedService,
}: {
layerFilter: LayerFilter
showDb: boolean
showRag: boolean
showApis: boolean
selectedService: ArchService | null
setSelectedService: React.Dispatch<React.SetStateAction<ArchService | null>>
}) {
const { nodes: initialNodes, edges: initialEdges } = useArchGraph({
layerFilter,
showDb,
showRag,
showApis,
selectedService,
})
const [nodes, setNodes, onNodesChange] = useNodesState([])
const [edges, setEdges, onEdgesChange] = useEdgesState([])
useEffect(() => {
setNodes(initialNodes)
setEdges(initialEdges)
}, [initialNodes, initialEdges, setNodes, setEdges])
const onNodeClick = useCallback((_event: React.MouseEvent, node: Node) => {
const service = ARCH_SERVICES.find(s => s.id === node.id)
if (service) {
setSelectedService(prev => (prev?.id === service.id ? null : service))
}
}, [setSelectedService])
const onPaneClick = useCallback(() => {
setSelectedService(null)
}, [setSelectedService])
return (
<div className="flex bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden" style={{ height: '700px' }}>
{/* Canvas */}
<div className="flex-1 relative">
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onNodeClick={onNodeClick}
onPaneClick={onPaneClick}
fitView
fitViewOptions={{ padding: 0.15 }}
attributionPosition="bottom-left"
>
<Controls />
<MiniMap
nodeColor={node => {
if (node.id.startsWith('db-')) return '#94a3b8'
if (node.id.startsWith('rag-')) return '#22c55e'
if (node.id.startsWith('api-')) return '#c4b5fd'
const svc = ARCH_SERVICES.find(s => s.id === node.id)
return svc ? LAYERS[svc.layer].colorBorder : '#94a3b8'
}}
maskColor="rgba(0,0,0,0.08)"
/>
<Background variant={BackgroundVariant.Dots} gap={16} size={1} />
{/* Legende */}
<Panel
position="bottom-right"
className="bg-white/95 p-3 rounded-lg shadow-lg text-xs"
>
<div className="font-medium text-slate-700 mb-2">Legende</div>
<div className="space-y-1">
{LAYER_ORDER.map(layerId => {
const layer = LAYERS[layerId]
return (
<div key={layerId} className="flex items-center gap-2">
<span
className="w-3 h-3 rounded"
style={{
background: layer.colorBg,
border: `1px solid ${layer.colorBorder}`,
}}
/>
<span className="text-slate-600">{layer.name}</span>
</div>
)
})}
<div className="border-t border-slate-200 my-1.5 pt-1.5">
<div className="flex items-center gap-2">
<span className="w-3 h-3 rounded bg-slate-200 border border-slate-400" />
<span className="text-slate-500">DB-Tabelle</span>
</div>
<div className="flex items-center gap-2 mt-0.5">
<span className="w-3 h-3 rounded bg-green-100 border border-green-500" />
<span className="text-slate-500">RAG-Collection</span>
</div>
<div className="flex items-center gap-2 mt-0.5">
<span className="w-3 h-3 rounded bg-violet-100 border border-violet-400" />
<span className="text-slate-500">API-Endpunkt</span>
</div>
</div>
</div>
</Panel>
{/* Swim-Lane Labels */}
{layerFilter === 'alle' && (
<Panel position="top-left" className="pointer-events-none">
<div className="space-y-1">
{LAYER_ORDER.map(layerId => {
const layer = LAYERS[layerId]
return (
<div
key={layerId}
className="px-3 py-1 rounded text-xs font-medium opacity-50"
style={{
background: layer.colorBg,
color: layer.colorText,
border: `1px solid ${layer.colorBorder}`,
}}
>
{layer.name}
</div>
)
})}
</div>
</Panel>
)}
</ReactFlow>
</div>
{/* Detail Panel */}
{selectedService && (
<DetailPanel
service={selectedService}
onClose={() => setSelectedService(null)}
/>
)}
</div>
)
}

View File

@@ -0,0 +1,33 @@
'use client'
export default function ArchHeader({
stats,
}: {
stats: {
services: number
dbTables: number
ragCollections: number
edges: number
}
}) {
return (
<div className="bg-white rounded-xl border border-slate-200 p-5 shadow-sm">
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-xl bg-slate-700 flex items-center justify-center text-white">
<svg className="w-7 h-7" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5}
d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01" />
</svg>
</div>
<div>
<h2 className="text-xl font-bold text-slate-900">
Architektur-Uebersicht
</h2>
<p className="text-sm text-slate-500">
{stats.services} Services | {stats.dbTables} DB-Tabellen | {stats.ragCollections} RAG-Collections | {stats.edges} Verbindungen
</p>
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,164 @@
'use client'
import { ARCH_SERVICES, LAYERS, type ArchService } from '../architecture-data'
export default function DetailPanel({
service,
onClose,
}: {
service: ArchService
onClose: () => void
}) {
const layer = LAYERS[service.layer]
return (
<div className="w-80 bg-white border-l border-slate-200 overflow-y-auto">
<div className="sticky top-0 bg-white z-10 border-b border-slate-200">
<div className="flex items-center justify-between p-4">
<h3 className="font-bold text-slate-900">{service.name}</h3>
<button
onClick={onClose}
className="text-slate-400 hover:text-slate-600 text-lg leading-none"
>
x
</button>
</div>
<div className="px-4 pb-3 flex items-center gap-2">
<span
className="px-2 py-0.5 rounded text-xs font-medium"
style={{ background: layer.colorBg, color: layer.colorText }}
>
{layer.name}
</span>
<span className="text-xs text-slate-400">{service.tech}</span>
</div>
</div>
<div className="p-4 space-y-4">
{/* Beschreibung */}
<p className="text-sm text-slate-700 leading-relaxed">{service.description}</p>
<p className="text-xs text-slate-500 leading-relaxed mt-1">{service.descriptionLong}</p>
{/* Tech + Port + Container */}
<div className="bg-slate-50 rounded-lg p-3 space-y-2">
<div className="flex items-center justify-between text-sm">
<span className="text-slate-500">Tech</span>
<span className="font-medium text-slate-800">{service.tech}</span>
</div>
{service.port && (
<div className="flex items-center justify-between text-sm">
<span className="text-slate-500">Port</span>
<code className="text-xs bg-slate-200 px-1.5 py-0.5 rounded">{service.port}</code>
</div>
)}
{service.url && (
<div className="flex items-center justify-between text-sm">
<span className="text-slate-500">URL</span>
<a
href={service.url}
target="_blank"
rel="noopener noreferrer"
className="text-xs text-blue-600 hover:underline truncate max-w-[180px]"
>
{service.url}
</a>
</div>
)}
<div className="flex items-center justify-between text-sm">
<span className="text-slate-500">Container</span>
<code className="text-xs bg-slate-200 px-1.5 py-0.5 rounded truncate max-w-[180px]">{service.container}</code>
</div>
</div>
{/* DB Tables */}
{service.dbTables.length > 0 && (
<div>
<h4 className="text-xs font-semibold text-slate-500 uppercase mb-1.5">
DB-Tabellen ({service.dbTables.length})
</h4>
<div className="space-y-1">
{service.dbTables.map(table => (
<div
key={table}
className="text-sm bg-slate-100 rounded px-2 py-1"
>
<code className="text-slate-700 text-xs">{table}</code>
</div>
))}
</div>
</div>
)}
{/* RAG Collections */}
{service.ragCollections.length > 0 && (
<div>
<h4 className="text-xs font-semibold text-slate-500 uppercase mb-1.5">
RAG-Collections ({service.ragCollections.length})
</h4>
<div className="space-y-1">
{service.ragCollections.map(rag => (
<div
key={rag}
className="text-sm bg-green-50 rounded px-2 py-1"
>
<code className="text-green-700 text-xs">{rag}</code>
</div>
))}
</div>
</div>
)}
{/* API Endpoints */}
{service.apiEndpoints.length > 0 && (
<div>
<h4 className="text-xs font-semibold text-slate-500 uppercase mb-1.5">
API-Endpunkte ({service.apiEndpoints.length})
</h4>
<div className="space-y-1">
{service.apiEndpoints.map(ep => (
<div
key={ep}
className="text-sm bg-violet-50 rounded px-2 py-1"
>
<code className="text-violet-700 text-xs">{ep}</code>
</div>
))}
</div>
</div>
)}
{/* Dependencies */}
{service.dependsOn.length > 0 && (
<div>
<h4 className="text-xs font-semibold text-slate-500 uppercase mb-1.5">
Abhaengigkeiten
</h4>
<div className="space-y-1">
{service.dependsOn.map(depId => {
const dep = ARCH_SERVICES.find(s => s.id === depId)
return (
<div
key={depId}
className="text-sm text-slate-600 bg-slate-50 rounded px-2 py-1"
>
{dep?.name || depId}
</div>
)
})}
</div>
</div>
)}
{/* Open URL */}
{service.url && (
<button
onClick={() => window.open(service.url!, '_blank')}
className="w-full mt-2 px-4 py-2 bg-purple-600 text-white rounded-lg text-sm font-medium hover:bg-purple-700 transition-colors"
>
Service oeffnen
</button>
)}
</div>
</div>
)
}

View File

@@ -0,0 +1,253 @@
'use client'
import React from 'react'
import { ARCH_SERVICES, LAYERS, type ArchService } from '../architecture-data'
import { type LayerFilter } from '../_layout'
export default function ServiceTable({
layerFilter,
expandedServices,
onToggleExpanded,
onMarkInGraph,
}: {
layerFilter: LayerFilter
expandedServices: Set<string>
onToggleExpanded: (id: string) => void
onMarkInGraph: (service: ArchService) => void
}) {
const filtered = ARCH_SERVICES.filter(
s => layerFilter === 'alle' || s.layer === layerFilter
)
return (
<div className="bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden">
<div className="px-4 py-3 bg-slate-50 border-b">
<h3 className="font-medium text-slate-700">
Alle Services ({
layerFilter === 'alle'
? ARCH_SERVICES.length
: `${ARCH_SERVICES.filter(s => s.layer === layerFilter).length} / ${ARCH_SERVICES.length}`
})
</h3>
</div>
<div className="divide-y max-h-[600px] overflow-y-auto">
{filtered.map(service => {
const layer = LAYERS[service.layer]
const isExpanded = expandedServices.has(service.id)
return (
<div key={service.id}>
{/* Row Header */}
<button
onClick={() => onToggleExpanded(service.id)}
className={`w-full flex items-center gap-3 p-3 text-left transition-colors ${
isExpanded
? 'bg-purple-50'
: 'hover:bg-slate-50'
}`}
>
{/* Chevron */}
<svg
className={`w-4 h-4 text-slate-400 shrink-0 transition-transform duration-200 ${
isExpanded ? 'rotate-90' : ''
}`}
fill="none" stroke="currentColor" viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
<span
className="w-8 h-8 rounded-lg flex items-center justify-center text-[10px] font-bold shrink-0"
style={{ background: layer.colorBg, color: layer.colorText }}
>
{service.port ? `:${service.port}` : '--'}
</span>
<div className="flex-1 min-w-0">
<div className="font-medium text-slate-800 text-sm">
{service.name}
</div>
<div className="text-xs text-slate-500 flex items-center gap-2 mt-0.5">
<span className="text-slate-400">{service.tech}</span>
{service.dbTables.length > 0 && (
<span className="text-slate-400">
DB: {service.dbTables.length}
</span>
)}
{service.ragCollections.length > 0 && (
<span className="text-green-600">
RAG: {service.ragCollections.length}
</span>
)}
{service.apiEndpoints.length > 0 && (
<span className="text-violet-600">
API: {service.apiEndpoints.length}
</span>
)}
</div>
</div>
<code className="text-[10px] text-slate-400 shrink-0 hidden sm:block">
{service.container}
</code>
<span
className="px-2 py-0.5 rounded text-[10px] font-medium shrink-0"
style={{ background: layer.colorBg, color: layer.colorText }}
>
{layer.name}
</span>
</button>
{/* Expanded Detail */}
{isExpanded && <ExpandedRow service={service} onMarkInGraph={onMarkInGraph} />}
</div>
)
})}
</div>
</div>
)
}
function ExpandedRow({
service,
onMarkInGraph,
}: {
service: ArchService
onMarkInGraph: (service: ArchService) => void
}) {
return (
<div className="px-4 pb-4 pt-1 bg-slate-50/50 border-t border-slate-100">
{/* Beschreibung */}
<p className="text-sm text-slate-700 leading-relaxed">
{service.description}
</p>
<p className="text-xs text-slate-500 leading-relaxed mt-1 mb-3">
{service.descriptionLong}
</p>
{/* Info Grid */}
<div className="grid grid-cols-2 sm:grid-cols-4 gap-3 mb-3">
<div className="bg-white rounded-lg border border-slate-200 p-2.5">
<div className="text-[10px] font-semibold text-slate-400 uppercase">Tech</div>
<div className="text-sm font-medium text-slate-800 mt-0.5">{service.tech}</div>
</div>
<div className="bg-white rounded-lg border border-slate-200 p-2.5">
<div className="text-[10px] font-semibold text-slate-400 uppercase">Port</div>
<div className="text-sm font-medium text-slate-800 mt-0.5">
{service.port ? `:${service.port}` : 'Intern'}
</div>
</div>
<div className="bg-white rounded-lg border border-slate-200 p-2.5">
<div className="text-[10px] font-semibold text-slate-400 uppercase">Container</div>
<div className="text-xs font-mono text-slate-700 mt-0.5 truncate">{service.container}</div>
</div>
{service.url && (
<div className="bg-white rounded-lg border border-slate-200 p-2.5">
<div className="text-[10px] font-semibold text-slate-400 uppercase">URL</div>
<a
href={service.url}
target="_blank"
rel="noopener noreferrer"
className="text-xs text-blue-600 hover:underline mt-0.5 block truncate"
>
{service.url}
</a>
</div>
)}
</div>
{/* Sections */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3">
{service.dbTables.length > 0 && (
<div className="bg-white rounded-lg border border-slate-200 p-3">
<h4 className="text-[10px] font-semibold text-slate-500 uppercase mb-2">
DB-Tabellen ({service.dbTables.length})
</h4>
<div className="space-y-1 max-h-40 overflow-y-auto">
{service.dbTables.map(table => (
<div key={table} className="bg-slate-50 rounded px-2 py-1">
<code className="text-xs text-slate-700">{table}</code>
</div>
))}
</div>
</div>
)}
{service.ragCollections.length > 0 && (
<div className="bg-white rounded-lg border border-slate-200 p-3">
<h4 className="text-[10px] font-semibold text-slate-500 uppercase mb-2">
RAG-Collections ({service.ragCollections.length})
</h4>
<div className="space-y-1">
{service.ragCollections.map(rag => (
<div key={rag} className="bg-green-50 rounded px-2 py-1">
<code className="text-xs text-green-700">{rag}</code>
</div>
))}
</div>
</div>
)}
{service.apiEndpoints.length > 0 && (
<div className="bg-white rounded-lg border border-slate-200 p-3">
<h4 className="text-[10px] font-semibold text-slate-500 uppercase mb-2">
API-Endpunkte ({service.apiEndpoints.length})
</h4>
<div className="space-y-1 max-h-40 overflow-y-auto">
{service.apiEndpoints.map(ep => (
<div key={ep} className="bg-violet-50 rounded px-2 py-1">
<code className="text-xs text-violet-700">{ep}</code>
</div>
))}
</div>
</div>
)}
{service.dependsOn.length > 0 && (
<div className="bg-white rounded-lg border border-slate-200 p-3">
<h4 className="text-[10px] font-semibold text-slate-500 uppercase mb-2">
Abhaengigkeiten ({service.dependsOn.length})
</h4>
<div className="space-y-1">
{service.dependsOn.map(depId => {
const dep = ARCH_SERVICES.find(s => s.id === depId)
const depLayer = dep ? LAYERS[dep.layer] : null
return (
<div key={depId} className="flex items-center gap-2 bg-slate-50 rounded px-2 py-1">
{depLayer && (
<span
className="w-2 h-2 rounded-full shrink-0"
style={{ background: depLayer.colorBorder }}
/>
)}
<span className="text-xs text-slate-700">{dep?.name || depId}</span>
</div>
)
})}
</div>
</div>
)}
</div>
{/* Open in Graph + URL */}
<div className="flex items-center gap-2 mt-3">
<button
onClick={() => {
onMarkInGraph(service)
window.scrollTo({ top: 0, behavior: 'smooth' })
}}
className="px-3 py-1.5 bg-slate-100 text-slate-700 rounded-lg text-xs font-medium hover:bg-slate-200 transition-colors"
>
Im Graph markieren
</button>
{service.url && (
<a
href={service.url}
target="_blank"
rel="noopener noreferrer"
className="px-3 py-1.5 bg-purple-600 text-white rounded-lg text-xs font-medium hover:bg-purple-700 transition-colors"
>
Service oeffnen
</a>
)}
</div>
</div>
)
}

View File

@@ -0,0 +1,98 @@
'use client'
import { ARCH_SERVICES, LAYERS } from '../architecture-data'
import { LAYER_ORDER, type LayerFilter } from '../_layout'
export default function Toolbar({
layerFilter,
showDb,
showRag,
showApis,
onLayerFilter,
onToggleDb,
onToggleRag,
onToggleApis,
}: {
layerFilter: LayerFilter
showDb: boolean
showRag: boolean
showApis: boolean
onLayerFilter: (f: LayerFilter) => void
onToggleDb: () => void
onToggleRag: () => void
onToggleApis: () => void
}) {
return (
<div className="bg-white rounded-xl border border-slate-200 p-4 shadow-sm">
<div className="flex flex-wrap items-center gap-2">
{/* Layer Filter */}
<button
onClick={() => onLayerFilter('alle')}
className={`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${
layerFilter === 'alle'
? 'bg-slate-800 text-white'
: 'bg-slate-100 text-slate-700 hover:bg-slate-200'
}`}
>
Alle ({ARCH_SERVICES.length})
</button>
{LAYER_ORDER.map(layerId => {
const layer = LAYERS[layerId]
const count = ARCH_SERVICES.filter(s => s.layer === layerId).length
return (
<button
key={layerId}
onClick={() => onLayerFilter(layerFilter === layerId ? 'alle' : layerId)}
className="px-3 py-1.5 rounded-lg text-sm font-medium transition-all flex items-center gap-1.5"
style={{
background: layerFilter === layerId ? layer.colorBorder : layer.colorBg,
color: layerFilter === layerId ? 'white' : layer.colorText,
}}
>
<span
className="w-2.5 h-2.5 rounded-full"
style={{ background: layer.colorBorder }}
/>
{layer.name} ({count})
</button>
)
})}
{/* Separator */}
<div className="w-px h-6 bg-slate-200 mx-1" />
{/* Toggles */}
<button
onClick={onToggleDb}
className={`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${
showDb
? 'bg-slate-700 text-white'
: 'bg-slate-100 text-slate-600 hover:bg-slate-200'
}`}
>
DB-Tabellen
</button>
<button
onClick={onToggleRag}
className={`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${
showRag
? 'bg-green-600 text-white'
: 'bg-green-50 text-green-700 hover:bg-green-100'
}`}
>
RAG-Collections
</button>
<button
onClick={onToggleApis}
className={`px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${
showApis
? 'bg-violet-600 text-white'
: 'bg-violet-50 text-violet-700 hover:bg-violet-100'
}`}
>
API-Endpunkte
</button>
</div>
</div>
)
}