FlexiRule Docs
Frontend Technical
The FlexiRule frontend is a Vue 3 application that synchronizes complex graph logic with Frappe's relational data model.
Frontend Technical Deep Dive#
The FlexiRule frontend is a Vue 3 application that synchronizes complex graph logic with Frappe’s relational data model.
State Synchronization#
The builder manages three distinct layers of state:
- Frappe Model: The
RuleandRule Actiondocuments infrappe.model. - Pinia Stores: The reactive application state (
nodes,edges,is_dirty). - VueFlow State: The internal DOM representation of the canvas.
The topological Sort for Persistence#
Because Frappe child tables are linear (indexed), but Rule logic is a graph, we must ensure that actions are stored in a logical sequence. Before saving, useRuleStore calls a topological sort algorithm:
- Algorithm: Breadth-First Search (BFS) starting from the
Entry Action. - Purpose: Ensures that when the Rule Engine loads the rule sequentially from the database, nodes that depend on upstream results are generally loaded after their dependencies, facilitating faster registry hydration.
Intelligent & Reactive Controls#
Schema Renderer & Control Factory#
The SchemaRenderer component takes a backend JSON schema and iterates through its properties. For each property, it uses the ControlFactory to mount a Vue component:
- Reactivity: Every control emits a
changeevent that triggers a re-validation of the entire node’s schema. - Awareness: Controls like
FieldPickeruse thegetAvailableVariablesalgorithm to traverse the graph and provide real-time suggestions.
Variable Resolution Algorithm#
Implemented in useGraphStore.getAvailableVariables, this is the heart of the builder’s context-awareness:
- Backwards Traversal: Starting from node $N$, find all nodes reachable by following incoming edges.
- Ancestry Collection: Identify the set of all ancestor nodes.
- Variable Aggregation: For each ancestor, inspect its
return_variableandreturn_type. - Schema Projection: If an ancestor is a
Processwith a knownoutput_schema, project those fields as selectable child properties (e.g.,vars.my_result.status).
Performance & Optimization#
- Snapshot-based History: Undo/Redo is implemented by taking full snapshots of the
nodesandedgesarrays. To optimize memory, consecutive identical states are deduplicated. - Metadata Caching:
useMetaStoremaintains a request-level cache of DocType schemas to prevent redundantget_doctype_fieldsAPI calls while the user is designing.
Was this page helpful?