@rulecad/pcb

Circuit boards from the same rules: parts from rule sets or KiCad footprints, nets, routing, any board shape, fab files.

npm 0.6.0sourceMITNode >=20.6
npm install @rulecad/pcb

See it

A 3 × 3 macropad: nine MX switches, a diode each, and a Pico beside them

keyboard(v, grid(3, 3, v.mx.pitch)): the switch, Pico and diode sizes come from the mx, pico and sod123 rule sets; every matrix track is drawn by rule.

D1D2D3D4D5D6D7D8D9rulecad: diodes point to the rowsUSB+-+-+-+-+-+-+-+-+-
Its schematic, drawn from the same description
U11GP02GP13GND4GP25GP36GP47GP59GP610GP711GP812GP914GP1015GP1116GP1217GP1319GP1420GP1521GP1622GP1724GP1825GP1926GP2027GP2129GP2230RUN31GP2632GP2733AGND34GP2835ADC_VREF363V3373V3_EN39VSYS40VBUSK1D1K2D2K3D3K4D4K5D5K6D6K7D7K8D8K9D9

The same macropad on a shaped board

outline: shape.rounded(width, height, 6): any outline works (rounded, bevelled, circle, or your own points), and the checks find any pad outside it.

D1D2D3D4D5D6D7D8D9rulecad: diodes point to the rowsUSB+-+-+-+-+-+-+-+-+-

Reference

Circuit boards from rules, for @rulecad/cad designs with "engine": "pcb". Footprints come from rule sets (datasheets, KiCad's library) rather than numbers in code. The keyboard router draws every matrix track by rule, with one diode per key on the back. The output is what a fab needs: Gerbers, drill files, a JLCPCB BOM and placement file, and KiCad files.

No framework. The board is written directly as Circuit JSON, an open data format, and the work is done by tscircuit's framework-free libraries: footprints (footprinter), the autorouter, the design checks, and the Gerber, KiCad and drawing exporters. React, which tscircuit's own board-building layer uses, is never loaded. Two of those libraries list tscircuit among their dependencies, so React may be installed alongside them, unused; rulecad's tests fail if it's ever loaded.

Any board. Place parts from rule sets or any standard footprint, turn them in quarter turns, join their pins with nets, and let the autorouter draw the tracks:

// projects/macropad/objects/pcb.js: four keys wired straight to a XIAO, and a Qwiic socket for a small display
export function main(v) {
  const { xiao, mx, qwiic } = v.pcb, p = v.mx.pitch;
  const keys = Array.from({ length: v.keys }, (_, i) => mx(`K${i + 1}`, (i - (v.keys - 1) / 2) * p, v.key_y, v.mx));
  return {
    center: { x: 0, y: 0 }, width: p * v.keys + v.margin * 2, height: v.height, thickness: v.thickness, track: v.track, autoroute: true,
    parts: [
      ...keys,                                                       // one MX switch per key, from the mx rules
      xiao('U1', 0, v.mcu_y, v.xiao),                                // pins labelled D0..D10, 3V3, GND, 5V from the xiao rules
      qwiic('J1', v.qwiic_x, v.mcu_y, v.qwiic, { rotation: v.qwiic_turn }) // turned to face the board's edge
    ],
    nets: { GND: ['U1.GND', 'J1.GND', ...keys.map((k) => `${k.name}.pin2`)], SDA: ['U1.D4', 'J1.SDA'], SCL: ['U1.D5', 'J1.SCL'],
      ...Object.fromEntries(keys.map((k, i) => [`KEY${i + 1}`, [`${k.name}.pin1`, `U1.D${i}`]])) },
    traces: [], silk: [], holes: []
  };
}

A keyboard:

// projects/macropad/objects/board.js: main(v) returns a board, built with v.pcb
export function main(v) {
  const keys = v.pcb.grid(v.rows, v.cols, v.mx.pitch);
  return v.pcb.keyboard(v, keys);              // { board, matrix }
}
npm install @rulecad/pcb
npx cad check macropad/board      # tscircuit's checks, JLCPCB's limits, the matrix
npx cad preview macropad/board    # copper from above, the schematic, and the board in 3D
npx cad export macropad/board     # <name>-fab.zip for JLCPCB, KiCad files, the matrix for your firmware

Licence

MIT (see LICENSE). fixedTraces in circuit.mjs follows tscircuit's MIT-licensed withFixedTraces: its copyright notice is in THIRD-PARTY.md, which goes with any copy of the package.