A powerful, production-ready workflow engine built with TypeScript. Features a robust state machine core with advanced enterprise capabilities including parallel execution, hierarchical states, saga patterns, middleware, retry logic, idempotency, and validation.
- 🎯 State Machine Core - Robust state machine with transitions, guards, and actions
- ⚡ Parallel States - Execute multiple regions concurrently
- 🏗️ Hierarchical States - Nested state machines for complex workflows
- 🎭 Saga Pattern - Built-in compensation/rollback for distributed transactions
- 🔁 Sub-Flows - Compose workflows from reusable components
- 🔌 Middleware - Hooks for logging, metrics, observability
- ♻️ Retry Logic - Automatic retry with exponential backoff
- 🔐 Idempotency - Prevent duplicate executions
- ✅ Validation - Schema-based context validation
- 📝 YAML DSL - Define workflows declaratively
- 🏷️ Type-Safe - Full TypeScript support
- 🧪 Well Tested - 162+ comprehensive tests
# Install dependencies
npm install
# Build packages
npm run build
# Run tests
npm testimport { FlowEngine, StateMachineConfig } from '@tsflow/flow-engine';
const config: StateMachineConfig = {
id: 'order-flow',
initialState: 'pending',
states: {
pending: {
name: 'pending',
transitions: [
{ event: 'APPROVE', to: 'approved' },
{ event: 'REJECT', to: 'rejected' }
]
},
approved: { name: 'approved', type: 'final' },
rejected: { name: 'rejected', type: 'final' }
}
};
const engine = new FlowEngine(config);
const flow = await engine.start({ context: { orderId: '12345' } });
await engine.execute(flow.flowId, { event: 'APPROVE' });
console.log('Order approved!');id: order-flow
initial: pending
states:
pending:
on:
APPROVE: approved
REJECT: rejected
approved:
final: true
rejected:
final: trueComplete documentation for using tsFlow in your projects:
- Getting Started - Installation, setup, and your first workflow
- Advanced Patterns - Parallel states, saga pattern, sub-flows, middleware
- YAML Workflows - Declarative workflow definitions
- Examples - Real-world production examples (e-commerce, DevOps, finance, etc.)
- API Reference - Complete API documentation
👉 Start here: Documentation Home
- E-Commerce - Order processing, payments, fulfillment
- User Management - Registration, verification, onboarding
- Content Management - Approval workflows, publishing pipelines
- DevOps - CI/CD, infrastructure provisioning, deployments
- Finance - Loan applications, KYC, transaction processing
- Customer Support - Ticket management, escalation workflows
- IoT - Device provisioning, commissioning, updates
tsFlow/
├── packages/
│ └── flow-engine/ # Core workflow engine package
│ ├── src/
│ │ ├── flow-engine.ts # Main FlowEngine class
│ │ ├── state-machine.ts # State machine implementation
│ │ ├── storage.ts # Storage interfaces
│ │ └── yaml-parser.ts # YAML DSL parser
│ ├── examples/ # Example workflows
│ └── tests/ # Comprehensive test suite
├── docs/ # Complete documentation
└── examples/ # Additional examples
# Run all tests
npm test
# Watch mode
npm run test:watch
# Coverage report
npm run test:coverage
# Run specific test file
npm test flow-engine.test.tsCurrent test status: 162 tests passing ✅
- @tsflow/flow-engine - Main workflow engine package
- FlowEngine - High-level workflow orchestration
- StateMachine - Core state machine implementation
- Storage - Pluggable storage backends
- YamlParser - YAML workflow parser
Contributions are welcome! This is a monorepo using:
- Turbo - Build system
- TypeScript - Language
- Vitest - Testing
- Vite - Build tool
[Your License Here]
Ready to build workflows? Start with the Getting Started Guide!