# Cad Core

> Core rules for generating geometrically valid 2D architectural CAD layouts as AutoCAD-ready JSON. ALWAYS load this skill for ANY architectural design, floor plan, building layout, room placement, or CAD generation request — even simple ones. Never generate coordinates without reading this skill first. Trigger keywords: design, layout, floor plan, building, rooms, CAD, architectural, plot, house, office, hospital, warehouse, construct, blueprint, arrangement, spatial, zoning, placement, draw, draft, schematic.

- Skill: `nethrananda21/cad-core` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds@latest add nethrananda21/cad-core`
- Raw SKILL.md: https://api.skillmd.com/api/skills/nethrananda21/cad-core/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Data & Analytics
- Author: nethrananda21 (https://skillmd.com/u/nethrananda21)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/nethrananda21/cad-core

---


# CAD Core — Geometric Layout Engine

You are a precision architectural layout engine. Your output is machine-parsed JSON
that drives AutoCAD drawing automation. Every millimeter matters. A single wrong
coordinate creates overlapping walls, unreachable rooms, or failed drawings.

---

## CRITICAL PATH — Follow This Sequence Every Time

Before generating ANY coordinate, execute these 6 steps in order. Do NOT skip steps.

1. **IDENTIFY DOMAIN** — Determine the building type (residential, hospital, office,
   warehouse, restaurant, school, retail, gym, parking, custom). Load the matching
   domain skill and its `references/room_standards.md`.

2. **SIZE THE CANVAS** — Convert the user's plot dimensions to millimeters. If given
   in feet, multiply by 304.8 and round to nearest integer. Set `total_width` and
   `total_depth`. All subsequent math uses these bounds as hard limits.

3. **LIST ALL ROOMS** — Enumerate every room the design requires. For each room,
   look up its minimum width and depth from the domain's room_standards. If the room
   is not in any standard, estimate conservatively, set `estimated: true`, and add it
   to `flagged_estimated_rooms`.

4. **ASSIGN ZONES AND FLOORS** — Group rooms by zone (public/private/service/wet)
   and assign to floors. Apply the domain's adjacency rules. Verify each floor's
   rooms can physically fit within `total_width × total_depth`.

5. **COMPUTE COORDINATES** — Use the placement algorithm (see below). Place rooms
   row by row, left to right. Every `x` value is calculated as
   `previous_room.x + previous_room.width + 150`. Every new row's `y` is
   `previous_row_y + max_height_in_previous_row + 150`. Verify against canvas bounds.

6. **VALIDATE** — Run the self-check checklist (see below). Fix any violations
   before outputting. If a violation cannot be fixed, shrink the offending room to
   its minimum size, never below.

---

## ABSOLUTE RULES — Non-Negotiable Geometric Constraints

**RULE 1 — Unit is millimeters.**
All coordinates, widths, heights, offsets, and dimensions MUST be integers in
millimeters (mm). 1 foot = 304.8 mm. 1 meter = 1000 mm.

**RULE 2 — Wall gap between adjacent rooms.**
Adjacent rooms MUST have exactly `wall_thickness` gap (default 150mm) between them:
- Horizontal neighbor: `room_B.x = room_A.x + room_A.width + 150`
- Vertical neighbor: `room_B.y = room_A.y + room_A.height + 150`

**RULE 3 — Overlap detection formula.**
For any two rooms A and B on the same floor, they overlap if ALL four conditions
are true simultaneously:
```
A.x < B.x + B.width   AND
B.x < A.x + A.width   AND
A.y < B.y + B.height   AND
B.y < A.y + A.height
```
If this is true for ANY pair, the layout is INVALID. Fix it before outputting.

**RULE 4 — Boundary containment.**
Every room MUST fit within the canvas:
```
room.x + room.width  <= total_width
room.y + room.height <= total_depth
room.x >= 0
room.y >= 0
```

**RULE 5 — Multi-floor offset.**
For floor number N: `offset_y = N * (total_depth + 2000)`
Ground floor (N=0) has offset_y = 0.

**RULE 6 — Door/window validity.**
- `door.offset + door.width < wall_length` where wall_length is `room.width` for
  north/south walls and `room.height` for east/west walls.
- Leave at least 200mm from corners for doors, 300mm for windows.
- `door.room` and `window.room` MUST exactly match a room name on that floor.

---

## ANTI-PATTERNS — Things You Must Never Do

- **NEVER output meters.** If any dimension value is below 100, you are using meters.
  Multiply by 1000. A room width of 4.5 means you output 4500.
- **NEVER share walls between rooms.** Zero gap is forbidden. Two rooms touching
  at x=4500 means the next room starts at x=4650 (4500 + 150), not 4500.
- **NEVER truncate output.** If the JSON is long, output ALL of it. A truncated
  JSON is worse than no JSON.
- **NEVER invent schema keys** not defined in the output format. Do not add keys
  like `area`, `perimeter`, `color`, `type` to room objects unless the schema says so.
- **NEVER place rooms at negative coordinates.** Every x and y MUST be >= 0.
- **NEVER exceed canvas bounds.** If a room doesn't fit, shrink it or move to a new
  row/floor. Do not extend beyond `total_width` or `total_depth`.
- **NEVER place a door on a wall that doesn't exist** for that room's geometry.
- **NEVER create isolated rooms.** Every room must be reachable from the entrance
  through doors and corridors.
- **NEVER place clean utility adjacent to dirty utility** in hospital layouts.
- **NEVER give scrub stations a door** — they are open wet zones.
- **NEVER model CSSD as a single room** — it requires dirty corridor + clean corridor
  as separate spaces.
- **NEVER generate a bathroom as a top-level (parent) room** unless it is a public
  multi-user restroom with corridor access.
- **NEVER place a closet as a standalone parent room.** Closets MUST be children
  inside a bedroom or suite.
- **NEVER create a child room larger than its parent.**
- **NEVER give a child room direct corridor access.** Children open to their parent.

---

## ROOM HIERARCHY — Parent / Child / Connector

Architecture is HIERARCHICAL, not flat. Every building has parent containers
(rooms packed into the building grid) and child elements (spaces nested inside
parents). CRITICAL: child elements do NOT participate in building-level packing.

### Classification Rules

**PARENT rooms** — atomic units that touch building corridors:
- Get positioned by the packing algorithm (row-by-row)
- MUST have direct access to building circulation
- Examples: Living Room, Bedroom, Patient Room, Office Suite, Classroom,
  Kitchen, Dining Room, OR Suite, Guest Room, Warehouse Shell

**CHILD spaces** — nested inside parents, never touch corridors directly:
- Inherit access/egress through their parent
- Positioned inside parent using `placement.anchor_wall`
- Examples: Bathroom (inside bedroom), Walk-in Closet, Storage Nook,
  Prep Room (inside kitchen), Ensuite, Vestibule, Pantry

**CONNECTOR rooms** — link two parent rooms:
- Placed in the shared wall between exactly 2 parents
- Examples: Jack-and-Jill Bath (between two bedrooms), Airlock (clean→dirty),
  Walk-through Closet (bedroom→bathroom)

### Room Output Format

Every room MUST include `type` field. Children MUST include `parent_id`:

```json
{"name": "Bedroom 1", "type": "parent", "x": 0, "y": 0, "width": 4500, "height": 5200}
{"name": "Ensuite Bath", "type": "child", "parent_id": "Bedroom 1", "x": 0, "y": 0, "width": 1800, "height": 2400, "placement": {"anchor_wall": "south", "position": "rear_left"}}
```

### Sizing Rule for Parents with Children

When a parent contains children, its `width` and `height` MUST include enough
space for ALL children + 50% circulation buffer:
- Parent area ≥ sum(child areas) × 1.5
- Parent width ≥ widest child + 900mm (for circulation path beside child)
- Calculate parent size BEFORE placement. Never shrink a parent below the sum
  of its children.

### Hierarchy Steps (Execute After Step 3 above)

3a. **Identify parent containers** — rooms that touch corridors.
3b. **Identify children** — which rooms live INSIDE which parents.
3c. **Size parents** — calculate parent dimensions to include all children
    plus 50% circulation buffer.
3d. **Pack parents only** — use the placement algorithm with ONLY parent rooms.
3e. **Place children** — position children inside parents using anchor_wall:
    - `south/rear_left`: child.x = parent.x, child.y = parent.y
    - `south/rear_right`: child.x = parent.x + parent.width - child.width,
      child.y = parent.y
    - `north/front_left`: child.x = parent.x,
      child.y = parent.y + parent.height - child.height
    - `east/entry_wall`: child.x = parent.x + parent.width - child.width,
      child.y = parent.y + (parent.height - child.height) / 2
    - `west/window_wall`: child.x = parent.x,
      child.y = parent.y + (parent.height - child.height) / 2
3f. **Validate containment** — every child must fit completely inside its parent.

### Domain Hierarchy Patterns

| Domain      | Parent Example        | Children                                      |
|-------------|-----------------------|-----------------------------------------------|
| Residential | Bedroom               | Bathroom, Walk-in Closet, Window Nook         |
| Hospital    | Patient Room          | Toilet, Shower, Family Zone, Storage Alcove   |
| Hospital    | OR Suite              | Scrub Area, Equipment Storage                 |
| Hotel       | Guest Room            | Bathroom, Closet, Entry Nook                  |
| Office      | Office Suite          | Reception, Conference, Break Room, Storage    |
| Education   | Classroom             | Teacher Prep, Storage Closet, Reading Nook    |
| Restaurant  | Restaurant Shell      | Kitchen, Restrooms, Storage, Office           |
| Warehouse   | Warehouse Shell       | Office Suite, Restrooms, Utility Rooms        |

---

## PLACEMENT ALGORITHM

Execute this algorithm exactly. Do not improvise coordinate placement.

**Step 1:** Divide the plot into rows. Each row spans the full `total_width`.

**Step 2:** Row 0 starts at y=0. Place rooms left-to-right:
- First room: `x = 0`
- Next room: `x = previous.x + previous.width + 150`

**Step 3:** When the next room would exceed `total_width` (i.e.,
`current_x + room.width > total_width`), start a new row:
- `new_row_y = previous_row_y + max_height_in_previous_row + 150`

**Step 4:** Verify total coverage: `last_room.y + last_room.height <= total_depth`.

**Step 5:** Check every pair of rooms for overlap using RULE 3 before outputting.

### Worked Example — 9000mm Wide Plot, 5 Rooms

| Room        | Width | Height | Row | x     | y     | Calculation                           |
|-------------|-------|--------|-----|-------|-------|---------------------------------------|
| Living Room | 4500  | 4500   | 0   | 0     | 0     | First room in row 0                   |
| Kitchen     | 4350  | 3000   | 0   | 4650  | 0     | 0 + 4500 + 150 = 4650                |
| Bedroom 1   | 4500  | 3600   | 1   | 0     | 4650  | New row: 0 + 4500 + 150 = 4650       |
| Dining      | 4350  | 3600   | 1   | 4650  | 4650  | 0 + 4500 + 150 = 4650                |
| Bathroom    | 2000  | 2000   | 2   | 0     | 8400  | New row: 4650 + 3600 + 150 = 8400    |

Verify: 8400 + 2000 = 10400 ≤ 12000 (total_depth) ✓

Read `references/placement_algorithm.md` for a full multi-row walkthrough.

---

## SELF-CHECK CHECKLIST

Before outputting JSON, answer every question YES. If any answer is NO, fix it.

1. Are ALL coordinates non-negative integers in millimeters?
2. Does every room fit within total_width × total_depth?
3. Is there a 150mm wall gap between every pair of adjacent PARENT rooms?
4. Do zero PARENT rooms overlap (checked ALL pairs with the overlap formula)?
5. Does every door reference a valid room name on its floor?
6. Is `door.offset + door.width < wall_length` for every door?
7. Does every window reference a valid room name on its floor?
8. Is `window.offset + window.width < wall_length` for every window?
9. Does every habitable room have at least one door?
10. Does every habitable room have at least one window on an exterior wall?
11. Is the kitchen adjacent to the dining room?
12. Is `offset_y = floor_number * (total_depth + 2000)` for every floor?
13. Does every room have a `type` field (`parent`, `child`, or `connector`)?
14. Does every `child` room have a valid `parent_id` matching a parent on the same floor?
15. Is every child's bounding box fully inside its parent's bounding box?
16. Is parent area ≥ sum(child areas) × 1.5?
17. Are bathrooms and closets `type: "child"` (not parent), unless they are public restrooms?

---

## OUTPUT FORMAT

Read `references/output_schema.md` for the exact JSON structure with field-by-field
annotations and a complete worked example. Every room, door, and window MUST follow
that schema exactly.

---

## LOADING DOMAIN SKILLS

After loading this core skill, ALWAYS load the matching domain skill:
- Residential house/apartment → load `residential/SKILL.md`
- Hospital/clinic → load `hospital/SKILL.md`
- Office/corporate → load `office/SKILL.md`
- Warehouse/industrial → load `warehouse/SKILL.md`
- Restaurant/cafe → load `restaurant/SKILL.md`
- School/college → load `school/SKILL.md`
- Retail/shop → load `retail/SKILL.md`
- Gym/fitness → load `gym/SKILL.md`
- Parking lot/garage → load `parking/SKILL.md`
- Anything else → load `custom/SKILL.md`

The domain skill contains room standards, adjacency rules, and a worked example
specific to that building type.

