# Using graphs

## Conceptual Breakdown of the Data Domain

```plain
DataDomain (Root container)
  ├── DomainNamespace (logical grouping)
  │   └── DomainModel
  │       └── DomainEntity
  │           ├── Property (name, type, ...)
  │           ├── Association (name, cardinality, target Entity)
  │           └── ParentEntity (reference to another DomainEntity)
  ├── DomainModel
  │   └── DomainEntity
  │       ├── Property
  │       ├── Association
  │       └── ParentEntity
  └── ForeignDomainNamespace (immutable, imported from another DataDomain)
      └── DomainModel
          └── DomainEntity
              ├── Property
              ├── Association
              └── ParentEntity
```

## Graph Structure and Relationships

The data domain is represented as a directed graph where nodes represent the core elements (namespaces, models, entities, properties, and associations) and edges represent the relationships between them.

Here's a breakdown of how each element is represented in the graph:

**Nodes:**

* **Namespace:** Represents a `DomainNamespace`. It's a container for models and other namespaces.
* **Model:** Represents a `DomainModel`. It's a container for entities.
* **Entity:** Represents a `DomainEntity`. It's the fundamental building block, defining a specific type of data.
* **Property:** Represents a `DomainProperty`. It's an attribute of an entity.
* **Association:** Represents a `DomainAssociation`. It defines a relationship between entities.

**Edges:**

Edges define the relationships between nodes. Each edge can have a `type` label to specify the kind of relationship.

* **Namespace Hierarchy:**
  * A namespace can be a child of another namespace, creating a hierarchical structure.
  * **Edge:** No edges. We use the graph's parent-child logic.
  * **Cardinality:** A namespace can have only one parent namespace.
  * **Type:** No specific type, just a connection.
* **Namespace-Model:**
  * A model can be a child of a namespace. By default it is a child of a Data Domain.
  * **Edge:** No edges. We use the graph's parent-child logic.
  * **Cardinality:** A model can have only one parent namespace.
  * **Type:** No specific type, just a connection.
* **Model-Entity:**
  * An entity is always a child of a model.
  * **Edge:** No edges. We use the graph's parent-child logic.
  * **Cardinality:** An entity can have only one parent model.
  * **Type:** No specific type, just a connection.
* **Entity Inheritance (Parent):**
  * An entity can inherit from other entities.
  * **Edge:** An edge exists from the child entity to the parent entity.
  * **Cardinality:** An entity can have multiple parent entities.
  * **Type:** `{ type: 'parent' }`
* **Entity-Property:**
  * An entity has properties that describe its attributes.
  * **Edge:** An edge exists from the entity to the property.
  * **Cardinality:** An entity can have multiple properties.
  * **Type:** `{ type: 'property' }`
* **Entity-Association:**
  * An entity can have associations to other entities (including itself).
  * **Edge 1:** An edge exists from the entity to the association node.
  * **Edge 2:** An edge exists from the association node to each target entity.
  * **Cardinality:** An entity can have multiple associations, and each association can have multiple target entities.
  * **Type:**  `{ type: 'association' }`

## Conceptual Graph Visualization

The following diagram illustrates the relationships described above:

```mermaid
graph TD
    subgraph "Namespaces"
        N1[Namespace 1]
        N2[Namespace 2]
    end
    subgraph "Models"
        M1[Model 1]
        M2[Model 2]
    end
    subgraph "Entities"
        E1[Entity 1]
        E2[Entity 2]
        E3[Entity 3]
    end
    subgraph "Properties"
        P1[Property 1]
        P2[Property 2]
    end
    subgraph "Associations"
        A1[Association 1]
    end

    N2 --> N1
    N1 --> M1
    N2 --> M2
    M1 --> E1
    M1 --> E2
    M2 --> E3
    E1 -- "{ type: 'parent' }" --> E2
    E1 -- "{ type: 'property' }" --> P1
    E1 -- "{ type: 'property' }" --> P2
    E1 -- "{ type: 'association' }" --> A1
    A1 -- "{ type: 'association' }" --> E2
    A1 -- "{ type: 'association' }" --> E3
```
