Server mode keeps the latest saved diagram visible beside an agent chat:
beautiflow server architecture.mmd
It is deliberately read-only and zero-configuration.
Lifecycle#
- Resolve and render the input file.
- Bind to
127.0.0.1, starting at port 4242. - Try subsequent ports through 4252 when occupied.
- Open the local URL in the default browser.
- Watch the source directory for changes to the Mermaid file or sidecar.
- Debounce writes for 80ms and re-render.
- Push state through Server-Sent Events.
- Stop on
Ctrl+CorSIGTERM.
HTTP endpoints#
/— read-only viewer HTML/diagram.svg— latest successful SVG/api/state— current revision, status, family, timestamp, and error/events— Server-Sent Events stream
All responses disable caching where appropriate.
Last-good-render behavior#
Agent edits are often written in multiple steps. A transient parse failure must not blank the viewer:
valid revision N
→ invalid save
→ status becomes error
→ revision N remains visible
→ valid save
→ revision N+1 replaces it
The page reports “Last render kept” with the parse error and automatically recovers.
File watching#
Beautiflow watches the containing directory rather than only an open file descriptor. This catches editors that save by writing a temporary file and atomically renaming it over the original. Only the source basename and expected sidecar basename trigger a render.
Browser update protocol#
The page opens one SSE connection. A successful revision causes it to fetch /diagram.svg?v=<revision> with caching disabled and replace the inline SVG. A 15-second heartbeat keeps intermediaries from considering the stream idle.
Security boundary#
- The server binds to localhost only.
- It exposes no write endpoints.
- It executes no Mermaid-provided JavaScript.
- It does not invoke an agent or model.
- It never runs
polish,apply, ortransform.
The undocumented BEAUTIFLOW_NO_OPEN=1 environment variable is used by automated tests and headless environments to suppress browser launching.
Viewer behavior#
The diagram owns the viewport below a 48px status rail. Desktop fits the complete SVG. Narrow screens keep a readable minimum diagram width and allow horizontal scrolling. The viewer respects reduced motion and uses semantic live/error regions.