Build interactive system landscape simulator

This commit is contained in:
2026-11-05 22:03:46 +00:00
commit a28cb2e7b9
15 changed files with 2956 additions and 0 deletions
+99
View File
@@ -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)
}