Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
a5c1711
feat(model): add styled dimension properties and array/mirror constru…
JheisonMB Jun 12, 2026
97e290b
feat(svg): add full-fidelity vector renderer with grid, hatches, meas…
JheisonMB Jun 12, 2026
74ed01a
feat(preview): rasterize PNG previews from the SVG scene with an embe…
JheisonMB Jun 12, 2026
0bd5405
feat(serve): add live preview server with SSE auto-reload, entity ins…
JheisonMB Jun 12, 2026
74754ba
feat(compiler): expand constructions at load time, emit styled dimens…
JheisonMB Jun 12, 2026
c9d4308
feat(cli): wire serve, schema, preview formats, entity highlights and…
JheisonMB Jun 12, 2026
f2a5385
feat(scaffold): generate an AGENTS.md language guide in new projects
JheisonMB Jun 12, 2026
be9528a
feat(examples): add taller example showcasing polar arrays, mirror an…
JheisonMB Jun 12, 2026
ddd93ce
test: cover SVG rendering, preview pipeline, transform expansion and …
JheisonMB Jun 12, 2026
7a041ac
docs: rewrite README around the vibecoding workflow and viewer features
JheisonMB Jun 12, 2026
e064c2b
docs: add project specification and roadmap
JheisonMB Jun 12, 2026
fecbde8
chore: remove CLAUDE.md and ignore agent instruction files
JheisonMB Jun 12, 2026
76faed9
refactor(scaffold): drop AGENTS.md generation in favor of the cadforg…
JheisonMB Jun 12, 2026
3d63da1
feat(fmt): make cadforge fmt a real terraform-style formatter with ca…
JheisonMB Jun 12, 2026
18f5766
fix(import): dedup dimension companion graphics, recover layer and en…
JheisonMB Jun 12, 2026
5e1d4ee
docs(readme): replace the garbled banner with cadForge ascii art insi…
JheisonMB Jun 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ Cargo.lock
# End of https://www.toptal.com/developers/gitignore/api/rust
output.dxf
preview.png
preview.svg
preview.meta.json

# AI agent instruction files — not part of this repo
CLAUDE.md
AGENTS.md
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ serde_json = "1.0"
toml = "0.8"
toml_edit = "0.22"
indexmap = { version = "2", features = ["serde"] }
tiny-skia = "0.11"
notify = "6.1"
resvg = "0.47.0"

[profile.release]
opt-level = 3
lto = "thin"
codegen-units = 1
strip = "symbols"
129 changes: 92 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
██████ ████████ ██████ ████████ ██ ██ ██ ███████ ████████
██░░███ ░░███░░███░░░░░███ ░░███░░███░███ ░███ ██░███░░░░░░░███░
░███ ░░░ ░███ ░███ ███████ ░███ ░░░ ░███ ░██████░░█████ ░███
░███ ███ ░███ ░███ ███░░███ ░███ ░███ ░███░░░ ░███░░█ ░███
░░██████ ░███████░░████████ ░███ ░███████████ ███████ ░████████
░░░░░░ ░░░░░░░ ░░░░░░░░ ░░░ ░░░░░░░░░░░ ░░░░░░ ░░░░░░░
```text
█████ ███████████
░░███ ░░███░░░░░░█
██████ ██████ ███████ ░███ █ ░ ██████ ████████ ███████ ██████
███░░███ ░░░░░███ ███░░███ ░███████ ███░░███░░███░░███ ███░░███ ███░░███
░███ ░░░ ███████ ░███ ░███ ░███░░░█ ░███ ░███ ░███ ░░░ ░███ ░███░███████
░███ ███ ███░░███ ░███ ░███ ░███ ░ ░███ ░███ ░███ ░███ ░███░███░░░
░░██████ ░░████████░░████████ █████ ░░██████ █████ ░░███████░░██████
░░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░░░░░███ ░░░░░░
███ ░███
░░██████
░░░░░░
```

<p align="center">
<a href="https://github.com/UniverLab/cadforge/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/UniverLab/cadforge/ci.yml?branch=main&style=for-the-badge&label=CI" alt="CI"/></a>
Expand All @@ -12,7 +19,38 @@
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-2E8B57?style=for-the-badge" alt="License"/></a>
</p>

