# Build Plugins

Extend erxes with backend services and frontend remotes


Extend erxes with your own backend services and frontend remotes, from `pnpm create-plugin` to a deployed, permission-aware feature.

## Plugin anatomy

A complete plugin is a pair of Nx projects:

```text
backend/plugins/<name>_api     Express service: subgraph /graphql, /trpc router,
                               meta extension hooks, BullMQ workers, one port each
frontend/plugins/<name>_ui     Module Federation remote: ./config plus module,
                               settings, and widget exposes
```

The `_api` service calls `startPlugin({ name, port, ... })` from `erxes-api-shared` ([start-plugin.ts](https://github.com/erxes/erxes/blob/f91e8c6f4714c910a32c6b6e14fe085f6435c89e/backend/erxes-api-shared/src/utils/start-plugin.ts)) and registers with the gateway through Redis service discovery. The gateway composes its subgraph once the service answers `_service { sdl }`.

The `_ui` remote exposes `./config`, an `IUIConfig` object the `core-ui` host loads to build navigation, routes, settings entries, and widgets. Enable both at once by adding the base name (`inventory`, not `inventory_api`) to `ENABLED_PLUGINS`.

## The scope boundary

erxes enforces a hard plugin boundary:

- A backend-only task may write only under `backend/plugins/<name>_api/**`; a frontend-only task only under `frontend/plugins/<name>_ui/**`; a full-stack plugin task only under those two matching directories.
- Never edit `core-api`, `core-ui`, another plugin, a shared library, or root infrastructure to make a plugin feature work, and never import another plugin's source, models, state, or components.
- Use shared code only through the public APIs of `erxes-api-shared`, `erxes-ui`, and `ui-modules`. If the behavior cannot be implemented inside the boundary, stop and report the missing platform capability; a core or shared change is a separate task with explicit scope.

## Guides

- [Create a Plugin](https://erxes.io/docs/create-plugin): Learn how to create an erxes plugin from scratch
- [Standalone Plugins](https://erxes.io/docs/create-plugin-standalone): Develop a plugin in its own repository with create-erxes-plugin
- [Backend Plugins](https://erxes.io/docs/plugin-backend): Tenant-aware API services with gateway registration
- [Frontend Plugins](https://erxes.io/docs/plugin-frontend): Remotes loaded by Core UI
- [GraphQL & tRPC](https://erxes.io/docs/plugin-graphql-trpc): Federated operations and service procedures
- [Shared UI Components](https://erxes.io/docs/plugin-ui-components): Reuse erxes-ui and ui-modules
- [Plugin Metadata & Extensions](https://erxes.io/docs/plugin-metadata-extensions): Permissions and cross-module hooks
- [Workers & Background Jobs](https://erxes.io/docs/plugin-workers): BullMQ queues and delivery state

Start with [Create a Plugin](https://erxes.io/docs/create-plugin) (or [Standalone Plugins](https://erxes.io/docs/create-plugin-standalone) for a separate repository), then read the generated code alongside [Backend Plugins](https://erxes.io/docs/plugin-backend) and [Frontend Plugins](https://erxes.io/docs/plugin-frontend). For the core modules your `meta` hooks and tRPC calls target, see [Core Platform](https://erxes.io/docs/core-overview); for how plugins register and load, see [Architecture](https://erxes.io/docs/architecture-overview).

