This document compares the existing implementation with the requirements from the feature specification documents.
- Current: Single generic
HTMLElementclass that takes tag name as parameter - Implementation: Helper methods in
HTMLHelpersmodule that create instances of the generic class - Coverage: ~30 HTML elements have helper methods
- Base Classes:
Component(abstract base)StatelessComponent(with caching support)StatefulComponent(with JavaScript support)
- Features:
- Basic attribute management
- Component ID generation
- CSS class tracking
- Caching integration (basic)
- JavaScript integration hooks
- Implemented:
CacheStoreabstract classTestCacheStoreimplementationCacheablemoduleComponentCacheManager- Basic cache key generation
- Missing:
- Redis implementation
- Russian doll caching
- Cache warming
- Files Present:
component_manager.js- Basic component lifecycle managementcomponent_registry.js- Component registrationcomponent_system.js- System initialization and auto-discoverystateful_component_js.js- Base class for JavaScript components- Some example components (counter, dropdown, toggle)
- Analysis: This is a traditional component system, NOT the reactive WebSocket-based system specified
- Missing:
- WebSocket connection management
- DOM morphing algorithm
- Server state synchronization
- Reactive updates
- Stimulus renderer exists
- CSS registry for tracking used classes
- Basic asset pipeline integration
Specification Requirement: Every HTML5 element must have its own dedicated Crystal class
Current State: Generic HTMLElement class with tag name parameter
Gap: Missing 100+ individual element classes
This is the fundamental architectural difference. The specification requires:
# Required approach - individual classes
class Div < HTMLElement
class Input < VoidElement
class Form < HTMLElement
# Current approach - generic class
HTMLElement.container("div", content)Impact: This is a complete architectural mismatch. The entire component system depends on having proper element classes.
Required:
HTMLElementbase classVoidElementfor self-closing elementsContainerElementfor elements with children- Individual classes inheriting from appropriate base
Current: Single generic class handling all elements
Required: Each element class validates its specific attributes per HTML5 spec Current: No attribute validation
Required: Elements support builder pattern for nested structures Current: Basic nesting through helper methods
Required: Components built by composing element class instances Current: Components use string-based tag generation methods
Required: Full reactive system with WebSocket support Current: Basic stateful components with JavaScript hooks, no reactive system
Required: Production-ready Redis implementation Current: Only test implementation
Required: Parent components track child dependencies Current: Basic cache key generation only
Required: Pre-render expensive components Current: Not implemented
Required:
- WebSocket connection management
- DOM morphing algorithm
- Component registration
- Event dispatching
Current: Basic component JavaScript, no reactive client
Required:
- ReactiveSocket WebSocket handler
- ReactiveSession management
- State synchronization
- Server-initiated updates
Current: Not implemented
-
Keep existing HTMLHelpers temporarily for backwards compatibility
-
Create new element class hierarchy:
- Base classes:
HTMLElement,VoidElement,ContainerElement - All 100+ individual element classes
- Proper attribute validation
- Base classes:
-
Migration Path:
# Old way (keep working) HTMLHelpers.div(content, class: "card") # New way (implement) Div.new(class: "card") << content
- Modify
Componentbase class to work with element classes - Update
StatelessComponentandStatefulComponent - Create migration helpers
- Implement
RedisCacheStore - Add Russian doll caching to
Cacheable - Implement cache warming
- Create
amber-reactive.jsfrom scratch - Implement WebSocket handlers
- Create
ReactiveStatefulComponentbase class
- DO NOT try to retrofit the existing
HTMLElementclass - CREATE entirely new element class hierarchy alongside existing code
- MAINTAIN backwards compatibility during transition
- FOCUS on getting all element classes implemented first
- Namespace: Put new elements in
Components::Elementsnamespace - Backwards Compatibility: Keep
HTMLHelpersworking with deprecation warnings - Progressive Migration: Allow mixing old and new approaches initially
- Element Tests: Every element class needs comprehensive tests
- Migration Tests: Ensure old code continues working
- Integration Tests: Test new components with new elements
src/asset_pipeline/components/
elements/ # NEW - All individual element classes
base/ # NEW - Base element classes
html_element.cr
void_element.cr
container_element.cr
document/ # NEW - Html, Head, Body, etc.
sections/ # NEW - Header, Footer, Nav, etc.
grouping/ # NEW - Div, P, Span, etc.
# ... other categories
html/ # KEEP - For backwards compatibility
html_element.cr # Rename to generic_html_element.cr
html_helpers.cr # Add deprecation warnings
reactive/ # NEW - Reactive system
reactive_socket.cr
reactive_session.cr
reactive_component.cr
- Begin implementing base element classes (
HTMLElement,VoidElement,ContainerElement) - Start creating individual element classes by category
- Set up proper testing framework for elements
- Plan backwards compatibility strategy
Critical: No other work should proceed until the element class system is complete. This is the foundation everything else depends on.