orchestrata_ultimate.domaingen.models
Reference › orchestrata_ultimate › domaingen › models
models defines the canonical intermediate representation (IR) of the ontology-driven domain generator (SPEC-105). It is plain dataclasses with no internal imports. The IR is the single source of truth: reader builds it from an OWL or Turtle ontology, and ttl, constraints and generator project it back to a Turtle ontology, SHACL shapes and Python code. The types are Field (a datatype property, becoming a typed attribute), Relationship (an object property, becoming an edge with a target, a many flag, a required flag and an optional inverse), Entity (an OWL or RDFS class with an optional parent, fields and relationships), Module (a bounded context, a package in the modular monolith) and DomainModel (modules plus a name and ontology namespace; all_entities flattens the modules). XSD_TO_PY maps XSD datatype local names to the Python types used in generated code (REQ-105-018).
At a glance
| Source | src/orchestrata_ultimate/domaingen/models.py |
| Lines of code | 87 |
| Classes | 5 |
| Functions | 0 |
| Imports (internal) | none |
| Imported by | orchestrata_ultimate.domaingen, orchestrata_ultimate.domaingen.constraints, orchestrata_ultimate.domaingen.generator, orchestrata_ultimate.domaingen.reader, orchestrata_ultimate.domaingen.ttl |
| Tests that import it | none |
Class diagram
Dependency diagram
API
Constants
| Name | Type | Value |
|---|---|---|
XSD_TO_PY |
dict[str, str] |
{'string': 'str', 'normalizedString': 'str', 'anyURI': 'str', 'integer': 'int',… |
Classes
Field (dataclass)
Decorators: dataclass · Line 35
A datatype property → a typed attribute on an entity.
| Attribute | Type | Default |
|---|---|---|
name |
str |
|
type |
str |
'str' |
iri |
str |
'' |
required |
bool |
False |
doc |
str |
'' |
Relationship (dataclass)
Decorators: dataclass · Line 46
An object property → an edge to another entity.
| Attribute | Type | Default |
|---|---|---|
name |
str |
|
target |
str |
'' |
iri |
str |
'' |
many |
bool |
True |
required |
bool |
False |
inverse |
str | None |
None |
doc |
str |
'' |
Entity (dataclass)
Decorators: dataclass · Line 59
An OWL/RDFS class → a domain entity.
| Attribute | Type | Default |
|---|---|---|
name |
str |
|
iri |
str |
'' |
parent |
str | None |
None |
fields |
list[Field] |
field(default_factory=list) |
relationships |
list[Relationship] |
field(default_factory=list) |
doc |
str |
'' |
Module (dataclass)
Decorators: dataclass · Line 71
A bounded context — a package in the modular monolith.
| Attribute | Type | Default |
|---|---|---|
name |
str |
|
entities |
list[Entity] |
field(default_factory=list) |
DomainModel (dataclass)
Decorators: dataclass · Line 79
The whole domain: modules of entities, plus the ontology namespace.
| Attribute | Type | Default |
|---|---|---|
name |
str |
'domain' |
namespace |
str |
'https://example.org/domain#' |
modules |
list[Module] |
field(default_factory=list) |
| Method | Signature | Summary |
|---|---|---|
all_entities |
all_entities() -> list[Entity] |
Source
"""Domain-model IR (SPEC-105) — the canonical intermediate representation.
Pure dataclasses. ``parse_ontology`` (reader) builds these from OWL/Turtle;
``render_ontology`` (ttl) and ``generate_code`` (generator) project them back to
an ontology and to a screaming-architecture domain model. The IR is the single
source of truth — ontology and code are both views of it (FR-001..007).
"""
from __future__ import annotations
from dataclasses import dataclass, field
# xsd datatype IRI (local name) -> Python type used in generated code (REQ-105-018).
XSD_TO_PY: dict[str, str] = {
"string": "str",
"normalizedString": "str",
"anyURI": "str",
"integer": "int",
"int": "int",
"long": "int",
"short": "int",
"nonNegativeInteger": "int",
"positiveInteger": "int",
"decimal": "float",
"double": "float",
"float": "float",
"boolean": "bool",
"dateTime": "datetime",
"date": "datetime",
"dateTimeStamp": "datetime",
}
@dataclass
class Field:
"""A datatype property → a typed attribute on an entity."""
name: str
type: str = "str" # Python type (from XSD_TO_PY)
iri: str = ""
required: bool = False
doc: str = ""
@dataclass
class Relationship:
"""An object property → an edge to another entity."""
name: str
target: str = "" # target entity name
iri: str = ""
many: bool = True
required: bool = False
inverse: str | None = None
doc: str = ""
@dataclass
class Entity:
"""An OWL/RDFS class → a domain entity."""
name: str
iri: str = ""
parent: str | None = None
fields: list[Field] = field(default_factory=list)
relationships: list[Relationship] = field(default_factory=list)
doc: str = ""
@dataclass
class Module:
"""A bounded context — a package in the modular monolith."""
name: str
entities: list[Entity] = field(default_factory=list)
@dataclass
class DomainModel:
"""The whole domain: modules of entities, plus the ontology namespace."""
name: str = "domain"
namespace: str = "https://example.org/domain#"
modules: list[Module] = field(default_factory=list)
def all_entities(self) -> list[Entity]:
return [e for m in self.modules for e in m.entities]