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
+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)
}