Skip to main content

Data model: reuse or design

Every application on OctoMesh starts with a data model: what kinds of things exist, which properties they have and how they relate. In OctoMesh this model is a Construction Kit (CK). In this tutorial you decide when to reuse one of the public Construction Kits and when to design your own, and then you build a small own model that depends on a public one: you write it, compile it with octo-ckc, publish it to a local catalog, import it into your tenant and change it with a new version.

Time: about 45 minutes.

Requirements
  • A local tenant from the getting-started repository (OctoMesh 3.5.23 or newer on a local kind cluster) or any other tenant in which you may import Construction Kits. The examples use <tenant> for the tenant id; with getting-started this is meshtest.
  • octo-cli 3.5.0 or newer, logged in to that tenant (om-login-local.ps1 of getting-started does this).
  • The Construction Kit compiler octo-ckc and the .NET SDK, see Start creating libraries.
Use a test tenant

This tutorial writes to the tenant: it imports models and creates two entities. Work in a local or test tenant.

CK language 2 follows later

This tutorial teaches the current Construction Kit language. CK language 2 is an opt-in extension of it (see the overview) that you can adopt later without changing the steps below; this tutorial gets a note when it is generally available.

Reuse, extend or design?​

Before you write any YAML, check what already exists. The public Construction Kits of the repository meshmakers/octo-construction-kit cover recurring domains, and everything that builds on them is understood by Studio, queries and pipelines without extra work.

SituationDecision
A public type already describes your thing (a machine, a city, an employee, a meter)Reuse it. Create runtime entities of that type and do not model anything.
A public type is close, but you need extra properties or relationsExtend it. Write an own model that depends on the public one and derives a new type from the public type.
Your domain has nothing in common with a public kit, or you only need a few isolated typesDesign new. Write an own model, still derive from Basic or System types so that your entities share names, trees and associations with the rest of the platform.

Rules of thumb:

  • Reuse beats extend, extend beats design. Every attribute you do not define is one you never have to migrate.
  • Never copy a public model and rename it: you would lose its updates. Depend on it instead.
  • A model is a contract. Once other models or applications depend on a version, changes follow the versioning rules.

The public Construction Kits​

ModelWhat it contains
BasicGeneral building blocks: assets, trees, documents, employees, countries, states, cities and districts
Basic.EnergyMetering points, consumers, producers, operating facilities and energy measurements
Basic.AccountingBank accounts, bank connections, bank transactions and payment orders
EnergyCommunityAn energy community: customers, consumers, producers, participation periods, prices and billing documents
EnvironmentCarbon emissions and budgets, environmental goals, compliance records and certificates of origin
Industry.BasicMachines, runtime variables and events
Industry.EnergyEnergy meters, consumers, storage, photovoltaic systems, inverters, forecasts and costs
Industry.FluidWater and heat meters
Industry.LogisticsArticles, orders, parcels, shipments, stock and customers
Industry.MaintenanceOrders, workplaces, cost centers, accounts and journal entries for maintenance
Industry.ManufacturingProduction orders, shifts and feedback

Every model has its own page with types, attributes, enums and associations in the library reference. You can also list what your tenant can install:

octo-cli -c LibraryStatus

The result is a table of all models with the columns INSTALLED, CATALOG and STATE; models with Not Installed and the action Install are available to you.

What you build​

A small inspection model for any kind of asset: an Inspection has a date, an outcome (Passed, NeedsAction, Failed) and remarks, and it belongs to one Asset of the public Basic model. So the model has one type, one enum and one association, and it depends on a public Construction Kit.

Step 1: Import the public Construction Kit​

Your model derives from Basic, so Basic has to be in the tenant. Check what an import would bring in, then import it from the public catalog and wait for the job (-w):

octo-cli -c CheckDependencies -cn PublicGitHubCatalog -m Basic-2.5.0
octo-cli -c ImportFromCatalog -cn PublicGitHubCatalog -m Basic-2.5.0 -w
octo-cli -c LibraryStatus -io

CheckDependencies lists the models that will be imported. After the import LibraryStatus -io (installed only) shows the line

Basic 2.5.0 2.5.0 Available - -

