# `Bobbin.Node`
[🔗](https://github.com/heddlehq/Bobbin/blob/main/lib/bobbin/node.ex#L1)

Defines the behavior and macros for creating Bobbin nodes.

A node is the fundamental unit of logic in a flow. It consists of a `definition/0`
describing its interface and a `handler/2` to process data.

## Example

    defmodule MyNodes.HttpNode do
      use Bobbin.Node

      definition do
        %{
          name: "http_request",
          title: "HTTP Request",
          category: :network,
          color: "bg-blue-500",
          icon: "hero-globe-alt",
          inputs: [:exec, :url],
          outputs: [:success, :error]
        }
      end

      @impl true
      def handler(context, input) do
        {:ok, context, :success}
      end
    end

# `context`

```elixir
@type context() :: map()
```

# `input`

```elixir
@type input() :: any()
```

# `node_definition`

```elixir
@type node_definition() :: %{
  :name =&gt; String.t(),
  :title =&gt; String.t(),
  optional(:category) =&gt; atom() | String.t(),
  optional(:color) =&gt; String.t(),
  optional(:icon) =&gt; String.t(),
  optional(:inputs) =&gt; [map() | atom() | String.t()],
  optional(:outputs) =&gt; [map() | atom() | String.t()],
  optional(atom()) =&gt; any()
}
```

# `output_port`

```elixir
@type output_port() :: atom() | String.t()
```

# `definition`

```elixir
@callback definition() :: node_definition()
```

Returns the metadata and interface definition for the node.

# `handler`

```elixir
@callback handler(context(), input()) ::
  {:ok, context(), output_port()} | {:error, term()}
```

Processes the node logic.

Returns `{:ok, new_context, output_port}` on success, or `{:error, reason}` on failure.

# `definition`
*macro* 

Macro to define the node metadata.

# `to_rete`

```elixir
@spec to_rete(module()) :: map()
```

Converts a node module's definition to a Rete.js-compatible map.

The returned map follows the Rete.js node schema with `id`, `label`,
`inputs`, and `outputs` structured as socket definitions.

## Example

    Bobbin.Node.to_rete(MyNodes.HttpNode)
    # => %{
    #   id: "http_request",
    #   label: "HTTP Request",
    #   color: "bg-blue-500",
    #   inputs: [%{id: "exec", label: "Exec"}, %{id: "url", label: "Url"}],
    #   outputs: [%{id: "success", label: "Success"}, %{id: "error", label: "Error"}]
    # }

---

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