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

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching infrastructure diagrams.

This module is an incubating Lab syntax layer over the stable, pipe-first Choreo infrastructure builders. It returns a normal %Choreo{} system, so the result can be rendered and analysed with the same functions as any other Choreo graph.

The DSL is intentionally strict about references: bind nodes to variables and reuse those variables in edges. Typos in labels render as written; typos in variable names fail during macro expansion.

Examples

iex> import Choreo.Lab.DSL.Infrastructure
...> system = infrastructure do
...>   client = user("API Client")
...>   api = gateway("API Gateway")
...>   redis = cache("Redis", kind: :redis)
...>   db = database("Postgres", kind: :postgres)
...>
...>   client ~> api
...>   api ~> redis |> on("checks quota")
...>   edge api ~> db, with: "reads/writes"
...> end
iex> system.graph.nodes[:api].label
"API Gateway"
iex> system.graph.nodes[:redis].node_type
:cache
iex> system.edge_meta |> Map.values() |> Enum.map(& &1.label) |> Enum.sort()
[nil, "checks quota", "reads/writes"]

Supported cluster constructors:

Supported node constructors:

Cluster variables can be used in parent: and node cluster: options:

prod = vpc("Production VPC")
private = private_subnet("Private Subnet", parent: prod)
api = service("API", cluster: private)

Edge labels can use either pipe modifiers or the explicit edge form:

api ~> db |> on("reads")
api ~> db |> label("reads")
edge api ~> db, "reads"
edge api ~> db, label: "reads"
edge api ~> db, with: "reads"

Summary

Types

cluster_decl()

@type cluster_decl() :: %{id: String.t(), builder: atom(), opts: keyword()}

edge_decl()

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

node_decl()

@type node_decl() :: %{id: Yog.node_id(), builder: atom(), opts: keyword()}

Functions

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

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

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

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

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

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

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

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

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

infrastructure(list)

(macro)

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

infrastructure(opts, list)

(macro)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

taxonomy()

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

Returns the vocabulary supported by the infrastructure DSL.

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

iex> taxonomy = Choreo.Lab.DSL.Infrastructure.taxonomy()
iex> :vpc in taxonomy.clusters
true
iex> :service in taxonomy.nodes
true
iex> :~> in taxonomy.edges
true
iex> :on in taxonomy.modifiers
true

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

verbs()

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

Compatibility alias for taxonomy/0.

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