Choreo.Lab.DSL.UML (Choreo v0.12.0)

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching UML class diagrams.

This Lab DSL compiles to the stable, pipe-first Choreo.UML builders and returns an ordinary %Choreo.UML{}. Classes, structs, behaviors, protocols, and interfaces can be declared with block-based fields and functions. Edges expose UML relationship types as readable domain vocabulary.

Examples

iex> import Choreo.Lab.DSL.UML
...> diagram = uml do
...>   user = struct("User") do
...>     field :id, :integer
...>     private field(:email, :string)
...>     function :authenticate, 2, return: :boolean
...>   end
...>
...>   auth = behavior("AuthProvider") do
...>     function :verify, 1, return: :ok_error
...>   end
...>
...>   realizes user ~> auth, "implements"
...> end
iex> diagram.graph.nodes[:user].type
:struct
iex> diagram.graph.nodes[:user].fields |> Enum.map(& &1[:name])
["id", "email"]
iex> [meta] = Map.values(diagram.edge_meta)
iex> {meta.type, meta.label}
{:realizes, "implements"}

Relationship edges can use typed constructors, generic edge, or pipe modifiers:

inherits child ~> parent, "extends"
realizes adapter ~> protocol, "implements"
associates user ~> profile, "has one"
depends controller ~> repo, "calls"
edge controller ~> repo, depends: "calls"
controller ~> repo |> depends("calls")

The generic ~> form defaults to :depends, which matches a lightweight dependency sketch.

Summary

Types

class_decl()

@type class_decl() :: %{id: Yog.node_id(), opts: keyword()}

relationship_decl()

@type relationship_decl() :: %{
  from: Yog.node_id(),
  to: Yog.node_id(),
  opts: keyword()
}

Functions

associates(arg1 \\ nil, arg2 \\ nil, opts \\ [])

association(arg1 \\ nil, arg2 \\ nil, opts \\ [])

attr(arg1 \\ nil, arg2 \\ nil, opts \\ [])

attribute(arg1 \\ nil, arg2 \\ nil, opts \\ [])

behavior(arg1 \\ nil, arg2 \\ nil, opts \\ [])

class(arg1 \\ nil, arg2 \\ nil, opts \\ [])

dependency(arg1 \\ nil, arg2 \\ nil, opts \\ [])

depends(arg1 \\ nil, arg2 \\ nil, opts \\ [])

extends(arg1 \\ nil, arg2 \\ nil, opts \\ [])

field(arg1 \\ nil, arg2 \\ nil, opts \\ [])

function(arg1 \\ nil, arg2 \\ nil, opts \\ [])

has(arg1 \\ nil, arg2 \\ nil, opts \\ [])

implements(arg1 \\ nil, arg2 \\ nil, opts \\ [])

inherits(arg1 \\ nil, arg2 \\ nil, opts \\ [])

interface(arg1 \\ nil, arg2 \\ nil, opts \\ [])

method(arg1 \\ nil, arg2 \\ nil, opts \\ [])

operation(arg1 \\ nil, arg2 \\ nil, opts \\ [])

private(arg1 \\ nil, arg2 \\ nil, opts \\ [])

protected(arg1 \\ nil, arg2 \\ nil, opts \\ [])

protocol(arg1 \\ nil, arg2 \\ nil, opts \\ [])

public(arg1 \\ nil, arg2 \\ nil, opts \\ [])

realizes(arg1 \\ nil, arg2 \\ nil, opts \\ [])

struct(arg1 \\ nil, arg2 \\ nil, opts \\ [])

taxonomy()

@spec taxonomy() :: %{
  nodes: [atom()],
  members: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Returns the vocabulary supported by the UML DSL.

This is meant as a lightweight Livebook discovery helper when autocomplete is not enough.

iex> taxonomy = Choreo.Lab.DSL.UML.taxonomy()
iex> :struct in taxonomy.nodes
true
iex> :function in taxonomy.members
true
iex> :implements in taxonomy.edges
true

uml(list)

(macro)

Builds a %Choreo.UML{} from a compact Lab DSL block.

uml(opts, list)

(macro)

uses(arg1 \\ nil, arg2 \\ nil, opts \\ [])

verbs()

@spec verbs() :: %{
  nodes: [atom()],
  members: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Compatibility alias for taxonomy/0.