graph

package
v1.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package graph builds a graph of the workflows in an Arazzo document, showing how steps flow into each other and how workflows and steps depend on each other, and renders it as a Mermaid flowchart or a Graphviz DOT digraph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string

Direction is the direction the graph is laid out in.

const (
	// DirectionTopBottom lays the graph out from top to bottom.
	DirectionTopBottom Direction = "TB"
	// DirectionLeftRight lays the graph out from left to right.
	DirectionLeftRight Direction = "LR"
)

type Edge

type Edge struct {
	From  *Node
	To    *Node
	Kind  EdgeKind
	Label string
}

Edge is an edge in the graph.

type EdgeKind

type EdgeKind int

EdgeKind is the kind of an edge in the graph.

const (
	// EdgeStart goes from the start of a workflow to its first step.
	EdgeStart EdgeKind = iota
	// EdgeNext goes from a step to the next step, which runs when no success action ends the workflow or goes
	// elsewhere.
	EdgeNext
	// EdgeSuccessGoto is a success action going to a step or workflow.
	EdgeSuccessGoto
	// EdgeFailureGoto is a failure action going to a step or workflow.
	EdgeFailureGoto
	// EdgeRetry is a failure action retrying the step.
	EdgeRetry
	// EdgeDependsOn goes from a workflow or step to a workflow or step in its dependsOn.
	EdgeDependsOn
	// EdgeCall goes from a step to the workflow it runs.
	EdgeCall
)

type Format

type Format string

Format is an output format for a graph.

const (
	// FormatMermaid renders the graph as a Mermaid flowchart.
	FormatMermaid Format = "mermaid"
	// FormatDOT renders the graph as a Graphviz DOT digraph.
	FormatDOT Format = "dot"
)

type Graph

type Graph struct {
	// Direction is the direction the graph is laid out in.
	Direction Direction
	// Workflows are the workflows in the graph, in document order.
	Workflows []*Workflow
	// External are the nodes for workflows and steps outside the graph, in the order they are first referenced.
	External []*Node
	// Edges are the edges in the graph.
	Edges []*Edge
}

Graph is a graph of the workflows in an Arazzo document.

func Build

func Build(a *arazzo.Arazzo, opts Options) (*Graph, error)

Build builds a graph of the workflows in the document.

Steps run in order unless a success action ends the workflow or goes elsewhere. As actions are taken in order and the first that applies wins, an action without criteria always applies, so no later actions are shown, and the step only leads on to the next step if none of its success actions apply unconditionally. Workflow level actions apply to every step, unless the step has an action with the same name.

func (*Graph) Write

func (g *Graph) Write(w io.Writer, format Format) error

Write renders the graph in the given format.

func (*Graph) WriteDOT

func (g *Graph) WriteDOT(w io.Writer) error

WriteDOT renders the graph as a Graphviz DOT digraph. Each workflow is a cluster, success gotos are green, failure gotos and retries are dashed red, dependsOn edges are dotted grey and steps running a workflow are bold.

func (*Graph) WriteMermaid

func (g *Graph) WriteMermaid(w io.Writer) error

WriteMermaid renders the graph as a Mermaid flowchart. Each workflow is a subgraph, success gotos are green, failure gotos and retries are dashed red, dependsOn edges are dashed grey and steps running a workflow are thick.

type Node

type Node struct {
	// ID is a unique identifier for the node that is safe to use in Mermaid and DOT.
	ID string
	// Kind is the kind of node.
	Kind NodeKind
	// Label is the workflowId, stepId, or reference of the node.
	Label string
	// Detail is the operation, operation path, workflow or channel a step targets.
	Detail string
}

Node is a node in the graph.

type NodeKind

type NodeKind int

NodeKind is the kind of a node in the graph.

const (
	// NodeWorkflow is the start of a workflow in the document. Edges to a workflow point at it.
	NodeWorkflow NodeKind = iota
	// NodeStep is a step of a workflow in the document.
	NodeStep
	// NodeExternal is a workflow or step outside the graph, such as one in another Arazzo document referenced by a
	// sourceDescription, a workflow left out by Options.WorkflowID, or a reference that can't be resolved.
	NodeExternal
)

type Options

type Options struct {
	// WorkflowID limits the graph to a single workflow. Workflows and steps it references are shown as external nodes.
	WorkflowID string
	// Direction is the direction the graph is laid out in. Defaults to DirectionTopBottom.
	Direction Direction
}

Options configures Build.

type Workflow

type Workflow struct {
	// ID is a unique identifier for the workflow's cluster that is safe to use in Mermaid and DOT.
	ID string
	// WorkflowID is the workflow's workflowId.
	WorkflowID string
	// Title is the workflow's summary, or its workflowId if it has no summary.
	Title string
	// Start is the node edges to the workflow point at, which leads to its first step.
	Start *Node
	// Steps are the nodes for the workflow's steps, in order.
	Steps []*Node
}

Workflow is a workflow in the document, with the node for its start and a node for each of its steps.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL