Your first graph
In ExecKernel, a graph defines a process: its steps, the transitions between them and the conditions that allow progress. A session tracks one execution of that process. In this tutorial, you will learn to build that definition in JSON and add the text and results your application can use.
We will return to the delivery-choice example introduced in What is ExecKernel?: a store offers collection or home delivery, with delivery available only for addresses it serves. We will use that decision to learn how to represent alternative paths and a condition. You can then run the resulting graph through any of the integrations covered in the following quick starts.
You do not need a running service to follow the explanation. If you have completed Installation and requirements, you can also validate the finished file with the PHP command-line tool.
Start with the possible paths
Section titled “Start with the possible paths”The graph has three nodes: one question and two possible outcomes. A node is a position in the process. An edge connects one position to the next and identifies a transition the application can request.
The application sends an edge ID when making a choice. For example, choosing edge 10 moves the session from node 1 to node 2. Node 2 is the destination, not the value to send as the choice.
These paths give us the structural part of the JSON definition:
{ "graph_code": "delivery-options", "graph_id": 1001, "root_node_id": 1, "nodes": [ {"id": 1, "is_terminal": false}, {"id": 2, "is_terminal": true}, {"id": 3, "is_terminal": true} ], "edges": [ {"id": 10, "from": 1, "to": 2}, {"id": 20, "from": 1, "to": 3} ]}The graph_code is the name your application will use to request this graph. The additional numeric graph_id lets this same definition be registered in the HTTP API’s catalogue. Neither identifies a customer or a session.
The root_node_id explicitly selects the starting position. Marking nodes 2 and 3 with is_terminal: true says that navigation ends there; they have no outgoing edges. The numbers are identifiers you choose, and the connections in edges determine the route.
Give the application something to display
Section titled “Give the application something to display”The structure tells the engine where it can go, but it does not yet tell a customer what the choices mean. ExecKernel keeps the text of a choice in an edge label, and the text associated with a node in metadata.
The following fields belong alongside nodes and edges in the same JSON object. These excerpts use English; the complete file below includes Spanish as well.
"default_lang": "en","allowed_langs": ["en", "es"],"labels": [ {"edge_id": 10, "lang": "en", "text": "Collect from store"}, {"edge_id": 20, "lang": "en", "text": "Home delivery"}],"metadata": [ {"node_id": 1, "lang": "en", "title": "How would you like to receive your order?"}, {"node_id": 2, "lang": "en", "title": "Collection selected"}, {"node_id": 3, "lang": "en", "title": "Home delivery selected"}]The graph declares English as its default language with default_lang, and lists English and Spanish in allowed_langs. The complete definition supplies text for both.
Notice which identifier each entry refers to. A label belongs to an edge because it describes a choice; a title belongs to a node because it describes the current step or outcome. The engine includes the requested language’s text in the result. Your application decides how to present it, whether as buttons, a select field or another interface.
Make home delivery depend on the order
Section titled “Make home delivery depend on the order”The graph should not contain a different copy of the process for every address. Instead, the application supplies execution data as context when it starts or advances a session. Here that data includes a boolean named delivery_available, calculated by the application’s own delivery-area check.
Attach this condition to edge 20:
"conditions": [ { "edge_id": 20, "rule": "context_value", "params": { "key": "delivery_available", "operator": "==", "value": true } }]The built-in context_value rule compares a context entry with the value in the condition. Here it requires the boolean true; the string "true" is a different value. With delivery_available: false, the home-delivery edge is blocked, while collection remains available.
This is a condition on taking a path, not an instruction to take it automatically. Even when both choices are available, the application still requests the customer’s chosen edge. ExecKernel checks that request before changing the session.
The graph itself does not look up an address or contact a carrier. In your application, derive delivery_available from trusted order data rather than accepting a customer’s claim that a restricted option is available.
Describe the result at each terminal
Section titled “Describe the result at each terminal”Reaching a terminal can return content for the application. In this example, both terminals carry a short instruction:
"outputs": [ { "node_id": 2, "type": "content", "lang": "en", "content": "Bring your order number when you collect your order." }, { "node_id": 3, "type": "content", "lang": "en", "content": "Confirm the delivery address for your order." }]An output with type content carries a content string. We use plain text here so a consumer can display the message below the terminal’s title. It does not itself reserve stock, schedule delivery or update an order: those actions belong to your application.
The title and output serve different purposes. “Collection selected” names the outcome; the output tells the customer what to do next.
Use the complete definition
Section titled “Use the complete definition”Save the complete bilingual graph as graphs/delivery-options.json in your project. The file contains both languages, so changing the requested language does not require a separate graph.
Complete delivery-options.json
{ "graph_code": "delivery-options", "graph_id": 1001, "root_node_id": 1, "default_lang": "en", "allowed_langs": ["en","es"], "nodes": [ {"id":1,"is_terminal":false}, {"id":2,"is_terminal":true}, {"id":3,"is_terminal":true} ], "edges": [ {"id":10,"from":1,"to":2}, {"id":20,"from":1,"to":3} ], "labels": [ {"edge_id":10,"lang":"en","text":"Collect from store"}, {"edge_id":10,"lang":"es","text":"Recoger en tienda"}, {"edge_id":20,"lang":"en","text":"Home delivery"}, {"edge_id":20,"lang":"es","text":"Entrega a domicilio"} ], "metadata": [ {"node_id":1,"lang":"en","title":"How would you like to receive your order?"}, {"node_id":1,"lang":"es","title":"¿Cómo quieres recibir tu pedido?"}, {"node_id":2,"lang":"en","title":"Collection selected"}, {"node_id":2,"lang":"es","title":"Recogida seleccionada"}, {"node_id":3,"lang":"en","title":"Home delivery selected"}, {"node_id":3,"lang":"es","title":"Entrega a domicilio seleccionada"} ], "conditions": [ {"edge_id":20,"rule":"context_value","params":{"key":"delivery_available","operator":"==","value":true}} ], "outputs": [ {"node_id":2,"type":"content","lang":"en","content":"Bring your order number when you collect your order."}, {"node_id":2,"type":"content","lang":"es","content":"Trae el número de pedido cuando vengas a recogerlo."}, {"node_id":3,"type":"content","lang":"en","content":"Confirm the delivery address for your order."}, {"node_id":3,"type":"content","lang":"es","content":"Confirma la dirección de entrega de tu pedido."} ]}If you installed the PHP package, run this from your project directory:
vendor/bin/execkernel validate graphs/delivery-options.jsonFor this definition, the summary reports three nodes, two edges, two terminal nodes and zero warnings. Validation checks the definition; it does not start a session or make a delivery choice.
You now have a process definition ready to use. Continue with the Local PHP Quick Start to run it inside a PHP application, or the HTTP API Quick Start to make it available as a service.
To explore the underlying idea interactively, open Context and conditions in the Showcase. Change its context values and observe how the available choices change while the graph’s connections remain the same. The demo uses its own example; it complements the definition you have just built.