Available means the tenant has loaded the model without errors.

Step 2: Write the model​

Create a folder inspections with this structure:

inspections/
└── ConstructionKit/
├── ckModel.yaml
├── enums/inspection.yaml
├── attributes/inspection.yaml
├── associations/inspection.yaml
└── types/inspection.yaml

ckModel.yaml names the model, gives it a version and lists the models it depends on. The dependency is a version range: any Basic from 2.4 up to, but not including, 3.0.

$schema: https://schemas.meshmakers.cloud/construction-kit-meta.schema.json
modelId: Tutorial.Inspections-1.0.0
description: Inspections of assets, built on the public Basic Construction Kit.
dependencies:
- Basic-[2.4,3.0)

enums/inspection.yaml defines the closed value list:

$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
enums:
- enumId: InspectionOutcome
values:
- key: 0
name: Passed
- key: 1
name: NeedsAction
- key: 2
name: Failed

attributes/inspection.yaml defines the typed fields. The outcome uses the enum:

$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
attributes:
- id: InspectedAt
valueType: DateTime
description: Point in time of the inspection.
- id: Outcome
valueType: Enum
valueCkEnumId: ${this}/InspectionOutcome
description: Result of the inspection.
- id: Remarks
valueType: String
description: Free-text remarks of the inspector.

associations/inspection.yaml defines the relation as a role with a name and a multiplicity for each direction: an inspection has exactly one inspected asset, and an asset has many inspections.

$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
associationRoles:
- id: InspectionOfAsset
inboundName: Inspections
inboundMultiplicity: N
outboundName: InspectedAsset
outboundMultiplicity: One

types/inspection.yaml ties it together. The type derives from the public Basic/NamedEntity (which brings a name), uses the attributes and points the association at the public Basic/Asset:

$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
types:
- typeId: Inspection
description: One inspection of an asset.
derivedFromCkTypeId: ${Basic}/NamedEntity
attributes:
- id: ${this}/InspectedAt
name: InspectedAt
- id: ${this}/Outcome
name: Outcome
- id: ${this}/Remarks
name: Remarks
isOptional: true
associations:
- id: ${this}/InspectionOfAsset
targetCkTypeId: ${Basic}/Asset

${this} is your own model and ${Basic} the model named in dependencies. Attributes are not optional unless you say isOptional: true. The best practices explains the building blocks, the library guide the folder layout.

Step 3: Compile​

octo-ckc -c Compile -p inspections/ConstructionKit -o inspections/out

The compiler checks the YAML against the schemas and your model against its dependencies, which it resolves from the catalogs it knows. On success it ends with Construction kit model directory compiled and writes one file:

inspections/out/ck-tutorial.inspections.yaml

A typo is reported with the file and the path, for example a multiplicity ONE instead of One fails with Schema validation failed at '/associationRoles/0/outboundMultiplicity'.

Step 4: Publish to a local catalog​

octo-ckc -c Publish -f inspections/out/ck-tutorial.inspections.yaml

This copies the compiled model into your local catalog (by default ~/.octo/local-catalog; -lcr <directory> uses another directory) and ends with Construction kit model published. Publishing makes the model resolvable for everything on your machine: other models that depend on yours, and blueprints you build later. A version can be published once; publishing the same version again fails unless you add -r to replace it.

A kind tenant does not see your local catalog

The tenant of getting-started runs inside a Kubernetes cluster and reads the public catalog, not your home directory. That is why the next step imports the compiled file. On a local developer stack, whose services read ~/.octo/local-catalog, you can import by name instead with ImportFromCatalog -cn LocalFileSystemCatalog.

Step 5: Import into the tenant​

octo-cli -c ImportCk -f inspections/out/ck-tutorial.inspections.yaml -w
octo-cli -c LibraryStatus -io

-w waits for the import job, which reports has completed. The status now lists both models:

Basic 2.5.0 2.5.0 Available - -
Tutorial.Inspections 1.0.0 - Available - -

Both are Available. The CATALOG column of your model is - because no catalog the tenant can read contains it; that is expected for a file import.

Step 6: Create data​

