Skip to content

Domain Block

The domain block is used to group related entities together, providing logical organization and structure to your data model.

Purpose

Domains help organize your data model into logical business areas or functional groups. They make it easier to:

  • Navigate large data models
  • Understand entity relationships
  • Maintain clear boundaries between different areas of your business
  • Visualize related entities together

Syntax

mml
domain identifier {
  name = "Display Name"
  description = "Description of the domain"
  color = "#hexcolor"
}

Attributes

Required Attributes

name

The display name of the domain. This is shown in visualizations and documentation.

  • Type: String
  • Required: Yes
mml
domain sales {
  name = "Sales"
}

Optional Attributes

description

A detailed description of the domain's purpose and scope.

  • Type: String
  • Required: No
mml
domain sales {
  name = "Sales"
  description = "Contains all entities related to sales transactions, customers, and revenue"
}

color

A hex color code used for visual representation in diagrams and dashboards.

  • Type: String (hex color)
  • Required: No
  • Format: #RRGGBB
mml
domain sales {
  name = "Sales"
  color = "#2E7D32"
}

Examples

Basic Domain

A minimal domain definition with just the required attributes:

mml
domain analytics {
  name = "Analytics"
}

Complete Domain

A fully configured domain with all attributes:

mml
domain customer_data {
  name = "Customer Data"
  description = "All customer-related entities including profiles, preferences, and behavior"
  color = "#1976D2"
}

Domain with Multiple Entities

Domains serve as organizational containers. Entities reference domains using the belongs-to relationship:

mml
domain sales {
  name = "Sales & Revenue"
  description = "Sales transactions and revenue metrics"
  color = "#2E7D32"
}

entity customer {
  type = "entity"
  description = "Customer master data"

  belongs-to domain.sales
}

entity order {
  type = "entity"
  description = "Sales orders and transactions"

  belongs-to domain.sales
}

entity revenue {
  type = "metric"
  description = "Total revenue from sales"
  business_logic = "SUM(order.total_amount)"

  belongs-to domain.sales
  derived-from entity.order
}

entity customer_lifetime_value {
  type = "metric"
  description = "Total revenue per customer"
  business_logic = "SUM(order.total_amount) GROUP BY customer_id"

  belongs-to domain.sales
  derived-from entity.order
  contains entity.customer
}

Multiple Domains

Organize a large data model into multiple domains:

mml
domain sales {
  name = "Sales"
  description = "Sales and revenue tracking"
  color = "#2E7D32"
}

domain marketing {
  name = "Marketing"
  description = "Marketing campaigns and attribution"
  color = "#F57C00"
}

domain product {
  name = "Product"
  description = "Product catalog and inventory"
  color = "#1976D2"
}

domain customer_support {
  name = "Customer Support"
  description = "Support tickets and customer service"
  color = "#7B1FA2"
}

// Entities reference their respective domains
entity campaign {
  type = "entity"
  belongs-to domain.marketing
}

entity product_sku {
  type = "entity"
  belongs-to domain.product
}

entity support_ticket {
  type = "entity"
  belongs-to domain.customer_support
}

Domain for Analytics

An analytics-focused domain with derived metrics:

mml
domain web_analytics {
  name = "Web Analytics"
  description = "Website traffic and user behavior metrics"
  color = "#455A64"
}

entity pageview {
  type = "entity"
  description = "Individual page view events"

  belongs-to domain.web_analytics
}

entity session {
  type = "entity"
  description = "User session data"

  belongs-to domain.web_analytics
}

entity bounce_rate {
  type = "metric"
  description = "Percentage of single-page sessions"
  business_logic = "COUNT(single_page_sessions) / COUNT(total_sessions)"

  belongs-to domain.web_analytics
  derived-from entity.session
}

entity avg_session_duration {
  type = "metric"
  description = "Average time users spend per session"
  business_logic = "AVG(session.duration_seconds)"

  belongs-to domain.web_analytics
  derived-from entity.session
}

Best Practices

  1. Use clear, business-oriented names: Choose names that reflect business functions or departments

    mml
    // Good
    domain customer_experience
    
    // Avoid
    domain cx_data
  2. Group related entities: Place entities that are used together in the same domain

    mml
    domain sales {
      name = "Sales"
    }
    
    entity order { belongs-to domain.sales }
    entity order_line { belongs-to domain.sales }
    entity revenue { belongs-to domain.sales }
  3. Provide meaningful descriptions: Help users understand the domain's scope

    mml
    domain finance {
      name = "Finance"
      description = "Financial transactions, accounting, and reporting entities"
    }
  4. Use consistent colors: Choose colors that are visually distinct and meaningful

    mml
    domain sales { color = "#2E7D32" }      // Green
    domain costs { color = "#D32F2F" }       // Red
    domain profit { color = "#1976D2" }      // Blue
  5. Keep domains focused: Avoid creating overly broad domains that lose their organizational value

    mml
    // Good - Focused domains
    domain sales { name = "Sales" }
    domain marketing { name = "Marketing" }
    
    // Avoid - Too broad
    domain business_data { name = "Business Data" }

Released under the MIT License.