Эта страница пока недоступна на выбранном языке (Русский), поэтому показана на английском.
Plugin package layout and lifecycle
The folder a plugin lives in, what each file does, and what happens on preview, install, enable/disable and uninstall.
modules/<id>/
module.json manifest — validated with zod; id must equal the folder name
src/index.ts server entry: export function register() { return definePlugin({ ... }) }
src/*.ts pure logic (testable without a database) + server helpers
app/admin/**/page.tsx admin pages → /admin/<id>/<path>
app/admin/**/actions.ts "use server" actions used by those pages
app/api/**/route.ts API routes → /api/plugins/<id>/<path>
schema.prisma optional ADDITIVE Prisma fragment (new models / enums only)
messages/<locale>.json optional UI strings (en.json required when module.json → messages is set)
check.ts self-test (npm run plugin:check <id>) — pure functions, no DB
README.md, CHANGELOG.md shown on the plugin page<id> matches ^[a-z][a-z0-9-]{1,40}$. Import app code with the @/… alias like core code. Never edit generated files (src/lib/plugins/*.generated.ts, src/app/admin/(plugins)/<id>/**, src/app/api/plugins/<id>/**) — they are rewritten on every install, uninstall and toggle.
Lifecycle
| Step | What happens |
|---|---|
| Preview | Manifest validated, minAppVersion, conflicts (routes, permission groups, sidebar links, schema names), integrity (archive sha256, checksum), step list. Nothing is written. |
| Install / update | One job: preflight → snapshot → back up previous folder → copy files → (schema → prisma db push → prisma generate) → regenerate barrels and route wrappers → seed permissions, settings defaults, version row → typecheck → staged build → swap-restart. Any failure rolls back. |
| Enable / disable | A database flag read at runtime: pages show a notice, API answers 404, hooks / filters / widgets / jobs are skipped. No rebuild. |
| Uninstall | Disable → backup zip → remove folder → delete permissions and registration → rebuild. “Drop data” also deletes the plugin's Setting rows and its tables. |
Keep
register() free of side effects: it is imported at build time and on first use. Plugin code runs in-process with the app — review a plugin before installing it.Selling a plugin in the marketplace? The zip also needs
marketplace.json, may not ship a schema fragment or public /api/plugins/… routes, and stays within 300 files, 256 KB per file and 4 MB unpacked (text only, lines ≤ 1,500 characters). Reference: docs/DEVELOPERS/PLUGIN-SDK.md and examples/marketplace/plugin-booking-pulse/.Written from: docs/PLUGIN-DEVELOPER-GUIDE.md, docs/PLUGINS.md, src/lib/plugins/installer.ts, src/lib/plugins/generate.ts, docs/DEVELOPERS/PLUGIN-SDK.md, examples/marketplace/plugin-booking-pulse/module.json, src/lib/marketplace/plugin-scan.ts