FlowDSL
FlowDSL is a text notation for defining an ExecKernel graph. It gives nodes, edges, conditions and terminal outputs their own declarations, so someone reviewing a definition can read a connection together with its labels and the conditions that govern it. Your application imports that text into a Graph and uses the graph with the engine.
Choose FlowDSL when that grouping makes the process easier for your team to author and review. JSON or YAML may fit better when other tools already produce the definition as structured data. The choice changes how the definition is written; your application still supplies the runtime context and handles the results returned by ExecKernel.
We will reuse the learning-path graph introduced in Anatomy of a graph. Root 10 offers the guide through edge 101, ending at node 20, and browser practice through edge 102, ending at node 30. The practice edge requires practiceEnabled: true. The downloadable FlowDSL definition includes the same English and Spanish presentation and terminal outputs as that graph.
Read the structure
Section titled “Read the structure”A definition starts with flow and the graph code. The following structure excerpt shows the nodes and connections; presentation, the condition and terminal outputs are added in the sections below.
flow learning-path { lang en, es default_lang en
nodes { node 10 root node 20 terminal node 30 terminal }
edges { edge 101: 10 -> 20 {} edge 102: 10 -> 30 {} }}flow learning-path sets the graph identity. lang lists the allowed presentation languages, and default_lang names the default. These declarations describe the graph; they do not choose the language of a particular run. Your application requests that language when it calls the engine.
Inside nodes, each declaration gives a node its integer ID. root selects the starting node, and terminal marks a point where navigation ends. Inside edges, the ID before the colon identifies the choice. The two IDs after it give the origin and destination: edge 102: 10 -> 30 is the practice choice from the root to terminal 30.
Attach presentation to the item it describes
Section titled “Attach presentation to the item it describes”To give the root a title and instructions, expand its node declaration with localized meta blocks:
node 10 root { meta en { title "How would you like to learn?" description "Choose a guide to read or an exercise to try." extras {"screen": "learning-choice"} } meta es { title "¿Cómo quieres aprender?" description "Elige una guía para leer o un ejercicio para practicar." extras {"screen": "learning-choice"} }}A meta en block describes this node in English; meta es supplies the Spanish presentation of the same node. The quoted text becomes the title or description that the engine can place in its payload. The extras map carries application data, here the name of a screen that your application could render.
The complete file also gives both terminal nodes their localized titles. Keeping those records inside each node makes their association visible while editing, even though the imported graph stores metadata separately from node structure.
Edges use label for their visible choice text. Their condition appears in the same declaration:
edges { edge 101: 10 -> 20 { label en "Read the guide" label es "Leer la guía" } edge 102: 10 -> 30 { label en "Practise in the browser" label es "Practicar en el navegador" when context_value practiceEnabled == true }}The when clause attaches the built-in context_value rule to edge 102. It names the context entry, comparison and expected value. This is a rule declaration: it asks the engine to read practiceEnabled from the context supplied by your application. It does not assign that value.
Here, true is a boolean. The rule compares both value and type, so an application context containing practiceEnabled: true satisfies it, while false or the string "true" does not. When the rule fails, the engine can return the practice choice as blocked; the guide remains available.
Describe the terminal results
Section titled “Describe the terminal results”A terminals block associates outputs with terminal node IDs. This excerpt contains the English guide outputs and the shared practice destination; the complete file also contains the Spanish guide outputs.
terminals { terminal 20 { output content { lang en content "Read the guide at your own pace." } output url { lang en url "https://example.org/learning/guide" label "Open the guide" } } terminal 30 { output redirect { url "https://example.org/learning/practice" } }}output content supplies text; output url supplies a link and its label; output redirect supplies a navigation destination. The lang field associates a translated output with a language. The practice redirect has no lang, so the same destination can be returned for either language.
These declarations become terminal payload data. Your application performs the corresponding display or navigation when it receives them. FlowDSL describes that result without embedding the application’s business operations in the definition. The URLs above are example destinations; Terminal outputs explains how an application uses these output types.
Import the complete text
Section titled “Import the complete text”In a PHP project with its Composer autoloader loaded, read the complete file and pass its contents to SchemaImporter::importDsl():
use ExecKernel\Infrastructure\Importer\SchemaImporter;
$source = file_get_contents(__DIR__ . '/learning-path.flowdsl');if ($source === false) { throw new RuntimeException('Could not read the FlowDSL file.');}
$importer = new SchemaImporter(strict: true);$graph = $importer->importDsl($source);The importer parses the declarations, checks the resulting definition and returns a Graph. strict: true includes checks for default-language presentation and known condition types and parameters. The complete file passes those checks and produces a graph with three nodes, two edges and root 10.
Your application can now pass $graph to the engine, just as it would a graph built in PHP or loaded from JSON. The language source is no longer needed to select a choice.
If you want a file or text loader instead of reading the file yourself, DslGraphLoader provides that interface. Graph loaders and repositories explains how loaders fit into application code.
Export a graph back to FlowDSL
Section titled “Export a graph back to FlowDSL”FlowDslExporter takes a loaded Graph and writes the canonical declaration form:
use ExecKernel\Infrastructure\Importer\FlowDsl\FlowDslExporter;
$canonicalSource = (new FlowDslExporter())->export($graph);$canonicalSource is a string that can be imported with importDsl(). The exporter reconstructs declarations from the graph objects. It therefore preserves the graph’s data rather than the original file’s comments, spacing or choice of shorthand.
For example, the brief practice condition is exported as:
when condition context_value { params {"key":"practiceEnabled","operator":"==","value":true}}This full form carries the same rule and parameters as when context_value practiceEnabled == true. Importing the complete exported text restores the same definition, including its localized presentation and outputs.
Correct a syntax diagnostic
Section titled “Correct a syntax diagnostic”Suppose you change the practice condition in the downloadable file to use a single equals sign:
when context_value practiceEnabled = trueA single = is not a comparison operator accepted by this clause. Importing that changed file raises ImporterParseException. Its ekCode and context identify the failure:
{ "ek_code": "EK-LOADER-004", "format": "flowdsl", "graph_code": "learning-path", "reason": "invalid_context_operator", "line": 48, "column": 42, "expected": null}The line and column refer to the changed complete file. reason tells you that the parser was reading the comparison operator; the position points at the single equals sign. Correct the declaration to:
when context_value practiceEnabled == trueThe corrected file imports successfully. A different problem, such as changing the edge destination from 30 to undeclared node 99, can be valid FlowDSL syntax but fail graph validation. In that case, the diagnostic identifies the edge and its invalid destination rather than a syntax position. See Graph validation and diagnostics for those structural corrections.
Complete definition and validation
Section titled “Complete definition and validation”Download learning-path.flowdsl for the full bilingual definition, or load-learning-path-dsl.php for the complete PHP import and canonical export example. The PHP example expects the definition beside it and the Composer vendor/ directory in the same project directory.
The CLI recognizes FlowDSL files with the .flowdsl or .dsl extension. To validate the downloaded definition:
vendor/bin/execkernel validate learning-path.flowdsl --jsonThe report has ok: true, three nodes, two edges, two terminal nodes and zero warnings. For the full set of declarations and accepted forms, consult the FlowDSL syntax reference.