Introducing a new way to review your PRs.

Read the announcement

ohif / viewers

OHIF zero-footprint DICOM viewer and oncology specific Lesion Tracker, plus shared extension packages

View on GitHub

21 documents · Updated Nov 23, 2026

docs / project-scaffolding-and-plugin-distribution

Project scaffolding and plugin distribution

create-ohif turns an OHIF idea into a workspace, extension, mode, or deployment setup. The plugin distribution flow then turns extensions and modes into host-compatible bundles, declares where the viewer can find them, and checks that published artifacts keep the runtime contract.

System boundary

Product role

The system separates authoring from delivery. Authors work in a managed workspace or a standalone package. A viewer later consumes the result as a build-time plugin or as a runtime bundle.

References: platform/…/create-ohif.mjs• L1-3 platform/…/publishing.md• L10-14

Composition relationship

The package name is the identity shared across the authoring and delivery paths. The same identity appears in package metadata, plugin declarations, and runtime descriptors so the host can match a loaded artifact to the extension or mode it registers.

Authoring unitProduct roleViewer entry
WorkspaceOwns plugins and viewer configurationWorkspace harness
ExtensionAdds viewer modules and UI capabilityextensions
ModeDefines a viewer workflowmodes
Deployment setupSupplies viewer configuration and container wiringDeployed viewer

References: platform/…/pluginConfig.schema.json• L24-44 platform/…/pluginConfig.md• L25-41

Workspace scaffolding

Workspace harness

The workspace template creates a small project that owns its plugin list and viewer settings while using a pinned OHIF checkout as its harness. The committed manifest is the durable project record. The .ohif/ checkout is disposable and can be recreated when the pinned version changes.

The normal workspace flow is:

flowchart LR
    A[ohif.config.json] --> B[Ensure pinned OHIF harness]
    C[Workspace extensions and modes] --> D[Link declared plugins]
    E[config/app-config.js] --> F[Sync viewer config]
    B --> G[Dev or production viewer]
    D --> G
    F --> G

Adding a plugin from inside the workspace updates the manifest. The next development or build command links that plugin into the harness, so the workspace stays the source of truth for its composition.

References: platform/…/ohif.config.json• L1-5 platform/…/ohif.mjs• L4-22 platform/…/ohif.mjs• L131-193

Standalone and in-tree packages

An extension or mode can live in its own repository or directly in an OHIF checkout. Standalone packages carry the build contract needed to produce a deployable bundle. In-tree packages use the checkout's shared workspace settings and version, then require a viewer declaration before they become part of the build.

The extension scaffold lets the author select the module types to create. The mode scaffold creates a workflow package. The generated files contain only the selected extension modules, which keeps the package's public surface aligned with its purpose.

References: platform/…/create-ohif.md• L28-43 platform/…/create-ohif.md• L82-105 platform/…/create-ohif.md• L115-143

Deployment setup

The deployment template addresses a different need from a plugin package. It creates viewer configuration and container setup without creating extension or mode code. This lets a team deploy an existing viewer composition or runtime plugin set without starting a new package.

References: platform/…/create-ohif.md• L28-35 platform/…/create-ohif.mjs• L444-450

Plugin package contract

Extension and mode artifacts

An extension or mode produces one UMD bundle under dist/. The bundle exposes the package by its package name and gives the host the plugin object as its default value. Extensions contribute viewer modules. Modes contribute workflows and depend on extensions for the modules their routes use.

The package metadata supports both local source use and published use. Local directory loading points at the source entry. Publishing rewrites the entry to the built UMD file and includes the source needed by directory consumers.

References: platform/…/rspack.prod.js• L17-33 platform/…/rspack.prod.js• L17-32 platform/…/publishing.md• L16-48

Host-shared dependency boundary

Plugins are built to run beside the viewer, not as separate applications. The bundle leaves host-owned libraries outside the artifact so the viewer supplies one shared copy. This boundary protects shared state such as React context and also lets a runtime plugin use the viewer's shared OHIF and imaging libraries.

When a runtime plugin needs another extension, the host must load that extension before the dependent plugin. A plugin must not assume that every package matching an OHIF or imaging namespace is available at runtime.

References: platform/…/pluginExternals.js• L1-16 platform/…/publishing.md• L50-67 platform/…/runtime-plugins.md• L86-108

Build-time and runtime registration

Build-time registration uses platform/…/pluginConfig.json to choose extensions and modes for the viewer build. Runtime registration uses descriptors in app-config.js to point at prebuilt bundles. A package can therefore be compiled into a viewer, linked from a local checkout, installed as a dependency, or loaded after the viewer is built.

