How dali-benothmen/cronflow works
1. Repository shape
- Cronflow is a hybrid TypeScript + Rust workflow engine.
- The TypeScript side is the public developer API and integration layer; the Rust core package is the execution/runtime engine.
- The repo is organized as a publishable library, not an application: root package, sdk/, native core/, docs/examples, tests, and release/build tooling.
2. Primary boundary: SDK vs Rust core
- sdk/ contains the user-facing workflow DSL and runtime helpers.
- core/ contains the performance-sensitive pieces: workflow execution, state handling, trigger dispatch, persistence, and HTTP webhook serving.
- sdk/src/rust/* and core/src/bridge.rs form the native bridge between TypeScript and Rust.
3. Workflow authoring layer
- The workflow model lives in sdk/src/workflow/* and is exposed from the package entrypoints.
- This layer defines workflow metadata, steps, triggers, validation, and framework registration.
- User code builds a workflow graph in TypeScript; the resulting definition is then handed to the runtime for execution.
4. Trigger intake path
- Triggers are supported from several sources: webhooks, custom events, and manual/programmatic invocation.
- On the TypeScript side, sdk/src/webhook, sdk/src/triggers, and sdk/src/events manage registration and dispatch.
- The Rust core has corresponding webhook_server.rs, triggers.rs, and trigger_executor.rs components to receive and normalize incoming work.
5. Execution pipeline
- Once a trigger arrives, the core routes it through dispatcher.rs and workflow_state_machine.rs.
- step_orchestrator.rs coordinates step-by-step execution, while job.rs and state.rs track run-level progress.
- The flow is designed so each step can read prior output from workflow context and emit a new state/result.
6. Persistence and runtime state
- core/src/database.rs, schema.sql, and models.rs define the durable workflow/job state model.
- This is where execution records, step results, and pause/resume data are stored.
- The TypeScript side mirrors some of this with sdk/src/state/* for app-level state management and wrappers around workflow state.
7. Control flow and reliability
- Conditional branching is handled in Rust by condition_evaluator.rs and exposed through the workflow DSL.
- Reliability features are first-class in the SDK: retry logic, circuit breaker, concurrency management, and human-in-the-loop pause/resume.
- These concerns are separated into dedicated SDK modules (retry/, circuit-breaker/, execution/, human-loop/) so they wrap steps without polluting workflow definitions.
8. Webhook and framework integration
- Webhook support is a major boundary: sdk/src/webhook/server.ts and core/src/webhook_server.rs together provide route handling and request validation.
- The README shows integration with Express, Fastify, or custom routers, so Cronflow does not own the whole HTTP app.
- Instead, it registers handlers into an existing server or can run its own listener, depending on configuration.
9. Events, hooks, and orchestration helpers
- sdk/src/events, sdk/src/hooks, and sdk/src/scheduler.ts provide non-trigger orchestration mechanisms around the workflow engine.
- sdk/src/performance/* and sdk/src/testing/* are support subsystems for measuring, optimizing, and validating workflows.
- These modules sit outside the core execution path but shape how workflows are managed in production and in tests.
10. Native packaging and build/runtime concerns
- core/Cargo.toml, build.rs, tests/napi/*, and the Rust/TypeScript bridge indicate a native addon distribution model.
- The repo includes cross-platform binary packaging, release automation, and bundle-size optimization scripts.
- The README emphasizes Bun as the preferred runtime, but the architecture is really “TypeScript API + native Rust engine” with framework-agnostic host integration.
11. How data moves through the system
- A developer defines a workflow in TypeScript.
- A trigger enters via webhook/event/manual API.
- The SDK validates and routes the trigger, then calls into Rust.
- Rust persists state, evaluates conditions, dispatches steps, and updates workflow/job records.
- Results and pause/resume signals flow back through the bridge to the SDK and any external app integrations.
12. What to emphasize in an architecture diagram
- Draw a hard boundary between the public TypeScript SDK and the Rust execution core.
- Show trigger sources feeding into a trigger intake layer, then into workflow orchestration/state machine, then into persistence.
- Show reliability features as wrappers around step execution, not as separate apps.
- Show webhooks and framework integrations as adapters around the engine, not as the engine itself.
Main entry points: index.ts Workflow model · integration.ts Rust bridge · workflow_state_machine.rs State machine · bridge.rs Core bridge
Components 21
TypeScript SDK
Public workflow API, orchestration helpers, and runtime adapters.
- SDK entry · Public TypeScript exports and package surface.
sdk/index.ts - Workflow model · Workflow definitions, steps, triggers, validation, and framework registration.
sdk/src/workflow/index.ts - Workflow runtime · Workflow instances and type-aware workflow helpers.
sdk/src/workflow/instance.ts - Trigger API · SDK trigger registration and dispatch coordination.
sdk/src/triggers/trigger-manager.ts - Webhook adapter · Framework-facing webhook server and route integration.
sdk/src/webhook/server.ts - Events & hooks · Event manager and hook coordination around workflows.
sdk/src/events/event-manager.ts - Execution wrappers · Concurrency, step execution, retries, and workflow engine helpers.
sdk/src/execution/workflow-engine.ts - State wrappers · App-level state managers and workflow state wrappers.
sdk/src/state/manager.ts - Human loop · Pause and resume coordination for human-in-the-loop workflows.
sdk/src/human-loop/pause-manager.ts - Rust bridge · TypeScript integration layer into the native addon.
sdk/src/rust/integration.ts
Rust Core
Native execution engine, persistence, and webhook handling.
- Core bridge · Rust-side boundary for native calls from TypeScript.
core/src/bridge.rs - Trigger intake · Rust trigger normalization and execution entrypoint.
core/src/trigger_executor.rs - Dispatcher · Routes incoming triggers into workflow execution.
core/src/dispatcher.rs - State machine · Workflow state transitions and execution control.
core/src/workflow_state_machine.rs - Step orchestrator · Coordinates step-by-step workflow execution.
core/src/step_orchestrator.rs - Persistence · Durable workflow, job, and step state model.
core/src/database.rs - Webhook server · Native webhook listener and request validation.
core/src/webhook_server.rs - Conditions · Branching and condition evaluation for workflow flow.
core/src/condition_evaluator.rs - Runtime models · Core models, job state, and workflow state data structures.
core/src/models.rs
Tooling & Docs
Build, packaging, examples, and documentation around the library.
- Cronflow · Hybrid TypeScript + Rust workflow engine package.
package.json - Architecture docs · Repository architecture and integration guides.
docs/architecture.md
Connections 25
- Cronflow → SDK entry: exports · Primary package surface exposes the SDK.
- SDK entry → Workflow model: builds · Users define workflows through the DSL.
- Workflow model → Workflow runtime: instantiates · Workflow definitions produce runnable instances.
- Workflow model → Trigger API: registers · Workflow definitions declare trigger handling.
- Workflow model → Webhook adapter: binds · Webhook routes are attached to workflow triggers.
- Workflow model → Execution wrappers: wraps · Reliability helpers decorate workflow steps.
- Workflow model → State wrappers: tracks · SDK state layer mirrors workflow-level state.
- Workflow model → Human loop: pauses · Human-in-the-loop controls integrate with workflows.
- Trigger API → Events & hooks: dispatches · Triggers can be emitted through events and hooks.
- Webhook adapter → Rust bridge: invokes · Webhook intake forwards validated work into native runtime.
- Events & hooks → Rust bridge: invokes · Programmatic events can enter the native engine.
- Execution wrappers → Rust bridge: calls · Step execution and retries eventually cross into Rust.
- State wrappers → Rust bridge: syncs · State wrappers synchronize with native workflow state.
- Human loop → Rust bridge: pauses · Pause and resume signals cross the bridge.
- Rust bridge → Core bridge: bridges · TypeScript addon integration reaches the Rust boundary.
- Core bridge → Webhook server: accepts · Native webhook server receives external requests.
- Core bridge → Trigger intake: normalizes · Incoming triggers are normalized for execution.
- Trigger intake → Dispatcher: routes · Trigger intake hands work to the dispatcher.
- Dispatcher → State machine: advances · Dispatcher drives workflow state transitions.
- State machine → Conditions: branches · Workflow control flow evaluates conditions.
- State machine → Step orchestrator: orchestrates · State machine coordinates step execution.
- Step orchestrator → Persistence: persists · Execution progress and results are stored durably.
- State machine → Runtime models: updates · Core execution updates runtime models.
- Webhook server → Persistence: records · Webhook intake can create execution records.
- Architecture docs → Workflow model: describes · Docs explain the workflow authoring model.