Add reusable system preset library

This commit is contained in:
2026-11-05 22:16:27 +00:00
parent a28cb2e7b9
commit a734a0282f
5 changed files with 71 additions and 17 deletions
+21 -8
View File
@@ -1,15 +1,17 @@
<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'
import { cloneCapabilities, demoLandscape, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ConnectionModel, type LandscapeModel, type ScenarioModel, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
const STORAGE_KEY = 'dumas-system-landscape-v1'
const PRESET_STORAGE_KEY = 'dumas-system-presets-v1'
const landscape = ref<LandscapeModel>(loadLandscape())
const customPresets = ref<SystemPreset[]>(loadCustomPresets())
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 activeTab = ref<'systems' | 'scenarios' | 'presets'>('scenarios')
const graph = new LGraph()
let graphCanvas: any
let animationFrame = 0
@@ -20,10 +22,13 @@ const eventLog = ref<string[]>([])
const packetProgress = ref(0)
const importError = ref('')
const fileInput = ref<HTMLInputElement | null>(null)
const placingPreset = ref<SystemPreset | null>(null)
const selectedCapabilityIds = ref<string[]>([])
function loadLandscape(): LandscapeModel {
try { return validateLandscape(JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null')) } catch { return demoLandscape() }
}
function loadCustomPresets(): SystemPreset[] { try { const value = JSON.parse(localStorage.getItem(PRESET_STORAGE_KEY) || '[]'); return Array.isArray(value) ? value : [] } catch { return [] } }
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))
@@ -32,11 +37,15 @@ const currentConnections = computed(() => currentStep.value?.connectionIds.map((
const isRunning = computed(() => playing.value || stepIndex.value >= 0)
function persist() { localStorage.setItem(STORAGE_KEY, JSON.stringify(landscape.value)) }
function persistPresets() { localStorage.setItem(PRESET_STORAGE_KEY, JSON.stringify(customPresets.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()
const id = uid('system'); landscape.value.systems.push({ id, name: 'New system', description: 'Describe this system.', category: 'service', color: '#6d7cff', position: [160, 160], capabilities: [] }); selectSystem(id); persist(); rebuildGraph()
}
function openPreset(preset: SystemPreset) { placingPreset.value = preset; selectedCapabilityIds.value = preset.capabilities.map((capability) => capability.id) }
function placePreset() { if (!placingPreset.value) return; const position: [number, number] = [120 + (landscape.value.systems.length % 3) * 280, 120 + (landscape.value.systems.length % 3) * 150]; const system = systemFromPreset(placingPreset.value, selectedCapabilityIds.value, position); landscape.value.systems.push(system); selectSystem(system.id); placingPreset.value = null; persist(); rebuildGraph() }
function saveSelectedAsPreset() { if (!selectedSystem.value) return; const preset: SystemPreset = { id: `custom-${uid('preset')}`, name: `${selectedSystem.value.name} custom`, description: selectedSystem.value.description, category: selectedSystem.value.category, color: selectedSystem.value.color, capabilities: cloneCapabilities(selectedSystem.value.capabilities) }; customPresets.value.push(preset); persistPresets(); activeTab.value = 'presets' }
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)
@@ -89,10 +98,12 @@ function togglePlay() { if (!selectedScenario.value) return; if (playing.value)
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.addInput('in', 'SYSTEM'); node.addOutput('out', 'SYSTEM'); node.systemId = system.id; node.showActions = false
for (const capability of system.capabilities) { for (const input of capability.inputs) node.addInput(`${capability.id}:${input.id}`, input.name); for (const output of capability.outputs) node.addOutput(`${capability.id}:${output.id}`, output.name) }
if (system.capabilities.length) node.addWidget('button', 'Actions ▸', null, () => { node.showActions = !node.showActions; node.widgets[0].name = node.showActions ? 'Actions ▾' : 'Actions ▸'; graphCanvas?.draw(true, true) })
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) }
node.onDrawForeground = function(ctx: CanvasRenderingContext2D) { ctx.fillStyle = '#8d9bb8'; ctx.font = '11px Inter, sans-serif'; ctx.fillText(system.category.toUpperCase(), 12, 76); if (node.showActions) { ctx.fillStyle = '#c9d3e8'; ctx.font = '10px Inter, sans-serif'; system.capabilities.forEach((capability: CapabilityModel, index: number) => ctx.fillText(`${capability.name}: ${capability.actions.map((item) => item.name).join(', ')}`, 12, 92 + index * 13)) } }
graph.add(node); return node
}
function rebuildGraph() {
@@ -137,14 +148,15 @@ onUnmounted(stopAnimation)
<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 class="tabs"><button :class="{active: activeTab === 'scenarios'}" @click="activeTab = 'scenarios'">Scenarios</button><button :class="{active: activeTab === 'systems'}" @click="activeTab = 'systems'">Systems</button><button :class="{active: activeTab === 'presets'}" @click="activeTab = 'presets'">Presets</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 v-else-if="activeTab === 'systems'" 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 }} · {{ system.capabilities.length }} capabilities</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 v-else class="list-area"><div class="section-heading"><span>Built-in library</span></div><div v-for="preset in SYSTEM_PRESETS" :key="preset.id" class="preset-item" :title="preset.description"><span class="system-dot" :style="{background: preset.color}"></span><span class="list-copy"><strong>{{ preset.name }}</strong><small>{{ preset.capabilities.length }} capabilities</small></span><button class="run-mini" @click="openPreset(preset)">Place</button></div><div class="section-heading connections-heading"><span>Your presets</span></div><div v-if="!customPresets.length" class="muted">Save a customised system from its inspector.</div><div v-for="preset in customPresets" :key="preset.id" class="preset-item" :title="preset.description"><span class="system-dot" :style="{background: preset.color}"></span><span class="list-copy"><strong>{{ preset.name }}</strong><small>{{ preset.capabilities.length }} capabilities</small></span><button class="run-mini" @click="openPreset(preset)">Place</button></div></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-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><button class="ghost full" @click="saveSelectedAsPreset">Save as my preset</button><div class="capability-list"><div class="steps-head"><span>Capabilities</span></div><article v-for="capability in selectedSystem.capabilities" :key="capability.id" class="capability-card" :title="capability.description"><strong>{{ capability.name }}</strong><small>{{ capability.description }}</small><div class="port-line"><span>Inputs</span>{{ capability.inputs.map((item) => item.name).join(' · ') || 'None' }}</div><div class="port-line"><span>Outputs</span>{{ capability.outputs.map((item) => item.name).join(' · ') || 'None' }}</div><details><summary>Actions & sample payload</summary><div v-for="action in capability.actions" :key="action.id" class="action-row" :title="action.description"><b>{{ action.name }}</b><small>{{ action.description }}</small><textarea v-model="action.payload" rows="2" class="code"></textarea></div><label>Default capability payload<textarea v-model="capability.payload" rows="2" class="code"></textarea></label></details></article></div></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>
@@ -152,5 +164,6 @@ onUnmounted(stopAnimation)
</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>
<div v-if="placingPreset" class="modal-backdrop" @click.self="placingPreset = null"><section class="preset-modal panel"><div class="inspector-header"><div><span class="eyebrow">PLACE PRESET</span><h2>{{ placingPreset.name }}</h2><p>{{ placingPreset.description }}</p></div><button class="danger-icon" @click="placingPreset = null">×</button></div><p class="muted">Choose the capabilities to place. The new canvas system will have its own editable copies.</p><label v-for="capability in placingPreset.capabilities" :key="capability.id" class="capability-choice" :title="capability.description"><input v-model="selectedCapabilityIds" type="checkbox" :value="capability.id" /><span><b>{{ capability.name }}</b><small>{{ capability.description }}</small></span></label><div class="modal-actions"><button class="ghost" @click="placingPreset = null">Cancel</button><button class="primary" :disabled="!selectedCapabilityIds.length" @click="placePreset">Place system</button></div></section></div>
</main>
</template>
+9 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { demoLandscape, validateLandscape } from './model'
import { demoLandscape, getPreset, systemFromPreset, validateLandscape } from './model'
describe('landscape model', () => {
it('provides the editable demo landscape', () => {
@@ -15,4 +15,12 @@ describe('landscape model', () => {
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/) })
it('creates an isolated preset instance with selected capabilities', () => {
const preset = getPreset('website')!
const instance = systemFromPreset(preset, ['analytics'], [200, 300])
expect(instance.presetId).toBe('website')
expect(instance.capabilities.map((capability) => capability.id)).toEqual(['analytics'])
instance.capabilities[0].actions[0].payload = '{"changed":true}'
expect(preset.capabilities.find((capability) => capability.id === 'analytics')?.actions[0].payload).not.toBe('{"changed":true}')
})
})
+38 -7
View File
@@ -1,5 +1,10 @@
export type SystemCategory = 'application' | 'service' | 'data' | 'human' | 'external'
export interface PortModel { id: string; name: string; description: string }
export interface ActionModel { id: string; name: string; description: string; payload: string }
export interface CapabilityModel { id: string; name: string; description: string; inputs: PortModel[]; outputs: PortModel[]; actions: ActionModel[]; payload: string }
export interface SystemPreset { id: string; name: string; description: string; category: SystemCategory; color: string; capabilities: CapabilityModel[] }
export interface SystemModel {
id: string
name: string
@@ -7,6 +12,8 @@ export interface SystemModel {
category: SystemCategory
color: string
position: [number, number]
presetId?: string
capabilities: CapabilityModel[]
}
export interface ConnectionModel {
@@ -43,14 +50,37 @@ export interface LandscapeModel {
export const uid = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2, 9)}`
const port = (id: string, name: string, description: string): PortModel => ({ id, name, description })
const action = (id: string, name: string, description: string, payload: string): ActionModel => ({ id, name, description, payload })
const capability = (id: string, name: string, description: string, inputs: PortModel[], outputs: PortModel[], actions: ActionModel[], payload: string): CapabilityModel => ({ id, name, description, inputs, outputs, actions, payload })
export const SYSTEM_PRESETS: SystemPreset[] = [
{ id: 'website', name: 'Website', description: 'Customer-facing storefront and account experience.', category: 'application', color: '#6d7cff', capabilities: [
capability('contact-forms', 'Contact forms', 'Collect a visitor message and route it to a service team.', [port('form-submit', 'Form submit', 'A visitor-submitted contact form.')], [port('contact-request', 'Contact request', 'Validated contact details and message.')], [action('submit-contact', 'Submit contact form', 'Create a fictional support request.', '{"requestId":"req_1001","email":"sam@example.test","message":"Please call me"}')], '{"requestId":"req_1001","email":"sam@example.test"}'),
capability('sample-ordering', 'Sample ordering', 'Allow visitors to request a product sample.', [port('sample-request', 'Sample request', 'A request for a product sample.')], [port('sample-order', 'Sample order', 'A created sample order.')], [action('place-sample', 'Place sample order', 'Create a fictional sample order.', '{"orderId":"smp_1042","sku":"sample-blue","quantity":1}')], '{"orderId":"smp_1042","sku":"sample-blue"}'),
capability('commercial-ordering', 'Commercial ordering', 'Accept a normal customer purchase.', [port('cart', 'Cart', 'A cart ready for checkout.')], [port('order-request', 'Order request', 'A submitted commercial order.')], [action('place-order', 'Place commercial order', 'Create a fictional commercial order.', '{"orderId":"ord_1042","total":129.5,"currency":"GBP"}')], '{"orderId":"ord_1042","total":129.5}'),
capability('analytics', 'Analytics', 'Emit behavioural and conversion events.', [port('page-event', 'Page event', 'A page-view or conversion event.')], [port('analytics-event', 'Analytics event', 'An event ready for analytics processing.')], [action('track-event', 'Track event', 'Send a fictional page event.', '{"event":"product_view","visitorId":"vis_204"}')], '{"event":"product_view","visitorId":"vis_204"}'),
capability('account-registration', 'Account registration', 'Create an account from a registration form.', [port('registration', 'Registration', 'New account details.')], [port('customer-registration', 'Customer registration', 'Validated customer registration.')], [action('register', 'Register account', 'Create a fictional customer registration.', '{"customerId":"cus_89","email":"sam@example.test"}')], '{"customerId":"cus_89","email":"sam@example.test"}')
]},
{ id: 'crm', name: 'CRM', description: 'Customer profile and lifecycle management.', category: 'data', color: '#dd6bca', capabilities: [capability('customer-records', 'Customer records', 'Create and update customer profiles.', [port('customer-update', 'Customer update', 'Customer data to store.')], [port('customer-record', 'Customer record', 'The stored customer profile.')], [action('upsert-customer', 'Upsert customer', 'Store a fictional customer record.', '{"customerId":"cus_89","status":"active"}')], '{"customerId":"cus_89","status":"active"}'), capability('lifecycle', 'Lifecycle messaging', 'Track customer lifecycle changes.', [port('lifecycle-event', 'Lifecycle event', 'A customer lifecycle event.')], [port('segment-event', 'Segment event', 'An event for downstream messaging.')], [action('mark-welcome', 'Mark welcome sent', 'Record a fictional welcome event.', '{"customerId":"cus_89","event":"welcome_sent"}')], '{"customerId":"cus_89","event":"welcome_sent"}') ]},
{ id: 'erp', name: 'ERP', description: 'Back-office fulfilment and inventory management.', category: 'data', color: '#f2a65a', capabilities: [capability('orders', 'Order management', 'Create and progress fulfilment orders.', [port('order-request', 'Order request', 'An order to fulfil.')], [port('order-status', 'Order status', 'Current fulfilment status.')], [action('create-order', 'Create order', 'Create a fictional ERP order.', '{"orderId":"ord_1042","status":"new"}')], '{"orderId":"ord_1042","status":"new"}'), capability('inventory', 'Inventory', 'Check and reserve fictional stock.', [port('stock-check', 'Stock check', 'A product stock request.')], [port('stock-result', 'Stock result', 'Available stock information.')], [action('reserve-stock', 'Reserve stock', 'Reserve fictional stock.', '{"sku":"sample-blue","available":24,"reserved":1}')], '{"sku":"sample-blue","available":24}') ]},
{ id: 'email', name: 'Email Platform', description: 'Transactional and lifecycle messaging.', category: 'external', color: '#4aa3df', capabilities: [capability('transactional-email', 'Transactional email', 'Send a message from a template.', [port('email-request', 'Email request', 'A message request.')], [port('delivery-event', 'Delivery event', 'Delivery status.')], [action('send-email', 'Send email', 'Send a fictional transactional email.', '{"messageId":"msg_44","template":"order-confirmation","to":"sam@example.test"}')], '{"template":"order-confirmation","to":"sam@example.test"}'), capability('campaigns', 'Campaigns', 'Send lifecycle or campaign messages.', [port('campaign-request', 'Campaign request', 'A campaign message request.')], [port('campaign-event', 'Campaign event', 'Campaign delivery status.')], [action('send-campaign', 'Send campaign', 'Send a fictional campaign message.', '{"campaign":"welcome","customerId":"cus_89"}')], '{"campaign":"welcome","customerId":"cus_89"}') ]},
{ id: 'analytics', name: 'Analytics', description: 'Collect and report product and business events.', category: 'data', color: '#8f7cf2', capabilities: [capability('event-collection', 'Event collection', 'Accept events from connected systems.', [port('event', 'Event', 'A product or business event.')], [port('accepted-event', 'Accepted event', 'An accepted analytics event.')], [action('capture-event', 'Capture event', 'Capture a fictional analytics event.', '{"event":"checkout_completed","visitorId":"vis_204"}')], '{"event":"checkout_completed","visitorId":"vis_204"}'), capability('reporting', 'Reporting', 'Produce a simple report payload.', [port('report-query', 'Report query', 'A report query.')], [port('report', 'Report', 'A generated report.')], [action('run-report', 'Run report', 'Generate a fictional report.', '{"report":"weekly-orders","orders":42}')], '{"report":"weekly-orders","orders":42}') ]},
{ id: 'api', name: 'API', description: 'Orchestrate requests between applications and services.', category: 'service', color: '#26c6a6', capabilities: [capability('http-api', 'HTTP API', 'Receive and route application requests.', [port('request', 'Request', 'An inbound API request.')], [port('response', 'Response', 'A response returned to the caller.')], [action('handle-request', 'Handle request', 'Handle a fictional API request.', '{"requestId":"req_1001","status":"accepted"}')], '{"requestId":"req_1001","status":"accepted"}'), capability('webhooks', 'Webhooks', 'Send outbound event notifications.', [port('event', 'Event', 'An event to publish.')], [port('webhook', 'Webhook', 'An outbound webhook delivery.')], [action('send-webhook', 'Send webhook', 'Send a fictional webhook.', '{"event":"order.created","id":"ord_1042"}')], '{"event":"order.created","id":"ord_1042"}') ]}
]
export function getPreset(id: string) { return SYSTEM_PRESETS.find((preset) => preset.id === id) }
export function cloneCapabilities(capabilities: CapabilityModel[], selectedIds?: string[]) { return structuredClone(capabilities.filter((item) => !selectedIds || selectedIds.includes(item.id))) }
export function systemFromPreset(preset: SystemPreset, selectedCapabilityIds: string[], position: [number, number]): SystemModel { return { id: uid('system'), presetId: preset.id, name: preset.name, description: preset.description, category: preset.category, color: preset.color, position, capabilities: cloneCapabilities(preset.capabilities, selectedCapabilityIds) } }
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] }
{ id: 'website', name: 'Website', description: 'Customer-facing storefront and account experience.', category: 'application', color: '#6d7cff', position: [80, 180], presetId: 'website', capabilities: cloneCapabilities(getPreset('website')!.capabilities) },
{ id: 'api', name: 'API', description: 'Order and customer orchestration service.', category: 'service', color: '#26c6a6', position: [360, 180], presetId: 'api', capabilities: cloneCapabilities(getPreset('api')!.capabilities) },
{ id: 'erp', name: 'ERP', description: 'Back-office order fulfilment and inventory system.', category: 'data', color: '#f2a65a', position: [650, 100], presetId: 'erp', capabilities: cloneCapabilities(getPreset('erp')!.capabilities) },
{ id: 'crm', name: 'CRM', description: 'Customer profile and lifecycle management.', category: 'data', color: '#dd6bca', position: [650, 290], presetId: 'crm', capabilities: cloneCapabilities(getPreset('crm')!.capabilities) },
{ id: 'email', name: 'Email Platform', description: 'Transactional and lifecycle messaging.', category: 'external', color: '#4aa3df', position: [930, 290], presetId: 'email', capabilities: cloneCapabilities(getPreset('email')!.capabilities) }
],
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}' },
@@ -87,7 +117,8 @@ export function validateLandscape(value: unknown): 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))
const systems = landscape.systems.map((item) => ({ ...item, capabilities: Array.isArray(item.capabilities) ? item.capabilities : [] }))
const systemIds = new Set(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.`)
}
@@ -95,5 +126,5 @@ export function validateLandscape(value: unknown): LandscapeModel {
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)
return structuredClone({ ...landscape, systems } as LandscapeModel)
}
+1 -1
View File
File diff suppressed because one or more lines are too long