Skip to main content

Understanding plugin system

The Scope plugin system enables third-party extensions to provide custom pipelines. This document describes the architectural design and data flows that enable plugin discovery, installation, and lifecycle management.

Architecture Layers

Desktop App (Electron) → Frontend (React) → Backend (FastAPI) → Plugins
Each layer has distinct responsibilities, communicating through well-defined interfaces.

Key Technologies

  • pluggy: Python hook system for pipeline registration and discovery
  • uv: Fast Python package manager for dependency resolution and installation
  • Electron IPC: Communication bridge between desktop app and frontend

System Architecture

┌─────────────────────────────────────────────────────────────────┐
│                        Desktop App (Electron)                    │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────────┐  │
│  │ Deep Links  │───▶│  IPC Bridge  │◀──▶│ Python Process    │  │
│  │ File Browse │    │              │    │ Manager           │  │
│  └─────────────┘    └──────────────┘    └───────────────────┘  │
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│                         Frontend (React)                         │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────────┐  │
│  │ Settings UI │───▶│  API Client  │───▶│ State Management  │  │
│  └─────────────┘    └──────────────┘    └───────────────────┘  │
└─────────────────────────────────────────────────────────────────┘
                              │ HTTP

┌─────────────────────────────────────────────────────────────────┐
│                      Backend (FastAPI)                           │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────────┐  │
│  │  REST API   │───▶│Plugin Manager│───▶│ Pipeline Registry │  │
│  └─────────────┘    └──────────────┘    └───────────────────┘  │
│                              │                                   │
│                     ┌────────┴────────┐                         │
│                     ▼                 ▼                         │
│              ┌────────────┐    ┌────────────┐                   │
│              │ Dependency │    │   Venv     │                   │
│              │ Validator  │    │ Snapshot   │                   │
│              └────────────┘    └────────────┘                   │
└─────────────────────────────────────────────────────────────────┘

Plugin Discovery

Plugins integrate with Scope through Python’s entry point mechanism:
  1. Plugins declare entry points in their pyproject.toml under [project.entry-points."scope"]
  2. The backend uses pluggy hooks to discover installed plugins at startup
  3. Each plugin implements a register_pipelines hook to register its pipeline implementations
  4. The Pipeline Registry maintains a mapping of pipeline IDs to their implementations

Plugin Sources

SourceDescription
PyPIStandard Python packages
GitDirect repository installation
LocalFile system paths (editable mode for development)

Installation Flow

User                Frontend              Backend              Desktop App
 │                    │                     │                      │
 │ Click Install      │                     │                      │
 │───────────────────▶│                     │                      │
 │                    │ POST /plugins       │                      │
 │                    │────────────────────▶│                      │
 │                    │                     │ Validate deps        │
 │                    │                     │────────┐             │
 │                    │                     │◀───────┘             │
 │                    │                     │ Capture venv         │
 │                    │                     │────────┐             │
 │                    │                     │◀───────┘             │
 │                    │                     │ Install via uv       │
 │                    │                     │────────┐             │
 │                    │                     │◀───────┘             │
 │                    │     200 OK          │                      │
 │                    │◀────────────────────│                      │
 │                    │ Request restart     │                      │
 │                    │─────────────────────────────────────────────▶
 │                    │                     │                      │ Respawn
 │                    │                     │                      │────────┐
 │                    │                     │                      │◀───────┘
 │                    │ Poll health         │                      │
 │                    │────────────────────▶│                      │
 │                    │ Refresh pipelines   │                      │
 │                    │────────────────────▶│                      │
Installation steps:
  1. User initiates install (UI or deep link)
  2. Frontend sends install request to backend API
  3. Backend validates dependencies won’t conflict with existing environment
  4. Backend captures current venv state (for rollback)
  5. Backend resolves and installs dependencies via uv
  6. Backend updates plugin registry
  7. Frontend triggers server restart
  8. Server restarts with new plugin loaded
  9. Frontend polls until server is healthy
  10. Frontend refreshes pipeline list
Rollback: If installation fails at any step, the venv is restored to its captured state.

Plugin Update Flow

The update flow has two phases: detection (happens automatically when plugins are listed) and execution (triggered by the user). The execution phase reuses the installation flow with an upgrade: true flag.

Update Detection

Frontend                        Backend
 │                                │
 │ GET /plugins                   │
 │───────────────────────────────▶│
 │                                │ For each plugin:
 │                                │ _check_plugin_update()
 │                                │────────┐
 │                                │        │ Compare installed
 │                                │        │ vs latest version
 │                                │◀───────┘
 │  Plugin list                   │
 │  (with update_available flags) │
 │◀───────────────────────────────│
Step by step:
  1. Frontend fetches the plugin list via GET /plugins
  2. Backend iterates over installed plugins and calls _check_plugin_update() for each
  3. For PyPI plugins, the installed version is compared against the latest version on PyPI
  4. For Git plugins, the installed commit hash is compared against the latest commit on the remote
  5. Local plugins are skipped (use Reload instead)
  6. Each plugin in the response includes an update_available flag
  7. Frontend displays an update badge on plugins where the flag is true

Update Execution

