Class Diagrams

What are Class Diagrams?

Mermaid's class diagrams help you visualize data structures and their relationships in your projects. For analytics engineers, they're particularly useful for documenting data models, transformation logic, and system architectures.

Creating Your First Class Diagram

  1. From the Code IDE, Click Apps and Agents from the lefthand panel

  2. Select Mermaid. Paradime will automatically start a new mermaid project

  3. In the terminal that appears, use the arrow keys to select "Class Diagrams"

  4. A new classDiagram.mmd file will be created in your editor with this starter template:

---
title: Animal example
---
classDiagram
    note "From Duck till Zebra"
    Animal <|-- Duck
    note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
    Animal <|-- Fish
    Animal <|-- Zebra
    Animal : +int age
    Animal : +String gender
    Animal: +isMammal()
    Animal: +mate()
    class Duck{
        +String beakColor
        +swim()
        +quack()
    }
    class Fish{
        -int sizeInFeet
        -canEat()
    }
    class Zebra{
        +bool is_wild
        +run()
    }
  1. Click the eye icon (👁️) in the top right corner of your Mermaid file to preview the diagram

  1. Edit and update your .mmd file as needed - the preview will update automatically

Diagram Syntax Guide

Class Structure

A class diagram represents data objects and their relationships. Each class shows:

  • The class name

  • Its attributes (properties)

  • Its methods (operations)

Basic Syntax

classDiagram
    class DataModel {
        +tableName: string
        +schema: string
        +refreshData()
        -validateSchema()
    }

Access Levels

Show visibility with these symbols:

  • + : Public access

  • - : Private access

  • # : Protected access

  • ~ : Internal access

Connections

Show relationships between classes:

classDiagram
    FactTable --> DimensionTable
    BaseModel <|-- CustomModel

Common relationships:

  • Parent-child: <|--

  • Contains: *--

  • Uses: -->

  • Optional: o--

Data Team Examples

Data Models

classDiagram
    class FactSales {
        +order_date: date
        +customer_key: int
        +product_key: int
        +calculateRevenue()
    }
    class DimCustomer {
        +customer_key: int
        +customer_name: string
        +getLTV()
    }
    FactSales --> DimCustomer

Transformation Pipeline

classDiagram
    class Staging {
        +raw_data: table
        +clean()
        +validate()
    }
    class Warehouse {
        +processed_data: table
        +transform()
        +loadData()
    }
    Staging --> Warehouse

Best Practices

  1. Name classes clearly and consistently

  2. Show only relevant attributes and methods

  3. Group related classes together

  4. Add notes for complex relationships

  5. Keep diagrams focused on one aspect of your system

Additional Resources

For more syntax options and advanced features, visit the official Mermaid documentation

Last updated

Was this helpful?