Skip to content

Graph definition schema

A graph definition describes the nodes your application can visit, the edges it can choose, the conditions on those edges and the presentation returned at each node. SchemaImporter::importJson(array $schema): Graph accepts the two representations below. The argument is decoded data, including an array produced by a YAML parser.

The flat representation is the portable form emitted by GraphSchemaExporter. The nested representation groups presentation and rules with their node or edge. Choose one representation for a document. JSON and YAML graph definitions covers loading; this page gives the field contract.

Part Flat definition Nested definition
Graph identity and configuration Top-level fields such as graph_code and root_node_id graph object, with code and startNode
Nodes and edges Top-level nodes and edges collections Top-level nodes and edges collections
Node presentation Top-level metadata rows, each with node_id and lang nodes[].metadata, with a language map for each presentation field
Edge presentation Top-level labels rows, each with edge_id edges[].labels
Edge conditions Top-level conditions: edge_id, rule, params edges[].rules: factory rule name and operands in the same object
Terminal results Top-level outputs, each with node_id Top-level terminals, each with nodeId; each record is one output
Webhook subscriptions Top-level, node or edge webhooks graph.webhooks or top-level webhooks, plus node and edge webhooks

The presence of the top-level graph key selects the nested importer. Combining it with top-level graph_code, graph_id, root_node_id, their camel-case aliases, labels, metadata, metadatas, conditions or outputs is rejected as mixed_schema_representations. Nesting a field does not make the flat and nested forms interchangeable.

The tables describe fields that participate in the graph contract. Do not use unknown keys as storage: an importer may ignore them, and export only retains represented graph data. Application presentation data belongs in the declared extras fields.

Collections below contain entity records. In JSON, write them as arrays. IDs are PHP-range integers, including zero and negative values; quoted numbers are strings and are not accepted as IDs.

Field Type and default Contract
graph_code Nonblank string Canonical graph identity. If absent or null, an integer graph_id is required and its string form becomes the code.
graph_id Integer or null; default null Optional compatibility identity. It does not replace the canonical code when both exist.
root_node_id Required integer ID of the one starting node. It must exist and be nonterminal.
nodes Required array Nonempty node collection.
edges Required array Directed connections. Structural rules below apply even when validation is flexible.
metadata, labels, conditions, outputs Arrays; default [] Associated records, described below. An explicitly null collection follows the same empty default in this loading path.
default_lang Nonempty string or null; default null Preferred fallback presentation language.
allowed_langs Array of nonempty strings; default [] Languages the graph allows your application to request. An empty list adds no graph-specific restriction.
graph_version String or null; default null Graph revision, normally numeric MAJOR.MINOR.PATCH. Compatibility validation checks it separately from graph structure.
dsl_version, schema_version Strings or null; default null Model versions in numeric MAJOR.MINOR or MAJOR.MINOR.PATCH form.
webhooks Array; default [] Graph-level subscriptions. See Webhook contracts and signatures.
strict_validation Boolean; default false Enables strict presentation and rule validation. strict is an alias. Caller-supplied strict validation cannot be weakened by the document.

JSON normalization also accepts graphCode, graphId, rootNodeId, defaultLang, allowedLangs, graphVersion, dslVersion and schemaVersion. Two aliases for the same field must have exactly equal values and types. The root is stricter: supplying both root_node_id and rootNodeId is rejected even when they agree. Direct ArrayGraphLoader input uses root_node_id; JSON alias normalization is a separate step.

Record Field Type, default and meaning
Node id Required integer, unique among nodes.
Node is_terminal Boolean; omitted or null means false. Integer 0 and 1 are normalized to booleans. JSON alias: isTerminal.
Node webhooks Optional subscription array for this node.
Edge id Required integer, unique among edges. Node and edge IDs have separate namespaces.
Edge from, to Required integer node IDs. JSON aliases: fromNode, toNode.
Edge webhooks Optional subscription array for this edge.

