Skip to main content
warning

Automatic layout is in beta! We're changing and improving the layout algorithms, if it doesn't work for you stay tuned! Many changes are on the way!

Automatic PCB Layout

tscircuit provides three main methods for automatic PCB layout, each suited for different use cases:

  • pcbFlex - Lay out components using flexbox
  • pcbGrid - Lay out components in a grid with changeable cell widths and overlaps
  • pcbPack - Pack components together to minimize space using packing strategies

pcbGrid Layout

Grid layout arranges components in a structured grid pattern. This is ideal for matrix keyboards, LED grids, or any regular array of components. Components can dynamically span multiple cells using all the conventions and patterns of CSS Grid.

export default () => (
<board pcbGrid pcbGridGap="1mm" pcbGridColumns={3}>
<resistor name="R1" resistance="1k" footprint="0402" />
<resistor name="R2" resistance="1k" footprint="0402" />
<resistor name="R3" resistance="1k" footprint="0402" />
<resistor name="R4" resistance="1k" footprint="0402" />
<resistor name="R5" resistance="1k" footprint="0402" />
<resistor name="R6" resistance="1k" footprint="0402" />
</board>
)
PCB Circuit Preview

pcbFlex Layout

Flex layout provides automatic spacing and alignment along a single axis, similar to CSS flexbox. Perfect for linear arrangements of components.

export default () => (
<board>
<group pcbFlex pcbFlexGap="1mm">
<resistor name="R1" resistance="1k" footprint="0402" />
<capacitor name="C1" capacitance="100nF" footprint="0402" />
<group pcbFlex pcbFlexDirection="column" pcbFlexGap="1mm">
<resistor name="R2" resistance="10k" footprint="0402" />
<capacitor name="C2" capacitance="1uF" footprint="0603" />
</group>
</group>
</board>
)
PCB Circuit Preview

You can customize the flex layout with additional options:

<group 
pcbLayout={{
flex: true,
direction: "column",
gap: 2
}}
>
<resistor name="R1" resistance="1k" footprint="0402" />
<resistor name="R2" resistance="2.2k" footprint="0402" />
</group>

pcbPack Layout

Pack layout automatically places components to minimize space while avoiding overlaps. Ideal for dense layouts where space efficiency is crucial.

export default () => (
<board pcbPack pcbGap="1mm">
<chip name="U1" footprint="soic8" connections={{ pin1: "R1.pin1" }} />
<resistor name="R1" resistance="1k" footprint="0402"/>
<resistor name="R2" resistance="2.2k" footprint="0605" connections={{ pin1: "R1.pin2" }}/>
<capacitor name="C1" capacitance="100nF" footprint="0402" connections={{ pin1: "R2.pin2" }}/>
<capacitor name="C2" capacitance="10uF" footprint="0402" connections={{ pin1: "C1.pin2" }}/>
</board>
)
PCB Circuit Preview

Combining Layout Methods

You can mix different layout methods within the same board for complex arrangements:

TODO