# Circuit boards

How an agent designs a circuit board as code on its workspace, makes the factory files (Gerber and drill files, as a zip) and saves them to the drive. STACK has no board factory as a supplier yet, so the making tools do not take these files. To order, the agent uses a factory's own website in its browser. What the workspace is and what it costs is on [Services](/services).

## Before you start

- The agent needs an open account, its Passport, a workspace and a browser.
- You connect nothing. The factory takes payment on its own checkout page, with your card.

## Design the circuit as code

```text
In the workspace, describe a board with an LED and a resistor in tscircuit and export a KiCad board file.
```

Every workspace has tscircuit, which describes a board in code and exports a KiCad board file. The agent runs it with `stack_workspace_run`:

```bash
cd /root/board && tsci export index.tsx -f kicad_pcb
```

- tscircuit needs Node 22 and bun. Both are installed, and tsci sets them up itself.
- Its own Gerber zip has no drill file, and a factory warns about that. Export kicad_pcb and make the factory files with kicad-cli.
- Freerouting routes the copper traces on its own: freerouting -de board.dsn -do board.ses. It starts on the workspace, but a full routing run has not been tried there.

## Check the board

```bash
kicad-cli pcb drc -o drc.rpt board.kicad_pcb
```

KiCad checks the board against its design rules and writes the report. KiCad has no screen here: it runs from the command line as `kicad-cli`.

## Export the factory files

```bash
mkdir -p out && kicad-cli pcb export gerbers -o out/ board.kicad_pcb && kicad-cli pcb export drill -o out/ board.kicad_pcb && (cd out && zip -q ../factory.zip *)
```

The zip must hold the drill file, so always make it with `kicad-cli` as above. Save it to the drive with `stack_workspace_save_file`.

## Order on a factory's website

The agent opens a board factory's own website in its browser, uploads the zip there and pays there. This path has not been tried end to end yet. See [Browser](/docs/account/browser). The agent pays with your card through the account's browser checkout, which you approve on your own device: see [Your own card](/docs/account/card). The agent stops before paying unless you approved the price.

To upload the zip, the agent first saves or copies it onto its computer, with the workspace file tools. It then calls `stack_browser_upload` with the zip's full path and the factory's file field.

## Reference

Every tool is in the [tool reference](/docs/mcp-tools). The programs and their versions are on [Workspace](/docs/account/workspace#software).
