Build interactive system landscape simulator
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
dist
|
||||
.DS_Store
|
||||
src/*.js
|
||||
vite.config.js
|
||||
@@ -0,0 +1,33 @@
|
||||
# System Landscape Simulator
|
||||
|
||||
An interactive, frontend-only architecture map for modelling systems and simulated data journeys. It uses a classic ComfyUI-style LiteGraph canvas, but does not fork or modify ComfyUI and performs no live integrations.
|
||||
|
||||
## Run locally
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
The initial landscape contains Website, API, ERP, CRM and Email Platform plus two demo journeys:
|
||||
|
||||
- **Place order:** Website → API → ERP, followed by parallel CRM and Email Platform updates.
|
||||
- **Register customer:** Website → API → CRM → Email Platform.
|
||||
|
||||
## Features
|
||||
|
||||
- Drag and rearrange systems on the dark LiteGraph canvas.
|
||||
- Edit or add systems, connections, scenario steps and parallel branches.
|
||||
- Run, pause, advance and reset scenarios with animated packets and event log output.
|
||||
- Adjust playback speed and inspect the active payload.
|
||||
- Persist the complete landscape, including node positions, in browser local storage.
|
||||
- Export and import the landscape as JSON. Invalid imports and deleted connection references are rejected with actionable errors.
|
||||
|
||||
```bash
|
||||
npm test
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Limitations
|
||||
|
||||
This is intentionally a local simulation prototype. It has no authentication, collaboration, server persistence, external API calls, real payload delivery, or production-grade graph editing. Playback state is transient and is not included in saved JSON. LiteGraph supplies canvas rendering and cable interaction; scenario semantics are managed by the Vue application.
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#0b1020" />
|
||||
<title>System Landscape Simulator</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+2559
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "system-landscape-simulator",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"test": "vitest run src/model.test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"litegraph.js": "^0.7.18",
|
||||
"vue": "^3.5.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^26.6.6",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"jsdom": "^26.1.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.1.7",
|
||||
"vitest": "^3.2.4",
|
||||
"vue-tsc": "^3.1.0"
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { LGraph, LGraphCanvas, LiteGraph } from 'litegraph.js'
|
||||
import { demoLandscape, type ConnectionModel, type LandscapeModel, type ScenarioModel, type SystemModel, uid, validateLandscape } from './model'
|
||||
|
||||
const STORAGE_KEY = 'dumas-system-landscape-v1'
|
||||
const landscape = ref<LandscapeModel>(loadLandscape())
|
||||
const canvasEl = ref<HTMLCanvasElement | null>(null)
|
||||
const selectedSystemId = ref('')
|
||||
const selectedConnectionId = ref('')
|
||||
const selectedScenarioId = ref(landscape.value.scenarios[0]?.id || '')
|
||||
const activeTab = ref<'systems' | 'scenarios'>('scenarios')
|
||||
const graph = new LGraph()
|
||||
let graphCanvas: any
|
||||
let animationFrame = 0
|
||||
const playing = ref(false)
|
||||
const stepIndex = ref(-1)
|
||||
const speed = ref(1)
|
||||
const eventLog = ref<string[]>([])
|
||||
const packetProgress = ref(0)
|
||||
const importError = ref('')
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
|
||||
function loadLandscape(): LandscapeModel {
|
||||
try { return validateLandscape(JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null')) } catch { return demoLandscape() }
|
||||
}
|
||||
const selectedSystem = computed(() => landscape.value.systems.find((item) => item.id === selectedSystemId.value))
|
||||
const selectedConnection = computed(() => landscape.value.connections.find((item) => item.id === selectedConnectionId.value))
|
||||
const selectedScenario = computed(() => landscape.value.scenarios.find((item) => item.id === selectedScenarioId.value))
|
||||
const currentStep = computed(() => selectedScenario.value?.steps[stepIndex.value])
|
||||
const currentConnections = computed(() => currentStep.value?.connectionIds.map((id) => landscape.value.connections.find((item) => item.id === id)).filter(Boolean) as ConnectionModel[] || [])
|
||||
const isRunning = computed(() => playing.value || stepIndex.value >= 0)
|
||||
|
||||
function persist() { localStorage.setItem(STORAGE_KEY, JSON.stringify(landscape.value)) }
|
||||
function selectSystem(id: string) { selectedSystemId.value = id; selectedConnectionId.value = '' }
|
||||
function selectConnection(id: string) { selectedConnectionId.value = id; selectedSystemId.value = '' }
|
||||
function addSystem() {
|
||||
const id = uid('system'); landscape.value.systems.push({ id, name: 'New system', description: 'Describe this system.', category: 'service', color: '#6d7cff', position: [160, 160] }); selectSystem(id); persist(); rebuildGraph()
|
||||
}
|
||||
function deleteSystem(id: string) {
|
||||
landscape.value.systems = landscape.value.systems.filter((item) => item.id !== id)
|
||||
landscape.value.connections = landscape.value.connections.filter((item) => item.sourceId !== id && item.targetId !== id)
|
||||
landscape.value.scenarios.forEach((scenario) => scenario.steps.forEach((step) => step.connectionIds = step.connectionIds.filter((connectionId) => landscape.value.connections.some((item) => item.id === connectionId))))
|
||||
selectedSystemId.value = ''; persist(); rebuildGraph()
|
||||
}
|
||||
function addConnection() {
|
||||
if (landscape.value.systems.length < 2) return
|
||||
const connection: ConnectionModel = { id: uid('connection'), sourceId: landscape.value.systems[0].id, targetId: landscape.value.systems[1].id, label: 'New connection', description: '', payload: '{}' }
|
||||
landscape.value.connections.push(connection); selectConnection(connection.id); persist(); rebuildGraph()
|
||||
}
|
||||
function deleteConnection(id: string) {
|
||||
landscape.value.connections = landscape.value.connections.filter((item) => item.id !== id)
|
||||
landscape.value.scenarios.forEach((scenario) => scenario.steps.forEach((step) => step.connectionIds = step.connectionIds.filter((connectionId) => connectionId !== id)))
|
||||
selectedConnectionId.value = ''; persist(); rebuildGraph()
|
||||
}
|
||||
function addScenario() {
|
||||
const scenario: ScenarioModel = { id: uid('scenario'), name: 'New scenario', description: 'Describe the journey.', startSystemId: landscape.value.systems[0]?.id || '', steps: [] }
|
||||
landscape.value.scenarios.push(scenario); selectedScenarioId.value = scenario.id; activeTab.value = 'scenarios'; persist()
|
||||
}
|
||||
function addStep() {
|
||||
if (!selectedScenario.value || !landscape.value.connections[0]) return
|
||||
selectedScenario.value.steps.push({ id: uid('step'), connectionIds: [landscape.value.connections[0].id], explanation: 'Explain what happens here.', payload: '{}', delayMs: 1000 }); persist()
|
||||
}
|
||||
function deleteStep(index: number) { selectedScenario.value?.steps.splice(index, 1); persist() }
|
||||
|
||||
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; stopAnimation() }
|
||||
function startScenario(systemId?: string) {
|
||||
if (systemId) {
|
||||
const candidate = landscape.value.scenarios.find((scenario) => scenario.startSystemId === systemId)
|
||||
if (candidate) selectedScenarioId.value = candidate.id
|
||||
}
|
||||
resetPlayback(); if (selectedScenario.value?.steps.length) { playing.value = true; advanceStep() }
|
||||
}
|
||||
function advanceStep() {
|
||||
if (!selectedScenario.value || stepIndex.value + 1 >= selectedScenario.value.steps.length) { playing.value = false; return }
|
||||
stepIndex.value += 1; packetProgress.value = 0
|
||||
const step = selectedScenario.value.steps[stepIndex.value]
|
||||
eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.explanation}`)
|
||||
animatePacket(step.delayMs / speed.value)
|
||||
}
|
||||
function animatePacket(duration: number) {
|
||||
stopAnimation(); const started = performance.now()
|
||||
const tick = (now: number) => { packetProgress.value = Math.min(1, (now - started) / duration); drawPackets(); if (packetProgress.value < 1) animationFrame = requestAnimationFrame(tick); else if (playing.value) setTimeout(advanceStep, 180 / speed.value) }
|
||||
animationFrame = requestAnimationFrame(tick)
|
||||
}
|
||||
function stopAnimation() { if (animationFrame) cancelAnimationFrame(animationFrame); animationFrame = 0 }
|
||||
function togglePlay() { if (!selectedScenario.value) return; if (playing.value) { playing.value = false; stopAnimation() } else { playing.value = true; if (stepIndex.value < 0) advanceStep(); else animatePacket(currentStep.value?.delayMs || 1000) } }
|
||||
|
||||
function buildNode(system: SystemModel) {
|
||||
const node = LiteGraph.createNode('Landscape/System')
|
||||
node.id = system.id; node.title = system.name; node.pos = [...system.position]; node.color = system.color; node.bgcolor = '#111827'; node.size = [190, 100]
|
||||
node.addInput('in', 'SYSTEM'); node.addOutput('out', 'SYSTEM'); node.systemId = system.id
|
||||
node.onDblClick = () => selectSystem(system.id)
|
||||
node.onMouseDown = () => selectSystem(system.id)
|
||||
node.onDrawForeground = function(ctx: CanvasRenderingContext2D) { ctx.fillStyle = '#8d9bb8'; ctx.font = '11px Inter, sans-serif'; ctx.fillText(system.category.toUpperCase(), 12, 76) }
|
||||
graph.add(node); return node
|
||||
}
|
||||
function rebuildGraph() {
|
||||
graph.clear(); landscape.value.systems.forEach(buildNode)
|
||||
for (const connection of landscape.value.connections) {
|
||||
const source = graph.getNodeById(connection.sourceId); const target = graph.getNodeById(connection.targetId)
|
||||
if (source && target) source.connect(0, target, 0)
|
||||
}
|
||||
nextTick(() => { graphCanvas?.draw(true, true); drawPackets() })
|
||||
}
|
||||
function drawPackets() {
|
||||
if (!graphCanvas) return
|
||||
const original = graphCanvas.onDrawForeground
|
||||
graphCanvas.onDrawForeground = undefined
|
||||
graphCanvas.draw(true, true)
|
||||
graphCanvas.onDrawForeground = original
|
||||
if (!currentConnections.value.length || stepIndex.value < 0) return
|
||||
const ctx = graphCanvas.ctx as CanvasRenderingContext2D
|
||||
for (const connection of currentConnections.value) {
|
||||
const from = graph.getNodeById(connection.sourceId); const to = graph.getNodeById(connection.targetId)
|
||||
if (!from || !to) continue
|
||||
const x = from.pos[0] + from.size[0] + (to.pos[0] - from.pos[0] - from.size[0]) * packetProgress.value
|
||||
const y = from.pos[1] + 50 + (to.pos[1] + 50 - from.pos[1] - 50) * packetProgress.value
|
||||
ctx.save(); ctx.fillStyle = '#f8c15c'; ctx.shadowColor = '#f8c15c'; ctx.shadowBlur = 16; ctx.beginPath(); ctx.arc(x, y, 7, 0, Math.PI * 2); ctx.fill(); ctx.restore()
|
||||
}
|
||||
}
|
||||
function exportJson() {
|
||||
const blob = new Blob([JSON.stringify(landscape.value, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'system-landscape.json'; link.click(); URL.revokeObjectURL(url)
|
||||
}
|
||||
function importJson(event: Event) {
|
||||
const input = event.target as HTMLInputElement; const file = input.files?.[0]; if (!file) return
|
||||
const reader = new FileReader(); reader.onload = () => { try { landscape.value = validateLandscape(JSON.parse(String(reader.result))); selectedScenarioId.value = landscape.value.scenarios[0]?.id || ''; importError.value = ''; persist(); rebuildGraph() } catch (error) { importError.value = error instanceof Error ? error.message : 'Invalid landscape file.' } }; reader.readAsText(file); input.value = ''
|
||||
}
|
||||
watch(landscape, persist, { deep: true })
|
||||
onMounted(() => { if (!canvasEl.value) return; graphCanvas = new LGraphCanvas(canvasEl.value, graph); graphCanvas.background_image = null; graphCanvas.render_shadows = false; graphCanvas.ds.scale = 0.85; graphCanvas.onDrawForeground = drawPackets; rebuildGraph() })
|
||||
onUnmounted(stopAnimation)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="app-shell">
|
||||
<header class="topbar"><div><span class="eyebrow">DUMAS LABS / SIMULATION</span><h1>System Landscape <em>Simulator</em></h1></div><div class="top-actions"><button class="ghost" @click="exportJson">Export JSON</button><button class="ghost" @click="fileInput?.click()">Import JSON</button><input ref="fileInput" type="file" accept="application/json" hidden @change="importJson" /></div></header>
|
||||
<section v-if="importError" class="import-error">{{ importError }} <button @click="importError = ''">Dismiss</button></section>
|
||||
<div class="workspace">
|
||||
<aside class="sidebar panel">
|
||||
<div class="tabs"><button :class="{active: activeTab === 'scenarios'}" @click="activeTab = 'scenarios'">Scenarios</button><button :class="{active: activeTab === 'systems'}" @click="activeTab = 'systems'">Systems</button></div>
|
||||
<div v-if="activeTab === 'scenarios'" class="list-area"><div class="section-heading"><span>Journeys</span><button class="icon-button" @click="addScenario">+</button></div><div v-for="scenario in landscape.scenarios" :key="scenario.id" class="list-item" :class="{selected: selectedScenarioId === scenario.id}" @dblclick="selectedScenarioId = scenario.id; startScenario()"><span class="status-dot"></span><span class="list-copy" @click="selectedScenarioId = scenario.id; resetPlayback()"><strong>{{ scenario.name }}</strong><small>{{ scenario.steps.length }} steps · {{ scenario.description }}</small></span><button class="run-mini" title="Run scenario" @click.stop="selectedScenarioId = scenario.id; startScenario()">▶</button></div></div>
|
||||
<div v-else class="list-area"><div class="section-heading"><span>Systems</span><button class="icon-button" @click="addSystem">+</button></div><button v-for="system in landscape.systems" :key="system.id" class="list-item" :class="{selected: selectedSystemId === system.id}" @click="selectSystem(system.id)"><span class="system-dot" :style="{background: system.color}"></span><span><strong>{{ system.name }}</strong><small>{{ system.category }}</small></span></button><div class="section-heading connections-heading"><span>Connections</span><button class="icon-button" @click="addConnection">+</button></div><button v-for="connection in landscape.connections" :key="connection.id" class="list-item compact" :class="{selected: selectedConnectionId === connection.id}" @click="selectConnection(connection.id)"><span class="arrow">↗</span><span><strong>{{ connection.label }}</strong><small>{{ landscape.systems.find(s => s.id === connection.sourceId)?.name }} → {{ landscape.systems.find(s => s.id === connection.targetId)?.name }}</small></span></button></div>
|
||||
<div class="sidebar-foot"><span class="live-dot"></span> Local simulation · auto-saved</div>
|
||||
</aside>
|
||||
<section class="canvas-panel panel"><div class="canvas-toolbar"><div><span class="eyebrow">LANDSCAPE / LIVE MAP</span><strong>{{ selectedScenario?.name || 'Untitled landscape' }}</strong></div><div class="canvas-hint">Drag nodes to rearrange · scroll to zoom</div></div><canvas ref="canvasEl" width="1200" height="670"></canvas><div class="canvas-legend"><span><i class="legend-node"></i> System</span><span><i class="legend-packet"></i> Active packet</span><span>Pan: drag empty canvas</span></div></section>
|
||||
<aside class="inspector panel">
|
||||
<div v-if="selectedSystem" class="inspector-content"><div class="inspector-header"><div><span class="eyebrow">SYSTEM</span><h2>{{ selectedSystem.name }}</h2></div><button class="danger-icon" @click="deleteSystem(selectedSystem.id)">×</button></div><label>Name<input v-model="selectedSystem.name" @change="rebuildGraph" /></label><label>Category<select v-model="selectedSystem.category"><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="human">Human</option><option value="external">External</option></select></label><label>Colour<input v-model="selectedSystem.color" type="color" /></label><label>Description<textarea v-model="selectedSystem.description" rows="4"></textarea></label><button class="primary full" @click="persist">Save system</button></div>
|
||||
<div v-else-if="selectedConnection" class="inspector-content"><div class="inspector-header"><div><span class="eyebrow">CONNECTION</span><h2>{{ selectedConnection.label }}</h2></div><button class="danger-icon" @click="deleteConnection(selectedConnection.id)">×</button></div><label>Label<input v-model="selectedConnection.label" /></label><label>From<select v-model="selectedConnection.sourceId" @change="rebuildGraph"><option v-for="system in landscape.systems" :key="system.id" :value="system.id">{{ system.name }}</option></select></label><label>To<select v-model="selectedConnection.targetId" @change="rebuildGraph"><option v-for="system in landscape.systems" :key="system.id" :value="system.id">{{ system.name }}</option></select></label><label>Description<textarea v-model="selectedConnection.description" rows="3"></textarea></label><label>Example payload<textarea v-model="selectedConnection.payload" rows="5" class="code"></textarea></label></div>
|
||||
<div v-else-if="selectedScenario" class="inspector-content scenario-inspector"><div class="inspector-header"><div><span class="eyebrow">SCENARIO</span><h2>{{ selectedScenario.name }}</h2></div><button class="primary run-button" @click="startScenario()">▶ Run</button></div><label>Name<input v-model="selectedScenario.name" /></label><label>Description<textarea v-model="selectedScenario.description" rows="3"></textarea></label><div class="steps-head"><span>Steps</span><button class="icon-button" @click="addStep">+</button></div><div v-for="(step, index) in selectedScenario.steps" :key="step.id" class="step-editor"><div class="step-number">{{ String(index + 1).padStart(2, '0') }}</div><div class="step-fields"><select v-model="step.connectionIds" multiple><option v-for="connection in landscape.connections" :key="connection.id" :value="connection.id">{{ connection.label }}</option></select><input v-model="step.explanation" placeholder="What happens?" /><textarea v-model="step.payload" rows="2" class="code" placeholder="Payload"></textarea><button class="text-danger" @click="deleteStep(index)">Remove step</button></div></div></div>
|
||||
<div v-else class="empty-inspector"><div class="empty-icon">⌘</div><h2>Select an item</h2><p>Choose a system, connection, or scenario to inspect and edit its details.</p></div>
|
||||
</aside>
|
||||
</div>
|
||||
<footer class="playback panel"><div class="playback-scenario"><span class="eyebrow">SIMULATION</span><strong>{{ selectedScenario?.name || 'No scenario selected' }}</strong></div><button class="control" @click="resetPlayback">↺</button><button class="control play" @click="togglePlay">{{ playing ? 'Ⅱ' : '▶' }}</button><button class="control" @click="advanceStep">›</button><div class="timeline"><div class="timeline-track"><span v-for="(step, index) in (selectedScenario?.steps || [])" :key="step.id" class="timeline-step" :class="{complete: index < stepIndex, current: index === stepIndex}" :style="{width: `${100 / Math.max(1, selectedScenario?.steps.length || 1)}%`}"><i></i><small>{{ index + 1 }}</small></span></div><div class="timeline-label"><span>{{ currentStep?.explanation || 'Ready to run' }}</span><span>{{ stepIndex + 1 < 0 ? 0 : stepIndex + 1 }} / {{ selectedScenario?.steps.length || 0 }}</span></div></div><label class="speed">Speed <select v-model.number="speed"><option :value="0.5">0.5×</option><option :value="1">1×</option><option :value="2">2×</option><option :value="4">4×</option></select></label></footer>
|
||||
<section class="event-drawer" v-if="eventLog.length"><span class="eyebrow">EVENT LOG</span><span v-for="event in eventLog.slice(0, 3)" :key="event">{{ event }}</span><span v-if="currentStep" class="payload"><b>Payload</b> {{ currentStep.payload }}</span></section>
|
||||
</main>
|
||||
</template>
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
declare module 'litegraph.js' {
|
||||
export const LiteGraph: any
|
||||
export const LGraph: any
|
||||
export const LGraphCanvas: any
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import './style.css'
|
||||
import './style.css'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { demoLandscape, validateLandscape } from './model'
|
||||
|
||||
describe('landscape model', () => {
|
||||
it('provides the editable demo landscape', () => {
|
||||
const landscape = demoLandscape()
|
||||
expect(landscape.systems).toHaveLength(5)
|
||||
expect(landscape.scenarios.map((scenario) => scenario.name)).toEqual(['Place order', 'Register customer'])
|
||||
expect(landscape.scenarios[0].steps[2].connectionIds).toHaveLength(2)
|
||||
})
|
||||
it('round-trips a valid landscape and preserves positions', () => {
|
||||
const source = demoLandscape(); const imported = validateLandscape(JSON.parse(JSON.stringify(source)))
|
||||
expect(imported).toEqual(source); expect(imported.systems.find((system) => system.id === 'website')?.position).toEqual([80, 180])
|
||||
})
|
||||
it('rejects connections that reference deleted systems', () => { const source = demoLandscape(); source.connections[0].targetId = 'deleted-system'; expect(() => validateLandscape(source)).toThrow(/missing system/) })
|
||||
it('rejects scenario steps that reference deleted connections', () => { const source = demoLandscape(); source.scenarios[0].steps[0].connectionIds = ['deleted-connection']; expect(() => validateLandscape(source)).toThrow(/deleted connection/) })
|
||||
it('rejects unsupported or malformed imports', () => { expect(() => validateLandscape(null)).toThrow(/JSON object/); expect(() => validateLandscape({ version: 2 })).toThrow(/Unsupported landscape format/) })
|
||||
})
|
||||
@@ -0,0 +1,99 @@
|
||||
export type SystemCategory = 'application' | 'service' | 'data' | 'human' | 'external'
|
||||
|
||||
export interface SystemModel {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
category: SystemCategory
|
||||
color: string
|
||||
position: [number, number]
|
||||
}
|
||||
|
||||
export interface ConnectionModel {
|
||||
id: string
|
||||
sourceId: string
|
||||
targetId: string
|
||||
label: string
|
||||
description: string
|
||||
payload: string
|
||||
}
|
||||
|
||||
export interface ScenarioStep {
|
||||
id: string
|
||||
connectionIds: string[]
|
||||
explanation: string
|
||||
payload: string
|
||||
delayMs: number
|
||||
}
|
||||
|
||||
export interface ScenarioModel {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
startSystemId: string
|
||||
steps: ScenarioStep[]
|
||||
}
|
||||
|
||||
export interface LandscapeModel {
|
||||
version: 1
|
||||
systems: SystemModel[]
|
||||
connections: ConnectionModel[]
|
||||
scenarios: ScenarioModel[]
|
||||
}
|
||||
|
||||
export const uid = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2, 9)}`
|
||||
|
||||
export const demoLandscape = (): LandscapeModel => ({
|
||||
version: 1,
|
||||
systems: [
|
||||
{ id: 'website', name: 'Website', description: 'Customer-facing storefront and account experience.', category: 'application', color: '#6d7cff', position: [80, 180] },
|
||||
{ id: 'api', name: 'API', description: 'Order and customer orchestration service.', category: 'service', color: '#26c6a6', position: [360, 180] },
|
||||
{ id: 'erp', name: 'ERP', description: 'Back-office order fulfilment and inventory system.', category: 'data', color: '#f2a65a', position: [650, 100] },
|
||||
{ id: 'crm', name: 'CRM', description: 'Customer profile and lifecycle management.', category: 'data', color: '#dd6bca', position: [650, 290] },
|
||||
{ id: 'email', name: 'Email Platform', description: 'Transactional and lifecycle messaging.', category: 'external', color: '#4aa3df', position: [930, 290] }
|
||||
],
|
||||
connections: [
|
||||
{ id: 'website-api', sourceId: 'website', targetId: 'api', label: 'Order request', description: 'Website submits a new order to the API.', payload: '{"orderId":"ord_1042","total":129.5}' },
|
||||
{ id: 'api-erp', sourceId: 'api', targetId: 'erp', label: 'Create order', description: 'API creates the order in the ERP.', payload: '{"orderId":"ord_1042","status":"new"}' },
|
||||
{ id: 'api-crm', sourceId: 'api', targetId: 'crm', label: 'Update customer', description: 'API updates the customer record.', payload: '{"customerId":"cus_88","lastOrder":"ord_1042"}' },
|
||||
{ id: 'api-email', sourceId: 'api', targetId: 'email', label: 'Send confirmation', description: 'API asks the email platform to send a confirmation.', payload: '{"template":"order-confirmation","to":"alex@example.com"}' },
|
||||
{ id: 'website-api-register', sourceId: 'website', targetId: 'api', label: 'Registration', description: 'Website submits a new customer registration.', payload: '{"email":"alex@example.com"}' },
|
||||
{ id: 'api-crm-register', sourceId: 'api', targetId: 'crm', label: 'Create customer', description: 'API creates the customer profile.', payload: '{"customerId":"cus_89","status":"active"}' },
|
||||
{ id: 'crm-email', sourceId: 'crm', targetId: 'email', label: 'Welcome email', description: 'CRM triggers the welcome message.', payload: '{"template":"welcome","customerId":"cus_89"}' }
|
||||
],
|
||||
scenarios: [
|
||||
{
|
||||
id: 'place-order', name: 'Place order', description: 'Fulfil an order and notify customer systems.', startSystemId: 'website',
|
||||
steps: [
|
||||
{ id: 'order-1', connectionIds: ['website-api'], explanation: 'The customer places an order on the website.', payload: '{"orderId":"ord_1042"}', delayMs: 800 },
|
||||
{ id: 'order-2', connectionIds: ['api-erp'], explanation: 'The API forwards the order to the ERP for fulfilment.', payload: '{"status":"new"}', delayMs: 1200 },
|
||||
{ id: 'order-3', connectionIds: ['api-crm', 'api-email'], explanation: 'The API updates the CRM and sends a confirmation in parallel.', payload: '{"orderId":"ord_1042","fanout":true}', delayMs: 1200 }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'register-customer', name: 'Register customer', description: 'Create a profile and send a welcome email.', startSystemId: 'website',
|
||||
steps: [
|
||||
{ id: 'register-1', connectionIds: ['website-api-register'], explanation: 'The visitor submits the registration form.', payload: '{"email":"alex@example.com"}', delayMs: 800 },
|
||||
{ id: 'register-2', connectionIds: ['api-crm-register'], explanation: 'The API creates the CRM customer record.', payload: '{"status":"active"}', delayMs: 1000 },
|
||||
{ id: 'register-3', connectionIds: ['crm-email'], explanation: 'The CRM triggers a welcome email.', payload: '{"template":"welcome"}', delayMs: 1000 }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
export function validateLandscape(value: unknown): LandscapeModel {
|
||||
if (!value || typeof value !== 'object') throw new Error('Import must contain a JSON object.')
|
||||
const landscape = value as Partial<LandscapeModel>
|
||||
if (landscape.version !== 1 || !Array.isArray(landscape.systems) || !Array.isArray(landscape.connections) || !Array.isArray(landscape.scenarios)) {
|
||||
throw new Error('Unsupported landscape format. Expected version 1 with systems, connections, and scenarios arrays.')
|
||||
}
|
||||
const systemIds = new Set(landscape.systems.map((item) => item.id))
|
||||
for (const connection of landscape.connections) {
|
||||
if (!systemIds.has(connection.sourceId) || !systemIds.has(connection.targetId)) throw new Error(`Connection “${connection.label}” references a missing system.`)
|
||||
}
|
||||
const connectionIds = new Set(landscape.connections.map((item) => item.id))
|
||||
for (const scenario of landscape.scenarios) for (const step of scenario.steps) for (const connectionId of step.connectionIds) {
|
||||
if (!connectionIds.has(connectionId)) throw new Error(`Scenario “${scenario.name}” references a deleted connection.`)
|
||||
}
|
||||
return structuredClone(landscape as LandscapeModel)
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||
"types": ["vite/client", "node"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"strict": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({ plugins: [vue()] })
|
||||
Reference in New Issue
Block a user