XYLEX Group

Getting Started

Install Worlds Engine and create your first workflow

Getting Started

Install Worlds Engine and create your first workflow in minutes.

Installation

npm install worlds-engine

Or with other package managers:

yarn add worlds-engine
pnpm add worlds-engine

Your First Workflow

1. Create an Activity

Activities are the building blocks that perform actual work:

import { activity } from 'worlds-engine';

const processOrder = activity('process-order', async (ctx, order) => {
  // Simulate processing
  await new Promise(resolve => setTimeout(resolve, 1000));
  
  return {
    orderId: order.id,
    status: 'processed',
    total: order.items.reduce((sum, item) => sum + item.price, 0)
  };
});

2. Create a Workflow

Workflows orchestrate activities:

import { workflow } from 'worlds-engine';

const orderWorkflow = workflow('order-workflow', async (ctx, input) => {
  // Run the processing activity
  const result = await ctx.run(processOrder, input.order);
  
  // Return the result
  return {
    success: true,
    order: result
  };
});

3. Initialize the World

The World manages workflow execution:

import { World } from 'worlds-engine';

const world = new World({
  minWorkers: 2,
  maxWorkers: 10,
  persistence: 'hybrid'
});

// Register workflows and activities
world.register(orderWorkflow, processOrder);

// Start the world
await world.start();

4. Execute a Workflow

const handle = await world.execute('order-workflow', {
  order: {
    id: '12345',
    items: [
      { name: 'Widget', price: 10.99 },
      { name: 'Gadget', price: 24.99 }
    ]
  }
});

// Wait for completion
const result = await handle.result();
console.log(result);

Configuration Options

const world = new World({
  // Worker scaling
  minWorkers: 2,              // Minimum worker count
  maxWorkers: 10,             // Maximum worker count
  scaleThreshold: 0.7,        // Scale up at 70% workload
  scaleDownThreshold: 0.3,    // Scale down at 30% workload
  
  // Storage
  persistence: 'hybrid',      // 'memory' | 'file' | 'hybrid'
  persistencePath: '.worlds-engine',
  
  // Failure handling
  failureStrategy: 'retry',   // 'retry' | 'compensate' | 'cascade' | 'ignore' | 'quarantine'
  
  // Health monitoring
  heartbeatInterval: 5000,    // Heartbeat every 5 seconds
  heartbeatTimeout: 30000     // Timeout after 30 seconds
});

Next Steps