# lutaml/lutaml-model architecture

> Architecture diagram of the GitHub repository lutaml/lutaml-model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lutaml/lutaml-model
- Repository: https://github.com/lutaml/lutaml-model

## Overview

##### Main Components

a. Core Model Layer:
- Model Definition (Serializable/Serialize)
- Attribute System
- Type System
- Validation System

b. Serialization Layer:
- XML Adapter System
- JSON Adapter System
- YAML Adapter System
- TOML Adapter System

c. Configuration System
- Adapter Configuration
- Global Settings

##### Key Relationships

a. Model to Serialization:
- How models are transformed into different formats
- Role of adapters in the transformation process

b. Type System Integration:
- Connection between attributes and supported types
- Type validation flow

c. Adapter Pattern Implementation:
- How different adapters plug into the system
- Format-specific handling

**┌─────────────────────────────────────────────────────────────────────┐**
- LutaML Model System                           │
- ┘

- ┌──────────────────┴───────────────────┐

**┌──────────┴───────────┐              ┌──────────┴───────────┐**
- Core Model Layer   │              │  Serialization Layer │

- ┌──────────────────┐ │              │ ┌────────────────┐   │
- Model Definition│ │              │ │ Adapter System │   │
- Serializable  │ │              │ │ ┌────────────┐ │   │
- Serialize     │ │              │ │ │XML Adapters│ │   │
- ┘ │              │ │ │- Nokogiri  │ │   │
- ┌──────────────────┐ │              │ │ │- Ox       │ │   │
- Attribute System │ │              │ │ │- Oga      │ │   │
- Definitions    │ │              │ │ └────────────┘ │   │
- Mappings      │◄├──────────────►│ │ ┌────────────┐ │   │
- ┘ │              │ │ │JSON/YAML   │ │   │
- ┌──────────────────┐ │              │ │ │Adapters    │ │   │
- Type System    │ │              │ │ └────────────┘ │   │
- Basic Types    │ │              │ │ ┌────────────┐ │   │
- Custom Types   │ │              │ │ │TOML        │ │   │
- ┘ │              │ │ │Adapters    │ │   │
- ┌──────────────────┐ │              │ │ └────────────┘ │   │
- Validation    │ │              │ └────────────────┘   │
- ┘ │              └────────────────────────

**┌─────────────────────────────────────────────────────────────────────┐**
- Configuration System                            │
- ┤
- Adapter Selection                                                │
- Global Settings                                                  │
- ┘

Important elements to highlight:

##### Data Flow
- How data moves from model definition through serialization
- Validation checkpoints
- Adapter selection points

##### Component Relationships
- Inheritance relationships in model system
- Adapter interfaces
- Validation integration points

##### Special Features
- XML namespace handling
- Collection handling
- Custom serialization points

- The overall architecture of the system
- How different components interact
- The role of each adapter
- The data transformation process
- Where validation occurs
- How configuration affects the system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph LutaML["LutaML Model System"]
        subgraph CoreModel["Core Model Layer"]
            ModelDef["Model Definition"]
            Attribute["Attribute System"]
            TypeSystem["Type System"]
            Validation["Validation System"]
        end

        subgraph Serialization["Serialization Layer"]
            subgraph Adapters["Adapter System"]
                XML["XML Adapters"]
                JSON["JSON Adapters"]
                YAML["YAML Adapters"]
                TOML["TOML Adapters"]
                
                subgraph XMLImpl["XML Implementations"]
                    Nokogiri["Nokogiri"]
                    Ox["Ox"]
                    Oga["Oga"]
                end
                
                subgraph JSONImpl["JSON Implementations"]
                    MultiJSON["MultiJSON"]
                    StandardJSON["Standard JSON"]
                end
                
                subgraph YAMLImpl["YAML Implementations"]
                    StandardYAML["Standard YAML"]
                end
                
                subgraph TOMLImpl["TOML Implementations"]
                    TomlRB["TomlRB"]
                    Tomlib["Tomlib"]
                end
            end
        end

        subgraph Config["Configuration System"]
            AdapterConfig["Adapter Selection"]
            GlobalSettings["Global Settings"]
        end
    end

    %% Relationships
    ModelDef --> Attribute
    Attribute --> TypeSystem
    TypeSystem --> Validation
    
    Attribute --> XML
    Attribute --> JSON
    Attribute --> YAML
    Attribute --> TOML
    
    XML --> XMLImpl
    JSON --> JSONImpl
    YAML --> YAMLImpl
    TOML --> TOMLImpl
    
    Config --> Adapters

    %% Click events for component mapping
    click ModelDef "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/serializable.rb"
    click Attribute "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/attribute.rb"
    click TypeSystem "https://github.com/lutaml/lutaml-model/tree/main/lib/lutaml/model/type/"
    click Validation "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/validation.rb"
    click XML "https://github.com/lutaml/lutaml-model/tree/main/lib/lutaml/model/xml_adapter/"
    click JSON "https://github.com/lutaml/lutaml-model/tree/main/lib/lutaml/model/json_adapter/"
    click YAML "https://github.com/lutaml/lutaml-model/tree/main/lib/lutaml/model/yaml_adapter/"
    click TOML "https://github.com/lutaml/lutaml-model/tree/main/lib/lutaml/model/toml_adapter/"
    click Config "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/config.rb"
    click Nokogiri "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb"
    click Ox "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/xml_adapter/ox_adapter.rb"
    click Oga "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/xml_adapter/oga_adapter.rb"
    click MultiJSON "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/json_adapter/multi_json_adapter.rb"
    click StandardJSON "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/json_adapter/standard_json_adapter.rb"
    click StandardYAML "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/yaml_adapter/standard_yaml_adapter.rb"
    click TomlRB "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/toml_adapter/toml_rb_adapter.rb"
    click Tomlib "https://github.com/lutaml/lutaml-model/blob/main/lib/lutaml/model/toml_adapter/tomlib_adapter.rb"

    %% Styling
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef adapter fill:#fff3e0,stroke:#ff6f00
    classDef config fill:#f3e5f5,stroke:#4a148c
    classDef impl fill:#fff,stroke:#666

    class ModelDef,Attribute,TypeSystem,Validation core
    class XML,JSON,YAML,TOML adapter
    class AdapterConfig,GlobalSettings config
    class Nokogiri,Ox,Oga,MultiJSON,StandardJSON,StandardYAML,TomlRB,Tomlib impl
```
