Skip to main content

Introduction to Chevere Workflow

Chevere Workflow is a PHP library for building and executing multi-step procedures with automatic dependency resolution. Define independent jobs that can run synchronously or asynchronously, pass data between them using typed responses, and let the engine handle execution order automatically.

Declarative definitions

Define what to do, not how to orchestrate it. The engine handles execution order automatically.

Automatic dependency graph

Jobs execute in optimal order based on their dependencies. Parallel execution when possible.

Sync and async execution

Mix blocking and non-blocking jobs freely. The engine optimizes execution strategy.

Type-safe responses

Access job outputs with full type safety. No guessing about return types.

Conditional execution

Run jobs based on variables or previous responses. Skip unnecessary work.

Built-in retry policies

Handle transient failures automatically with configurable retry strategies.

How it works

Workflow is built around four main concepts:
ConceptDescription
JobA unit of work that produces a response
VariableExternal input provided when running the workflow
ResponseReference to output from a previous job
GraphAutomatic execution order based on job dependencies

Execution flow

1

Define jobs

Create jobs using sync() or async() functions with Actions, closures, or callables.
2

Declare inputs

Jobs declare their inputs: literal values, variable() references, or response() from other jobs.
3

Build dependency graph

The engine automatically builds a dependency graph from your job definitions.
4

Execute in optimal order

Jobs execute in the optimal order, running in parallel when possible.
5

Access typed responses

Retrieve job outputs with full type safety after execution completes.

Quick example

Here’s a minimal workflow to get a taste of how it works:
use function Chevere\Workflow\{workflow, sync, variable, run};

// Define a workflow with jobs
$workflow = workflow(
    greet: sync(
        fn(string $name): string => "Hello, {$name}!",
        name: variable('username')
    )
);

// Run with variables
$result = run($workflow, username: 'World');

// Get typed responses
echo $result->response('greet')->string();
// Output: Hello, World!

Core functions

Workflow provides a simple functional API:
FunctionPurpose
workflow()Create a workflow from named jobs
sync()Create a synchronous (blocking) job
async()Create an asynchronous (non-blocking) job
variable()Declare a runtime variable
response()Reference another job’s output
run()Execute a workflow with variables

Why Workflow?

Traditional approach

// Manual orchestration, hard to test, tightly coupled
$data = fetchData($url);
$processed = processData($data);
$validated = validateData($processed);
if ($validated['needsTransform']) {
    $transformed = transformData($validated);
    return storeData($transformed);
}
return storeData($validated);

With Workflow

// Declarative, testable, automatically optimized
$workflow = workflow(
    fetch: async(FetchData::class, url: variable('url')),
    process: async(ProcessData::class, data: response('fetch')),
    validate: sync(ValidateData::class, data: response('process')),
    transform: async(
        TransformData::class,
        data: response('validate')
    )->withRunIf(response('validate', 'needsTransform')),
    store: sync(
        StoreData::class,
        data: response('transform') ?? response('validate')
    )
);

$result = run($workflow, url: $apiUrl);
Each job is independently testable, the execution graph is automatically optimized, and conditional logic is declarative.

Integration with Chevere ecosystem

Workflow works seamlessly with other Chevere packages:
These integrations are optional. You can use Workflow with plain closures and callables, but the Chevere ecosystem provides stronger guarantees and reduces boilerplate.

Next steps

Installation

Install Workflow via Composer and get your environment ready

Quick start

Build your first workflow in under 5 minutes

Build docs developers (and LLMs) love