# dali-benothmen/cronflow architecture

> Architecture diagram of the GitHub repository dali-benothmen/cronflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dali-benothmen/cronflow
- Repository: https://github.com/dali-benothmen/cronflow

## Overview

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: [`sdk/src/workflow/index.ts`](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/workflow/index.ts) (Workflow model), [`sdk/src/rust/integration.ts`](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/rust/integration.ts) (Rust bridge), [`core/src/workflow_state_machine.rs`](https://github.com/dali-benothmen/cronflow/blob/master/core/src/workflow_state_machine.rs) (State machine), [`core/src/bridge.rs`](https://github.com/dali-benothmen/cronflow/blob/master/core/src/bridge.rs) (Core bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sdk["TypeScript SDK"]
  node_sdk_entry["SDK entry<br/>ts entry<br/>[index.ts]"]
  node_workflow_model["Workflow model<br/>dsl<br/>[index.ts]"]
  node_workflow_runtime["Workflow runtime<br/>[instance.ts]"]
  node_trigger_api["Trigger API<br/>ingress<br/>[trigger-manager.ts]"]
  node_webhook_adapter["Webhook adapter<br/>[server.ts]"]
  node_event_hooks["Events & hooks<br/>orchestration<br/>[event-manager.ts]"]
  node_execution_wrap["Execution wrappers<br/>reliability<br/>[workflow-engine.ts]"]
  node_state_wrap["State wrappers<br/>[manager.ts]"]
  node_human_loop["Human loop<br/>pause/resume<br/>[pause-manager.ts]"]
  node_rust_bridge["Rust bridge<br/>native bridge<br/>[integration.ts]"]
end

subgraph group_core["Rust Core"]
  node_core_bridge["Core bridge<br/>ffi bridge<br/>[bridge.rs]"]
  node_trigger_core["Trigger intake<br/>ingress"]
  node_dispatcher["Dispatcher<br/>routing<br/>[dispatcher.rs]"]
  node_state_machine["State machine<br/>orchestration"]
  node_step_orchestrator["Step orchestrator<br/>execution"]
  node_persistence[("Persistence<br/>database<br/>[database.rs]")]
  node_webhook_core["Webhook server<br/>[webhook_server.rs]"]
  node_condition_eval["Conditions<br/>logic"]
  node_runtime_models["Runtime models<br/>state model<br/>[models.rs]"]
end

subgraph group_tooling["Tooling & Docs"]
  node_root["Cronflow<br/>[package.json]"]
  node_docs_arch["Architecture docs<br/>[architecture.md]"]
end

node_root -->|"exports"| node_sdk_entry
node_sdk_entry -->|"builds"| node_workflow_model
node_workflow_model -->|"instantiates"| node_workflow_runtime
node_workflow_model -->|"registers"| node_trigger_api
node_workflow_model -->|"binds"| node_webhook_adapter
node_workflow_model -->|"wraps"| node_execution_wrap
node_workflow_model -->|"tracks"| node_state_wrap
node_workflow_model -->|"pauses"| node_human_loop
node_trigger_api -->|"dispatches"| node_event_hooks
node_webhook_adapter -->|"invokes"| node_rust_bridge
node_event_hooks -->|"invokes"| node_rust_bridge
node_execution_wrap -->|"calls"| node_rust_bridge
node_state_wrap -->|"syncs"| node_rust_bridge
node_human_loop -->|"pauses"| node_rust_bridge
node_rust_bridge -->|"bridges"| node_core_bridge
node_core_bridge -->|"accepts"| node_webhook_core
node_core_bridge -->|"normalizes"| node_trigger_core
node_trigger_core -->|"routes"| node_dispatcher
node_dispatcher -->|"advances"| node_state_machine
node_state_machine -->|"branches"| node_condition_eval
node_state_machine -->|"orchestrates"| node_step_orchestrator
node_step_orchestrator -->|"persists"| node_persistence
node_state_machine -->|"updates"| node_runtime_models
node_webhook_core -->|"records"| node_persistence
node_docs_arch -.->|"describes"| node_workflow_model

click node_root "https://github.com/dali-benothmen/cronflow/blob/master/package.json"
click node_sdk_entry "https://github.com/dali-benothmen/cronflow/blob/master/sdk/index.ts"
click node_workflow_model "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/workflow/index.ts"
click node_workflow_runtime "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/workflow/instance.ts"
click node_trigger_api "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/triggers/trigger-manager.ts"
click node_webhook_adapter "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/webhook/server.ts"
click node_event_hooks "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/events/event-manager.ts"
click node_execution_wrap "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/execution/workflow-engine.ts"
click node_state_wrap "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/state/manager.ts"
click node_human_loop "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/human-loop/pause-manager.ts"
click node_rust_bridge "https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/rust/integration.ts"
click node_core_bridge "https://github.com/dali-benothmen/cronflow/blob/master/core/src/bridge.rs"
click node_trigger_core "https://github.com/dali-benothmen/cronflow/blob/master/core/src/trigger_executor.rs"
click node_dispatcher "https://github.com/dali-benothmen/cronflow/blob/master/core/src/dispatcher.rs"
click node_state_machine "https://github.com/dali-benothmen/cronflow/blob/master/core/src/workflow_state_machine.rs"
click node_step_orchestrator "https://github.com/dali-benothmen/cronflow/blob/master/core/src/step_orchestrator.rs"
click node_persistence "https://github.com/dali-benothmen/cronflow/blob/master/core/src/database.rs"
click node_webhook_core "https://github.com/dali-benothmen/cronflow/blob/master/core/src/webhook_server.rs"
click node_condition_eval "https://github.com/dali-benothmen/cronflow/blob/master/core/src/condition_evaluator.rs"
click node_runtime_models "https://github.com/dali-benothmen/cronflow/blob/master/core/src/models.rs"
click node_docs_arch "https://github.com/dali-benothmen/cronflow/blob/master/docs/architecture.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sdk_entry,node_workflow_model,node_workflow_runtime,node_trigger_api,node_webhook_adapter,node_event_hooks,node_execution_wrap,node_state_wrap,node_human_loop,node_rust_bridge toneBlue
class node_core_bridge,node_trigger_core,node_dispatcher,node_state_machine,node_step_orchestrator,node_persistence,node_webhook_core,node_condition_eval,node_runtime_models toneAmber
class node_root,node_docs_arch toneMint
```

## Components

### TypeScript SDK

Public workflow API, orchestration helpers, and runtime adapters.

- [SDK entry](https://github.com/dali-benothmen/cronflow/blob/master/sdk/index.ts): ts entry · Public TypeScript exports and package surface. · `sdk/index.ts`
- [Workflow model](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/workflow/index.ts): dsl · Workflow definitions, steps, triggers, validation, and framework registration. · `sdk/src/workflow/index.ts`
- [Workflow runtime](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/workflow/instance.ts): runtime · Workflow instances and type-aware workflow helpers. · `sdk/src/workflow/instance.ts`
- [Trigger API](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/triggers/trigger-manager.ts): ingress · SDK trigger registration and dispatch coordination. · `sdk/src/triggers/trigger-manager.ts`
- [Webhook adapter](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/webhook/server.ts): adapter · Framework-facing webhook server and route integration. · `sdk/src/webhook/server.ts`
- [Events & hooks](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/events/event-manager.ts): orchestration · Event manager and hook coordination around workflows. · `sdk/src/events/event-manager.ts`
- [Execution wrappers](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/execution/workflow-engine.ts): reliability · Concurrency, step execution, retries, and workflow engine helpers. · `sdk/src/execution/workflow-engine.ts`
- [State wrappers](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/state/manager.ts): state · App-level state managers and workflow state wrappers. · `sdk/src/state/manager.ts`
- [Human loop](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/human-loop/pause-manager.ts): pause/resume · Pause and resume coordination for human-in-the-loop workflows. · `sdk/src/human-loop/pause-manager.ts`
- [Rust bridge](https://github.com/dali-benothmen/cronflow/blob/master/sdk/src/rust/integration.ts): native bridge · TypeScript integration layer into the native addon. · `sdk/src/rust/integration.ts`

### Rust Core

Native execution engine, persistence, and webhook handling.

- [Core bridge](https://github.com/dali-benothmen/cronflow/blob/master/core/src/bridge.rs): ffi bridge · Rust-side boundary for native calls from TypeScript. · `core/src/bridge.rs`
- [Trigger intake](https://github.com/dali-benothmen/cronflow/blob/master/core/src/trigger_executor.rs): ingress · Rust trigger normalization and execution entrypoint. · `core/src/trigger_executor.rs`
- [Dispatcher](https://github.com/dali-benothmen/cronflow/blob/master/core/src/dispatcher.rs): routing · Routes incoming triggers into workflow execution. · `core/src/dispatcher.rs`
- [State machine](https://github.com/dali-benothmen/cronflow/blob/master/core/src/workflow_state_machine.rs): orchestration · Workflow state transitions and execution control. · `core/src/workflow_state_machine.rs`
- [Step orchestrator](https://github.com/dali-benothmen/cronflow/blob/master/core/src/step_orchestrator.rs): execution · Coordinates step-by-step workflow execution. · `core/src/step_orchestrator.rs`
- [Persistence](https://github.com/dali-benothmen/cronflow/blob/master/core/src/database.rs): database · Durable workflow, job, and step state model. · `core/src/database.rs`
- [Webhook server](https://github.com/dali-benothmen/cronflow/blob/master/core/src/webhook_server.rs): server · Native webhook listener and request validation. · `core/src/webhook_server.rs`
- [Conditions](https://github.com/dali-benothmen/cronflow/blob/master/core/src/condition_evaluator.rs): logic · Branching and condition evaluation for workflow flow. · `core/src/condition_evaluator.rs`
- [Runtime models](https://github.com/dali-benothmen/cronflow/blob/master/core/src/models.rs): state model · Core models, job state, and workflow state data structures. · `core/src/models.rs`

### Tooling & Docs

Build, packaging, examples, and documentation around the library.

- [Cronflow](https://github.com/dali-benothmen/cronflow/blob/master/package.json): library · Hybrid TypeScript + Rust workflow engine package. · `package.json`
- [Architecture docs](https://github.com/dali-benothmen/cronflow/blob/master/docs/architecture.md): docs · Repository architecture and integration guides. · `docs/architecture.md`

## Connections

- 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.
