Complete system architecture and design documentation for Wire-DSL.
┌─────────────────────────────────────────────────────────────────┐
│ WireDSL Ecosystem │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ User Interfaces (Input) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────┐ │
│ │ Web Editor │ │ CLI Tool │ │ Future: VS │ │
│ │ (React + Monaco)│ │ (Commander.js) │ │ Code Ext │ │
│ │ - Live preview │ │ - render │ │ │ │
│ │ - AI generation │ │ - validate │ │ │ │
│ │ - Code editor │ │ - init │ │ │ │
│ └────────┬─────────┘ └────────┬─────────┘ └──────────────┘ │
│ │ │ │
└───────────┼─────────────────────┼───────────────────────────────┘
│ │
└─────────────┬───────┘
│
Input: .wire files
│
┌─────────────▼──────────────────────────────────┐
│ @wire-dsl/engine │
├────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ 1. PARSER (Chevrotain) │ │
│ │ Input: .wire (text) │ │
│ │ Output: AST (tokens) + SourceMap │ │
│ │ - SourceMap tracks code positions │ │
│ │ - Semantic stable IDs │ │
│ └──────────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────────▼───────────────────────────┐ │
│ │ 2. IR GENERATOR │ │
│ │ Input: AST │ │
│ │ Output: IR Contract (JSON) │ │
│ │ - Validates schema with Zod │ │
│ └──────────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────────▼───────────────────────────┐ │
│ │ 3. LAYOUT ENGINE │ │
│ │ Input: IR │ │
│ │ Output: Positioned components │ │
│ │ - CSS Grid resolver │ │
│ │ - Calculates x, y, width, height │ │
│ └──────────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────────▼───────────────────────────┐ │
│ │ 4. SVG RENDERER │ │
│ │ Input: Layout + IR │ │
│ │ Output: SVG (DOM-independent) │ │
│ │ - Accessible, optimized │ │
│ │ - Exportable, scalable │ │
│ │ - data-node-id attributes (SourceMap) │ │
│ └──────────────┬───────────────────────────┘ │
│ │ │
└─────────────────┼──────────────────────────────┘
│
Output: SVG / IR / AST
│
┌─────────────────┴───────────────────────────────┐
│ │
┌───────▼──────────┐ ┌───────────▼───┐
│ Preview/Export │ │ Further Uses │
│ - SVG file │ │ - Figma │
│ - PNG file │ │ - Code gen │
│ - PDF file │ │ - Prototyping │
└──────────────────┘ └───────────────┘
Wire-DSL provides a human-readable, structured format inspired by Mermaid.
Requirements:
- Easy to read and write
- Easy to parse
- Easy to generate by AI
Strategy: Hybrid DSL (blocks + key: value properties)
Example:
project "Dashboard" {
style {
density: "normal"
spacing: "md"
}
screen Dashboard {
layout stack(direction: vertical, gap: md) {
component Heading text: "Welcome"
component Button text: "Start"
}
}
}
- Parser transforms DSL into an AST (what the user wrote)
- Preserves locations (line/column) for error reporting and tooling
- AST is direct representation of source code
- Parses both
define Componentanddefine Layoutdeclarations - Emits semantic diagnostics for naming,
Childrenslot rules, and definition usage arity
Implementation: Chevrotain (TypeScript grammar-based parser)
AST is converted to stable IR, applying:
- Defaults from style tokens
- Normalization (spacing, sizing)
- Semantic validations
- Schema validation with Zod
- Expansion of custom definitions:
define Componentexpansion → produces anIRInstanceNodewrapper that preserves the call-site identitydefine Layoutexpansion → similarly wrapped by anIRInstanceNodeprop_*dynamic binding substitution (resolved inside the expansion)- Internal nodeIds are scoped per instance:
layout-stack-0@component-mycomp-0
- Warning/error policy for missing/unused dynamic arguments
IR node kinds: container | component | instance.
IR is the technical source of truth for rendering.
Example IR structure:
{
"irVersion": "1.0",
"project": {
"id": "proj_dashboard",
"name": "Dashboard",
"style": { ... },
"screens": [ ... ],
"nodes": { ... }
}
}Responsible for calculating final positions and sizes from declarative constraints.
Supported Layouts (core):
- Stack (vertical/horizontal) - Linear layouts
- Grid (12-column) - Multi-column grid
- Split (sidebar + main) - Two-pane layouts
- Panel (bordered box) - Grouped content
- Card (flexible box) - Self-contained items
Layout engine operates on IR and produces Render Tree with concrete bounding boxes.
Instance nodes (kind instance) are transparent wrappers: the layout engine calculates positions for the expanded content and copies the bounding box to the instance node itself. Built-in container types at computation time are still only stack, grid, split, panel, card.
Algorithm:
- Traverse IR nodes top-down
- Calculate available space from parent
- Resolve child dimensions (fixed, fill, content)
- Apply gaps and padding
- Generate (x, y, width, height) for each node
Main implementation: SVG Renderer (DOM-independent)
Rendering modes:
- Wireframe (gray, low-fidelity) - Default wireframing
- Interactive (click → navigation) - Future: interactive prototyping
Output formats:
- SVG (scalable, optimized)
- PNG (raster export)
- PDF (print-friendly)
Declarative interactions:
- Navigation between screens
- Event handling (onClick, onRowClick)
- State management for interactive previews
(Currently: Events removed from DSL per v1.0 scope. Future: Re-add for interactive prototypes)
Export IR/rendered output to various formats:
- JSON (IR export)
- SVG (diagrams)
- PNG/PDF (static exports)
- Future: HTML, React code, Figma
Purpose: Enable bidirectional code↔canvas selection
Components:
- SourceMapBuilder - Tracks nodes during parsing
- PropertySourceMap - Property-level precision (nameRange, valueRange)
- SourceMapResolver - Query API for bidirectional selection
- SVG Integration -
data-node-idattributes in rendered output
Features:
- Click in code editor → Highlight element in canvas
- Click on canvas element → Jump to code definition
- Property-level selection and editing
- Stable, semantic node IDs (
component-button-0,layout-stack-1) - O(1) lookup by ID, O(n) lookup by position
Use Cases:
- Interactive web editor (Wire Studio)
- VS Code extension
- Developer tools and debugging
- Code navigation and refactoring
See SourceMap Guide for complete documentation.
Responsibility: Domain types and business logic
Components:
- Parser (Chevrotain) - Tokenization and parsing
- SourceMap Builder - Code↔canvas mapping during parsing
- IR Generator - AST → IR transformation with Zod validation
- Layout Engine - Position and size calculation
- SVG Renderer - Render tree to SVG with
data-node-idattributes - SourceMap Resolver - Query API for bidirectional selection
- IR types - TypeScript interfaces for IR schema
- Validations - Semantic and structural validation
Key APIs:
// Standard parsing
const { ast } = parseWireDSL(code);
// Parsing with SourceMap
const { ast, sourceMap } = parseWireDSLWithSourceMap(code);
const resolver = new SourceMapResolver(sourceMap);
// Bidirectional selection
const node = resolver.getNodeByPosition(line, col); // Code → Canvas
const node = resolver.getNodeById('component-button-0'); // Canvas → CodeResponsibility: CLI interface and file operations
Commands:
wire validate <file.wire> # Validate syntax and semantics
wire render <file.wire> --svg # Render to SVG
wire render <file.wire> --pdf # Render to PDF
wire init <project-name> # Initialize new projectDependencies: Commander.js, Chalk, Ora, Sharp
Responsibility: Interactive web-based editor
Features:
- Live code editor (Monaco)
- Real-time preview
- AI-assisted generation
- Project management
- Export functionality
Technologies:
- React 18 + Vite
- Monaco Editor
- Zustand (state management)
- Tailwind CSS + Radix UI
.wire file (text)
│
▼
PARSER (Chevrotain)
│
▼
AST (Tokens)
│
▼
IR GENERATOR
│
▼
IR Contract (JSON)
│
▼
LAYOUT ENGINE
│
▼
Layout Positions (x, y, width, height)
│
├────────────────┐
│ │
▼ ▼
SVG Renderer Code Generator
│ │
▼ ▼
SVG File React/Vue Code
@wire-dsl/web (React App)
├─ @wire-dsl/engine
├─ monaco-editor
├─ react 18
├─ zustand
└─ tailwindcss
@wire-dsl/cli (CLI Tool)
├─ @wire-dsl/engine
├─ @wire-dsl/exporters
├─ commander
├─ chalk
├─ ora
└─ sharp
@wire-dsl/engine (Engine)
├─ chevrotain (parser)
└─ zod (validation)
GitHub (main branch)
│
├──────────────────┬──────────────┬──────────────┐
│ │ │ │
▼ ▼ ▼ ▼
Build & Test Publish NPM Deploy Web
(GitHub Actions) (@wire-dsl/*) (Cloudflare Pages)
│ │ │
└──────────────────┼──────────────┘
│ │
┌──────▼────┐ ┌──────▼──────┐
│ NPM Reg │ │ Cloudflare │
│ │ │ Pages/CDN │
│@wire-dsl/ │ │ │
│ core │ │wire-dsl.org │
│@wire-dsl/ │ │(web editor) │
│ cli │ │ │
│@wire-dsl/ │ │ │
│ web │ │ │
└───────────┘ └─────────────┘
- Parser: Chevrotain 11.x (TypeScript grammar-based)
- Validation: Zod 3.x (schema validation)
- Build: tsup (TypeScript bundler)
- Framework: React 18 + Vite
- Code Editor: Monaco Editor
- State Management: Zustand
- Styling: Tailwind CSS + PostCSS
- Components: Radix UI
- CLI Framework: Commander.js
- Output Formats: SVG, PNG, PDF (via Sharp)
- Colors: Chalk
- Progress: Ora spinner
- Build Orchestration: Turborepo
- Package Manager: pnpm
- Testing: Vitest + Chai
- Linting: ESLint
- Formatting: Prettier
- Release: Changesets
- CI/CD: GitHub Actions
- Hosting: Cloudflare Pages
The IR is immutable once generated, ensuring predictability and enabling caching.
Errors detected during parsing/normalization phases, not during rendering.
Examples:
- invalid
define Layoutnames - invalid
Childrenslot usage/count - missing required
prop_*bindings - circular references across component/layout definitions
Each layer has single responsibility:
- Parser: Syntax
- IR Generator: Validation + Normalization
- Layout Engine: Position calculation
- Renderer: Visual output
Each layer independently testable with isolated unit tests.
New components and layouts added via:
- Component registry system
- Plugin architecture (future)
- Custom validators
Structure designed for LLM comprehension and generation:
- Regular, predictable syntax
- Comprehensive prompt guides
- Clear component catalogs
- Deterministic output
- Define component type in
ir/index.ts - Add Zod schema for validation
- Implement renderer in
renderer/index.ts - Add tests in
renderer/index.test.ts - Document in component catalog
- Define layout structure in IR
- Implement layout algorithm in
layout/index.ts - Add dimension calculation logic
- Implement renderer support
- Add comprehensive tests
Use IR versioning:
- Bump
irVersionfield - Provide migration function
- Maintain backward compatibility where possible
- Document migration path
- Target: <100ms for typical files
- Chevrotain grammar optimized
- Error recovery enabled
- O(n) tree traversal algorithm
- Memoization for repeated calculations
- Batch calculations where possible
- SVG output is DOM-independent
- Optimized for small file sizes
- CSS classes reused across components
- Target: <50MB for large projects
- Immutable IR reduces copies
- Streaming exports for large files
- HTML semantic export
- React component generation
- Figma integration
- Code generation
- Conditional rendering
- Data binding
- Custom validations
- Plugin system
Last Updated: January 23, 2026
Status: ✅ Complete Architecture Definition