This document describes the structure of the sample plugin at a more detailed level.
sample-plugin/
├── backend/
│ ├── Cargo.toml
│ └── src/lib.rs # Extism entry point
├── frontend/
│ └── index.mjs # ESM frontend module
├── plugin.json # Manifest for distribution
├── README.md
└── docs/
├── overview.md
└── architecture.md # (this file)
- Rust crate (
sample_plugin_backend) compiled towasm32-wasip1. - Single entry function
exec(Json<ExecInput>)matching RefMD’s ABI. - Pattern matches on
sample.*actions and emits effects likecreateDocument,createRecord,deleteRecord,showToast,navigate. - Helper functions guard required fields (
require_doc_id,require_record_id) and reduce duplication. - The WASM artifact is copied to
plugins/sample/0.1.0/backend/plugin.wasmby the publish script.
- Default export
mount(container, host)builds the DOM using template literals—no framework dependency. - Relies on the
sample.createExtism command to provision demo documents via effects (createDocument,putKv,navigate). - When mounted on
/sample/<docId>, resolves the identifier from the current path and operates on that document only. It expects the document to havemeta.isSample = true(set by the backend command) so the host can reroute it. - Simple event delegation handles button clicks (
say-hello,reload-records, etc.) and form submission for creating records. - Markdown rendering uses the host’s server-side pipeline so it stays consistent with the main app features.
canOpenandgetRouteare exported so the host router can map documents withtype: 'sample'back to/sample/<docId>.
plugin.jsondeclares:id: "sample"frontend.entry: "index.mjs", mode: "esm"backend.wasm: "backend/plugin.wasm"mounts: ["/sample/*"]commands: ["sample.create", "sample.hello", ...]ui.toolbarexposing "New Sample Document" (sample.create)ui.fileTree.identifyusingkvFlag(meta.isSample == true)to reacquire demo documentsauthor/repositorymetadata exposed to the host UI