---
title: "Illustrative · Sequence"
description: "Sequence diagrams with the diagram component - participants, lifelines, calls and dashed returns, self messages, a flow token; message by message and as a protocol delta."
slug: "diagram-sequence"
---

import { DocPage, PageHeader, DocLink, DocText, H2, SourceFiles, SourceNote } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="diagram-sequence" title="Illustrative · Sequence" component="diagram">
  Who says what, in which order: participants on top, the edge list inside the canvas - one row per message, time running down. Calls are solid, returns <code>data-line="dashed"</code> with an open head, an edge to the same participant is a self message.
</PageHeader>

<H2 id="example">Example</H2>

```html example label="Authorization code + PKCE" component="diagram" hint="In a sequence the list is inside .diagram-canvas: its rows give the messages their height."
<figure class="diagram" id="dg-seq" data-type="sequence" aria-label="OAuth 2.0 authorization code flow with PKCE">
  <figcaption class="diagram-caption">
    <span class="diagram-eyebrow">Sequence</span>
    <span class="diagram-title">Sign-in: authorization code + PKCE</span>
    <span class="diagram-dek">Time runs down. Calls are solid, returns dashed; the token response is the accent.</span>
  </figcaption>
  <div class="diagram-canvas" style="--cols: 4">
    <div class="diagram-node" data-node="user">
      <span class="diagram-node-eyebrow">Actor</span>
      <span class="diagram-node-name">User</span>
    </div>
    <div class="diagram-node" data-node="app">
      <span class="diagram-node-eyebrow">SPA</span>
      <span class="diagram-node-name">Browser app</span>
    </div>
    <div class="diagram-node" data-node="auth" data-tone="accent">
      <span class="diagram-node-eyebrow">IdP</span>
      <span class="diagram-node-name">Auth server</span>
    </div>
    <div class="diagram-node" data-node="api">
      <span class="diagram-node-eyebrow">Resource</span>
      <span class="diagram-node-name">Orders API</span>
    </div>
    <ol class="diagram-edges">
      <li class="diagram-edge" data-from="user" data-to="app">click “Sign in”</li>
      <li class="diagram-edge" data-from="app" data-to="app">make verifier + challenge</li>
      <li class="diagram-edge" data-from="app" data-to="auth">GET /authorize ?code_challenge</li>
      <li class="diagram-edge" data-from="auth" data-to="user" data-line="dashed">login + consent</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed">302 ?code=…</li>
      <li class="diagram-edge" data-from="app" data-to="auth">POST /token code + verifier</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-tone="accent" data-flow="1600"
        >access + refresh token</li
      >
      <li class="diagram-edge" data-from="app" data-to="api">GET /orders · Bearer</li>
      <li class="diagram-edge" data-from="api" data-to="app" data-line="dashed">200 orders</li>
    </ol>
  </div>
</figure>
```

<H2 id="step-by-step">Step by step</H2>

```html example label="Message by message" component="diagram" hint="A sequence plays its messages in order - no data-step needed."
<figure
  class="diagram"
  id="dg-seq-steps"
  data-type="sequence"
  data-steps
  data-autoplay
  aria-label="OAuth 2.0 authorization code flow with PKCE"
>
  <figcaption class="diagram-caption">
    <span class="diagram-eyebrow">Sequence</span>
    <span class="diagram-title">Sign-in: authorization code + PKCE</span>
    <span class="diagram-dek">Time runs down. Calls are solid, returns dashed; the token response is the accent.</span>
  </figcaption>
  <div class="diagram-canvas" style="--cols: 4">
    <div class="diagram-node" data-node="user">
      <span class="diagram-node-eyebrow">Actor</span>
      <span class="diagram-node-name">User</span>
    </div>
    <div class="diagram-node" data-node="app">
      <span class="diagram-node-eyebrow">SPA</span>
      <span class="diagram-node-name">Browser app</span>
    </div>
    <div class="diagram-node" data-node="auth" data-tone="accent">
      <span class="diagram-node-eyebrow">IdP</span>
      <span class="diagram-node-name">Auth server</span>
    </div>
    <div class="diagram-node" data-node="api">
      <span class="diagram-node-eyebrow">Resource</span>
      <span class="diagram-node-name">Orders API</span>
    </div>
    <ol class="diagram-edges">
      <li class="diagram-edge" data-from="user" data-to="app">click “Sign in”</li>
      <li class="diagram-edge" data-from="app" data-to="app">make verifier + challenge</li>
      <li class="diagram-edge" data-from="app" data-to="auth">GET /authorize ?code_challenge</li>
      <li class="diagram-edge" data-from="auth" data-to="user" data-line="dashed">login + consent</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed">302 ?code=…</li>
      <li class="diagram-edge" data-from="app" data-to="auth">POST /token code + verifier</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-tone="accent" data-flow="1600"
        >access + refresh token</li
      >
      <li class="diagram-edge" data-from="app" data-to="api">GET /orders · Bearer</li>
      <li class="diagram-edge" data-from="api" data-to="app" data-line="dashed">200 orders</li>
    </ol>
  </div>
</figure>
```

