In this document, you’ll learn about the directory structure of a Medusa backend. It’ll help you understand the purpose of each file and folder in your Medusa backend project.
These are files present at the root of your Medusa backend.
Defines Babel’s configurations, which are used when running the
build command that transpiles files from the
src directory to the
Includes the values of environment variables. This is typically only used in development. In production you should define environment variables based on your hosting provider.
Gives an example of what variables may be included in
Specifies files that shouldn’t be committed to a Git repository.
Ensures dependencies are always installed in
node-modules. This ensures compatibility with pnpm.
Defines an entry file, which is useful when starting the Medusa backend with a process manager like pm2.
Defines the Medusa backend’s configurations, including the database configurations, plugins used, modules used, and more.
Read more: Medusa backend configurations.
Since the Medusa backend is an NPM package, this file defines its information as well as its dependencies. It will also include any new dependencies you install.
Provides general information about the Medusa backend.
Defines the TypeScript configurations that are used to transpile admin customization files. So, it only works for files under the src/admin directory.
Defines the general TypeScript configurations used to transpile files from the
src directory to the
Defines the TypeScript configurations that are used to transpile Medusa backend customization files. It works for all files except for the files under the
Defines TypeScript configurations for test files. These are files that either reside under a
__tests__ directory under
src, or that have a file name ending with one of the following:
yarn.lock or package-lock.json
An automatically generated file by
npm that holds the current versions of all dependencies installed to ensure the correct versions are always installed.
If you used the
create-medusa-app command to install the Medusa backend, it’ll attempt to use
yarn by default to install the dependencies. If
yarn is not installed on your machine, it will then fall back to using
Based on the package manager used to install the dependencies, either
package-lock.json will be available, or both.
These are the directories present at the root of your Medusa backend.
This directory will only be available if you have the Medusa admin installed and you’ve already started your Medusa backend at least once before. It holds all cached files related to building the Medusa admin assets.
This directory will only be available if you have the Medusa admin installed and you’ve either built your admin files or ran the Medusa backend at least once before. It holds the built files that are used to serve the admin in your browser.
This directory holds a JSON file used to seed your Medusa backend with dummy data which can be useful for demo purposes. The data is seeded automatically if you include the
--seed option when using either the
medusa new commands.
You can also seed the data by running the following command:
This directory holds the transpiled Medusa backend customizations. This directory may not be available when you first install the Medusa backend. It’ll be available when you run the
build command or start your Medusa backend with the
The files under this directory are the files that are used in your Medusa backend. So, when you make any changes under
src, make sure the changes are transpiled into the
dist directory. If you’re using the
medusa develop commands, this is handled automatically whenever changes occur under the
This directory holds all installed dependencies in your project.
This directory holds all Medusa backend and admin customizations. More details about each subdirectory are included in this section.
This directory holds all file uploads to the Medusa backend. It’s only used if you’re using the Local File Service plugin, which is installed by default.
Files under the
src directory hold the Medusa backend and admin customizations. These files should later be transpiled into the
dist directory for them to be used during the backend’s runtime.
If any of these directories are not available, you can create them yourself.
This directory holds all Medusa admin customizations. The main subdirectories of this directory are:
This directory holds all custom API Routes, which are defined in
route.js files. These files can be created in sub-directories of the
api directory based on the API Route's path.
Read more: API Routes
This directory holds scripts that run when the Medusa backend starts. For example, the scripts can define a scheduled job.
Read more: Loaders
This directory holds all migration scripts that reflect changes on the database the Medusa backend is connected to.
Read more: Migrations
This directory holds all custom entities, which represent tables in your database. You can create a new entity, or customize a Medusa entity.
Read more: Entities
This directory holds all custom repositories which provide utility methods to access and modify data related to an entity.
Read more: Repositories
This directory holds all custom services. Services define utility methods related to an entity or feature that can be used across the Medusa backend’s resources.
Read more: Services
This directory holds all custom subscribers. Subscribers listen to emitted events and registers method to handle them.
Read more: Subscribers