Workflow Engine SDK

The Workflow Engine SDK (@allternit/workflow-engine) is a TypeScript library for defining and running directed acyclic graph (DAG) workflows. It provides a lightweight engine, a parallel task scheduler, and visualizers that export workflows to SVG, Mermaid, or Graphviz.

Overview

Use this SDK when you want to:
  • Build deterministic, multi-step automation pipelines in TypeScript.
  • Orchestrate HTTP requests, transforms, conditional branches, delays, and loops from a single workflow graph.
  • Execute workflows locally with built-in concurrency controls and lifecycle hooks.
  • Render workflow definitions as diagrams for documentation or a visual editor.

Installation

Quick start

Core concepts

Workflow

A workflow is a declarative DAG made of nodes and connections. It is registered by ID and version, then executed by calling engine.execute(workflowId, inputs). Each execution receives its own execution ID and isolated context.

Nodes and connections

Nodes are the units of work. Connections describe the directed edges between them. The engine starts with nodes that have no incoming connections, then walks the graph as each node completes.

Execution context

Every workflow execution maintains a context that carries workflow variables, node results, and the execution path. Node executors receive this context plus resolved inputs, and return a result object that downstream nodes can consume.

Scheduler

The scheduler manages parallel task submission, concurrency limits, and cancellation. You can use it directly for advanced scenarios or let the engine manage execution for you.

Visualizer

The visualizer computes layered layouts and exports them to SVG, Mermaid, or Graphviz DOT format for embedding in documentation or a UI canvas.

Built-in node types

Triggers

Transforms

Logic

Actions

Engine configuration

Execution lifecycle

Execution statuses:

Conditional branching

Add a condition property to a connection to route execution dynamically:
The condition is evaluated against the source node’s result and the current execution context.

Input and output mappings

Map workflow variables into node inputs using expressions:
Workflow outputs are collected automatically from every output:result node at the end of execution.

Custom node types

Register your own node types to extend the engine:

Scheduler

Use the scheduler directly when you need fine-grained control over task concurrency:

Visualization

The visualizer performs a layered auto-layout based on topological order and assigns colors and icons for built-in node types.

Engine methods

Types

All workflow types are exported for TypeScript users:

Error handling

Errors are captured per node and surfaced on the execution object:
Common errors:

Global instances

For convenience, the package exports pre-created singletons:
These are useful for scripts and small prototypes. For production services, prefer createWorkflowEngine() and createScheduler() so instances remain isolated.