# PraisonAIUI Integration

> Use interactive diagrams and automatic Mermaid upgrades in any PraisonAIUI docs site or chat app.

This documentation site is built with **PraisonAIUI** (`aiui`), which consumes `aidiagram-js` inside a lazy Markdown chunk (zero bytes on boot and zero bytes on `index.css`).

## How Integration Works

```diagram
type: flow
label: "PraisonAIUI routes supported Mermaid fences and diagram fences to the lazy aidiagram-js viewer."
eyebrow: Markdown Pipeline
numbered: true
steps:
  - title: Author Markdown
    note: "```mermaid or ```diagram"
    description: "Write standard Mermaid blocks or native 8-layout YAML specs in docs/."
  - title: Fidelity Check
    note: "aidiagram-js importer"
    description: "Verifies the entire Mermaid diagram can be represented with zero silent loss."
    highlight: true
  - title: Interactive Viewer
    note: "Lazy React SVG chunk"
    description: "Renders Play/Pause, keyboard stepping, hover focus, pan/zoom, SVG/PNG export, and a Classic toggle."
  - title: Classic Fallback
    note: "Streamdown Mermaid.js"
    description: "Unsupported or opted-out Mermaid diagrams pass verbatim to Mermaid.js."
    fallback: true
```

## Step 1: Write Standard Mermaid in Docs

Any supported `flowchart`, `graph`, or `sequenceDiagram` block inside `docs/` upgrades automatically:

````markdown
```mermaid
flowchart LR
  A[Open pull request] --> B[Review changes]
  B --> C[Maintainer decides whether to merge]
```
````

Readers can click **Classic** in the diagram toolbar at any time to switch back to static Mermaid.js.

## Step 2: Use Native `diagram` Fences in Docs & Chat

For `flow`, `loop`, `stack`, `fan`, `timeline`, `map`, or rich inspector fields (`description`, `code`, `href`), use a `diagram` fence (legacy aliases `visual` and `praisonai-visual` also work):

````markdown
```diagram
type: stack
label: Prompt inside Context inside Harness.
outer_dashed: true
layers:
  - { title: Harness, detail: "tools= · guardrails=" }
  - { title: Context, detail: "memory= · knowledge=" }
  - { title: Prompt, detail: "instructions= · schema=" }
```
````

## Step 3: Build & Serve Your Docs Site

```bash
pip install aiui
aiui validate --strict
aiui build --output aiui-output/
aiui serve --output aiui-output/ --port 8000
```

## Step 4: Opt Out Per Block

Place `%% diagram: off` (or `%% visual: off`) at the top of any `mermaid` fence to keep it on classic Mermaid.js permanently.

## Related pages

- [Keep Writing Mermaid](https://diagram.praison.ai/docs/getting-started/mermaid.md)
- [Fan Layout](https://diagram.praison.ai/docs/layouts/fan.md)
- [Python CLI & API](https://diagram.praison.ai/docs/guides/python-cli.md)
