> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mermaid-js/mermaid/llms.txt
> Use this file to discover all available pages before exploring further.

# Requirement diagrams

> Visualize requirements and their relationships with requirement diagrams in Mermaid.

Requirement diagrams provide a visualization for requirements and their connections to each other and other documented elements. The modeling specs follow those defined by SysML v1.6.

## Basic example

Rendering requirements is straightforward:

```mermaid theme={null}
requirementDiagram

    requirement test_req {
    id: 1
    text: the test text.
    risk: high
    verifymethod: test
    }

    element test_entity {
    type: simulation
    }

    test_entity - satisfies -> test_req
```

## Syntax overview

There are three types of components to a requirement diagram: requirement, element, and relationship.

### Requirements

A requirement definition contains a requirement type, name, id, text, risk, and verification method:

```
<type> user_defined_name {
    id: user_defined_id
    text: user_defined text
    risk: <risk>
    verifymethod: <method>
}
```

**Available options:**

| Keyword            | Options                                                                                                                 |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
| Type               | requirement, functionalRequirement, interfaceRequirement, performanceRequirement, physicalRequirement, designConstraint |
| Risk               | Low, Medium, High                                                                                                       |
| VerificationMethod | Analysis, Inspection, Test, Demonstration                                                                               |

### Elements

An element definition contains an element name, type, and document reference:

```
element user_defined_name {
    type: user_defined_type
    docref: user_defined_ref
}
```

### Relationships

Relationships connect source and destination nodes:

```
{name of source} - <type> -> {name of destination}
```

or

```
{name of destination} <- <type> - {name of source}
```

**Relationship types:** contains, copies, derives, satisfies, verifies, refines, traces

## Markdown formatting

You can use markdown formatting in text fields by surrounding the text in quotes:

```mermaid theme={null}
requirementDiagram

requirement "__test_req__" {
    id: 1
    text: "*italicized text* **bold text**"
    risk: high
    verifymethod: test
}
```

## Complete example

This example demonstrates all requirement types and relationship options:

```mermaid theme={null}
requirementDiagram

    requirement test_req {
    id: 1
    text: the test text.
    risk: high
    verifymethod: test
    }

    functionalRequirement test_req2 {
    id: 1.1
    text: the second test text.
    risk: low
    verifymethod: inspection
    }

    performanceRequirement test_req3 {
    id: 1.2
    text: the third test text.
    risk: medium
    verifymethod: demonstration
    }

    interfaceRequirement test_req4 {
    id: 1.2.1
    text: the fourth test text.
    risk: medium
    verifymethod: analysis
    }

    physicalRequirement test_req5 {
    id: 1.2.2
    text: the fifth test text.
    risk: medium
    verifymethod: analysis
    }

    designConstraint test_req6 {
    id: 1.2.3
    text: the sixth test text.
    risk: medium
    verifymethod: analysis
    }

    element test_entity {
    type: simulation
    }

    element test_entity2 {
    type: word doc
    docRef: reqs/test_entity
    }

    element test_entity3 {
    type: "test suite"
    docRef: github.com/all_the_tests
    }


    test_entity - satisfies -> test_req2
    test_req - traces -> test_req2
    test_req - contains -> test_req3
    test_req3 - contains -> test_req4
    test_req4 - derives -> test_req5
    test_req5 - refines -> test_req6
    test_entity3 - verifies -> test_req5
    test_req <- copies - test_entity2
```

## Direction

The diagram can be rendered in different directions:

```mermaid theme={null}
requirementDiagram

direction LR

requirement test_req {
    id: 1
    text: the test text.
    risk: high
    verifymethod: test
}

element test_entity {
    type: simulation
}

test_entity - satisfies -> test_req
```

**Valid directions:** TB (top to bottom), BT (bottom to top), LR (left to right), RL (right to left)

## Styling

<Accordion title="Direct styling">
  Use the `style` keyword to apply CSS styles directly:

  ```mermaid theme={null}
  requirementDiagram

  requirement test_req {
      id: 1
      text: styling example
      risk: low
      verifymethod: test
  }

  element test_entity {
      type: simulation
  }

  style test_req fill:#ffa,stroke:#000, color: green
  style test_entity fill:#f9f,stroke:#333, color: blue
  ```
</Accordion>

<Accordion title="Class definitions">
  Define reusable styles using `classDef` and apply them with the `class` keyword or `:::` syntax:

  ```mermaid theme={null}
  requirementDiagram

  requirement test_req:::important {
      id: 1
      text: "class styling example"
      risk: low
      verifymethod: test
  }

  element test_entity {
      type: simulation
  }

  classDef important font-weight:bold

  class test_entity important
  style test_entity fill:#f9f,stroke:#333
  ```
</Accordion>

<Note>
  A class named `default` will be applied to all nodes. Specific styles should be defined afterwards to override the default styling.
</Note>
