I designed @kruschdev/pascal-plugin-electrical as a clean, multi-entrypoint Pascal Editor Plugin API v1 package (E-014, E-016, E-017) where the deterministic NEC engineering engine, the 3D CAD geometry builders, the Zod agent contracts, and the React editor UI are strictly isolated by bundler-verified boundary gates.
flowchart LR
Scene["Pascal Scene Graph (walls, doors, stairs, zones, pipes, ducts, fixtures)"]
NEC["./nec Pure TS Engine (Art. 220, 310.16, 314.16, Bones Interop, Routing, Auto-Populate, Audit, BOM)"]
CAD["./cad Three.js Builders (50 MIT Models + Cover-Off / Panel-Cover-On Interior)"]
Render["./render Viewer Manifest (4 electrical:* Nodes, 3D + 2D Floorplan)"]
Tools["./agent-tools & ./agent-operations (8 Pure E-016 Contracts)"]
UI["Editor UI (Rail Panel, Inspector Card, Schedule View, 3D Panel Interior)"]
Scene --> NEC
NEC --> Tools
NEC --> UI
CAD --> Render
Render --> UI
Tools --> Scene
Every subpath export in package.json is enforced on every commit by bun run check:render (scripts/check-render-entry.ts):
| Subpath | Module | Runtime Dependencies Allowed | Purpose |
|---|---|---|---|
. |
src/index.ts |
@pascal-app/core, @pascal-app/editor, React, Three.js, Zustand |
Full editor integration (electricalPlugin, electricalHostPanel, electricalScheduleView, electricalChatExtension) |
./render |
src/render.ts |
@pascal-app/core, Three.js, Zod |
Read-only viewer manifest (electricalRenderPlugin) with zero @pascal-app/editor or next imports |
./cad |
src/cad/index.ts |
Three.js + ./nec types |
Standalone 50-model MIT electrical CAD & cover-off / Panel-Cover-On interior builders with zero React or editor imports |
./nec |
src/nec/index.ts |
Pure TypeScript only | Zero React, zero Three.js, zero @pascal-app/*; runs identically in Node, Bun, Cloudflare Workers, or browsers |
./agent-tools |
src/agent-tools.ts |
@pascal-app/core/agent-tools, Zod |
Pure Zod schemas and skill metadata (E-016) for MCP servers and LLM tool registries |
./agent-operations |
src/agent-operations.ts |
@pascal-app/core, ./nec, ./render |
Pure deterministic scene operations returning { result, changes } diffs without touching DOM or React |
electrical:panel(src/nodes/panel.ts): Residential split-phase (120/240V-1P) and commercial three-phase (120/208V-3P,277/480V-3P) panelboards with NEMA ratings (NEMA-1,NEMA-3R,NEMA-4X), bus/main ratings, solar backfeed amps, optionalcoverRemovedmain-viewport cutaway (showing exposed copper busbars and the main breaker in the main 3D scene, while full wired branch circuits and terminal lugs render inPanelInteriorView), a 3D translucent NEC 110.26 working-space prism, and 2D IEEE floorplan symbols.electrical:device(src/nodes/device.ts): 25 live equipment and device kinds (duplex,gfci,afci,usb-duplex,weatherproof-gfci,floor-box,dedicated-240v,evse,switch-1p,switch-3way,dimmer,luminaire,ceiling-fan,under-cabinet-led,smoke-co,exit-sign,motor-load,vfd,spd,solar-inverter,battery-ess,transfer-switch,generator-inlet,rapid-shutdown, andjunction-box) supporting fullWIRE_GAUGE_ORDER(#14to750kcmil), live NEC 314.16 Box Fill tracking, and integral-enclosure gang-box exemption (usesSeparateRoughInBox).electrical:conduit-run(src/nodes/conduit-run.ts): 3D polyline raceways and cables (nm-b,mc,emt,pvc-40,rmc) built bybuildConduitRunCadas continuous filletedTubeGeometrywith box connectors, couplings, and support straps, 10-color per-circuit coding (CIRCUIT_COLOR_PALETTEsynced across 3D runs, 2D floorplans, and the Electrical rail Circuit Legend, withcircuitNumberincluded ingeometryKey), live ampacity derating, Chapter 9 fill, 360-degree bend limits, and voltage drop.electrical:transformer(src/nodes/transformer.ts): Commercial dry-type step-down transformers (480V -> 208Y/120V 3P) with NEC Table 450.3(B) FLA/OCPD sizing, rotated 3D primary/secondary ports, and local-yaw working-space clearance envelopes.
Electrical runs never relocate structural or gravity-bound trades. extractTradeObstacles reads every Pascal beam, column, stair, structural:beam, structural:column, pipe-segment, pipe-fitting, pipe-trap, liquid-line, plumbing:pipe-run, plumbing:equipment, duct-segment, duct-fitting, duct-terminal, hvac-equipment, lineset, hvac:duct-run, and hvac:equipment node into 3D bounding volumes with configurable clearance margins, and also respects door and window wall openings when routing along framed walls.
routeElectricalRun evaluates three code-compliant 3D routing families using extractRoutingCavities (inspecting Pascal roof, ceiling, raised slab, and lower crawlspace/basement levels):
- Wall-Cavity Manhattan: Orthogonal stud chases and Dijkstra wall-top-plate runs around wall corners (always used on slab-on-grade flat-roof builds and for all rigid
EMT/RMC/PVC-40conduit perNEC 110.12 / 358.30). - Hybrid Wall-to-Attic Euclidean (
NEC 334.23 / 320.23): Vertical stud-bay riser through bored top plates into a straight Euclidean attic crossing whenever shorter and clash-free forNM-B/MC(emittingNEC 334.23 / 320.23guard-strip drafting notes). - Hybrid Wall-to-Crawl-Space Euclidean (
NEC 334.15(C) / 334.12(B)(4)): Vertical stud-bay drop through sole plates into dry floor-joist cavities for low wall outlets (emittingNEC 334.15(C)bored-joist/running-board drafting notes, while automatically blockingNM-Bin wet/damp crawl spaces perNEC 334.12(B)(4)).
Every candidate detects segment intersections against higher-priority obstacles (including diagonal over/under detours in attics and crawl spaces), deduplicates coincident vertices, counts cumulative bend angles (countPathBendDegrees) against the NEC 358.26 360-degree pull-point limit, and feeds the exact routed 3D length straight into Voltage Drop (calculateVoltageDrop) and Material Takeoff (buildElectricalTakeoff).
I integrated with @kruschdev/pascal-plugin-structural, @pascal-app/plugin-bones, and companion plumbing/HVAC plugins strictly through Pascal's scene graph with zero hard npm dependencies:
- Framing & Stud-Bay Alignment (
structural:assembly,bones:framing,bones:service): When astructural:assemblynode exists on the active level it takes Priority #1 overbones:framing;resolveWallFramingContextreadsstudSpacingIn(12" OC,16" OC, or24" OC) and per-wallwallOverrides(bypassing CMU masonry walls cleanly), computes stud centerlines usingcomputeWallStudPositions, snaps nail-on outlets, GFCIs, and switches flush against the side face of the nearest stud (snapWallOffsetToStud, clamped to remaining NEC 210.52(A)/(C) spacing slack), and centersMDP-1cleanly inside a stud bay (snapPanelOffsetToStudBay) or aligns withbones:service(serviceType: 'panel'). When neither framing plugin is installed, the engine defaults gracefully to standard16" OCstud centers. - Cross-Trade MEP Equipment (
plumbing:*andhvac:*electricalDemand):planNecAutoPopulateandcalculateSceneLoadinspectplumbing:*andhvac:*equipment nodes carrying anelectricalDemandmetadata/property contract (water heaters, pumps, air handlers, condensers, heat pumps) so dedicated circuits, breaker poles, ampacity, and service loads stay synchronized automatically without hard-coupling plugin packages.
Rotated panels and floor-mounted transformers cannot be checked accurately with world-axis AABBs. getEquipmentSpacePrisms builds oriented prisms aligned to each panel or transformer's rotation yaw (cos, sin), and prismIntersectsAabb runs a full 2D Separating Axis Theorem (SAT) test in XZ plus Y overlap against every cabinet, fixture, column, HVAC unit, and overhead pipe/duct. Shared level ancestry helpers (resolveNodeLevelId and belongsToLevel in src/nec/routing.ts) strictly scope rooms, wet fixtures, stairways, dedicated circuits, and trade obstacles to each node's owning level so multi-story buildings never produce cross-floor false positives. CSV panel schedules and BOM exports also pass every cell through sanitizeCsvCell to neutralize spreadsheet formula injection triggers.
buildWiredPanelInteriorCad consumes a live PanelSchedule and generates:
- A hollow galvanized steel tub with rear mounting flanges and knockouts.
- Exposed copper 2-bus (split-phase) or 3-bus (three-phase) central stabs, main breaker or MLO lugs, and service entrance feeders.
- Isolated neutral and ground bus bars with an NEC 250.28 green bonding screw on main-breaker service panels.
- Populated 1P, 2P, and 3P molded-case breakers with colored handles, AFCI/GFCI test buttons, neutral pigtails, and brass wire lugs.
- Every individual Hot, Neutral, and Ground branch conductor routed down the side wiring gutters with 90-degree bends into its exact terminal, using NEC phase color coding (
Black/Redfor 120/240V,Black/Red/Bluefor 120/208V,Brown/Orange/Yellowfor 277/480V).
PanelInteriorView mounts a single persistent WebGLRenderer with ResizeObserver, preserves camera orbit across toggle changes, supports Cover Off / Panel Cover On / Cover Closed and Hots / Neutrals / Grounds / Feeders visibility filters, and raycasts clicks on any wire or breaker to highlight its circuit details.
All plugin-local UI state (occupancy, activeTab, selectedPanelId, residentialMethod, commercialBuildingType) lives inside useElectricalUi. Scene edits triggered from the rail panel (such as Auto-Populate NEC Layout & Wiring or Auto-Route Around Trades) wrap multi-node creations inside Pascal's runAsSingleSceneHistoryStep(useScene, ...) so one Ctrl+Z cleanly undoes the entire layout.