Tool

Generate parametric CAD models in JavaScript with type safety

JavaScript library for code-first parametric CAD modeling with type-safe geometry, boolean operations, and STEP export powered by WebAssembly.

Works with threejsbabylonjswebglopenscadnextjs

Maintainer of this project? Claim this page to edit the listing.


91
Spark score
out of 100
Updated last month
Version 1.0.0

Add to Favorites

Why it matters

Engineers and developers hire brepjs to programmatically create precise 3D CAD parts in JavaScript with compile-time type safety, enabling parametric design workflows for enclosures, brackets, fixtures, and mechanical components that can be exported to industry-standard STEP format.

Outcomes

What it gets done

01

Define 3D solids using TypeScript code with exact mathematical boundaries instead of triangle meshes

02

Perform boolean operations (cut, union, fillet) on shapes with guaranteed geometric validity at compile time

03

Export parametric parts to STEP format for manufacturing or import into professional CAD tools

04

Verify AI-generated CAD code with automated dimension checking and multi-view snapshots before production

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/andymai-brepjs | bash

Overview

Brepjs

A TypeScript library for programmatic CAD modeling that represents shapes as exact mathematical boundaries. Supports boolean operations, fillets, edge finding, and STEP export. Built on OpenCascade WebAssembly with a kernel abstraction layer. Includes compile-time type safety through branded types, Result types, and phantom types. Choose brepjs when building parametric mechanical parts (enclosures, brackets, fixtures) through code in a browser environment, and you need STEP export capability with TypeScript type safety. Skip it if you need organic sculpting, built-in rendering, 2D-only output, server-side rendering, or a visual editor.

What it does

brepjs is a JavaScript/TypeScript library for programmatic CAD modeling in the browser. It uses exact mathematical boundaries rather than triangle meshes for shape representation. TypeScript types enforce geometry validity at compile time, catching errors before runtime.

When to use - and when NOT to

Use brepjs when you need parametric parts defined by code: enclosures, brackets, fixtures, gridfinity bins, or any mechanical component driven by parameters. It's designed for type-safe CAD in the JavaScript ecosystem with browser-based execution.

Do NOT use brepjs for organic sculpting or freeform modeling - the API is built for parametric workflows, not artistic sculpting. It does not render geometry itself (you must pass mesh output to Three.js, Babylon.js, or WebGL), does not output SVG or 2D files as standalone formats, and does not provide a GUI or visual editor.

Inputs and outputs

You provide TypeScript code defining shapes through functions like box, cylinder, cut, fillet, and edgeFinder. The library accepts dimensions, positions, and geometric operations as parameters.

You receive shape data that can be exported to STEP format or meshed for rendering. Here's the canonical workflow:

// Drill a hole, fillet the vertical edges, export to STEP
import { box, cut, cylinder, fillet, edgeFinder, exportSTEP, unwrap } from 'brepjs/quick';

const b = box(30, 20, 10);
const hole = cylinder(5, 15, { at: [15, 10, -2] });
const drilled = unwrap(cut(b, hole));

const edges = edgeFinder().inDirection('Z').findAll(drilled);
const part = unwrap(fillet(drilled, edges, 1.5));

const step = unwrap(exportSTEP(part));

Installation:

npm install brepjs occt-wasm

Integrations

occt-wasm: OpenCascade compiled to WebAssembly, the default geometry kernel. Handles WASM initialization automatically via brepjs/quick or manual setup.

brepkit: Rust-based geometry kernel in active development as a faster replacement (not yet production-ready). The kernel abstraction layer is designed to support switching between kernels.

Three.js, Babylon.js, WebGL: brepjs produces shape data that you mesh and pass to these rendering engines for display.

brepjs-verify: CLI and Claude Code skill for AI-assisted CAD authoring. Runs parts on a real kernel, generates deterministic reports including validity checks, measured dimensions, multi-view snapshots, and STEP export.

Who it's for

Developers who know TypeScript but aren't 3D modelers, and need parametric CAD in the browser. Engineers building web-based configurators for mechanical parts. Teams wanting type-safe CAD that catches geometry errors at compile time. Users migrating from OpenSCAD (code-first CAD outside JS) or replicad (OpenCascade in JS) who want stronger type safety. The architecture enforces clean boundaries across four layers: high-level API (sketching, text, projection), domain logic (topology, operations, 2D), core types/memory/errors, and WASM bindings.

Source README

brepjs

CAD modeling for JavaScript.

npm
CI
Last release
Commit activity
License

▶ Try the live playground - write code, watch the solid render, and export STEP, all in your browser.

Getting Started · Cheat Sheet · Docs

brepjs playground: write TypeScript on the left, see the exact solid render on the right