cadforge is an **Architecture as Code** CLI tool and Rust library for declarative 2D CAD modeling. Write geometry as code in `.cf` TOML format, compile to DXF, and generate PNG previews for AI agents.
cadforge is an **Architecture as Code** CLI tool and Rust library for declarative 2D CAD modeling. Write geometry as code in `.cf` TOML format, watch it live in the browser, and compile to DXF — built for humans and AI agents working together.

---

## Vibecoding CAD

The core loop: **describe geometry in TOML, see it instantly, iterate.**

```bash
cadforge new casa && cd casa
cadforge serve --open # live preview in the browser
```

Now edit any `.cf` file — by hand or by asking an AI agent — and the browser
updates on every save. Parse errors and constraint violations appear as an
overlay instead of a crash. When the design is right, `cadforge build` emits
a deterministic, AutoCAD-compatible DXF.

Agents get first-class support:

- `cadforge schema` — full `.cf` language reference in one command; agents
self-discover the format without prior training.
- `cadforge check --json` / `cadforge layers --json` — machine-readable
validation reports.
- `cadforge preview` — a faithful PNG render (real text, measured dimension
labels, hatches, line styles) + `preview.meta.json` with per-entity bounding
boxes in world and pixel coordinates, so multimodal agents can *look* at the
plan and locate every entity in the image.
- `cadforge preview --highlight ln-001,tx-002` — labeled amber markers around
specific entities, so an agent can visually confirm its edit landed where
intended.
- `cadforge preview --format svg` — same render as vector SVG.

---

Expand All @@ -21,25 +59,28 @@ cadforge is an **Architecture as Code** CLI tool and Rust library for declarativ
### 🎯 Core Platform

- **📐 Declarative Geometry** — Define architectural elements (lines, rects, circles, arcs, polylines, text, dimensions) in TOML `.cf` files. Deterministic, reproducible, version-controlled.
- **🛠️ Construction Tools** — `[[array]]` (linear and polar: spiral staircases, gear teeth, repeated columns) and `[[mirror]]` expand into concrete primitives at build time; copies get derived ids (`base@1`, `base@m`).
- **📏 Styled Dimensions** — Auto-measured labels with configurable `text_size`, `precision`, `show_units`, and `offset` per dimension.
- **🔴 Live Preview** — `cadforge serve` runs a local server with pan/zoom, auto-reload on save (SSE), click-to-inspect any entity (copy its source TOML as an agent prompt), per-layer ghost/hide states, a 3D stacked-layers view, and a build-error overlay. Zero config.
- **🔗 Layer System** — Organize geometry by layer with custom names, colors, and line weights. Compile single layers or full projects.
- **📄 DXF Export** — Compile `.cf` → DXF (AutoCAD-compatible). Full layer support, LWPOLYLINE for polylines, HATCH for solid fills, MTEXT for annotations.
- **🖼️ PNG Preview** — Generate raster previews with metadata JSON for AI agent integration. Renders fills, hatches, strokes, and text with boundary resolution. Configurable resolution and layer filtering.
- **✅ Validation Engine** — `cadforge check` validates geometry without generating output. Shows project metadata, layer colors, and entity counts.
- **🖼️ Previews for Agents** — Raster PNG + metadata JSON (entity bounding boxes) and full-fidelity SVG with real text, auto-measured dimensions, line styles, and clipped hatch patterns.
- **✅ Validation Engine** — `cadforge check` validates geometry and constraints without generating output; `--json` for tooling.

### 🏗️ Project Management

- **Project Scaffolding** — `cadforge new` creates a complete multi-layer project (muros, puertas, mobiliario, cotas) with meaningful architectural examples.
- **Multi-Layer Compilation** — Compile all layers or target specific layers with `--layer`. Custom output path with `--output`.
- **Auto-Rebuild** — `cadforge watch` monitors `.cf` and `.toml` files and auto-rebuilds on changes with 300ms debounce.
- **Auto-Rebuild** — `cadforge watch` monitors `.cf` and `.toml` files and auto-rebuilds DXF on changes with 300ms debounce.
- **Code Formatting** — `cadforge fmt` normalizes `.cf` files. `--check` mode for CI validation.
- **Boundary Resolution** — Automatic detection of closed boundaries for hatch generation. Shared boundary resolution across overlapping entities.
- **Polyline Support** — Full LWPOLYLINE support with bulge factors for arcs. Proper vertex handling and closure detection.
- **Constraints** — `parent`, `belongs_to`, and `spatial_dependency` rules between layers; warnings by default, build-blocking with `strict = true`.
- **DXF Import** — `cadforge import plano.dxf` migrates existing drawings into `.cf` layers + `project.toml`.

