Skip to content

Anatomy of a graph

A graph definition describes the steps in a process, the choices that connect them and the information associated with each position. Your application gives that definition to ExecKernel, supplies the data needed for a decision and uses the returned payload to present the current step or result.

The definition belongs to the process. Each session has its own progress through it, as explained in Context, session state and history. Several people can therefore use the same graph while making different choices.

Consider an application that offers two ways to learn: reading a guide or practising in the browser. The choice starts at node 10. Edge 101 selects the guide and ends at terminal 20; edge 102 selects practice and ends at terminal 30.

The practice option has a condition: the application must supply practiceEnabled: true in the session context. The guide remains available in either case. At the end, the application receives information for presenting the guide or opening the practice destination.

The learning-path graph starts at node 10. Edge 101 leads to terminal 20, which provides content and a URL for the guide. Edge 102 requires practiceEnabled true and leads to terminal 30, which provides a redirect destination for the application.

The following blocks are extracts from the complete learning-path definition. They separate the parts we are reading; the complete file contains them together, with English and Spanish presentation records.

The first part names the graph and declares its structure:

{
"graph_code": "learning-path",
"root_node_id": 10,
"nodes": [
{ "id": 10 },
{ "id": 20, "is_terminal": true },
{ "id": 30, "is_terminal": true }
],
"edges": [
{ "id": 101, "from": 10, "to": 20 },
{ "id": 102, "from": 10, "to": 30 }
]
}

graph_code is the graph’s identity. Your application can use it to select this definition when loading graphs from a repository. root_node_id identifies the node where a new session starts.

Each node has an integer id. The root is an ordinary node selected by root_node_id; it does not need a separate node type. The other two nodes declare is_terminal: true, so reaching either one ends navigation.

An edge also has its own ID. Its from and to fields refer to existing node IDs. This gives the application a stable value to submit for a choice: choosing edge 101 requests the connection from 10 to 20. Changing the wording of a button does not change that connection.

A condition associates a rule with an edge. In this example, the following record controls the practice option:

{
"conditions": [
{
"edge_id": 102,
"rule": "context_value",
"params": {
"key": "practiceEnabled",
"operator": "==",
"value": true
}
}
]
}

edge_id binds the condition to edge 102. The context_value rule checks a value in the session context; its parameters name the key, the comparison and the expected value. Here, true is a JSON boolean.

Your application decides whether browser practice is available and supplies that boolean to execution. The engine evaluates the condition when determining whether the edge can be followed. The definition contains the rule; the session supplies the value being checked. Condition evaluation and edge availability develops that evaluation.

The structure identifies the choice. Node metadata describes the step to the person using your application, and an edge label gives a choice its visible name:

{
"metadata": [
{
"node_id": 10,
"lang": "en",
"title": "How would you like to learn?"
}
],
"labels": [
{ "edge_id": 101, "lang": "en", "text": "Read the guide" },
{ "edge_id": 102, "lang": "en", "text": "Practise in the browser" }
]
}

node_id and edge_id connect these records to the structure already declared. lang identifies the language of each record. The full example adds descriptions, application-defined data and Spanish records for those same IDs.

When the application requests a payload, ExecKernel selects the relevant presentation data. The application can use the title as a heading and the labels as the text of its controls. Labels, metadata and languages shows how to configure that presentation.

An output supplies information that the application can use after reaching a terminal. The guide terminal has a message and a link:

{
"outputs": [
{
"node_id": 20,
"type": "content",
"lang": "en",
"content": "Read the guide at your own pace."
},
{
"node_id": 20,
"type": "url",
"lang": "en",
"url": "https://example.org/learning/guide",
"label": "Open the guide"
}
]
}

Both outputs refer to terminal 20. The application can display the message followed by an “Open the guide” link. Terminal 30 instead declares a redirect output with the practice destination. Your application handles the navigation using that returned data.

The example.org destinations are illustrative; replace them with destinations belonging to your application. Terminal outputs explains the available types, their language selection and how to consume them.

The IDs connect the parts: the root names a node; edges connect nodes; conditions and labels name edges; metadata and outputs name nodes. A reference such as to: 30 has meaning because node 30 exists in the same definition.

This lets you change presentation text without rebuilding the route, or change a condition while keeping the same visible choice. Structural changes still need valid references: if you remove a node, every edge and record that refers to it must be considered. Graph validation and diagnostics shows how to identify those problems.

To create this definition, choose the approach that fits your project: PHP objects, JSON or YAML, or FlowDSL. The graph definition schema provides the complete field reference.