<H2 id="interactive">Interactive</H2>

<DocText>A click activates a box or an arrow: what it touches stays lit, everything else steps back. The buttons outside the figure drive the same activation - <code>data-diagram-for</code> + <code>data-diagram-action="next|prev|clear"</code> - and the <code>&lt;output data-diagram-for&gt;</code> names what is active. Keyboard: Tab to a box, Enter, arrows, Escape.</DocText>

```html example label="Implicit flow → PKCE" component="diagram" hint="A changed message keeps its old text in data-before; added and removed messages keep their row in Changes."
<figure
  class="diagram"
  id="dg-seq-delta"
  data-type="sequence"
  data-delta
  aria-label="Implicit flow to code flow with PKCE"
>
  <figcaption class="diagram-caption">
    <span class="diagram-eyebrow">Protocol change</span>
    <span class="diagram-title">From the implicit flow to PKCE</span>
  </figcaption>
  <div class="diagram-canvas" style="--cols: 3">
    <div class="diagram-node" data-node="app">
      <span class="diagram-node-eyebrow">SPA</span>
      <span class="diagram-node-name">Browser app</span>
    </div>
    <div class="diagram-node" data-node="auth">
      <span class="diagram-node-eyebrow">IdP</span>
      <span class="diagram-node-name">Auth server</span>
    </div>
    <div class="diagram-node" data-node="api">
      <span class="diagram-node-eyebrow">Resource</span>
      <span class="diagram-node-name">Orders API</span>
    </div>
    <ol class="diagram-edges">
      <li class="diagram-edge" data-from="app" data-to="app" data-change="added">make verifier + challenge</li>
      <li
        class="diagram-edge"
        data-from="app"
        data-to="auth"
        data-change="changed"
        data-before="GET /authorize ?response_type=token"
        >GET /authorize ?code_challenge</li
      >
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-change="removed"
        >#access_token=… in the URL</li
      >
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-change="added">302 ?code=…</li>
      <li class="diagram-edge" data-from="app" data-to="auth" data-change="added">POST /token code + verifier</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-tone="accent" data-change="added"
        >access + refresh token</li
      >
      <li class="diagram-edge" data-from="app" data-to="api">GET /orders · Bearer</li>
    </ol>
  </div>
</figure>
```