Save this file as inspections/sample.yaml. It creates an asset of the public type and an inspection of your type that points to it. Runtime ids are 24 hexadecimal characters, and type and role ids in an import file have the form Model/Name-Version:

$schema: https://schemas.meshmakers.cloud/runtime-model.schema.json
dependencies:
- Tutorial.Inspections-[1.0,2.0)
entities:
- rtId: 6a0000000000000000000001
ckTypeId: Basic/Asset-1
attributes:
- id: System/Name-1
value: Boiler 1
- rtId: 6a0000000000000000000002
ckTypeId: Tutorial.Inspections/Inspection-1
associations:
- roleId: Tutorial.Inspections/InspectionOfAsset-1
targetRtId: 6a0000000000000000000001
targetCkTypeId: Basic/Asset-1
attributes:
- id: System/Name-1
value: Annual inspection 2026
- id: Tutorial.Inspections/InspectedAt-1
value: "2026-10-16T08:00:00Z"
- id: Tutorial.Inspections/Outcome-1
value: NeedsAction
- id: Tutorial.Inspections/Remarks-1
value: Replace the pressure valve.
octo-cli -c ImportRt -f inspections/sample.yaml -w

The job completes. The tenant now holds one Basic/Asset and one Tutorial.Inspections/Inspection; the outcome is stored as the enum value 1 (NeedsAction). You can query both like any other entity, see tutorial 2.

Step 7: Change the model with a new version​

Add an optional field Inspector. In attributes/inspection.yaml append

- id: Inspector
valueType: String
description: Name of the person who carried out the inspection.

and in types/inspection.yaml add after Remarks

- id: ${this}/Inspector
name: Inspector
isOptional: true

The pitfall: the same version is ignored​

Compile and import without changing the version:

octo-ckc -c Compile -p inspections/ConstructionKit -o inspections/out
octo-cli -c ImportCk -f inspections/out/ck-tutorial.inspections.yaml -w

Both commands succeed and the job completes, but nothing changed: the tenant still knows only InspectedAt, Outcome and Remarks. A model version is immutable, so a rebuild of the same version stays invisible, without an error. Whenever a change does not show up, check the version first.

The fix: bump the version​

Adding an optional attribute is a compatible change, so raise the minor version in ckModel.yaml:

modelId: Tutorial.Inspections-1.1.0

The versioning rules say which change needs which bump: compatible additions raise the minor version, breaking changes the major version. Then compile, publish and import again:

octo-ckc -c Compile -p inspections/ConstructionKit -o inspections/out
octo-ckc -c Publish -f inspections/out/ck-tutorial.inspections.yaml
octo-cli -c ImportCk -f inspections/out/ck-tutorial.inspections.yaml -w
octo-cli -c LibraryStatus -io
Tutorial.Inspections 1.1.0 - Available - -

The new field is there, and the existing inspection kept its data with an empty Inspector.

Typical pitfalls​

  • A change does not show up. You imported the same model version again. Raise the version in ckModel.yaml, then compile and import again (step 7).
  • Compilation fails with a schema error. Read the path in the message, for example /associationRoles/0/outboundMultiplicity. Multiplicities are One, ZeroOrOne and N, and enum and type names are case sensitive.
  • The compiler cannot find a dependency. The version range in dependencies matches no model in a catalog the compiler can read. Check the model name and the range against the library reference.
  • A model is not Available. octo-cli -c LibraryStatus -na lists only the models that need attention, with the reason.
  • ImportRt does not update an entity. The default import mode only inserts. Use new rtId values for new entities.
  • Publishing the same version again fails. Versions are published once; raise the version or add -r while you iterate locally.

Summary​

  • Check the public Construction Kits first: reuse beats extend, extend beats design.
  • An own model is a few YAML files: ckModel.yaml with the version and the dependencies, plus enums, attributes, associations and types.
  • octo-ckc -c Compile validates and produces one file, octo-ckc -c Publish puts it into the local catalog, octo-cli -c ImportCk -w loads it into the tenant, and LibraryStatus tells you whether it is Available.
  • A model version is immutable. Every change needs a new version, otherwise it stays invisible.

Where to go next​