Skip to main content

Plugin structure

πŸ— Work in progress

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:

The following diagram is interactive: you can click on any file or folder name highlighted in purple to go to the corresponding documentation section.

. # 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)

A Strapi plugin is divided into 2 parts, each living in a different folder and offering a different API:

Plugin partDescriptionFolderAPI
Admin panelIncludes what will be visible in the admin panel (components, navigation, settings, etc.)/adminAdmin Panel API
Backend serverIncludes what relates to the backend server (content-types, controllers, middlewares, etc.)/serverServer API

✏️ Notes about the usefulness of the different parts for your specific use case
  • 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 the bootstrap 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.


πŸ€“ What to read next?

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.