Creating a New Plugin
Relevant source files
The following files were used as context for generating this wiki page:
- packages/contracts/src/lib/plugin.model.ts
- packages/plugin/src/lib/plugin.interface.ts
- packages/plugins/changelog/src/lib/changelog.plugin.ts
- packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts
- packages/plugins/registry/src/lib/infrastructure/controllers/plugin-version.controller.ts
- packages/plugins/registry/src/lib/infrastructure/controllers/plugin-source.controller.ts
- packages/desktop-lib/src/lib/plugin-system/data-access/strategies/cdn-download.strategy.ts
- packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-marketplace-item/plugin-marketplace-item.component.ts
- packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-marketplace-item/plugin-marketplace-item.component.html
- packages/plugins/job-proposal/package.json
The Gauzy platform features a modular architecture that allows for the extension of its functionality through plugins. These plugins can be developed for different environments, including Web, Desktop, and Mobile. Creating a plugin involves defining its data model, implementing its backend logic as a NestJS module, and registering it with the platform's plugin registry via a dedicated API.
This document provides a technical overview of the plugin system, detailing the data structures, API endpoints, and processes involved in creating, registering, and managing plugins within the Gauzy ecosystem. It covers the plugin data model, the API for creation and management, and the client-side installation process.
Plugin Data Model
The core of the plugin system is defined by a set of interfaces that describe the structure of a plugin, its versions, and its sources. These models are hierarchical, with a plugin containing one or more versions, and each version having one or more sources.
Sources: packages/contracts/src/lib/plugin.model.ts
Core Interfaces
The main interfaces are IPlugin, IPluginVersion, and IPluginSource.
This diagram shows that an IPlugin entity can have multiple IPluginVersion entities, and each IPluginVersion can have multiple IPluginSource entities.
Sources: packages/contracts/src/lib/plugin.model.ts:47-160
Plugin Enumerations
Several enumerations define the possible types, statuses, and sources for a plugin.
PluginType
Defines the supported platform targets for a plugin.
| Value | Description |
|---|---|
DESKTOP | Native desktop application plugin. |
WEB | Browser-based plugin. |
MOBILE | Mobile application plugin. |
Sources: packages/contracts/src/lib/plugin.model.ts:16-21
PluginStatus
Defines the lifecycle state of a plugin.
| Value | Description |
|---|---|
ACTIVE | Plugin is available for use. |
INACTIVE | Plugin is not available for use. |
DEPRECATED | Plugin is supported but will be removed in the future. |
ARCHIVED | Plugin is no longer available for new installations. |
Sources: packages/contracts/src/lib/plugin.model.ts:8-14
PluginSourceType
Defines how the plugin's code is distributed.
| Value | Description |
|---|---|
CDN | Hosted on a Content Delivery Network. Requires a url. |
NPM | Distributed as a package on an NPM registry. Requires a package name. |
GAUZY | Hosted and distributed by Gauzy's own file storage. Requires a file upload. |
Sources: packages/contracts/src/lib/plugin.model.ts:23-27
Plugin Registration API
Plugins are registered and managed through a set of RESTful API endpoints. The primary endpoint for creating a new plugin is POST /plugins. This process involves uploading the plugin's metadata and, if applicable, its source files.
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts
Create Plugin Endpoint
- Endpoint:
POST /plugins - Content-Type:
multipart/form-data - Description: Registers a new plugin, its initial version, and its sources.
The request body is defined by CreatePluginDTO, which includes metadata for the plugin and its first version. If the source type is GAUZY, the corresponding plugin file (e.g., a .zip archive) must be included in the multipart request.
Creation Flow
The diagram below illustrates the sequence of events when a new plugin is created via the API.
This sequence shows the user initiating a request, the controller validating and processing uploaded files for GAUZY type sources, dispatching a command, and finally persisting the new plugin in the database.
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts:68-120
Managing Versions and Sources
After a plugin is created, new versions and sources can be added using dedicated endpoints.
-
Add Version:
POST /plugins/:pluginId/versions- This endpoint allows adding a new version to an existing plugin. It accepts a
PluginVersionDTOand handles file uploads forGAUZYsources, similar to the main plugin creation endpoint.
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-version.controller.ts:69-129
- This endpoint allows adding a new version to an existing plugin. It accepts a
-
Add Source:
POST /plugins/:pluginId/versions/:versionId/sources- This endpoint associates a new source (e.g., a build for a different OS/architecture) with an existing plugin version.
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-source.controller.ts:80-140
- This endpoint associates a new source (e.g., a build for a different OS/architecture) with an existing plugin version.
Plugin Structure
A Gauzy plugin is fundamentally a NestJS module that adheres to a specific structure. It must export a class that implements the IGauzyPlugin interface.
Sources: packages/plugin/src/lib/plugin.interface.ts, packages/plugins/changelog/src/lib/changelog.plugin.ts
Example package.json
A typical plugin's package.json will include dependencies on Gauzy's core and plugin packages.
{
"name": "@gauzy/plugin-job-proposal",
"version": "0.1.0",
"description": "Ever Gauzy Platform Job Proposal Plugin",
"dependencies": {
"@gauzy/contracts": "^0.1.0",
"@gauzy/core": "^0.1.0",
"@gauzy/plugin": "^0.1.0",
"@nestjs/common": "^11.1.0",
"@nestjs/cqrs": "^11.0.3"
}
}
Sources: packages/plugins/job-proposal/package.json:1-29
Example Plugin Module
The entry point of a plugin is a NestJS module class. The ChangelogPlugin is a good example of a minimal implementation.
// packages/plugins/changelog/src/lib/changelog.plugin.ts
import { IGauzyPlugin, IPlugin } from '@gauzy/contracts';
import { Module } from '@nestjs/common';
import { ChangelogController } from './changelog.controller';
@Module({
controllers: [ChangelogController]
})
export class ChangelogPlugin implements IGauzyPlugin {
constructor() {}
// Required method from IGauzyPlugin interface
register(plugin: IPlugin): void | Promise<void> {
console.log('Registering changelog plugin');
}
}
Sources: packages/plugins/changelog/src/lib/changelog.plugin.ts
Client-Side Installation
The Gauzy Desktop application handles the installation of plugins. For plugins sourced from a CDN, the CdnDownloadStrategy is employed. This strategy downloads, verifies, and extracts the plugin into the appropriate directory.
Sources: packages/desktop-lib/src/lib/plugin-system/data-access/strategies/cdn-download.strategy.ts
CDN Installation Flow
The installation process for a CDN-sourced plugin follows a clear, multi-step procedure to ensure integrity and proper placement.
This flowchart outlines the steps taken by the CdnDownloadStrategy: URL validation, directory preparation, downloading, unzipping, manifest validation, final directory creation, and cleanup.
Sources: packages/desktop-lib/src/lib/plugin-system/data-access/strategies/cdn-download.strategy.ts:18-31
User Interface
The Gauzy UI provides a "Marketplace" for users to discover, install, and manage plugins. The interface allows plugin owners to perform administrative actions such as adding new versions, adding sources, editing metadata, and deleting the plugin.
The UI displays key information about each plugin, including:
- Name, Status, and Type
- Version history and changelogs
- Source details (CDN, NPM, or Gauzy)
- Metadata (author, license, repository)
- Usage statistics (download count)
Users can interact with plugins through buttons like Install, Uninstall, Update, and Add Version.
Sources: packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-marketplace-item/plugin-marketplace-item.component.html, packages/desktop-ui-lib/src/lib/settings/plugins/component/plugin-marketplace/plugin-marketplace-item/plugin-marketplace-item.component.ts