Plugin GUI Authoring Guide¶
This guide explains exactly how to add a GUI page for a CADDForge plugin/tool. It covers:
- Discovery and registration
- Backend API wiring
- Frontend module wiring
- Shared UI abstractions from
plugin_uikit.js - Shared backend helper abstractions from
plugin_runtime.py - Recommended patterns and checklist
Use this as the source of truth when implementing new plugin GUIs.
1. Runtime Architecture¶
caddforge-gui loads plugin GUI extensions via Python entry points and exposes them in two ways:
- API router mount
- If extension provides
router, it is mounted at: -
/api/v1/ext/{plugin_id}/... -
Static frontend asset mount
- If extension provides
frontend_dir, it is mounted at: /static/ext/{plugin_id}/...
The GUI shell asks /api/v1/gui/extensions for extension manifests, then dynamically imports each extension remote_entry.
2. Required Extension Contract¶
Extension discovery contract is defined in caddforge-core:
- caddforge-core/src/caddforge/gui/extensions.py
Your extension object/class must provide:
plugin_id: strdisplay_name: strapi_version: str(currently"v1")ui_compat_version: str(currently"1")nav_items: list[GuiNavItem]remote_modules: list[GuiRemoteModule]- Optional
router(FastAPIAPIRouter) - Optional
frontend_dir: str - Optional
remote_entry: str
Entry point registration¶
Register in plugin pyproject.toml:
[project.entry-points."caddforge.gui_extensions"]
my-plugin-gui = "my_plugin.gui_extension:MyGuiExtension"
3. Recommended Plugin File Layout¶
Inside plugin repo/package:
gui_extension.py: backend router + extension manifest classgui_static/my_tool.js: frontend module loaded by GUI shell
4. Backend Implementation Pattern¶
In gui_extension.py, define:
router = APIRouter()- Tool endpoints under
/{tool_name}/...(the GUI host prefixes/api/v1/ext/{plugin_id}) - Extension class with metadata and static asset config
Typical endpoint set:
GET /{tool}/backends:- Return available compute backends and default backend.
POST /{tool}/runorPOST /{tool}/run-upload:- Validate form/payload and submit job.
GET /{tool}/jobs:- List tool-specific jobs for analysis dropdowns.
GET /{tool}/analysis/{job_id}:- Return summary and artifact links.
4.1 Reusable backend helper modules¶
Use these instead of duplicating route helper code:
- GUI-specific helpers (
caddforge-gui) - Module:
caddforge_gui.plugin_runtime - Use for:
- artifact token encode/decode
- tool job list serialization
- upload staging and file moves
-
run-dir path validation for artifact serving
-
General runtime helpers (
caddforge-core) - Module:
caddforge.core.runtime_helpers - Use for:
- Slurm CLI availability checks
- backend availability payload generation
- registry path normalization
- Slurm backend construction from config
5. Frontend Module Contract¶
Current GUI shell (src/caddforge_gui/static/assets/app.js) loads extension modules and expects one of:
- Exported function:
- Called as
exported(window.CADDForge) -
If it returns
HTMLElement, that element is mounted. -
Exported object with
mount(host, window.CADDForge)function.
For plugin modules, defaulting to a function that returns HTMLElement is simplest.
6. Shared UI Abstractions (Use These)¶
Shared module:
- caddforge-gui/src/caddforge_gui/static/assets/plugin_uikit.js
From an extension module located at /static/ext/{plugin_id}/..., import with:
This resolves to /static/assets/plugin_uikit.js.
6.1 Low-level primitives¶
input(type, placeholder)numberInput(value)select(options)checkbox(checked)textarea(placeholder)field(label, control, { required, tip })row(items, minWidth)section(title)sectionNote(text)collapsible(title, open)createFilePicker(accept)createPathOrFileInput(accept, { pathPlaceholder })toolHero(title, subtitle)
6.2 Mid-level reusable patterns¶
stepSection(stepNumber, title, note)-
Standard “Step N - ...” container.
-
modeSwitchSection({ label, tip, modes, defaultMode }) - Generic mode selector + mode panel switching.
-
API:
addModePanel(modeValue, panelElement)setMode(value)getMode()modeSelectelement
-
backendSection() - Standard runtime/backend panel with backend dropdown + Slurm settings.
-
API:
backendSelectslurmfields:partition,time,account,nodes,ntasks,cpusPerTask,sbatchOptions,setupCommandssetBackends(available, defaultBackend)
-
submitBar(label) - Submit button + status area + busy state.
- API:
buttonsetStatus(message, tone)where tone isinfo|success|errorsetBusy(boolean)
6.3 Reusable docking 3D viewer (Mol*)¶
Shared module:
- caddforge-gui/src/caddforge_gui/static/assets/molstar_viewer.js
Import from plugin modules:
Purpose: - Provides a consistent Mol* viewer panel to inspect receptor + docked poses. - Handles lazy-loading Mol* assets from CDN. - Exposes a simple dataset API so tool-specific pages only provide artifact URLs.
API:
- createDockingMolstarViewer({ title, description }) returns:
- panel: HTMLElement
- setDataset({ receptorFile, poseFiles })
- setPoseSequence(sequenceItems) for Prev/Next navigation across many poses
- selectSequenceById(sequenceId, { autoLoad? })
- setStatus(message, tone?)
- loadAdhocPose({ name, url, format?, complexUrl?, surroundingsUrl? })
Dataset shape:
- receptorFile:
- { name, url, format? } or null
- poseFiles:
- list of { id, name, url, format?, complexUrl?, surroundingsUrl? }
- sequenceItems (optional):
- list of { id, name, url?, format?, complexUrl?, surroundingsUrl? }
Notes:
- url values should be absolute or already prefixed with GUI base path.
- format can be omitted; the viewer infers by file extension.
- If no receptor is available, pose-only viewing still works.
- If complexUrl is present, the viewer loads the merged protein+ligand file directly (single-file complex mode).
- The shared viewer also provides built-in Prev Pose/Next Pose controls, supports left/right arrow-key cycling
when a sequence is configured, and prefetches adjacent sequence items for faster navigation.
7. Golden Implementation Sequence¶
When adding a new tool GUI:
- Build backend endpoints in plugin
gui_extension.py. - Return backend availability endpoint first.
- Add run endpoint and validate payload/form data.
- Add analysis/listing endpoints.
- Build frontend using UI kit:
toolHerostepSectionfor each major flow stepbackendSectionas final sectionsubmitBarfor run action- Register extension entry point.
- Verify manifest appears via
/api/v1/gui/extensions. - Verify extension route and job submission flow end-to-end.
8. Minimal Skeleton¶
8.1 Python extension skeleton¶
from fastapi import APIRouter
from caddforge.gui import GuiNavItem, GuiRemoteModule
from caddforge.core.runtime_helpers import (
build_slurm_backend_from_config,
detect_available_backends,
normalize_registry_path,
)
from caddforge_gui.plugin_runtime import (
decode_path_token,
encode_path_token,
ensure_job_within_run_dir,
list_tool_jobs,
make_staging_dir,
move_to_directory,
store_upload,
)
router = APIRouter()
@router.get("/mytool/backends")
def mytool_backends():
return {"available": ["local"], "default": "local"}
class MyGuiExtension:
plugin_id = "myplugin"
display_name = "My Plugin"
api_version = "v1"
ui_compat_version = "1"
nav_items = [GuiNavItem(path="/mytool", label="My Tool", module="default", export="default", order=50)]
remote_modules = [GuiRemoteModule(module="default", export="default")]
router = router
frontend_dir = "..."
remote_entry = "my_tool.js"
8.2 JS extension skeleton¶
import { toolHero, stepSection, backendSection, submitBar } from "../../assets/plugin_uikit.js";
export default function MyToolPage() {
const root = document.createElement("div");
root.style.display = "grid";
root.style.gap = "1rem";
const hero = toolHero("My Tool", "Run My Tool jobs.");
const step1 = stepSection(1, "Inputs", "Provide required inputs.");
const runtime = backendSection();
const actions = submitBar("Submit My Tool Job");
actions.button.onclick = async () => {
actions.setBusy(true);
try {
actions.setStatus("Submitting...");
// submit...
actions.setStatus("Submitted.", "success");
} catch (err) {
actions.setStatus(`Submission failed: ${err.message || err}`, "error");
} finally {
actions.setBusy(false);
}
};
root.appendChild(hero);
root.appendChild(step1.panel);
root.appendChild(runtime.panel);
root.appendChild(actions.container);
return root;
}
9. Versioning and Compatibility¶
Keep these aligned with GUI shell compatibility:
api_version = "v1"ui_compat_version = "1"
If compatibility changes in caddforge-gui, update plugin manifests accordingly.
10. Debugging and Validation¶
Useful checks:
GET /api/v1/gui/extensions- Verify plugin manifest fields and
remote_entryURL. - Open browser DevTools network panel:
- Check extension JS and API requests.
- Validate relative import path to UI kit:
- Extension module path:
/static/ext/{plugin_id}/... - UI kit path:
../../assets/plugin_uikit.js
11. Quality Checklist (Before Merge)¶
- Entry point registered under
caddforge.gui_extensions. - Extension appears in
/api/v1/gui/extensions. remote_entryloads without import errors.- Uses shared UI kit primitives (no copy/paste local widgets).
- Uses
backendSectionandsubmitBarfor consistent runtime UX. - Required/optional inputs clearly marked.
- Run submission validates before request.
- Error/success states visible in submit status area.
- Tool jobs and analysis endpoints behave correctly.
- README/doc updated with tool-specific usage notes.