Skip to content

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:

  1. API router mount
  2. If extension provides router, it is mounted at:
  3. /api/v1/ext/{plugin_id}/...

  4. Static frontend asset mount

  5. If extension provides frontend_dir, it is mounted at:
  6. /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: str
  • display_name: str
  • api_version: str (currently "v1")
  • ui_compat_version: str (currently "1")
  • nav_items: list[GuiNavItem]
  • remote_modules: list[GuiRemoteModule]
  • Optional router (FastAPI APIRouter)
  • 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"

Inside plugin repo/package:

src/my_plugin/
  gui_extension.py
  gui_static/
    my_tool.js
  • gui_extension.py: backend router + extension manifest class
  • gui_static/my_tool.js: frontend module loaded by GUI shell

4. Backend Implementation Pattern

In gui_extension.py, define:

  1. router = APIRouter()
  2. Tool endpoints under /{tool_name}/... (the GUI host prefixes /api/v1/ext/{plugin_id})
  3. Extension class with metadata and static asset config

Typical endpoint set:

  • GET /{tool}/backends:
  • Return available compute backends and default backend.
  • POST /{tool}/run or POST /{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:

  1. GUI-specific helpers (caddforge-gui)
  2. Module: caddforge_gui.plugin_runtime
  3. Use for:
  4. artifact token encode/decode
  5. tool job list serialization
  6. upload staging and file moves
  7. run-dir path validation for artifact serving

  8. General runtime helpers (caddforge-core)

  9. Module: caddforge.core.runtime_helpers
  10. Use for:
  11. Slurm CLI availability checks
  12. backend availability payload generation
  13. registry path normalization
  14. 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:

  1. Exported function:
  2. Called as exported(window.CADDForge)
  3. If it returns HTMLElement, that element is mounted.

  4. 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:

import { ... } from "../../assets/plugin_uikit.js";

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()
    • modeSelect element
  • backendSection()

  • Standard runtime/backend panel with backend dropdown + Slurm settings.
  • API:

    • backendSelect
    • slurm fields:
    • partition, time, account, nodes, ntasks, cpusPerTask, sbatchOptions, setupCommands
    • setBackends(available, defaultBackend)
  • submitBar(label)

  • Submit button + status area + busy state.
  • API:
    • button
    • setStatus(message, tone) where tone is info|success|error
    • setBusy(boolean)

6.3 Reusable docking 3D viewer (Mol*)

Shared module: - caddforge-gui/src/caddforge_gui/static/assets/molstar_viewer.js

Import from plugin modules:

import { createDockingMolstarViewer } from "../../assets/molstar_viewer.js";

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:

  1. Build backend endpoints in plugin gui_extension.py.
  2. Return backend availability endpoint first.
  3. Add run endpoint and validate payload/form data.
  4. Add analysis/listing endpoints.
  5. Build frontend using UI kit:
  6. toolHero
  7. stepSection for each major flow step
  8. backendSection as final section
  9. submitBar for run action
  10. Register extension entry point.
  11. Verify manifest appears via /api/v1/gui/extensions.
  12. 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_entry URL.
  • 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_entry loads without import errors.
  • Uses shared UI kit primitives (no copy/paste local widgets).
  • Uses backendSection and submitBar for 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.