# 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/`) and symlink `tools` and `knowledge/tooling` to it, 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//` | One directory per board: KiCad project, its enclosure, fab releases. | | `CAD/` | Mechanical parts not tied to one project. | | `datasheets/` | Datasheet PDFs, named `.pdf` (keep these out of public repos; vendors own the copyright). | | `tools/` | Scripts and helpers: placer, routers, board edits, checks. | | `experiments//` | Tool experiments on copies of boards; scratch output in `out/` is git-ignored. | ### Libraries Set the KiCad path variable `HW_LIB` to `/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/.step` - `libraries/blocks/HW.kicad_blocks/`: design blocks (reusable modules) - `libraries/templates//`: KiCad project templates (e.g. `DIN_TE`, generated by `tools/din_template.py`) Never use absolute paths or `${KIPRJMOD}/../..` paths to these libraries. ### Projects ``` projects// README.md purpose, status, link to knowledge/projects/.md kicad/ .kicad_pro / .kicad_sch / .kicad_pcb, .konnect/project.json cad/ enclosure and mechanical files for this board fab// released fab outputs (gerbers, drill, BOM, CPL), committed out/ scratch exports (git-ignored) ``` Release tags: `/v`, 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](knowledge/tooling/pnr.md) | | Route a placed board | `tools/router-rs` (`route.toml`) | [Rust router](knowledge/tooling/rust-router.md) | | Place parts | `tools/placer` (`placement.toml`) | [Placer](knowledge/tooling/placer.md) | | Rate a placement | `tools/placement_check.py` | [Placement check](knowledge/tooling/placement-check.md) | | Generate a schematic from Python | `tools/schgen.py` | [schgen](knowledge/tooling/schgen.md) | | Update PCB from schematic, headless | `tools/sync_board.py` | [KiCad notes](knowledge/tooling/kicad.md) | | Compose a base board from modules | `tools/compose_board.py` | [Compose board](knowledge/tooling/compose-board.md) | | Net classes for all projects | `tools/netclasses.py` | [Net classes](knowledge/topics/netclasses.md) | | Edge connector tabs, thermal vias, silk refs, copper pruning | `connector_tab.py`, `thermal_vias.py`, `silk_refs.py`, `prune_copper.py` | [index](knowledge/index.md) | | 3D model, height and housing checks | `model_check.py`, `height_check.py`, `housing_inputs.py` | [index](knowledge/index.md) | | KiCad MCP server | `tools/konnect` (submodule, AGPL) | [Konnect](knowledge/tooling/konnect.md) | 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](knowledge/tooling/kicad.md)). - **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/.pdf`. When a part is used, write its key facts to `knowledge/parts/.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