# `Runic.Workflow.Serializer`
[🔗](https://github.com/zblanco/runic/blob/main/lib/workflow/serializer.ex#L1)

Behaviour for workflow serialization to various graph formats.

Implements serializers for:
- Mermaid (flowcharts and sequence diagrams)
- DOT (Graphviz)
- Cytoscape.js (JSON elements)
- Edgelist (simple edge pairs)

## Usage

    # Serialize workflow structure (excludes memory/runtime state)
    Runic.Workflow.Serializer.Mermaid.serialize(workflow)

    # Serialize causal reactions (for sequence diagrams)
    Runic.Workflow.Serializer.Mermaid.serialize_causal(workflow)

## Edge Labels

The workflow graph uses a multigraph with labeled edges:
- `:flow` - Static dataflow connections between steps
- `:component_of` - Component hierarchy (with :kind in properties)
- `:produced` / `:state_produced` / `:reduced` - Causal memory edges
- `:matchable` / `:runnable` / `:ran` / `:satisfied` - Runtime state edges

# `serialization_opts`

```elixir
@type serialization_opts() :: [
  include_memory: boolean(),
  include_facts: boolean(),
  direction: :TB | :LR | :BT | :RL,
  title: String.t() | nil
]
```

# `serialize`

```elixir
@callback serialize(Runic.Workflow.t(), serialization_opts()) ::
  String.t() | map() | list()
```

# `causal_edges`

Returns causal memory edges for sequence diagram generation.

# `escape_label`

Escapes special characters for Mermaid labels.

# `flow_edges`

Returns flow edges only (static dataflow, no memory).

# `group_by_component`

Groups vertices by their parent component using :component_of edges.
Returns a map of %{component => [child_vertices]}.

# `invokable_vertices`

Returns all vertices that are invokable nodes (not facts or memory).

# `node_class`

Returns Mermaid CSS class based on node type.

# `node_id`

Returns a unique, Mermaid-safe node ID for a vertex.

# `node_label`

Returns a display label for a vertex node.

# `node_shape`

Returns the node shape for Mermaid based on node type.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
