Skip to content

caid-technologies/OpenCAD

Repository files navigation

OpenCAD

A modular CAD system for parametric, programmable, and AI-assisted design

Components

  • opencad_kernel — geometry kernel and typed operation registry
  • opencad_solver — 2D sketch constraint solving (SolveSpace + Python fallback)
  • opencad_tree — parametric feature-tree DAG (CRUD + rebuild + stale propagation)
  • opencad_agent — AI agent that plans and executes operations
  • opencad_viewport — React + Three.js viewport UI (mock mode by default)

Layout

opencad_kernel/      # 1 – Geometry Kernel
opencad_solver/      # 2 – Constraint Solver
opencad_tree/        # 3 – Feature Tree
opencad_viewport/    # 4 – 3D Viewport (frontend)
opencad_agent/       # 5 – AI Chat Agent
scripts/             # Backend smoke tests

Quickstart

Prereqs: Python 3.11+ and Node.js 18+

1. Install

For a packaged install (for example from a wheel or a PyPI release), use:

pip install opencad

For local development from this repository:

python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e ".[test]"
cp .env.example .env

Install optional integrations as needed, for example:

pip install -e ".[full]"
pip install -e ".[llm]"

2. Start backend services

Each service runs on its own port:

python -m uvicorn opencad_kernel.api:app --reload --port 8000   # 1 – Kernel
python -m uvicorn opencad_solver.api:app --reload --port 8001   # 2 – Solver
python -m uvicorn opencad_tree.api:app   --reload --port 8002   # 3 – Tree
python -m uvicorn opencad_agent.api:app  --reload --port 8003   # 5 – Agent

3. Check health

curl -s http://127.0.0.1:8000/healthz   # → {"status":"ok"}
curl -s http://127.0.0.1:8001/healthz
curl -s http://127.0.0.1:8002/healthz
curl -s http://127.0.0.1:8003/healthz

4. Start the frontend

cd opencad_viewport
npm install
npm run dev                              # → http://localhost:5173

The viewport uses mock geometry/solver data by default (no backend required for those flows). Chat targets the live agent service by default; set VITE_USE_CHAT_MOCK=true if you explicitly want mocked chat output. Set VITE_USE_MOCK=false to connect the rest of the viewport to the live services above.

Configuration

Runtime defaults are documented in .env.example.

  • OPENCAD_ENABLE_DOCS=true|false toggles OpenAPI/docs route exposure.
  • OPENCAD_CORS_ALLOW_ORIGINS sets a comma-separated browser origin allowlist.
  • OPENCAD_KERNEL_BACKEND=analytic|occt selects the kernel backend.
  • OPENCAD_SOLVER_BACKEND=auto|solvespace|python selects the solver backend.

For production, disable docs and set a strict CORS origin list.

Security

Use TLS + authentication at your reverse proxy/API gateway. Do not commit .env files, tokens, or private datasets. See SECURITY.md for coordinated vulnerability reporting.

Testing

pytest

Headless Scripting

OpenCAD now includes a first-class in-process API for scripting workflows with automatic feature-tree logging.

from opencad import Part, Sketch

part = Part()
sketch = Sketch().rect(10, 20).circle(3, subtract=True)
part.extrude(sketch, depth=5).fillet(edges="top", radius=0.5)
part.export("output.step")

Every fluent call appends a built FeatureNode to the in-memory DAG, so headless runs are recoverable. Fluent sketches also persist entities + profile_order metadata in the sketch node, matching agent-path ordering semantics for deterministic profile reconstruction.

CLI

opencad build model.json --output model.built.json
opencad run model.py --export output.step --tree-output output-tree.json

Examples

The examples/ directory contains end-to-end scripts for common device-development workflows:

  • hardware_mounting_bracket.py — bracket with fastener and cable pass-through holes
  • hardware_pcb_carrier.py — PCB carrier plate with mounting holes and clearance slot
  • software_hmi_panel.py — front panel for an operator interface with button and encoder cutouts
  • firmware_programmer_fixture.py — pogo-pin fixture plate for programming/debug access
  • full_device_cable_grommet.py — concentric cable grommet built from primitive booleans
  • examples/agents/generate_mounting_bracket_code.py — agent code-generation usage example

Run an example from the repository root with:

python -m opencad.cli run examples/hardware_mounting_bracket.py \
  --export bracket.step \
  --tree-output bracket-tree.json

The agent service can also generate example-style Python scripts for different LLM providers through LiteLLM by posting llm_provider, llm_model, and generate_code=true to /chat. When generate_code is enabled, the response includes generated_code and leaves the feature tree unchanged.

For a runnable script example, see examples/agents/README.md.

Documentation