Host pattern
How the plugin SDK connects to the player through hosts.
Nuclear exposes player functionality to plugins through the host pattern. Every feature area the plugin system supports follows the same three-layer structure:
Host type - the contract (SDK, no implementation)
API class - what plugins actually call (SDK, wraps the host)
Host implementation - bridges the API to player internals (player)
Plugins call methods on an API class (e.g. api.Queue.addToQueue()), which holds a reference to the host and delegates to it.
The three layers
1. Host interface (packages/plugin-sdk/src/types/)
A TypeScript type with no implementation. Defines exactly what the player must provide for a domain.
// types/queue.ts
export type QueueHost = {
getQueue(): Queue;
addToQueue(tracks: Track[]): void;
// ...
};2. API class (packages/plugin-sdk/src/api/)
The surface plugins interact with. Holds an optional reference to the host and guards every call with #withHost, which throws if the host isn't present (e.g. in a test environment where no player is running).
All API classes are assembled into NuclearAPI in packages/plugin-sdk/src/api/index.ts, which is what plugins receive as their api object.
3. Host implementation (packages/player/src/services/)
Lives in the player. Implements the host interface and bridges it to whatever backs the domain - a Zustand store, a provider registry, a Tauri API, etc.
The singleton is passed into NuclearPluginAPI by createPluginAPI (packages/player/src/services/plugins/createPluginAPI.ts) when a plugin loads.
What hosts wrap
Queue, Settings, Favorites
Zustand store
Metadata, Streaming, Dashboard
Plugin provider registry and optional store
HTTP
Fetch wrapper (implemented in Rust)
Shell
Tauri shell API
Logger
Scoped logger
Provider-backed hosts resolve which registered provider to call and check capabilities where the domain supports them. See the Providers doc for how providers register and what kinds exist.
Data flow
When a plugin calls api.Metadata.search({ query: 'Radiohead' }):
Plugin calls
api.Metadata.search(params)MetadataAPI.#withHostchecks host is present, callsmetadataHost.search(params)metadataHostresolves the active metadata provider from the registrymetadataHostcallsprovider.searchArtists(params)(or whatever the provider implements)Provider calls its external API, returns
ArtistRef[]metadataHostreturnsSearchResultsto the plugin
Adding a new domain
Define the host interface in
packages/plugin-sdk/src/types/yourDomain.tsCreate the API class in
packages/plugin-sdk/src/api/yourDomain.ts- wraps the host with#withHostAdd the host option and API field to
NuclearAPIinpackages/plugin-sdk/src/api/index.tsImplement the host in
packages/player/src/services/yourDomainHost.tsPass the singleton into
NuclearPluginAPIincreatePluginAPI.ts
Last updated