* initialized next.js project * finished markdown sections * added operation schema component * change page metadata * eslint fixes * fixes related to deployment * added response schema * resolve max stack issue * support for different property types * added support for property types * added loading for components * added more loading * type fixes * added oneOf type * removed console * fix replace with push * refactored everything * use static content for description * fixes and improvements * added code examples section * fix path name * optimizations * fixed tag navigation * add support for admin and store references * general enhancements * optimizations and fixes * fixes and enhancements * added search bar * loading enhancements * added loading * added code blocks * added margin top * add empty response text * fixed oneOf parameters * added path and query parameters * general fixes * added base path env variable * small fix for arrays * enhancements * design enhancements * general enhancements * fix isRequired * added enum values * enhancements * general fixes * general fixes * changed oas generation script * additions to the introduction section * added copy button for code + other enhancements * fix response code block * fix metadata * formatted store introduction * move sidebar logic to Tags component * added test env variables * fix code block bug * added loading animation * added expand param + loading * enhance operation loading * made responsive + improvements * added loading provider * fixed loading * adjustments for small devices * added sidebar label for endpoints * added feedback component * fixed analytics * general fixes * listen to scroll for other headings * added sample env file * update api ref files + support new fields * fix for external docs link * added new sections * fix last item in sidebar not showing * move docs content to www/docs * change redirect url * revert change * resolve build errors * configure rewrites * changed to environment variable url * revert changing environment variable name * add environment variable for API path * fix links * fix tailwind settings * remove vercel file * reconfigured api route * move api page under api * fix page metadata * fix external link in navigation bar * update api spec * updated api specs * fixed google lint error * add max-height on request samples * add padding before loading * fix for one of name * fix undefined types * general fixes * remove response schema example * redesigned navigation bar * redesigned sidebar * fixed up paddings * added feedback component + report issue * fixed up typography, padding, and general styling * redesigned code blocks * optimization * added error timeout * fixes * added indexing with algolia + fixes * fix errors with algolia script * redesign operation sections * fix heading scroll * design fixes * fix padding * fix padding + scroll issues * fix scroll issues * improve scroll performance * fixes for safari * optimization and fixes * fixes to docs + details animation * padding fixes for code block * added tab animation * fixed incorrect link * added selection styling * fix lint errors * redesigned details component * added detailed feedback form * api reference fixes * fix tabs * upgrade + fixes * updated documentation links * optimizations to sidebar items * fix spacing in sidebar item * optimizations and fixes * fix endpoint path styling * remove margin * final fixes * change margin on small devices * generated OAS * fixes for mobile * added feedback modal * optimize dark mode button * fixed color mode useeffect * minimize dom size * use new style system * radius and spacing design system * design fixes * fix eslint errors * added meta files * change cron schedule * fix docusaurus configurations * added operating system to feedback data * change content directory name * fixes to contribution guidelines * revert renaming content * added api-reference to documentation workflow * fixes for search * added dark mode + fixes * oas fixes * handle bugs * added code examples for clients * changed tooltip text * change authentication to card * change page title based on selected section * redesigned mobile navbar * fix icon colors * fix key colors * fix medusa-js installation command * change external regex in algolia * change changeset * fix padding on mobile * fix hydration error * update depedencies
7.3 KiB
description
| description |
|---|
| 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. |
Medusa Backend Directory Structure
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.
Note about Beta
Files that have the beta label are only available if you installed the Medusa backend using the create-medusa-app command.
Root Files
These are files present at the root of your Medusa backend.
.babelrc.js
Defines Babel’s configurations, which are used when running the build command that transpiles files from the src directory to the dist directory.
.env
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.
.env.template
Gives an example of what variables may be included in .env.
.gitignore
Specifies files that shouldn’t be committed to a Git repository.
.yarnrc.yml
Ensures dependencies are always installed in node-modules. This ensures compatibility with pnpm.
index.js
Defines an entry file, which is useful when starting the Medusa backend with a process manager like pm2.
medusa-config.js
Defines the Medusa backend’s configurations, including the database configurations, plugins used, modules used, and more.
Read more: Medusa backend configurations.
package.json
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.
README.md
Provides general information about the Medusa backend.
tsconfig.admin.json (beta)
Defines the TypeScript configurations that are used to transpile admin customization files. So, it only works for files under the src/admin directory.
tsconfig.json
Defines the general TypeScript configurations used to transpile files from the src directory to the dist directory.
If you have the beta configuration files, they will extend the configurations in this file along with the configurations they each define.
tsconfig.server.json (beta)
Defines the TypeScript configurations that are used to transpile Medusa backend customization files. It works for all files except for the files under the src/admin directory.
tsconfig.spec.json
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:
.test.tsor.test.js.spec.tsor.test.js
yarn.lock or package-lock.json
An automatically generated file by yarn or 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 npm.
Based on the package manager used to install the dependencies, either yarn.lock or package-lock.json will be available, or both.
Root Directories
These are the directories present at the root of your Medusa backend.
.cache
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.
build
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.
data
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 create-medusa-app or medusa new commands.
You can also seed the data by running the following command:
npm run seed
dist
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 dev command.
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 dev or medusa develop commands, this is handled automatically whenever changes occur under the src directory.
node_modules
This directory holds all installed dependencies in your project.
src
This directory holds all Medusa backend and admin customizations. More details about each subdirectory are included in this section.
uploads
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.
src Subdirectories
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.
admin (beta)
This directory holds all Medusa admin customizations. The main subdirectories of this directory are:
widgets: Holds all Medusa admin widgets.routes: Holds all Medusa admin UI routes.
api
This directory holds all custom endpoints. You can create as many subdirectories and files that hold endpoint definitions, but only endpoints exported by the index.ts file are registered in the Medusa backend.
Read more: Endpoints
loaders
This directory holds scripts that run when the Medusa backend starts. For example, the scripts can define a scheduled job.
Read more: Loaders
migrations
This directory holds all migration scripts that reflect changes on the database the Medusa backend is connected to.
Read more: Migrations
models
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
repositories
This directory holds all custom repositories which provide utility methods to access and modify data related to an entity.
Read more: Repositories
services
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
subscribers
This directory holds all custom subscribers. Subscribers listen to emitted events and registers method to handle them.
Read more: Subscribers