User       Frontend              Backend              Desktop App
 │           │                     │                      │
 │ Click     │                     │                      │
 │ Update    │                     │                      │
 │──────────▶│                     │                      │
 │           │ POST /plugins       │                      │
 │           │ {upgrade: true}     │                      │
 │           │────────────────────▶│                      │
 │           │                     │ Capture venv         │
 │           │                     │────────┐             │
 │           │                     │◀───────┘             │
 │           │                     │ Compile with         │
 │           │                     │ --upgrade-package    │
 │           │                     │────────┐             │
 │           │                     │◀───────┘             │
 │           │                     │ Sync deps            │
 │           │                     │────────┐             │
 │           │                     │◀───────┘             │
 │           │     200 OK          │                      │
 │           │◀────────────────────│                      │
 │           │ Request restart     │                      │
 │           │─────────────────────────────────────────────▶
 │           │                     │                      │ Respawn
 │           │                     │                      │────────┐
 │           │                     │                      │◀───────┘
 │           │ Poll health         │                      │
 │           │────────────────────▶│                      │
 │           │ Refresh pipelines   │                      │
 │           │────────────────────▶│                      │
Step by step:
  1. User clicks the Update button on a plugin
  2. Frontend sends POST /plugins with the plugin spec and upgrade: true
  3. Backend captures the current venv state (for rollback)
  4. Backend runs uv pip compile with --upgrade-package targeting only the plugin package
  5. Backend syncs the environment with the newly resolved dependencies
  6. Backend updates the plugin registry
  7. Frontend triggers server restart
  8. Server restarts with the updated plugin loaded
  9. Frontend polls until server is healthy
  10. Frontend refreshes pipeline list
Rollback: If the update fails at any step, the venv is restored to its pre-update state, just like a failed installation.

Source-Specific Update Behavior

SourceDetection MethodNotes
PyPICompares installed version against latest version on PyPIStandard version comparison
GitCompares installed commit hash against latest remote commitDetects new commits on the default branch
LocalSkippedLocal plugins use Reload instead

Uninstallation Flow

  1. User initiates uninstall
  2. Backend unloads any active pipelines from the plugin
  3. Backend removes plugin from registry
  4. Backend uninstalls package via uv
  5. Frontend triggers server restart
  6. Frontend refreshes pipeline list

Manual Reload Flow

For local/editable plugins, developers can trigger a reload to pick up code changes:
  1. Developer modifies code
  2. Developer clicks Reload button
  3. Frontend requests server restart
  4. Server restarts with fresh Python module imports
  5. Code changes take effect
In standalone mode (without the desktop app), the reload flow is the same except the server performs a self-restart instead of being respawned by the desktop app (see Standalone Mode below).

External sources can facilitate plugin installation via protocol URLs:
daydream-scope://install-plugin?package=<spec>
SourceRaw SpecEncoded URL
PyPImy-plugindaydream-scope://install-plugin?package=my-plugin
Gitgit+https://github.com/user/repo.gitdaydream-scope://install-plugin?package=git%2Bhttps%3A%2F%2Fgithub.com%2Fuser%2Frepo.git
Flow:
  1. External source opens the deep link URL
  2. Desktop app receives URL via OS protocol handler
  3. If app is starting: stores pending deep link for later processing
  4. Once frontend is loaded: sends action via IPC to renderer
  5. Frontend opens settings with plugin tab and pre-filled package spec
  6. User confirms installation

Component Responsibilities

Backend Components

ComponentResponsibility
Plugin ManagerSingleton that manages plugin lifecycle (install, uninstall, update, reload)
Dependency ValidatorPre-validates that new packages won’t break existing environment
Venv SnapshotCaptures and restores environment state for safe rollback
Pipeline RegistryMaps pipeline IDs to their implementations and source plugins
REST APIExposes plugin operations to frontend

Frontend Components

ComponentResponsibility
Settings DialogUser interface for plugin management
API ClientHTTP calls to backend plugin endpoints
Restart CoordinatorHandles server restart and health polling
Pipeline ContextRefreshes available pipelines after changes

Desktop App Components

ComponentResponsibility
Python Process ManagerSpawns/respawns backend server, handles restart signals
Deep Link HandlerReceives and parses protocol URLs
IPC BridgeCommunicates between main process and renderer
File BrowserNative dialog for selecting local plugin directories
The File Browser is a desktop convenience feature. In standalone mode, users can type local paths directly into the plugin installation input field.

Server Restart Protocol

Managed Mode (Desktop App)

When running in the desktop app, server restarts are handled automatically:
  • Backend exits with code 42 (signals intentional restart)
  • Desktop app waits for port release
  • Desktop app respawns server process
  • Frontend polls health endpoint until ready

Standalone Mode

When running the server directly (uv run daydream-scope):
  • Unix/macOS: Uses os.execv() to replace the current process in-place
  • Windows: Spawns a new subprocess and exits the old one

Data Storage

Plugin state is persisted in the user’s data directory:
DataLocationPurpose
Plugin list~/.daydream-scope/plugins/plugins.txtInstalled package specs
Resolved deps~/.daydream-scope/plugins/resolved.txtLock file for reproducibility; baseline for update detection
Venv backup~/.daydream-scope/plugins/freeze.txtRollback state

Error Handling

The plugin system uses defensive error handling at each stage:
Error TypeDetectionRecovery
Dependency conflictsDry-run compilation before installInstallation blocked with clear error message
Installation failuresException during uv installVenv rolled back to pre-install state
Runtime errorsPipeline execution failurePipeline unloaded without affecting others
Network errorsHealth check timeoutsFrontend retries with exponential backoff
This multi-layer approach ensures that plugin operations cannot corrupt the base Scope installation.

See Also