by gorango
A lightweight workflow engine
# Add to your Claude Code skills
git clone https://github.com/gorango/flowcraftflowcraftBuild complex, multi-step processes with a lightweight, composable, and type-safe approach. Model complex business processes, data pipelines, ETL workflows, or AI agents and scale from in-memory scripts to distributed systems without changing the core business logic.
No comments yet. Be the first to share your thoughts!
npm install flowcraft
Define and run a simple workflow in a few lines of code.
import { createFlow, FlowRuntime, type NodeContext } from 'flowcraft'
// 1. Define your functions for the nodes
async function startNode({ context }: NodeContext) {
const output = await context.get('value')
return { output }
}
async function doubleNode({ input, context }: NodeContext) {
const output = input * 2
context.set('double', output)
return { output }
}
// 2. Define the workflow structure
const flow = createFlow('simple-workflow')
.node('start', startNode)
.node('double', doubleNode)
.edge('start', 'double')
// 3. Initialize the runtime
const runtime = new FlowRuntime()
// 4. Execute the workflow
async function run() {
const result = await flow.run(runtime, { value: 42 })
console.log(result.context) // { start: 42, double: 84 }
console.log(result.status) // 'completed'
}
run()
BaseNode for more complex lifecycle management.action of a source node.FlowRuntime is the engine that interprets a blueprint and executes its nodes in the correct order. It manages state, handles resiliency, and coordinates the entire process.Design robust workflows with built-in resiliency features.
maxRetries property on a node to automatically retry it on failure.fallback node ID in a node's configuration. If the node fails all its retry attempts, the fallback node will be executed instead, preventing the entire workflow from failing.For more granular control, you can implement a node using the BaseNode class, which provides prep, exec, post, fallback, and recover lifecycle methods.
Flowcraft includes tools to help you validate and visualize your workflows.
lintBlueprint): Statically analyze a blueprint to find common errors, such as orphan nodes, invalid edges, or nodes with missing implementations.analyzeBlueprint): Programmatically inspect a blueprint to detect cycles, find start/terminal nodes, and get other graph metrics.generateMermaid): Automatically generate a Mermaid syntax string from a blueprint to easily visualize your workflow's structure.The FlowRuntime can be configured with pluggable components to tailor its behavior to your specific needs:
ILogger implementation (e.g., Pino, Winston) to integrate with your existing logging infrastructure.JsonSerializer with a more robust one (e.g., superjson) to handle complex data types like Date, Map, and Set in the workflow context.PropertyEvaluator for a more powerful expression engine (like jsep or govaluate) to enable complex logic in edge conditions. For trusted environments, an UnsafeEvaluator is also available.workflow:start, node:finish, etc.).Flowcraft's architecture is designed for progressive scalability. The BaseDistributedAdapter provides a foundation for running workflows across multiple machines. Flowcraft provides official adapters for BullMQ, AWS, GCP, Azure, RabbitMQ, Kafka, Vercel, and Cloudflare.
For a complete overview of features, patterns, examples, and APIs, see the full documentation.
Flowcraft is licensed under the MIT License.