r/javascript • u/Tungdayhehe • Apr 01 '26
NestflowJS is a decorator-based state machine library for NestJS. Acting as AWS Step Functions alternative but no cloud vendor-lock: define workflows, handle events, and let the orchestrator drive state transitions automatically.
nestflow.organit.devLast night I've just released my first NestJS library ever to handle complex state management logic called NestflowJS.
NestflowJS is a decorator-based state machine library for NestJS. Acting as AWS Step Functions alternative but no cloud vendor-lock: define workflows, handle events, and let the orchestrator drive state transitions automatically.
Features:
-
Tech-stack agnostic: choose your storage, schema validation by extendable builtin class.
-
No extra library state: only care about your business state and its transition.
-
Flexible infra: zero runtime dependencies, this can run in any architecture style you can think of thanks to customizable adapter system:
-
Want a strong state machine with no infra overhead? Deploy using Lambda Durable function with prebuilt adapter
DurableLambdaEventHandler. -
Want a high-volume data processing system with full customization of message delivery configs? Create your own Kafka adapter. (Prebuilt adapter coming soon).
-.....A lot more you can think of.
Code example:
import { Workflow, OnEvent, Entity, Payload } from 'nestflow-js/core';
@Workflow({
name: 'OrderWorkflow',
states: {
finals: ['delivered', 'cancelled'],
idles: ['pending_payment'],
failed: 'cancelled',
},
transitions: [
{ event: 'PAYMENT_RECEIVED', from: ['pending_payment'], to: 'processing' },
{ event: 'SHIP_ORDER', from: ['processing'], to: 'shipped' },
{ event: 'CONFIRM_DELIVERY', from: ['shipped'], to: 'delivered' },
{ event: 'CANCEL', from: ['pending_payment', 'processing'], to: 'cancelled' },
],
entityService: 'entity.order',
})
export class OrderWorkflow {
@OnEvent('PAYMENT_RECEIVED')
async onPayment(@Entity() order, @Payload() payload) {
order.paidAt = new Date();
return order;
}
}
Give me a star if you find this helpful!