Every nonterminal node must have at least one outgoing edge; terminals have none. A graph must have a terminal, every node must be reachable from the root, and every node must have a structural path to a terminal. Conditions are not executed to prove that path.

Self-loops and repeated connections with the same from/to pair are rejected, even if their edge IDs differ. Longer cycles are possible when the structural path to a terminal remains; execution also applies cycle protection. The root is explicit and may have incoming edges.

Metadata describes a node; a label describes an edge’s selectable text. Their language code must match [a-z]{2}(-[A-Z]{2})?, for example en, es or pt-BR.

Collection Fields Presence and constraints
metadata node_id, lang, title Required integer reference, language string and nonblank title. JSON alias: nodeId.
metadata id Optional integer persistence identifier. Missing IDs are allocated locally; your definition does not need to supply them.
metadata subtitle, description Optional string or null; default null.
metadata extras Optional declarative array or null; default null.
labels edge_id, lang, text Required integer reference, language string and nonblank text. JSON alias: edgeId.
labels description, extras Optional string/null and declarative array/null respectively; default null.

Each node/language pair and edge/language pair must be unique. Metadata and labels must reference existing entities. Strict validation additionally requires metadata for every node and a label for every edge in default_lang; it checks declared metadata/label languages against a nonempty allowed_langs.

extras can contain nested arrays, scalar values and null. It cannot contain PHP objects, resources or recursive references. These graph data rules are distinct from the session-context policy. See Labels, metadata and languages for how your application uses this presentation.

Field Type and presence Meaning
edge_id Required integer Existing edge receiving the condition. JSON alias: edgeId.
rule Required nonempty string Evaluator rule name, such as context_value.
params Array; defaults to [] when omitted or null Named parameters for the selected rule, which validates its required operands. The flat loader also accepts a JSON string that decodes to an array; prefer structured data.
version Optional string or null Rule version. A supplied version must be numeric MAJOR.MINOR.PATCH; built-in rule compatibility currently accepts major 1.

Multiple conditions on an edge form an ordered conjunction. The graph permits at most 32 conditions per edge. A condition’s edge_id attaches it to the current choice; an ID inside params may refer to another node or earlier edge.

A full condition record is:

{
"edge_id": 10,
"rule": "context_value",
"params": {"key": "ready", "operator": "==", "value": true}
}

This record requires boolean ready: true in the session context. It does not assign that context value. Built-in rules and condition parameters gives parameter types, operator semantics and the important distinction between evaluator names and factory aliases.

For the flat loader’s compatibility form, time_condition is converted to time, and operator: "between" can construct target from string from/to when target is absent. This conversion happens during construction, after validation; use canonical rule: "time" and params.target for strict imports.

Field Type and presence Meaning
node_id Required integer Existing terminal node. JSON alias: nodeId.
type Required nonempty string Built-in content, url, redirect, mixed, or a registered output type.
content String or null; default null Required and nonempty for content and mixed.
url String or null; default null Required and nonempty for url, redirect and mixed. The built-in validator does not impose a URL-scheme policy.
label String or null; default null Optional action text; a present string must be nonblank.
open_behavior String or null; default null Application-defined opening preference. JSON alias: openBehavior; there is no built-in enum.
lang String or null; default null Null means language-neutral. This field does not use metadata/label language validation.

A terminal may have zero or several outputs. Repeated output records are not treated as duplicate metadata; their order is meaningful. Output records do not provide an arbitrary extras container. Registering a new output type supplies a validator, while the standard TerminalOutput still stores the fields above. Node and terminal payloads describes the returned data and extension hooks.

The nested format retains top-level nodes, edges and optional terminals. nodes is required; omitted/null edges or terminals become empty arrays before structural validation.

