Overview
Lutaml::Model implements a three-layer architecture for data modeling and serialization:
╔═══════════════════════╗ ╔════════════════════╗ ╔═══════════════════════╗
║ Core Model Layer ║ ║ Transformation ║ ║ Serialization Layer ║
║ ║ ║ Layer ║ ║ ║
║ - Serializable ║──────▶║ - Mappings ║──────▶║ - Adapters ║
║ - Type::Value ║ ║ - MappingRules ║ ║ - Documents ║
║ - Attribute ║ ║ - Transforms ║ ║ - Format Libraries ║
║ - Collection ║ ║ - Validators ║ ║ ║
╚═══════════════════════╝ ╚════════════════════╝ ╚═══════════════════════╝Core principles
Model-driven design
-
Models are manipulated, not serializations: Work with model instances, serialize only when needed
-
Model-to-model interaction over functional interaction
-
Recursive attribute model: Models contain attributes, attributes have types (Model or Value), creating tree structures
MECE (Mutually exclusive, collectively exhaustive)
-
Each component has distinct, non-overlapping responsibilities
-
All concerns are addressed without gaps
-
No redundant or duplicate functionality
DRY (Don’t repeat yourself)
-
Single source of truth for all definitions
-
Never define or auto-detect data in multiple places
-
Register-based architecture for centralized definitions
Separation of concerns
lib/lutaml/model/
├── serializable.rb # Core model definition
├── attribute.rb # Attribute specifications
├── type/ # Value types (leaf nodes)
├── mapping/ # Serialization mappings
├── services/ # Business logic (validation, transformation)
├── {format}/ # Format-specific implementations
└── error/ # Error hierarchyKey design patterns
Registry pattern
-
Type.register(:symbol, Class)for reusable types -
GlobalRegisterfor model registration -
Registerfor custom registries
Adapter pattern
-
Pluggable serialization libraries without changing model code
-
SerializationAdapterbase class -
Format-specific adapters: Nokogiri, Ox, Oga for XML; JSON, MultiJson, Oj for JSON
Strategy pattern
-
Format-specific behavior via adapter selection
-
Config.configurefor global strategy selection
Builder pattern
-
Document construction via
doc.create_element,doc.add_element -
XML builders in
xml/builder/
Data flow
Component relationships
Metadata tracking
Every Serializable instance maintains optional metadata:
-
schema_location: XSD schema reference -
encoding: Character encoding for XML -
element_order: XML element ordering forordered: true -
__parent: Reference to parent model instance -
__root: Reference to root model instance