```html example label="Sequence, interactive" component="diagram" hint="data-interactive on the figure; nothing else to write - the controls and the output are declared in markup, no script."
<div class="flex flex-wrap items-center gap-2 mb-3">
  <button class="btn" data-variant="outline" data-size="sm" data-diagram-for="dg-seq-live" data-diagram-action="prev"
    >Previous</button
  >
  <button class="btn" data-variant="outline" data-size="sm" data-diagram-for="dg-seq-live" data-diagram-action="next"
    >Next</button
  >
  <button class="btn" data-variant="ghost" data-size="sm" data-diagram-for="dg-seq-live" data-diagram-action="clear"
    >Clear</button
  >
  <output class="text-sm text-muted-foreground" data-diagram-for="dg-seq-live"
    >Click a box or an arrow - or press Next.</output
  >
</div>
<figure
  class="diagram"
  id="dg-seq-live"
  data-interactive
  data-type="sequence"
  aria-label="OAuth 2.0 authorization code flow with PKCE"
>
  <figcaption class="diagram-caption">
    <span class="diagram-eyebrow">Sequence</span>
    <span class="diagram-title">Sign-in: authorization code + PKCE</span>
    <span class="diagram-dek">Time runs down. Calls are solid, returns dashed; the token response is the accent.</span>
  </figcaption>
  <div class="diagram-canvas" style="--cols: 4">
    <div class="diagram-node" data-node="user">
      <span class="diagram-node-eyebrow">Actor</span>
      <span class="diagram-node-name">User</span>
    </div>
    <div class="diagram-node" data-node="app">
      <span class="diagram-node-eyebrow">SPA</span>
      <span class="diagram-node-name">Browser app</span>
    </div>
    <div class="diagram-node" data-node="auth" data-tone="accent">
      <span class="diagram-node-eyebrow">IdP</span>
      <span class="diagram-node-name">Auth server</span>
    </div>
    <div class="diagram-node" data-node="api">
      <span class="diagram-node-eyebrow">Resource</span>
      <span class="diagram-node-name">Orders API</span>
    </div>
    <ol class="diagram-edges">
      <li class="diagram-edge" data-from="user" data-to="app">click “Sign in”</li>
      <li class="diagram-edge" data-from="app" data-to="app">make verifier + challenge</li>
      <li class="diagram-edge" data-from="app" data-to="auth">GET /authorize ?code_challenge</li>
      <li class="diagram-edge" data-from="auth" data-to="user" data-line="dashed">login + consent</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed">302 ?code=…</li>
      <li class="diagram-edge" data-from="app" data-to="auth">POST /token code + verifier</li>
      <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-tone="accent" data-flow="1600"
        >access + refresh token</li
      >
      <li class="diagram-edge" data-from="app" data-to="api">GET /orders · Bearer</li>
      <li class="diagram-edge" data-from="api" data-to="app" data-line="dashed">200 orders</li>
    </ol>
  </div>
</figure>
```

<H2 id="inspect">Inspect and edit</H2>

<DocText>Select, inspect, edit: a click hands the selection to a <a class="link" href="property-grid.html">Property Grid</a> in a closable <a class="link" href="panel.html">Panel</a> - <code>df$.shadcn.diagram.properties()</code> reads the box or the arrow as JSON, <code>propertySchema()</code> gives the grid its options, <code>setProperties()</code> writes an edit back and the diagram redraws. The × closes the panel, the Inspector button toggles it.</DocText>