The registration path still needs an explicit declaration. A package under extensions/ or modes/ is not loaded merely because its folder exists. The source location and the plugin identity must resolve together.

References: platform/…/pluginConfig.md• L8-22 platform/…/pluginConfig.md• L135-160 platform/…/runtime-plugins.md• L65-84

Distribution and validation

Published package path

The publish path is designed for a package registry. The author builds the UMD artifact, inspects the packed contents, and publishes with pnpm so the package metadata points at the deployable bundle. The package keyword also gives registry tools a way to identify extensions and modes.

OHIF's own release checks apply the same contract to its published SDK packages. Packages outside the approved SDK set remain private, which prevents internal workspace packages from being distributed by accident.

References: platform/…/publishing.md• L69-85 platform/…/publishing.md• L110-145 scripts/verify-tarballs.mjs• L28-50 scripts/verify-tarballs.mjs• L85-115

Runtime delivery

The official deployment path serves prebuilt bundles under /plugins/. Versioned paths are treated as immutable, so a new bundle uses a new version path. Unversioned paths revalidate on each load and suit local or fast-changing deployments.

Runtime descriptors name the package, bundle URL, UMD global, and compatible OHIF version range. A CDN can serve the same artifact, but the deployment must use an exact package version and provide the required origin and integrity controls.

References: platform/…/runtime-plugins.md• L33-63 platform/…/runtime-plugins.md• L65-118 platform/…/runtime-plugins.md• L120-155

Validation gates

Validation checks the link between declaration, package, host version, and artifact. The plugin helper checks config shape, source resolution, OHIF version compatibility, duplicate host libraries, and missing plugin references. Tarball checks then confirm that published packages contain usable entry points, resolved dependency versions, the UMD bundle, and no bundled React copy.

These gates cover different risks. The plugin helper protects the viewer's current composition. Tarball verification protects what other viewers will install. Both are needed because a package can work from a checkout and still fail after publication.

References: scripts/ohif-plugin.mjs• L476-595 scripts/ohif-plugin.mjs• L603-728 scripts/verify-tarballs.mjs• L239-315 scripts/verify-tarballs.mjs• L316-425

  • Viewer application composition explains how the viewer assembles extensions, modes, and services.
  • Application startup and runtime explains how the host starts and loads the resulting composition.
  • Create an extension or mode gives the command-level scaffolding guide.
  • Runtime plugins covers deployment and browser loading details.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the package name, plugin id, UMD global name, and every build-time or runtime declaration aligned.
  • When the shared host package set changes, update the plugin externals contract, runtime globals, and the version guidance used by migration and validation.
  • When a workspace pin changes, recreate the harness and re-link every manifest plugin before using the synced app config.
  • When a published bundle changes, update its versioned runtime path or accept the no-cache behavior of an unversioned path.
  • When the published package set changes, keep the release list, package privacy rules, and tarball verification set in sync.

Important failure modes

TriggerConsequenceGuard
A plugin exists in a workspace folder but is not declaredThe viewer ignores itAdd it to the workspace manifest or pluginConfig.json; run doctor
A plugin bundles a host-owned libraryDuplicate React state or other shared runtime failuresKeep host packages external; use the singleton and tarball checks
A runtime descriptor has an incompatible OHIF rangeThe host refuses to load the pluginKeep the descriptor range aligned with the package peer range and host version
A package is published with npm instead of pnpmPublished entry points can still target source filesUse pnpm packaging and inspect the packed manifest
A versioned plugin URL is overwrittenBrowsers can keep serving the old bytesPublish under a new version path and update the descriptor

Key files

FileWhy to read it
platform/…/create-ohif.mjsDefines the scaffold choices, context detection, and workspace manifest update
platform/…/ohif.mjsShows how a workspace pins, prepares, and runs its OHIF harness
platform/…/ohif.config.jsonShows the durable workspace composition record
platform/…/rspack.prod.jsShows the extension bundle boundary
platform/…/rspack.prod.jsShows the mode bundle boundary
platform/…/pluginConfig.schema.jsonDefines the accepted build-time plugin declaration shape
scripts/ohif-plugin.mjsManages plugin declarations and reports composition problems
scripts/verify-tarballs.mjsProtects the published package and dependency contract
platform/…/publishing.mdExplains the package-to-registry delivery path
platform/…/runtime-plugins.mdExplains serving and loading prebuilt runtime bundles