# core/plugins/diagram.sequence.plugin.ts

> 48 lines of code and 7 definitions.

Tree: GovLab Docs
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-plugins-diagram-sequence-plugin-ts
Source text: https://banes-lab.com/source/docs/core/plugins/diagram.sequence.plugin.ts.txt

Listed in [core/plugins](https://banes-lab.com/api/source/docs/core/plugins.md), after [core/plugins/diagram.package.plugin.ts](https://banes-lab.com/source/docs/core/plugins/diagram.package.plugin.ts.md) and before [core/plugins/diagram.shell.plugin.ts](https://banes-lab.com/source/docs/core/plugins/diagram.shell.plugin.ts.md).

## Definitions

- `render` (method_definition, line 25, exported)
- `MIN_PARTICIPANTS` (lexical_declaration, line 11)
- `MIN_MESSAGES` (lexical_declaration, line 12)
- `diagram` (lexical_declaration, line 14, exported)
- `appliesTo` (method_definition, line 15, exported)
- `protocol` (lexical_declaration, line 26, exported)
- `model` (lexical_declaration, line 30, exported)

## Contained in

- [core/plugins](https://banes-lab.com/anatomy/docs/folder-docs-core-plugins.md)

## Uses

- [core/formatters/diagram.sequence.formatter.ts](https://banes-lab.com/source/docs/core/formatters/diagram.sequence.formatter.ts.md)

## Linked from

- [core/formatters](https://banes-lab.com/anatomy/docs/folder-docs-core-formatters.md)

## Source

```typescript
import {
    DIAGRAM_DESCRIPTIONS,
    DIAGRAM_LEGENDS,
    DIAGRAM_TITLES,
    orchestrationTitle,
} from "#configuration/strings/figure.strings";
import type { DiagramKind } from "#types/figure.types";
import type { SequenceModel } from "#types/diagram.types";
import { emitSequence } from "#core/formatters/diagram.sequence.formatter";

const MIN_PARTICIPANTS = 2;
const MIN_MESSAGES = 2;

export const diagram: DiagramKind = {
    appliesTo(context) {
        const protocol = context.codeGraph?.protocol ?? null;
        return (
            protocol !== null &&
            protocol.participants.length >= MIN_PARTICIPANTS &&
            protocol.messages.length >= MIN_MESSAGES
        );
    },
    id: "sequence",
    order: 6,
    render(context) {
        const protocol = context.codeGraph?.protocol ?? null;
        if (protocol === null || protocol.messages.length < MIN_MESSAGES) {
            return null;
        }
        const model: SequenceModel = {
            accDescr: DIAGRAM_DESCRIPTIONS.sequence,
            accTitle: orchestrationTitle(context.moduleName),
            autonumber: true,
            participants: [
                { id: protocol.self, label: protocol.self },
                ...protocol.participants.map((participant) => ({ id: participant, label: participant })),
            ],
            steps: protocol.messages.map((message) => ({
                message: {
                    from: protocol.self,
                    kind: message.async ? "async" : "sync",
                    text: message.text,
                    to: message.to,
                },
            })),
        };
        return { legend: DIAGRAM_LEGENDS.sequence, mermaid: emitSequence(model), sources: [] };
    },
    title: DIAGRAM_TITLES.sequence,
};
```
