# Ecosystem

A diagram language is only useful where people can write it, read about it and paste the result. This page is the
map of what exists around the Tritone library, where each piece lives, and what is still missing. It follows the
shape of Mermaid's ecosystem on purpose: whoever knows one finds their way in the other.

## The pieces

| Piece | Where | What it is | Its counterpart in Mermaid | State |
| --- | --- | --- | --- | --- |
| **Library** | `packages/tritone` | The story language, the renderers, the player, the plugin points | `mermaid`, in the `mermaid-js/mermaid` repository | Works. Not on npm |
| **Markdown plugin** | `tritone/markdown-it` | A `tritone` code block becomes an iframe, an image, or an element for a page that loads Tritone | Plugins written by the community | Works, for markdown-it only |
| **Editor extension** | `apps/vscode` | A `tritone` code block of a Markdown file plays in the preview of VS Code and of Cursor: the Markdown plugin, a script that mounts what it wrote, and Mermaid as a file for the blocks that are not stories | `mermaid-markdown-features`, which VS Code ships | First version: stories and Mermaid text. On no marketplace |
| **Highlighter** | `tritone/highlight` | Story text as markup, a class per kind of token | The grammars editors ship for Mermaid | Works, for stories |
| **Image handler** | `tritone/server` | A function from a request to a self-playing SVG | `mermaid.ink`, a separate project that drives a headless browser | Works, for stories |
| **Live editor** | `apps/live` | Write, watch, share: the editor, a React app, with the page an iframe shows and the image endpoint | `mermaid-js/mermaid-live-editor`, served at mermaid.live | First version |
| **MCP server** | `apps/mcp` | A tool a model calls with a story, and the player as its interface inside the conversation: an [MCP App](hosting.md#the-mcp-server), over Streamable HTTP and stdio | MCP servers by Mermaid Chart and by the community | First version, for stories. Checked with the SDK's own client and host; not tried in Claude or ChatGPT yet |
| **Site** | `apps/docs`, from `docs/` | The landing page, and the pages you are reading, with every example drawn, built by Astro | The site inside `mermaid-js/mermaid`, served at mermaid.js.org | First version |
| **Look** | `packages/ui` | A design system: tokens, components (a stylesheet and a React component each), the fonts, the mark and the theme switch. The editor draws the components in the browser, and the site's build writes their markup into its pages | | Internal |
| **Hosted site** | Two Vercel projects, `vercel.json`, `api/svg.js`, `api/mcp.js` | The site on one domain; the editor, its image endpoint and the MCP server on another | Three hosts: mermaid.live, mermaid.js.org, mermaid.ink | No public instance yet |

## How they fit

```text
                                  packages/tritone
                   the library: no dependencies, no DOM before the player
         ▲                    ▲                    ▲                    ▲
         │                    │                    │                    │  only through its
      apps/mcp             apps/live            apps/docs            apps/vscode   public exports
 MCP server, and the    editor (React),      landing page,        the extension: in the
 page a chat draws      embed page           docs/*.md → pages    preview of VS Code and
                                             (Astro)              Cursor, a block → the player
                              ▲                    ▲
                              └─── packages/ui ────┘  one look: tokens, and
         │                    │                    │  components in React
 editor.example.org    editor.example.org       example.org
 /mcp (api/mcp.js)     /  /live.html            /   /docs/
                       /embed.html
                       /svg/… (api/svg.js)
```

The extension is one more user of the library, with nothing of the live editor or of the site: it is two scripts,
with no page and no look of its own, since a diagram brings its own and the preview has its editor's.

The two apps do not know each other's code. Each is built on its own and links to the other by its address,
written in when it is built: `EDITOR_URL` in the site, `SITE_URL` in the editor ([hosting](hosting.md)). With
neither, the links are relative, and the two work on one domain when their files are put together. What they share
is how they look: a library of stylesheets and of functions that return markup, which Astro and React both write
into their pages.

The MCP server knows the code of neither. It links to the editor by `EDITOR_URL`, and the page it hands a host is
the library and nothing of the look: it is drawn inside another product, in that product's theme.

## One repository, for now

Mermaid is spread over several repositories: the library and its documentation in one, the live editor in
another, the command line tool in a third, and the image service is somebody else's project. That split fits a
library that is on npm and changes slowly.

Tritone keeps everything in one repository, as workspaces, because the language still moves: a new statement
touches the parser, the highlighter and the language reference, and those should land in one change.
Nothing is on npm either, so a separate editor would have nothing to depend on.

One rule keeps a later split cheap: **the apps import `tritone`, `tritone/highlight`, `tritone/markdown-it` and
`tritone/server`, and nothing else from the library.** They are ordinary users of it. Moving `apps/live` to a repository of its own is
then a move of one folder and a change of one dependency from `workspace:*` to a version. The time to do it is
when the library is on npm and the editor has a release rhythm of its own.

## What a server needs

Mermaid measures text in the page while it draws, so anything that draws it outside a browser (its command line
tool, mermaid.ink) has to run a headless one. Tritone's story renderer is a pure function from text to an SVG
string: labels are monospace, so their width is arithmetic. That is why the image endpoint is one small function
that runs on any JavaScript runtime, and why the documentation site can draw its own examples while it is built.
The MCP server checks a story the same way before it answers a model: it draws it.

It only holds for stories. Mermaid text is still parsed by Mermaid, in a browser, so graph views have no image
form and no build-time form.

## Not there yet

| Missing | Why it matters | In the meantime |
| --- | --- | --- |
| The npm package, and a CDN address | `import tritone from 'tritone'` outside this repository | Build the file: `bun run build:lib` |
| A public instance | Links, iframes, images and the MCP server need a host | [Run your own](hosting.md): one command |
| Graph views in a conversation | The MCP App shows stories only: Mermaid is fetched from another host, and the frame of an MCP App loads one only if its server declares it | Open the Mermaid text in the live editor |
| A command line tool | `tritone story.txt -o story.svg` in a build | `render(text)` in a three-line script |
| Plugins for remark, MDX and others | Most docs tools are not markdown-it | Write the `<iframe>` or the image by hand |
| The extension on the Marketplace and on Open VSX | Installing it from VS Code, and from Cursor, which reads Open VSX | Package it and install the file: CONTRIBUTING.md |
| Highlighting in an editor (VS Code and others) | Colours while you write a `tritone` block, outside the live editor | The live editor; `tritone/highlight` for a page of your own |
| Native support in hosts such as GitHub | A code block that draws itself, as Mermaid's does. It is GitHub's to add, and nobody else's | The [Markdown image](embedding.md#3-markdown-image), as a link to the diagram |
| Shorter addresses | A long story makes a long link | Addresses are plain base64, so a prefix can add compression later without breaking old links |
| History in the live editor | Getting back a diagram you closed | The address is the save file: bookmark it |

## Building on Tritone

| You want to | Use |
| --- | --- |
| Show a diagram in a page you control | The [custom element](embedding.md#4-custom-element) or [`run()`](embedding.md#5-api) |
| Show a story inside a conversation with a model | The [MCP server](hosting.md#the-mcp-server): add its address to Claude or ChatGPT |
| Show one where scripts are stripped | The [image](embedding.md#3-markdown-image), from the endpoint or committed as a file: [what each place allows](embedding.md#where-a-diagram-moves-and-where-it-answers) |
| Hand one to the reader of a chat that has no MCP server | A [link with the text in it](embedding.md#in-a-chat), which a model writes with no tool |
| Support `tritone` code blocks in a docs tool | `encode(text)` and the two address formats in [Embedding](embedding.md#1-iframe); the markdown-it plugin is fifty lines to copy from |
| Draw at build time or on a server | `render(text)`: no DOM needed for a story |
| Add shapes, layouts or a whole new kind of diagram | [Plugins](plugins.md) |
| Run the editor for your team | [Hosting](hosting.md) |