aboutsummaryrefslogtreecommitdiff

Hardware repo conventions (hw-toolchain)

Conventions for AI-assisted hardware development with KiCad 10 for electronics, a parametric CAD tool for mechanics (SolidCraft here; the rules apply to any), and a Markdown knowledge graph (IWE). The toolchain in tools/ and the notes in knowledge/tooling/ and knowledge/topics/ come from this repo. Your own boards, libraries and notes live beside them.

Using this inside your own repo: add this repo as a submodule (e.g. toolchain/), symlink tools to toolchain/tools, and run sh tools/link_toolchain.sh to link the notes into knowledge/, so that every path below holds. Your repo's own AGENTS.md should start with "Read toolchain/AGENTS.md first", then add what is yours: identity, hosting, project rules. Where the two disagree, your repo's file wins.

Layout

Path Contents
knowledge/ Markdown knowledge graph (IWE). Everything learned while working goes here.
libraries/ Your shared KiCad libraries, referenced through the HW_LIB path variable.
modules/ One small KiCad test project per design block, so each block can pass ERC/DRC on its own.
projects/<name>/ One directory per board: KiCad project, its enclosure, fab releases.
CAD/ Mechanical parts not tied to one project.
datasheets/ Datasheet PDFs, named <MPN>.pdf (keep these out of public repos; vendors own the copyright).
tools/ Scripts and helpers: placer, router, board edits, checks.
experiments/<name>/ Tool experiments on copies of boards; scratch output in out/ is git-ignored.

Libraries

Set the KiCad path variable HW_LIB to <repo>/libraries, and register the HW libraries in the global library tables:

  • libraries/symbols/HW.kicad_sym: symbols
  • libraries/footprints/HW.pretty/: footprints
  • libraries/3dmodels/HW.3dshapes/: STEP models; reference them from footprints as ${HW_LIB}/3dmodels/HW.3dshapes/<name>.step
  • libraries/blocks/HW.kicad_blocks/: design blocks (reusable modules)
  • libraries/templates/<name>/: KiCad project templates (e.g. DIN_<k>TE, generated by tools/din_template.py)

Never use absolute paths or ${KIPRJMOD}/../.. paths to these libraries.

Projects

projects/<name>/
  README.md            purpose, status, link to knowledge/projects/<name>.md
  kicad/               .kicad_pro / .kicad_sch / .kicad_pcb, .konnect/project.json
  cad/                 enclosure and mechanical files for this board
  fab/<rev>/           released fab outputs (gerbers, drill, BOM, CPL), committed
  out/                 scratch exports (git-ignored)

Release tags: <project>/v<rev>, e.g. sensor-node/v1.0.

Tools

KiCad's Python and kicad-cli are found by tools/kicad_env.sh (shell) and tools/kicad_paths.py (Python). Override them with KICAD_PYTHON and KICAD_CLI. Run the tools from the repo root, with the board closed in KiCad.

Task Tool Notes
Place and route a whole board sh tools/pnr.sh run/install DIR pnr
Route a placed board tools/router (route.toml) Router
Place parts tools/placer (placement.toml) Placer
Rate a placement tools/placement_check.py Placement check
Generate a schematic from Python tools/schgen.py schgen
Update PCB from schematic, headless tools/sync_board.py KiCad notes
Compose a base board from modules tools/compose_board.py Compose board
Net classes for all projects tools/netclasses.py Net classes
Edge connector tabs, thermal vias, silk refs, copper pruning connector_tab.py, thermal_vias.py, silk_refs.py, prune_copper.py index
3D model, height and housing checks model_check.py, height_check.py, housing_inputs.py index
KiCad MCP server tools/konnect (submodule, AGPL) Konnect

Reusable scripts go into tools/ with a note in knowledge/tooling/, never only into a scratchpad.

Rules

  • KiCad files: direct edits are allowed, then reload. Prefer reliable MCP operations (Konnect) when convenient, and KiCad's own parser/API (pcbnew, kicad-cli) for file changes.
    • Before: save the current editor state and keep a checkpoint, and make sure a stale open editor cannot overwrite the change.
    • After: reload the exact document and verify by reading back, plus ERC/DRC as appropriate.
    • Preserve UUIDs, nets and unrelated work.
    • pcbnew's SaveBoard resets the .kicad_pro: copy it before and restore it after (KiCad notes).
  • Mechanical CAD: export STEP files for KiCad 3D models to libraries/3dmodels/. Board STEP exports for enclosure work go to the project's cad/.
  • Datasheets: save new datasheets as datasheets/<MPN>.pdf. When a part is used, write its key facts to knowledge/parts/<MPN>.md and link the datasheet: pinout gotchas, layout recommendations, errata, and the absolute maxima that matter.
  • Knowledge: record what you learn in knowledge/, including decisions and their reasons, mistakes and fab feedback. Do not leave it only in the chat. iwe docs agent explains how to find, create and update notes.
  • Git: never commit backups, lock files or *.kicad_prl.

Knowledge structure

  • knowledge/parts/: one note per part, named by MPN
  • knowledge/topics/: design topics (net classes, placement for routing, board formats …)
  • knowledge/vendors/: fab and assembly houses, their rules and capabilities
  • knowledge/lessons/: post-mortems and things that went wrong
  • knowledge/projects/: project journals and design decisions
  • knowledge/tooling/: KiCad, Konnect, CAD, IWE setup and quirks; one note per tool