Plexis
Quick Start
Section titled “Quick Start”Install Plexis:
npm install @tde.io/plexisDefine a pipeline and domain, then drive the domain forward:
import { defineDomain, definePipeline, when, on, target, pipeline, node, action, fork, terminal } from '@tde.io/plexis';
type OrderContext = { cardValid: boolean };
// Pipeline: runs once per invocation — validate then route to charge or declineconst payment = definePipeline<OrderContext>('payment', () => { node('validate', () => { fork('card-ok', target('charge'), (ctx) => ctx.cardValid); fork('card-invalid', target('decline'), (ctx) => !ctx.cardValid); }); node('charge', terminal()); node('decline', terminal()); return { initial: 'validate' };});
// Domain: durable order state — pending → processing → fulfilledconst order = defineDomain<OrderContext>('order', () => { when('pending', () => { on('submit', () => { pipeline(payment); return target('processing'); }); }); when('processing', () => { on('fulfill', target('fulfilled')); }); when('fulfilled', terminal()); return { context: { cardValid: true }, initial: 'pending' } as const;});
// Drive the domain forwardconst result = await order.follow('submit');console.log(result.status); // 'followed'console.log(result.to); // 'processing'Core Concepts
Section titled “Core Concepts”Plexis separates business logic into two complementary layers:
Domain — durable state that persists across time. A domain has named states, flows triggered by events, optional guards, lifecycle hooks (enter/exit), and can invoke pipelines on flows. Define one with defineDomain() and advance it with domain.follow(event).
Pipeline — a finite, single-run workflow. Execution starts at the initial node and follows the first matching fork at each step until it reaches a terminal node. Define one with definePipeline() and run it with pipeline.run(context).
The two layers compose naturally: a flow on a domain can invoke a pipeline, so workflow logic (validation, enrichment, side effects) lives in the pipeline while the domain tracks the resulting state.
Zero Dependencies
Section titled “Zero Dependencies”Plexis has no runtime dependencies. It runs in Node.js ≥ 19, modern browsers, and serverless environments without polyfills.