> ## 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.

# Introduction

> Learn how computers work by building digital logic from a single NAND gate up, in readable TypeScript.

`wires` is a TypeScript toolkit for **learning** digital logic by building it yourself. You start with one primitive gate and compose it into inverters, adders, multiplexers and memory, writing every circuit by hand in code that stays readable. Then you simulate it and look inside to see why it behaves the way it does.

```ts theme={null}
import { circuit, simulate } from "@pbzona/wires";
import { NAND } from "@pbzona/wires/components";

const NOT = circuit({ name: "NOT", inputs: ["a"], outputs: ["out"] }, ({ inputs, add, output }) => {
  const g = add(NAND, "g", { a: inputs.a, b: inputs.a });
  output("out", g.outputs.out);
});

const sim = simulate(NOT).set({ a: 1 }).run();
console.log(sim.read("out")); // 0
```

## Who this is for

`wires` is a learning tool for people: students, self-taught engineers, and anyone curious how a pile of identical gates becomes something that adds numbers and remembers things. It is meant to be read and written by humans.

That goal shapes every decision:

* **Readable over fast.** Circuits are plain code with named parts, and the simulator is simple enough to read in one sitting. Performance is good enough to explore, not tuned for scale.
* **Honest over convenient.** Signals start as unknown (`X`), every gate takes time, and glitches, races and oscillations show up instead of being smoothed away. The simulator never quietly turns an unknown into a 0 or 1.
* **Visible over hidden.** Topology, the flattened netlist, live signal values and transition traces are all plain data, so you can always see what is going on.
* **Built from the bottom.** The standard library uses NAND as its only primitive, so every component is something you could have built, and can take apart.

> [!WARNING]
>
> `wires` is **not** a production tool. It isn't a hardware description language or a replacement for Verilog or VHDL, it isn't a high-performance simulator for large designs or for embedding in a larger system, and it isn't an electrical or transistor-level simulator.

## Learning alongside AI agents

AI agents are welcome here as tutors and pair-builders. Typed port names, descriptive errors and serializable introspection make `wires` easy for them to read, write and debug.

The person learning is still the point. If you're an agent helping someone with `wires`:

* Prefer small, well-named circuits that a human can follow, built from components they already understand.
* Explain what each part does and why, and use `inspect()` and `trace()` to show behavior rather than just asserting it.
* Leave room for the learner to build things themselves, and don't generate large or optimized netlists for them.

## Where to go next

> [card] [Quickstart](https://wires.phil.bingo/quickstart.md)
>
> Install the library and simulate your first circuit in a few minutes.

> [card] [Core concepts](https://wires.phil.bingo/concepts/components.md)
>
> Definitions, instances, ports and connections.

> [card] [Standard library](https://wires.phil.bingo/library/overview.md)
>
> Gates, adders, multiplexers and an SR latch, all built from NAND.

> [card] [API reference](https://wires.phil.bingo/reference/gate.md)
>
> Every exported function, type and error.