### 🔧 Architecture

- **Compiler Pipeline** — Parse → Resolve → Compile → Emit. Modular design for easy extension.
- **DXF Writer** — Direct DXF entity writing with proper AutoCAD compatibility. Layer/color/lineweight mapping.
- **Preview Renderer** — Tiny-skia based raster rendering with anti-aliasing. PNG + JSON metadata output.
- **Renderer** — One handwritten SVG backend; the PNG preview rasterizes it via resvg with an embedded monospace font (deterministic text on any machine, including fontless containers).
- **Error Reporting** — Structured errors with file, line, and context. Fast-fail on validation errors.

---
Expand All @@ -54,10 +95,17 @@ cadforge is an **Architecture as Code** CLI tool and Rust library for declarativ
| `cadforge build --check` | Validate project and constraints without generating DXF |
| `cadforge build --output <path>` | Compile to custom output path |
| `cadforge build --layer <name>` | Compile specific layer only |
| `cadforge serve` | Live preview server — browser auto-reloads on save |
| `cadforge serve --open --port 4377` | Open browser automatically on a custom port |
| `cadforge check` | Validate with project metadata and layer colors |
| `cadforge check --json` | Machine-readable validation report |
| `cadforge layers` | List layers with entity counts and colors |
| `cadforge preview` | Generate PNG preview + metadata JSON |
| `cadforge preview --width 1024 --height 768` | Custom resolution preview |
| `cadforge layers --json` | Machine-readable layer listing |
| `cadforge schema` | Print the full `.cf` language reference (markdown) |
| `cadforge preview` | Faithful PNG render + metadata JSON |
| `cadforge preview --format svg` | Vector SVG preview (same renderer) |
| `cadforge preview --highlight <id1,id2>` | Amber markers around specific entities |
| `cadforge preview --width 1024 -H 768` | Custom resolution preview |
| `cadforge preview --layer <name>` | Preview specific layer only |
| `cadforge fmt` | Format .cf files (normalize whitespace) |
| `cadforge fmt --check` | Check formatting without modifying (CI) |
Expand All @@ -69,18 +117,14 @@ cadforge is an **Architecture as Code** CLI tool and Rust library for declarativ
| `cadforge config set <key> <value>` | Set global defaults (`author`, `units`) |
| `cadforge config show` | Show global defaults |

### Viewer controls (MVP)
### Live preview controls (`cadforge serve`)

- HUD flotante en pantalla con proyecto, vista, distancia, capas, selección y ayuda de atajos
- `T` / `F` / `V` / `R` → top / front / right / isometric preset views
- `Q` / `E` / `W` / `S` → orbit camera
- Mouse left-drag → orbit
- Mouse right-drag / arrows → pan
- Mouse wheel / `+` / `-` → zoom
- `1`..`9` → toggle layer visibility
- Click entity edge → select primitive id
- Selected entity is highlighted in amber in the viewport HUD context
- `C` → copy selected id to clipboard
- Scroll → zoom (centered on cursor) · drag → pan · double-click / `F` → fit
- **Click an entity** → inspector with its source TOML block; `copy for agent` produces a ready-made targeted-edit prompt
- Layer panel (or keys `1`-`9`) → cycle each layer **on → ghost → off**; ghost mode traces one floor plan over another
- `3D` button (or key `3`) → stacked exploded view of the layers
- Browser auto-reloads on every `.cf` / `project.toml` save (SSE)
- Build errors render as an overlay with file/line detail — the loop never breaks

---

Expand Down Expand Up @@ -117,7 +161,7 @@ to_angle = 90.0

[[polyline]]
id = "pl-001"
vertices = [[0, 0], [5, 0], [5, 3], [0, 3]]
points = [[0.0, 0.0], [5.0, 0.0], [5.0, 3.0], [0.0, 3.0]]
closed = true

[[text]]
Expand All @@ -135,7 +179,9 @@ offset = 0.5

### Supported Primitives

`line`, `polyline`, `rect`, `circle`, `arc`, `text`, `point`, `dim`, `hatch`, `solid`
`line`, `polyline`, `rect`, `circle`, `arc`, `text`, `point`, `dim`, `hatch`, `fill`, `group`

Run `cadforge schema` for the complete reference with all attributes.

---

