Overview
Arshu Assembler is a polyglot declarative framework implementing a component-oriented architecture
for composing markup and data. The framework follows consistent design patterns across all language
implementations while respecting idiomatic conventions of each language.
Key Design Principle: Structural consistency across all language implementations
is crucial. The same logic and structure is maintained across C#, Rust, Go, Node.js, PHP, and JavaScript,
using idiomatic patterns in respective languages.
Two Engine Architecture
The assembler implements two distinct engines for template processing:
Normal Engine
- Combines parsing and merging in a single pass
- Processes templates on-the-fly
- Simpler implementation with less memory overhead
- Ideal for straightforward template scenarios
PreProcess Engine
- Separates parsing from merging into distinct phases
- Parses templates and JSON into intermediate data structures
- Performs all JSON merging in the engine phase
- Provides better debugging and template analysis capabilities
- Outputs structure dumps for validation (Analysis folder)
Role Separation
| Component |
Normal Engine |
PreProcess Engine |
| Loader |
Loads templates |
Parse templates and structure, Parse JSON (no merging) |
| Engine |
Parse and merge together |
Use parsed data to merge templates, All JSON merging happens here |
Core Components
Assembler Library
The core library that implements:
- Normal Engine and PreProcess Engine implementations
- Template parsing and merging logic
- Five composition rules (Direct, Slotted, Contextual, JSON Key, JSON Array)
- File system abstraction for loading templates
AssemblerTest
Comprehensive test suite that:
- Validates all composition rules
- Compares outputs between Normal and PreProcess engines
- Provides performance benchmarking
- Generates template structure analysis dumps
- Supports command-line options for targeted testing
AssemblerWeb
Web server implementation that:
- Exposes assembler functionality via HTTP endpoints
- Provides interactive demo UI
- Supports both server-side and client-side assembly (JavaScript)
- Includes idle tracking for resource optimization
- Serves static assets and AppSites
AssemblerWebJs (C# only)
Specialized server for client-side JavaScript assembly:
- Hosts the JavaScript assembler implementation
- Demonstrates client-side assembly capabilities
- Provides comparison with server-side implementations
Template Processing Flow
Normal Engine Flow
1. Load Template Files
2. Parse & Merge Simultaneously
- Identify placeholders
- Replace with component content or JSON data
- Process nested components recursively
3. Output Final HTML
PreProcess Engine Flow
1. Load & Parse Templates
- Build template structure tree
- Identify all placeholders and slots
- Parse JSON data into objects
- Output structure dump (for debugging)
2. Merge Phase
- Walk the structure tree
- Resolve all placeholders
- Apply JSON data bindings
- Handle array iterations and conditionals
3. Output Final HTML
File Organization
AppSite Structure
Each AppSite (test case) follows a consistent structure:
AppSites/
└── <AppSiteName>/
├── index.html # Main entry template
├── Index.json # Data file (if needed)
├── Component/ # Reusable components
│ ├── Header.html
│ └── Footer.html
├── Common/ # Shared layouts
│ └── Layout.html
└── Views/ # Context-specific views
├── ViewA/
└── ViewB/
Output Structure
Analysis/
└── output/
├── <AppSite>_normal.html # Normal engine output
├── <AppSite>_preprocess.html # PreProcess engine output
└── structure/ # Debug dumps (PreProcess only)
└── <AppSite>_structure.json
Design Patterns
Consistent Naming Conventions
- Placeholder:
{{'{{'}}ComponentName{{'}}'}}
- JSON Data:
{{'{{'}}$JsonKey{{'}}'}}
- Slot Definition:
{{'{{'}}$SlotName{{'}}'}}
- Slot Usage:
{{'{{'}}@SlotName}}...{{'{{'}}/@SlotName{{'}}'}}
- Layout Block:
{{'{{'}}#LayoutName}}...{{'{{'}} /LayoutName{{'}}'}}
- Array Iteration:
{{'{{'}}@ArrayKey}}...{{'{{'}} /ArrayKey{{'}}'}}
- Empty State:
{{'{{'}}^ArrayKey}}...{{'{{'}} /ArrayKey{{'}}'}}
No Regular Expressions
The framework explicitly avoids using regular expressions for parsing, instead using:
- String scanning and tokenization
- Character-by-character parsing
- Stack-based block tracking
- Explicit state machines
Rationale: Avoiding regex ensures predictable behavior, better error messages,
and easier debugging across different language implementations.
Language Implementations
Implementation Philosophy
All language implementations follow the same core logic and structure, adapted to each language's
idiomatic patterns:
- C#: Object-oriented with LINQ for data processing
- Rust: Memory-safe with ownership patterns and Result types
- Go: Concurrent patterns with goroutines for performance
- Node.js: Asynchronous I/O with Promises
- PHP: Procedural and object-oriented hybrid
- JavaScript: Client-side browser execution
Validation Strategy: Each implementation is validated by comparing outputs
across all languages to ensure identical results for the same inputs.
Performance Considerations
Idle Tracking
All web servers implement idle tracking for deployment optimization:
- Auto-shutdown after 10 seconds of inactivity (configurable)
- Reduces resource consumption in cloud environments
- Usage-based infrastructure model
- Can be disabled with
--skipIdleTracking flag
Performance Testing
The test suite includes performance benchmarking:
- Measures template processing time
- Compares Normal vs PreProcess engine performance
- Identifies bottlenecks across implementations
- Provides timing bars in the demo UI
Future Architecture
Planned Features
- Data Flow: Hierarchical and cross-cutting data merging strategies
- Partial Rendering: Optimized UI Leaf updates (similar to virtual DOM)
- Markup Binding: HTMX-like event binding for full-stack interactivity
- API Connection: Uniform API for Ajax, WebSocket, WebRTC, WebTransport
- Expression Parsing: Dynamic content generation with expressions
- Metadata Generation: Automatic metadata extraction and generation