Shapes are exact mathematical boundaries - not triangle meshes - so booleans are precise, measurements are real, and you can export to STEP. TypeScript types prove the geometry is valid at compile time.

// Drill a hole, fillet the vertical edges, export to STEP
import { box, cut, cylinder, fillet, edgeFinder, exportSTEP, unwrap } from 'brepjs/quick';

const b = box(30, 20, 10);
const hole = cylinder(5, 15, { at: [15, 10, -2] });
const drilled = unwrap(cut(b, hole));

const edges = edgeFinder().inDirection('Z').findAll(drilled);
const part = unwrap(fillet(drilled, edges, 1.5));

const step = unwrap(exportSTEP(part));

Why?

brepjs grew out of the love and care I put into gridfinitylayouttool.com. I needed parametric CAD in the browser and I'm not a 3D modeler, but I know TypeScript. OpenSCAD nailed code-first CAD but lives outside the JS ecosystem. replicad proved OpenCascade works in JS but I kept hitting performance walls and fighting the API.

Neither had the type safety I wanted, so brepjs leans hard on it: branded types, Result<T,E>, phantom types that prove invariants at compile time. If it compiles, the geometry is valid. Best for parts defined by parameters (enclosures, brackets, fixtures, gridfinity bins) rather than organic sculpting.

Scope

To set expectations, this project deliberately does not:

  • Render or display geometry - brepjs produces shape data; pass mesh output to Three.js, Babylon.js, or raw WebGL for rendering.
  • Support organic or sculpting workflows - the API is built for parametric parts (enclosures, brackets, fixtures); freeform sculpting is out of scope.
  • Output SVG or 2D files - 2D drawing primitives exist solely as an intermediate step toward extruded 3D solids, not as a standalone 2D output format.
  • Run server-side (SSR) - WASM requires a browser or Node.js environment with WASM support; server-side rendering frameworks (Next.js, Nuxt, Remix) need a client-only import.
  • Provide a GUI - brepjs is a pure programmatic API; there is no visual editor, viewport, or file picker.

Status

occt-wasm (OpenCascade compiled to WebAssembly) is the default kernel. brepkit, a Rust-based kernel, is in active development as a faster replacement but not yet ready for production use. The kernel abstraction layer means switching is a one-line change. See benchmarks for performance comparisons.

Install

npm install brepjs occt-wasm

brepjs/quick handles WASM init automatically via top-level await (ESM only). Other options:

// Auto-detect kernel
import { init } from 'brepjs';
await init();

// Or manual setup
import { OcctKernel } from 'occt-wasm';
import { registerKernel, OcctWasmAdapter } from 'brepjs';
const kernel = await OcctKernel.init();
registerKernel('occt-wasm', OcctWasmAdapter.fromKernel(kernel));

Usage

The chapter-based guide is the recommended starting point:

Legacy single-page docs in ./docs/ remain available; the chapter site is the canonical location going forward.

Architecture

Layer 3  sketching/, text/, projection/   High-level API
Layer 2  topology/, operations/, 2d/ ...  Domain logic
Layer 1  core/                            Types, memory, errors
Layer 0  kernel/, utils/                  WASM bindings

Imports flow downward only. Boundaries are enforced in CI.

Authoring CAD with AI (brepjs-verify)

brepjs-verify helps an AI agent (or you) author parametric CAD in brepjs and prove it is correct before handing it off. An LLM can't see geometry - so it writes a .brep.ts part, runs it on a real kernel, and reads a deterministic report instead of guessing from how the code reads. It ships as two cooperating pieces: a Claude Code skill (the authoring loop) and a verification CLI (validity + measured dimensions + multi-view snapshots + STEP export).

Install both - they ride on two rails:

# 1. The skill - Claude Code plugin (delivered via this repo's marketplace)
/plugin marketplace add andymai/brepjs
/plugin install brepjs-verify@brepjs

# 2. The runtime - the CLI the skill drives
npm i -D brepjs-verify

brepjs-verify bundles its own brepjs + occt-wasm, so it runs in an empty directory; inside an existing brepjs project it prefers your installed versions so verified parts match what you ship. A model is a module that default-exports a zero-arg function returning a shape:

// bracket.brep.ts
import { box } from 'brepjs';
export const expected = { volume: 8000, tolerancePct: 1 }; // optional: assert intent
export default () => box(40, 20, 10, { centered: true });
npx -y brepjs-verify bracket.brep.ts --check --step bracket.step --json report.json

The command exits non-zero unless the report is ok (valid and every declared dimension within tolerance), so it drops straight into CI or an agent loop. See the Authoring with AI guide for the full loop, CLI reference, examples, and the measurement eval.

Projects Using brepjs

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.