Plans and carries out the move of a backend module from packages/cli/src/modules/<name> into its own workspace package at packages/modules/<name>/backend. Use when the user wants to extract, migrate or package a backend module, remove cli dependencies from a module, or move a cli service into @n8n/backend-services so that modules can use it.
The goal: a package at packages/modules/<name>/backend that does not import
cli. Read scripts/backend-module/backend-module-guide.md for the module
structure. This skill covers how to get there in small PRs.
Pitfalls with PR examples: reference.md.
grep -rhoE "from '@/[^']+'" packages/cli/src/modules/<name> \
--include='*.ts' --exclude='*.test.ts' | sort | uniq -c | sort -rn@n8n/backend-services,
@n8n/backend-common, @n8n/db and @n8n/decorators first. Many shared
services and proxies are already there (ProjectScopeService,
NodeTypesProxy, WorkflowProjectService, getN8nVersion(), …).Use the first option that applies:
| Situation | Fix |
|---|---|
| A shared package already has it | Import it from there |
| Only this module uses it | Move it into the module |
Two or more modules use it, and it has no @/ imports | Move it to @n8n/backend-services |
| The module calls one or two methods of a large cli service | Follow the steps below |
| The module only tells cli that something happened | Emit an event; a cli listener does the work |
When the module needs part of a large cli service, do these steps in order:
@n8n/backend-services.
List its @/ imports. If shared packages already supply them, or a few
small changes remove them, move the service. Examples: RoleService,
UrlService, WorkflowSharingService.@n8n/backend-services. Example:
ProjectScopeService.hasScopes replaced the module calls to
userHasScopes and merged in one PR.ProjectService, OwnershipService and userHasScopes
stalled, so get approval first.*Proxy in
@n8n/backend-services that cli registers (for example
NodeTypesProxy).Put REST, express and cache code in @n8n/backend-services, not in
@n8n/backend-common. n8n-core and @n8n/db depend on
@n8n/backend-common, so they would load that code too.
Layers
Container.get.OperationContext, not EntityManager. See the persistence section of the
root AGENTS.md.database/). The
typeorm-persistence-boundary code-health rule enforces the boundary.Moves
git mv. Rewrite all imports in the same PR. Do not keep
re-exports in the old location. Then git shows renames, not new files.biome format --write on the changed files and
typecheck cli before you push. A codemod can add duplicate imports or
remove imports that are still in use.package.json of the package that uses it. Put
type packages that appear in the published .d.ts files in
dependencies.Proxies
catch that now calls the proxy.init. A
Container.get in BaseCommand.init breaks the command tests, because cli
tests mock some services automatically.Tests
expect.any(Object) for In() or IsNull().setN8nVersion) in each test that needs it.After the move, search the repo for the old path and the moved symbol
names. Old references often stay in OWNERS,
scripts/lint-parity/samples.json, packages/cli/oxlint.config.mts,
packages/cli/eslint.config.mjs, .code-health-baseline.json and package
READMEs.
pnpm n8n-module-sdk create <name> --stack=backend, then git mv the
module files into it.@/ path and no n8n (cli) symbol.package.json exports ., ./module and ./testing. Each target is
in dist, and files publishes dist. Copy the shape of
packages/modules/data-table/backend/package.json../testing.packages/cli/src/modules/modules.manifest.ts.packages/cli/package.json and the cli
tsconfig.json references.test:postgres script and vitest.config.postgres.ts. The DB
workflow runs test:postgres for each packages/modules/*/backend.OWNERS, ownership-transfer.manifest.json and the
cli test server module setup if they name the module.n8n-io/n8n
e405c26
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.