UML Class and Struct Diagram builder on top of Yog.
Choreo.UML models software component architectures — classes, structs,
behaviors, protocols, and interfaces — with fields and functions, and
standard structural UML relationships.
Node types
:class/:struct/:behavior/:protocol/:interface
Relationship types
:inherits— solid line with hollow arrowhead (--|>) representing inheritance or behavior adoption.:realizes— dashed line with hollow arrowhead (..|>) representing protocol implementation.:associates— solid line with solid arrowhead (-->) representing composition or nesting.:depends— dashed line with open arrowhead (..>) representing invocation or dependency.
Quick Start
uml =
Choreo.UML.new()
|> Choreo.UML.add_class(:user,
type: :struct,
fields: [%{name: :id, type: :integer}],
functions: [%{name: "authenticate", arity: 1}]
)
|> Choreo.UML.add_class(:auth_provider,
type: :behavior,
functions: [%{name: "verify", arity: 1}]
)
|> Choreo.UML.add_relationship(:user, :auth_provider, type: :realizes, label: "implements")
dot = Choreo.UML.to_dot(uml)
mermaid = Choreo.UML.to_mermaid(uml)Diagram
| «struct» user |
| + id : integer |
| + authenticate(1) |
| «behavior» auth_provider |
| + verify(1) |
Summary
Functions
Adds a class, struct, behavior, or protocol to the diagram.
Adds a structural relationship between two classes/components.
Initializes a new, empty UML diagram.
Returns a theme for the UML diagram.
Renders the UML diagram to Graphviz DOT syntax.
Renders the UML diagram to Mermaid.js syntax.
Types
@type class_id() :: Yog.node_id()
@type t() :: %Choreo.UML{ edge_meta: %{optional(Yog.Multi.Graph.edge_id()) => map()}, graph: Yog.Multi.Graph.t(), strict: boolean(), strict_contract_validation: boolean() }
Functions
Adds a class, struct, behavior, or protocol to the diagram.
Options
:label(String.t/0) - Visual label for the class (defaults to ID string).:type- The UML class type: :class, :struct, :behavior, :protocol, or :interface. The default value is:class.:fields(term/0) - List of fields/attributes. The default value is[].:functions(term/0) - List of functions/operations. The default value is[].
Examples
iex> uml = Choreo.UML.new()
...> |> Choreo.UML.add_class(:user, type: :struct, fields: [%{name: :id, type: :integer}])
iex> %Choreo.UML{} = uml
iex> Map.has_key?(uml.graph.nodes, :user)
true
Adds a structural relationship between two classes/components.
Options
:type- Required. The connection relationship type.:label(String.t/0) - Optional label/text on the relationship line.
Examples
iex> uml = Choreo.UML.new()
...> |> Choreo.UML.add_class(:user)
...> |> Choreo.UML.add_class(:profile)
...> |> Choreo.UML.add_relationship(:user, :profile, type: :associates, label: "has_one")
iex> %Choreo.UML{} = uml
iex> map_size(uml.graph.edges)
1
Initializes a new, empty UML diagram.
Options
:strict_contract_validation- iftrue, validates that any class implementing a behavior/protocol/interface implements all its required functions (default:false).:strict- iftrue,add_relationship/4raises when an endpoint does not already exist (default:false).
Examples
iex> uml = Choreo.UML.new()
iex> %Choreo.UML{} = uml
iex> uml.strict_contract_validation
false
@spec theme( atom(), keyword() ) :: Choreo.Theme.t()
Returns a theme for the UML diagram.
Examples
iex> theme = Choreo.UML.theme(:dark)
iex> theme.graph_bgcolor
"#0f172a"
Renders the UML diagram to Graphviz DOT syntax.
Examples
iex> uml = Choreo.UML.new() |> Choreo.UML.add_class(:user)
iex> dot = Choreo.UML.to_dot(uml)
iex> dot =~ "digraph"
true
Renders the UML diagram to Mermaid.js syntax.
Examples
iex> uml = Choreo.UML.new() |> Choreo.UML.add_class(:user)
iex> Choreo.UML.to_mermaid(uml, syntax: :flowchart) =~ "graph"
true
iex> Choreo.UML.to_mermaid(uml, syntax: :class_diagram) =~ "classDiagram"
true