Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

ADR 0007: Custom Plugin API via Subprocess Protocol

Context

Users need to extend Kroki-rs with custom diagram providers without modifying the core codebase. The plugin system must work identically for both CLI and server usage, meaning it belongs in the core library (not the server layer).

Decision

Subprocess Protocol

Plugins are external executables that follow a simple stdin/stdout contract:

  1. Kroki-rs pipes diagram source text to the plugin’s stdin.

  2. The plugin writes rendered output (SVG/PNG bytes) to stdout.

  3. Exit code 0 = success; non-zero = failure (stderr captured for error messages).

This is the same pattern used by the built-in CommandProvider and run_process_with_timeout().

Configuration

[[plugins]]
name = "my-custom-diagram"
command = "/usr/local/bin/my-renderer"
args = ["--format", "{format}"]
stdin = true
formats = ["svg", "png"]
timeout_ms = 5000

{format} in args is template-substituted at invocation time with the requested output format.

Registration

Core Library Placement

The PluginProvider struct and registration logic live in src/diagrams/plugin.rs, ensuring they are available to both CLI (kroki-rs convert --type my-custom-diagram) and server (GET /my-custom-diagram/svg/...) modes. This prepares for the v0.0.6 workspace split where plugins will be part of kroki-core.

Consequences

TODO