```html example label="Sequence, inspect and edit" component="diagram" hint="Edit a name, the tone, the shape - or an arrow's label, line and ends: the diagram follows."
<div class="flex items-center gap-2 mb-3">
  <button type="button" class="btn" data-variant="outline" data-size="sm" data-panel-toggle="dg-seq-edit-panel"
    ><i data-lucide="panel-right"></i> Inspector</button
  >
  <span class="text-sm text-muted-foreground">Click a box or an arrow, then edit it.</span>
</div>
<div class="flex flex-col gap-3">
  <div style="flex: 1 1 0; min-width: 0">
    <figure
      class="diagram"
      id="dg-seq-edit"
      data-interactive
      data-type="sequence"
      aria-label="OAuth 2.0 authorization code flow with PKCE"
    >
      <figcaption class="diagram-caption">
        <span class="diagram-eyebrow">Sequence</span>
        <span class="diagram-title">Sign-in: authorization code + PKCE</span>
        <span class="diagram-dek"
          >Time runs down. Calls are solid, returns dashed; the token response is the accent.</span
        >
      </figcaption>
      <div class="diagram-canvas" style="--cols: 4">
        <div class="diagram-node" data-node="user">
          <span class="diagram-node-eyebrow">Actor</span>
          <span class="diagram-node-name">User</span>
        </div>
        <div class="diagram-node" data-node="app">
          <span class="diagram-node-eyebrow">SPA</span>
          <span class="diagram-node-name">Browser app</span>
        </div>
        <div class="diagram-node" data-node="auth" data-tone="accent">
          <span class="diagram-node-eyebrow">IdP</span>
          <span class="diagram-node-name">Auth server</span>
        </div>
        <div class="diagram-node" data-node="api">
          <span class="diagram-node-eyebrow">Resource</span>
          <span class="diagram-node-name">Orders API</span>
        </div>
        <ol class="diagram-edges">
          <li class="diagram-edge" data-from="user" data-to="app">click “Sign in”</li>
          <li class="diagram-edge" data-from="app" data-to="app">make verifier + challenge</li>
          <li class="diagram-edge" data-from="app" data-to="auth">GET /authorize ?code_challenge</li>
          <li class="diagram-edge" data-from="auth" data-to="user" data-line="dashed">login + consent</li>
          <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed">302 ?code=…</li>
          <li class="diagram-edge" data-from="app" data-to="auth">POST /token code + verifier</li>
          <li class="diagram-edge" data-from="auth" data-to="app" data-line="dashed" data-tone="accent" data-flow="1600"
            >access + refresh token</li
          >
          <li class="diagram-edge" data-from="app" data-to="api">GET /orders · Bearer</li>
          <li class="diagram-edge" data-from="api" data-to="app" data-line="dashed">200 orders</li>
        </ol>
      </div>
    </figure>
  </div>
  <section class="card panel" id="dg-seq-edit-panel" aria-labelledby="dg-seq-edit-title" style="">
    <header class="panel-header">
      <i data-lucide="sliders-horizontal" class="panel-icon" aria-hidden="true"></i>
      <h3 class="panel-title" id="dg-seq-edit-title">Inspector</h3>
      <div class="panel-tools">
        <button
          type="button"
          class="btn panel-close"
          data-variant="ghost"
          data-size="icon-sm"
          aria-label="Close Inspector"
          ><i data-lucide="x"></i
        ></button>
      </div>
    </header>
    <div class="panel-body" data-flush>
      <div
        class="property-grid"
        id="dg-seq-edit-grid"
        data-frame="none"
        data-empty-text="Click a box or an arrow."
        aria-label="Selection properties"
      ></div>
    </div>
  </section>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const { diagram, propertyGrid } = df$.shadcn;
    const fig = document.getElementById('dg-seq-edit');
    const grid = document.getElementById('dg-seq-edit-grid');
    const title = document.getElementById('dg-seq-edit-title');
    let ref = null;
    // a selection: its properties (and their options) into the grid
    fig.addEventListener('diagram-activate', (e) => {
      ref = e.detail.ref;
      title.textContent = ref ? 'Inspector · ' + e.detail.label : 'Inspector';
      propertyGrid.configure(grid, { sourceConfig: ref ? diagram.propertySchema(fig, ref) : {} });
      propertyGrid.setSource(grid, ref ? diagram.properties(fig, ref) : {});
    });
    // an edit: back into the diagram, which redraws
    grid.addEventListener('property-grid-change', (e) => {
      if (ref) diagram.setProperties(fig, ref, e.detail.source);
    });
  });
</script>
```

<H2 id="delta">Delta</H2>

<p class="text-sm text-muted-foreground">Rendered by the <a class="link" href="diagram.html">diagram</a> component - plain HTML nodes, an edge list, wires drawn from the measured layout; colors from the theme tokens, so every theme and dark mode apply. Visual grammar adapted from <a class="link" href="https://github.com/cathrynlavery/diagram-design">diagram-design</a> by Cathryn Lavery (MIT).</p>

<SourceFiles component="diagram">
  <SourceNote for="css">The diagram stylesheet - every type on this page is a preset in it.</SourceNote>
  <SourceNote for="js">The engine every example converges on: wire routing, steps, delta panels, specs and the State API.</SourceNote>
</SourceFiles>

</DocPage>
