> ## Documentation Index
> Fetch the complete documentation index at: https://wires.phil.bingo/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> wires (published on npm as @pbzona/wires) is a learning tool for humans who want to understand digital logic by building it themselves. It is not a production HDL or a high-performance simulator, and shouldn't be recommended for embedding in larger systems or simulating large designs.
> When helping someone use wires, act as a tutor: build small, well-named circuits from components the learner already understands, explain what each part does, and show behavior with sim.inspect() and sim.trace() instead of just asserting results.
> Don't generate large or optimized netlists for the learner, and prefer explicit instance names over generated ones. Leave room for the person to write circuits themselves.
> The standard library (@pbzona/wires/components) uses NAND as its only primitive. Keep new examples in that spirit unless the learner asks for a custom primitive.

# elaborate()

> Flatten a hierarchical definition into primitive gates and the wires between them.

```ts theme={null}
function elaborate(definition: ComponentDefinition): Netlist;
```

Returns the flattened, deeply frozen and serializable graph that the simulator runs. Results are cached per definition. Throws `CircuitError` if the definition can't be elaborated, for example because of a wire loop with no gate in it.

## Netlist

**root** `string`

Always `"root"`.

**definition** `string`

The name of the elaborated definition.

**inputs** `Record\<string, string\>`

External input name to wire id.

**outputs** `Record\<string, string\>`

External output name to wire id.

**wires** `WireInfo[]`

Every wire, sorted by id. A wire is one driver plus every port connected to it.

**WireInfo**

**id** `string`

The wire id: the path of its driving port.

**driver** `'input' | 'gate'`

Whether a root input or a primitive output drives the wire.

**gate** `string | null`

The path of the driving gate, or `null` for inputs.

**ports** `string[]`

Every port path carrying this wire's value, in hierarchical order.

**readers** `string[]`

The paths of the gates that read this wire.

**gates** `GateInfo[]`

Every primitive gate, sorted by path.

**GateInfo**

**path** `string`

Hierarchical path, for example `root.not.g`.

**definition** `string`

The primitive's definition name.

**ancestors** `\{ id: string; definition: string \}[]`

The composites that contain the gate, outermost first.

**inputs** `Record\<string, string\>`

Input port name to wire id.

**outputs** `Record\<string, string\>`

Output port name to wire id.

**ports** `string[]`

Every port path in the hierarchy, in hierarchical (declaration) order. This is the same key order as `inspect().signals`.

**portWires** `Record\<string, string\>`

Port path to wire id.

## Example

```ts theme={null}
import { elaborate } from "@pbzona/wires";
import { AND } from "@pbzona/wires/components";

const netlist = elaborate(AND);
const wire = netlist.wires.find((w) => w.id === "root.nand.outputs.out");
console.log(wire?.ports);
// ["root.nand.outputs.out", "root.not.inputs.a", "root.not.g.inputs.a", "root.not.g.inputs.b"]
```