Expand All @@ -160,20 +206,24 @@ offset = 0.5
- **Resolver** — Layer dependency resolution, coordinate validation, boundary detection
- **Compiler** — Entity compilation to DXF format, hatch generation, polyline closure
- **DXF Writer** — Direct DXF entity emission with proper layer/color/lineweight mapping
- **Preview Renderer** — Tiny-skia raster rendering with hatch/fill support
- **SVG Renderer** — Single vector backend: text, measured dims, hatches, highlights; PNG previews are resvg rasterizations of it

---

## Main Modules

- `compiler/` — Project compilation pipeline, layer targeting, validation, build stats
- `compiler/` — Project compilation pipeline, layer targeting, validation, JSON reports
- `dxf_writer/` — DXF entity writing, LWPOLYLINE, HATCH, MTEXT generation
- `preview/` — PNG rendering with configurable resolution, layer filtering, metadata JSON
- `svg/` — Vector SVG rendering: real text, measured dimensions, hatch clipping, grid
- `serve/` — Live preview server: file watcher + SSE auto-reload + error overlay
- `schema/` — Embedded `.cf` language reference for humans and agents
- `parser/` — TOML parsing, primitive extraction, array-of-tables handling
- `model/` — Data structures: Layer, Primitive, Project
- `scaffold/` — Multi-layer project creation with architectural examples
- `fmt/` — .cf file formatting and normalization
- `watch/` — File system watcher with auto-rebuild and debounce
- `importer/` — DXF → `.cf` migration
- `color/` — Color parsing and DXF color mapping

---
Expand All @@ -183,10 +233,10 @@ offset = 0.5
| Data | Location | Format |
|------|----------|--------|
| Project files | `./` | TOML (`.cf` + `project.toml`) |
| Build output | `output/` | DXF |
| Preview output | `output/preview.png` | PNG |
| Preview metadata | `output/preview.json` | JSON |
| Build cache | `target/` | Cargo build |
| Build output | `./output.dxf` | DXF |
| Preview output | `./preview.png`, `./preview.svg` | PNG / SVG |
| Preview metadata | `./preview.meta.json` | JSON |
| Language reference | `cadforge schema` (stdout) | Markdown |

---

Expand All @@ -198,7 +248,12 @@ cadforge new mi-proyecto
cd mi-proyecto
```

**Edit `.cf` files** (TOML format with your geometry)
**Live preview while you edit:**
```bash
cadforge serve --open # browser refreshes on every save
```

**Edit `.cf` files** (TOML format with your geometry — run `cadforge schema` for the reference)

**Format and validate:**
```bash
Expand All @@ -215,7 +270,7 @@ cadforge build --layer muros # compile single layer

**Preview:**
```bash
cadforge preview # default 2048x1536
cadforge preview # default 1600x1200 (fits content aspect)
cadforge preview --width 1024 --height 768 # custom resolution
cadforge preview --layer muros # single layer preview
```
Expand All @@ -229,7 +284,7 @@ cadforge watch # monitors .cf and .toml files

## Tech Stack

| Rust 2021 | clap | toml | toml_edit | tiny-skia | dxf | notify | anyhow | serde |
| Rust 2021 | clap | toml | toml_edit | resvg | dxf | notify | anyhow | serde |

---

Expand Down
Binary file added assets/fonts/DejaVuSansMono.ttf
Binary file not shown.
78 changes: 78 additions & 0 deletions assets/fonts/LICENSE-DejaVuSansMono.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: DejaVu fonts
Upstream-Author: Stepan Roh <src@users.sourceforge.net> (original author),
see /usr/share/doc/fonts-dejavu-core/AUTHORS for full list
Source: https://dejavu-fonts.github.io/

Files: *
Copyright: Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved.
Bitstream Vera is a trademark of Bitstream, Inc.
DejaVu changes are in public domain.
License: bitstream-vera
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
.
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
.
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.

Files: debian/*
Copyright: (C) 2005-2006 Peter Cernak <pce@users.sourceforge.net>
(C) 2006-2011 Davide Viti <zinosat@tiscali.it>
(C) 2011-2013 Christian Perrier <bubulle@debian.org>
(C) 2013 Fabian Greffrath <fabian+debian@greffrath.com>
License: GPL-2+
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more
details.
.
You should have received a copy of the GNU General Public
License along with this package; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
.
On Debian systems, the full text of the GNU General Public
License version 2 can be found in the file
/usr/share/common-licenses/GPL-2'.
Loading
Loading