Plugin structure
The content of this page might not be fully up-to-date with Strapi 5 yet.
When creating a plugin with the CLI generator, Strapi generates the following boilerplate structure for you in the ./src/plugins/my-plugin
folder:
- JavaScript-based plugins
- TypeScript-based plugins
. # root of the plugin folder (e.g., /src/plugins/my-plugin)
βββ admin # Admin panel part of your plugin.
β βββ src
β βββ components # Contains your front-end components
β β βββ Initializer
β β β βββ index.js # Plugin initializer
β β βββ PluginIcon
β β βββ index.js # Contains the icon of your plugin in the main navigation
β βββ pages # Contains the pages of your plugin
β β βββ App
β β β βββ index.js # Skeleton around the actual pages
β β βββ HomePage
β β βββ index.js # Homepage of your plugin
β βββ translations # Translations files to make your plugin i18n-friendly
β β βββ en.json
β β βββ fr.json
β βββ utils
β β βββ getTrad.js # getTrad function to return the corresponding plugin translations
β βββ index.js # Main setup of your plugin, used to register elements in the admin panel
β βββ pluginId.js # pluginId variable computed from package.json name
βββ node_modules
βββ server # Back-end part of your plugin
β βββ config
β β βββ index.js # Contains the default server configuration
β βββ content-types # Content-types specific to your plugin
β β βββ index.js # Loads all the plugin's content-types
β βββ controllers # Controllers specific to your plugin
β β βββ index.js # Loads all the plugin's controllers
β β βββ my-controller.js # Custom controller example. You can rename it or delete it.
β βββ middlewares # Middlewares specific to your plugin
β β βββ index.js # Loads all the plugin's middlewares
β βββ policies # Policies specific to your plugin
β β βββ index.js # Loads all the plugin's policies
β βββ routes # Routes specific to your plugin
β β βββ index.js # Contains an example route for the my-controller custom controller example
β βββ services # Services specific to your plugin
β β βββ index.js # Loads all the plugin's services
β β βββ my-service.js # Custom service example. You can rename it or delete it.
β βββ bootstrap.js # Function that is called right after the plugin has registered
β βββ destroy.js # Function that is called to clean up the plugin after Strapi instance is destroyed
β βββ index.js # Loads the code for all the server elements
β βββ register.js # Function that is called to load the plugin, before bootstrap.
βββ package.json
βββ README.md
βββ strapi-admin.js # Entrypoint for the admin panel (front end)
βββ strapi-server.js # Entrypoint for the server (back end)
. # root of the plugin folder (e.g., /src/plugins/my-plugin)
βββ admin # Admin panel part of your plugin.
β βββ src
β βββ components # Contains your front-end components
β β βββ Initializer
β β β βββ index.tsx # Plugin initializer
β β βββ PluginIcon
β β βββ index.tsx # Contains the icon of your plugin in the main navigation
β βββ pages # Contains the pages of your plugin
β β βββ App
β β β βββ index.tsx # Skeleton around the actual pages
β β βββ HomePage
β β βββ index.tsx # Homepage of your plugin
β βββ translations # Translations files to make your plugin i18n-friendly
β β βββ en.json
β β βββ fr.json
β βββ utils
β β βββ getTrad.ts # getTrad function to return the corresponding plugin translations
β βββ index.tsx # Main setup of your plugin, used to register elements in the admin panel
β βββ pluginId.tsx # pluginId variable computed from package.tsxon name
βββ dist # Build of the backend
βββ node_modules
βββ server # Back-end part of your plugin
β βββ config
β β βββ index.ts # Contains the default server configuration
β βββ content-types # Content-types specific to your plugin
β β βββ index.ts # Loads all the plugin's content-types
β βββ controllers # Controllers specific to your plugin
β β βββ index.ts # Loads all the plugin's controllers
β β βββ my-controller.ts # Custom controller example. You can rename it or delete it.
β βββ middlewares # Middlewares specific to your plugin
β β βββ index.ts # Loads all the plugin's middlewares
β βββ policies # Policies specific to your plugin
β β βββ index.ts # Loads all the plugin's policies
β βββ routes # Routes specific to your plugin
β β βββ index.ts # Contains an example route for the my-controller custom controller example
β βββ services # Services specific to your plugin
β β βββ index.ts # Loads all the plugin's services
β β βββ my-service.ts # Custom service example. You can rename it or delete it.
β βββ bootstrap.ts # Function that is called right after the plugin has registered
β βββ destroy.ts # Function that is called to clean up the plugin after Strapi instance is destroyed
β βββ index.ts # Loads the code for all the server elements
β βββ register.ts # Function that is called to load the plugin, before bootstrap.
βββ custom.d.ts # Generated types
βββ package.json
βββ README.md
βββ strapi-admin.js # Entrypoint for the admin panel (front end)
βββ strapi-server.js # Entrypoint for the server (back end)
βββ tsconfig.json # TypeScript compiler options for the admin panel part
βββ tsconfig.server.json # TypeScript compiler options for the server part
A Strapi plugin is divided into 2 parts, each living in a different folder and offering a different API:
Plugin part | Description | Folder | API |
---|---|---|---|
Admin panel | Includes what will be visible in the admin panel (components, navigation, settings, etc.) | /admin | Admin Panel API |
Backend server | Includes what relates to the backend server (content-types, controllers, middlewares, etc.) | /server | Server API |
Server-only plugin: You can create a plugin that will just use the server part to enhance the API of your application. For instance, this plugin could have its own visible or invisible content-types, controller actions, and routes that are useful for a specific use case. In such a scenario, you don't need your plugin to have an interface in the admin panel.
Admin panel plugin vs. application-specific customization: You can create a plugin to inject some components into the admin panel. However, you can also achieve this by creating a
./src/admin/app.js
file and invoking thebootstrap
lifecycle function to inject your components. In this case, deciding whether to create a plugin depends on whether you plan to reuse and distribute the code or if it's only useful for a unique Strapi application.
The next steps of your Strapi plugin development journey will require you to use any of the Strapi plugins APIs.
2 different types of resources help you understand how to use the plugin APIs:
- The reference documentation for the Admin Panel API and Server API give an overview of what is possible to do with a Strapi plugin.
- Guides cover some specific, use-case based examples.