# Mermaid Support

## Generate Diagram by Mermaid

[Mermaid](https://mermaid.js.org/) is a diagramming tool that renders Markdown-inspired text definitions into visual diagrams. It is a powerful way to create and visualize various types of diagrams, including flowcharts, sequence diagrams, class diagrams, and more, directly from text.

To  generate diagrams by Mermaid:

1. Select **Tools > Generate Diagram by Mermaid** menu.
2. Enter mermaid code and click **Generate** button.
3. Select a package where the generated diagram and elements to be contained.

## Supported Mermaid Diagrams

StarUML support the following Mermaid diagrams:

* Class Diagram
* Sequence Diagram
* State Diagram
* Flowchart
* Entity Relationship Diagram
* Requirement Diagram
* Mindmap

Please refer to the [official documentation](https://mermaid.js.org/intro/) for the specific Mermaid syntax.

{% hint style="warning" %}
There may be differences in style, layout, etc. between the diagram generated in StarUML using Mermaid syntax and the actual rendering of Mermaid.
{% endhint %}

### Class Diagram

You can create a class diagram with Mermaid. Keep in mind that the class diagram syntax in Mermaid is different from the UML specification. For example, an attribute is written as `age: int` in UML, but as `int age` in Mermaid. For more details, refer to the official Mermaid documentation.

Here is an example code for class diagram.

```mermaid
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()
    }
```

{% hint style="warning" %}
Mermaid for StarUML do not support followings in class diagram:

* Namespaces
* Styling and classes
* Markdown formatting
* Links
* Interactions
  {% endhint %}

### Sequence Diagram

A sequence diagram illustrates how objects interact in a particular scenario of a use case. It shows the sequence of messages exchanged between the objects to perform a specific function. Here is an example code for sequence diagram.

```mermaid
sequenceDiagram
    Alice->>Bob: Hello Bob, how are you ?
    Bob->>Alice: Fine, thank you. And you?
    create participant Carl
    Alice->>Carl: Hi Carl!
    create actor D as Donald
    Carl->>D: Hi!
    destroy Carl
    Alice-xCarl: We are too many
    Bob->>Alice: I agree
```

Message types that do not exist in the UML specification are not supported.

* Lines without arrowheads
* Lines with a cross at the end
* Lines with bidirectional arrowheads
* Dotted lines with arrowheads treated as `asyncSignal` type.&#x20;

In StarUML, activation cannot be controlled on a per-message basis. Therefore, if even a single message has an activation, the activation is shown throughout the entire diagram.

{% hint style="warning" %}
Mermaid for StarUML do not support followings in sequence diagram:

* Group/Box
* Background color
* Styles and classes
* Actor menu
  {% endhint %}

### State Diagram

A state diagram is a graphical representation of a system that shows its states, transitions, and events. Each state depicts a unique situation in the system, while transitions indicate how the system moves from one state to another based on events or conditions. Here is an example code for state diagram.

```mermaid
stateDiagram-v2
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
```

{% hint style="warning" %}
Mermaid for StarUML do not support followings in state diagram:

* Composite state
* Concurrency
* Styles and classes
* Markdown formatting
  {% endhint %}

### Flowchart

A flowchart is a visual representation of a process, system, or algorithm. It uses symbols like arrows, rectangles, ovals, and diamonds to depict the flow of steps, decisions, and information, allowing for easy understanding and communication of complex processes. Here is an example code for flowchart.

```mermaid
flowchart TD
    A[Start] --> B{Is it?}
    B -->|Yes| C[OK]
    C --> D[Rethink]
    D --> B
    B ---->|No| E[End]    
```

{% hint style="warning" %}
Mermaid for StarUML do not support followings in flowchart:

* Some node shapes (asymmetric, parallelogram alt, trapezoid, and double circle)
* Expanded node shapes and special shapes
* Link types and arrow types except solid arrows (means flow)
* Animation, interaction, style, classes and icons
* Markdown formatting
* Subgraph
  {% endhint %}

### Entity Relationship Diagram

An Entity Relationship Diagram (ERD) is a graphical representation of entities and their relationships in a database. It is a critical tool in database design that helps visualize how data is structured and how different entities interact within the system. Here is an example code for entity relationship diagram.

```mermaid
erDiagram
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER {
        string name
        string custNumber
        string sector
    }
    ORDER ||--|{ LINE-ITEM : contains
    ORDER {
        int orderNumber
        string deliveryAddress
    }
    LINE-ITEM {
        string productCode
        int quantity
        float pricePerUnit
    }
```

{% hint style="warning" %}
Mermaid for StarUML do not support followings in entity relationship diagram:

* Markdown formatting
* Styling and classes
  {% endhint %}

### Requirement Diagram

A requirement diagram is a visual representation used to capture, categorize, and manage requirements in a system or project. Primarily used in systems engineering and software engineering, it helps stakeholders understand requirement relationships and hierarchies. Here is an example code for requirement diagram.

```mermaid
requirementDiagram
    requirement test_req {
        id: 1
        text: the test text.
        risk: high
        verifymethod: test
    }
    
    element test_entity {
        type: simulation
    }
    
    test_entity - satisfies -> test_req
```

{% hint style="warning" %}
Mermaid for StarUML do not support followings in requirement diagram:

* Markdown formatting
* Styles and classes
  {% endhint %}

### Mindmap

A mindmap is a visual tool used for organizing information hierarchically. It starts with a central idea and branches out into related subtopics, helping to generate, organize, and visualize ideas or concepts. Mindmaps are useful for brainstorming and planning as they encourage a free flow of ideas. Here is an example code for mindmap.

```mermaid
mindmap
  root((mindmap))
    Origins
      Long history
      Popularisation
        British popular psychology author Tony Buzan
    Research
      On effectiveness and features
      On Automatic creation
        Uses
            Creative techniques
            Strategic planning
            Argument mapping
    Tools
      Pen and paper
      Mermaid
```

{% hint style="warning" %}
Mermaid for StarUML do not support followings in mindmap:

* Node shapes
* Icon and classes
* Markdown formatting
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.staruml.io/user-guide/mermaid-support.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
