Plugin Architecture
Relevant source files
The following files were used as context for generating this wiki page:
- apps/api/src/plugins.ts
- packages/contracts/src/lib/plugin.model.ts
- packages/desktop-lib/src/lib/plugin-system/data-access/strategies/cdn-download.strategy.ts
- packages/plugin/package.json
- packages/plugins/registry/src/lib/domain/entities/plugin.entity.ts
- packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts
- packages/plugins/registry/src/lib/infrastructure/controllers/plugin-source.controller.ts
- apps/api/src/plugin-config.ts
The Gauzy platform features a modular plugin architecture that allows for the extension of its core functionality. This system is designed to support various plugin types for different environments (Web, Desktop, Mobile) and enables dynamic loading, installation, and management of plugins from multiple sources. The architecture is built around a central RegistryPlugin that handles the discovery and lifecycle of other plugins.
Plugins are a fundamental part of the Gauzy ecosystem, with many core features like KnowledgeBase, JobProposal, and various integrations (GitHub, Jira, Zapier) implemented as plugins. This approach promotes modularity, separation of concerns, and makes the platform highly extensible.
Core Concepts and Data Models
The plugin system is defined by a set of core data models and enumerations that describe a plugin's properties, state, and source.
Sources: packages/contracts/src/lib/plugin.model.ts, packages/plugins/registry/src/lib/domain/entities/plugin.entity.ts
Enumerations
Several enums are used to define the characteristics and state of plugins.
| Enum | Description | Values |
|---|---|---|
PluginStatus | Defines the lifecycle state of a plugin. | ACTIVE, INACTIVE, DEPRECATED, ARCHIVED |
PluginType | Defines the supported platform targets for plugins. | DESKTOP, WEB, MOBILE |
PluginSourceType | Defines where the plugin code is hosted. | CDN, NPM, GAUZY (file upload) |
PluginOSType | Defines the operating system target for a plugin source. | LINUX, MAC, WINDOWS, UNIVERSAL |
PluginOSArch | Defines the CPU architecture for a plugin source. | X64, ARM |
PluginInstallationStatus | Defines the installation status of a plugin. | INSTALLED, UNINSTALLED, FAILED, IN_PROGRESS |
Sources: packages/contracts/src/lib/plugin.model.ts:8-30, 131-136
Data Model Relationships
The main entities in the plugin architecture are Plugin, PluginVersion, PluginSource, and PluginInstallation. Their relationships are illustrated in the diagram below.
This diagram shows that a Plugin can have multiple PluginVersions. Each version can have multiple PluginSources to support different operating systems or distribution methods. PluginInstallation records track the installation history of a plugin.
Sources: packages/contracts/src/lib/plugin.model.ts, packages/plugins/registry/src/lib/domain/entities/plugin.entity.ts
IPlugin Interface
The IPlugin interface is the core data structure for a plugin.
| Property | Type | Description |
|---|---|---|
name | string | The unique name of the plugin. |
description | string | An optional description of the plugin's functionality. |
type | PluginType | The target platform for the plugin (e.g., DESKTOP, WEB). |
status | PluginStatus | The current status of the plugin (e.g., ACTIVE, INACTIVE). |
versions | IPluginVersion[] | An array of all available versions for the plugin. |
version | IPluginVersion | The currently active or selected version. |
installed | boolean | A computed field indicating if the plugin is installed. |
author | string | The name of the plugin author. |
uploadedBy | IEmployee | The employee who uploaded the plugin. |
downloadCount | number | The total number of times the plugin has been downloaded. |
Sources: packages/contracts/src/lib/plugin.model.ts:58-81, packages/plugins/registry/src/lib/domain/entities/plugin.entity.ts:12-108
Plugin Loading and Registration
Plugins are loaded into the Gauzy API at startup. This is handled by a centralized plugins array. The RegistryPlugin is a special plugin responsible for managing other plugins dynamically.
Sources: apps/api/src/plugins.ts, apps/api/src/plugin-config.ts
Static Plugin Loading
Core plugins are statically imported and included in the plugins array. This ensures essential functionalities are always available.
The following diagram illustrates how plugins are configured and loaded by the API.
This flow shows that when the application starts, it reads configuration and then imports and registers the list of plugins before the main NestJS application is bootstrapped.
Sources: apps/api/src/plugins.ts:1-73, apps/api/src/plugin-config.ts:10-14, 107
An example of the static plugin registration:
// apps/api/src/plugins.ts
import { ChangelogPlugin } from '@gauzy/plugin-changelog';
import { IntegrationAIPlugin } from '@gauzy/plugin-integration-ai';
// ... other plugin imports
export const plugins = [
// ... other plugins
ChangelogPlugin,
IntegrationAIPlugin,
// ...
RegistryPlugin
];
Sources: apps/api/src/plugins.ts:3-23, 30-73
Plugin Management API
The RegistryPlugin exposes a set of REST API endpoints for creating, updating, deleting, and managing plugins and their sources. These operations are handled by PluginManagementController and PluginSourceController.
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts, packages/plugins/registry/src/lib/infrastructure/controllers/plugin-source.controller.ts
Endpoints
| Method | Endpoint | Controller | Description |
|---|---|---|---|
POST | /plugins | PluginManagementController | Creates a new plugin with an initial version and source. Supports multipart/form-data for file uploads. |
PUT | /plugins/:id | PluginManagementController | Updates an existing plugin's metadata. |
DELETE | /plugins/:id | PluginManagementController | Deletes a plugin. |
GET | /plugins/:pluginId/versions/:versionId/sources | PluginSourceController | Lists all sources for a specific plugin version. |
POST | /plugins/:pluginId/versions/:versionId/sources | PluginSourceController | Adds new sources to a plugin version. |
DELETE | /plugins/:pluginId/versions/:versionId/sources/:sourceId | PluginSourceController | Deletes a specific plugin source. |
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts:39-216, packages/plugins/registry/src/lib/infrastructure/controllers/plugin-source.controller.ts:47-239
Create Plugin Sequence
The sequence diagram below shows the process of creating a new plugin via a POST request to the /plugins endpoint.
This diagram illustrates the flow for creating a plugin, including file validation, metadata extraction, and database persistence via the Command Bus. It also shows the cleanup process on failure.
Sources: packages/plugins/registry/src/lib/infrastructure/controllers/plugin-management.controller.ts:57-133
Plugin Installation Strategy
On the client-side, particularly for the desktop application, plugins are downloaded and installed based on their source type. The CdnDownloadStrategy provides a clear example of how a plugin is fetched from a URL.
Sources: packages/desktop-lib/src/lib/plugin-system/data-access/strategies/cdn-download.strategy.ts
CDN Download Flow
The following flowchart details the steps involved in downloading and installing a plugin from a CDN.
This process ensures that the downloaded plugin is a valid .zip file, contains a proper manifest.json, and is stored in a unique, organized directory structure before it can be loaded by the application.
Conclusion
The Gauzy plugin architecture is a robust and flexible system for extending platform capabilities. It leverages a well-defined data model, a centralized registry for dynamic management, and clear strategies for plugin sourcing and installation. By treating core features as plugins, the architecture ensures modularity and maintainability, allowing developers to easily add or modify functionality without altering the core application. The provision of a management API further enhances this by allowing plugins to be managed dynamically at runtime.