Location Accepted fields and defaults
graph Required nonempty code; required integer startNode. start_node is explicitly rejected.
graph identity Optional integer id, with aliases graph_id/graphId; default null.
graph language defaultLang/default_lang (string or null, default null), allowedLangs/allowed_langs (array of strings, default []). Strict presentation validation still applies.
graph versions version/graph_version/graphVersion; dsl_version/dslVersion; schema_version/schemaVersion. DSL/schema versions can also be top-level; duplicates must agree exactly.
graph import annotations tags/versionTags/version_tags: string or array, normalized to unique lowercase stable, draft, deprecated. Unknown values are rejected in strict mode and ignored in flexible mode. Legacy status is an alias with a deprecation warning. Tags are not retained as a Graph field.
Graph subscriptions graph.webhooks or top-level webhooks; if both exist, they must agree.
nodes[] Required integer id; optional type is exactly decision or terminal. Without it, a node is a decision unless terminals names it.
nodes[].metadata Optional object containing title, subtitle, description (alias desc) and extras, each mapped by language. Every represented language needs a nonblank title.
edges[] Required integer id, from, to; optional labels, rules and webhooks arrays.
edges[].labels[] lang, text, optional description and extras. The edge supplies edge_id; an explicit edge_id/edgeId must agree.
edges[].rules[] A RuleFactory record: type or rule, with operands beside it. It is not the flat rule/params record.
terminals[] One output: integer nodeId, type, and the output fields above; openBehavior is accepted. An existing node is marked terminal unless its explicit type is decision, which is a contradiction.

Nested node flags is_terminal/isTerminal, when supplied, must agree exactly with the type derived from type and terminals; they are not an independent way to mark a nested terminal. Node webhooks remains available.

A nested edge may additionally use time_rules/timeRules/time or authz/authz_rules/authzRules/authzPolicies. Each accepts one object or a list. Missing rule types default respectively to time_window and authz_policy; these rules are appended after rules. Authorization-policy normalization does not register an authorization evaluator: an appropriate extension is still required.

Equivalent definitions and a rejected mixture

Section titled “Equivalent definitions and a rejected mixture”

The complete flat.json and nested.json both describe a confirmation choice: root 1, edge 10, terminal 2, and a boolean ready condition. They import to the same graph with English metadata, a label and terminal content.

These excerpts show the distinct identity fields:

{"graph_code": "reference-confirmation", "root_node_id": 1}
{"graph": {"code": "reference-confirmation", "startNode": 1}}

Each excerpt belongs to its corresponding complete file. Adding "root_node_id": 1 beside graph in the nested file is invalid, even though it names the same root. Import raises ImporterMalformedSchemaException, EK-IMPORT-005, with reason mixed_schema_representations and field root_node_id.

Structural checks are always applied. Flexible validation does not permit missing references, duplicate IDs, malformed presentation records or unusable topology. It can report unknown rule types, invalid rule parameters or provably impossible condition combinations as warnings; strict validation rejects them. Actual execution still validates rule contracts.

strict_validation controls graph validation. CompatibilityMode::STRICT is a separate importer setting: it requires graph, DSL and schema versions and rejects compatibility warnings. See the version compatibility matrix for exact supported versions. Import warnings are available through SchemaImporter::warnings() and reset on each import; deprecation notices use EK-WARN-033.

Problem Useful diagnostic
Flat/nested mixture or conflicting nested aliases EK-IMPORT-005 plus reason and field
Invalid JSON or conflicting JSON aliases ImporterParseException, EK-LOADER-004
Edge points to a missing node Underlying reference code EK-GRAPH-010; the flat loading path wraps it in EK-SEC-LOD-001 and preserves validation_ek_code
Invalid condition parameter under strict loading Graph condition code EK-GRAPH-040, with parameter error context; the flat path may wrap it as above
Unsupported version Version-compatibility exception; independent of presentation strictness

For the complete flat fixture, replacing edge 10’s destination with 99 produces from: 1, to: 99 and validation_ek_code: "EK-GRAPH-010" in the error context. Graph validation and diagnostics explains how to work from these coordinates to a correction; Error codes and exceptions covers the surrounding error contracts.