Module 2 — DTDL Fundamentals & Structur

Module Objective

By the end of this module, you will:


1️⃣ What Is DTDL?

DTDL stands for:

Digital Twins Definition Language

It is the modeling language used in Azure Digital Twins.

It defines:

Important:

DTDL defines the blueprint, not the actual twin instance.


2️⃣ DTDL Is JSON-Based

DTDL is written in JSON format.

If you understand JSON, you already understand 50% of DTDL.

Example JSON:

{
  "name": "Room",
  "temperature": 23
}

DTDL builds structured models using this format.


3️⃣ The Smallest Valid DTDL Model

Here is the smallest valid model:

{
  "@id": "dtmi:com:example:Room;1",
  "@type": "Interface",
  "@context": "dtmi:dtdl:context;2",
  "displayName": "Room",
  "contents": []
}

Let’s break this down carefully.


4️⃣ Required Fields Explained

🔹 @id

This is the Digital Twin Model Identifier (DTMI).

Format:

dtmi:<domain>:<modelName>;<version>

Example:

dtmi:com:example:Room;1

Breakdown:

Important Rules:

Example new version:

dtmi:com:example:Room;2

Never overwrite version 1.


🔹 @type

For models, this is usually:

"Interface"

An Interface defines a blueprint for a digital twin.

Think of it like:


🔹 @context

This tells Azure which DTDL version you are using.

For DTDL v2:

"dtmi:dtdl:context;2"

Always include it.

Without it → model validation fails.


🔹 displayName

Human-readable name.

Used in:

This does NOT affect logic.


🔹 contents

This is where the real modeling happens.

Inside contents you define:

Example:

"contents": []

An empty array means: The model currently has no properties.


5️⃣ Creating Your First Real Model

Let’s build something meaningful.

We will create a Room model with:

Here is the full model:

{
  "@id": "dtmi:com:smartbuilding:Room;1",
  "@type": "Interface",
  "@context": "dtmi:dtdl:context;2",
  "displayName": "Room",
  "contents": [
    {
      "@type": "Property",
      "name": "temperature",
      "schema": "double"
    },
    {
      "@type": "Telemetry",
      "name": "humidity",
      "schema": "double"
    }
  ]
}

Now you have a valid production-ready DTDL model.


6️⃣ Understanding Schema

The schema defines the data type.

Common primitive schemas:

Example:

{
  "@type": "Property",
  "name": "isOccupied",
  "schema": "boolean"
}

This means the Room has a boolean state.


7️⃣ Model Validation Thinking

Before uploading to Azure Digital Twins, ask:

DTDL is strict. Syntax errors will fail validation.


8️⃣ DTMI Naming Best Practices (Architect Level)

Good naming:

dtmi:com:yourcompany:building:Room;1

Bad naming:

dtmi:test:Room;1

Production guidelines:

Large systems may have:

dtmi:com:company:factory:ProductionLine;1
dtmi:com:company:factory:Machine;1
dtmi:com:company:factory:Sensor;1

Think enterprise scale.


9️⃣ Common Beginner Mistakes

❌ Forgetting version in @id
❌ Using invalid schema type
❌ Mixing telemetry and property
❌ Changing model without version bump
❌ Poor naming conventions

Avoid these early.


🔟 Conceptual Understanding

What did we just do?

We did NOT:

We created a blueprint.

Blueprint → Model
Model → Twin Instances
Twin Instances → Graph

DTDL is the foundation.


Knowledge Check

Answer mentally:

  1. What is the purpose of @context?
  2. Why must we version models?
  3. What happens if two models have same DTMI?
  4. Is DTDL defining data or structure?

If you can answer clearly → you understand this module.

In Module 3, we go deep into:

💬
AI Learning Assistant