Template Module
Quickstart template repository for creating custom Medusa modules.
Zero Development maintains an official starter template at github.com/zerodev-ca/Medusa-Template. The template includes complete implementations of every Medusa subsystem, preconfigured translation files for all 16 supported languages, audit logging, database models, Discord commands, and custom dashboard pages.
Cloning the Template
To begin creating a new module, clone the repository directly into your Medusa modules/ directory or as an isolated git worktree:
git clone https://github.com/zerodev-ca/Medusa-Template modules/my-module
cd modules/my-moduleIf you manage your module as an isolated git branch in the Medusa workspace:
git worktree add modules/my-module -b module/my-moduleRenaming the Module
Update the module identifier in the following files:
-
main.js: Update thenameproperty to match your folder name in lowercase, and specify a readabledisplayNamefor the web dashboard:modules/my-module/main.jssuper(medusa, { name: "my-module", displayName: "My Module", author: "Your Organization", version: "1.0.0.0", description: "Custom module built from the Medusa template." }); -
resources/lang/en/common.json(and other language folders): Update your localized display name:{ "name": "My Module" }
Directory Structure
The starter template includes the following pre-built files:
modules/my-module/
├── main.js
├── README.md
├── resources/
│ ├── config/
│ │ └── settings.js
│ ├── dashboard/
│ │ └── pages/
│ │ └── template/
│ │ ├── page.js
│ │ └── view.tsx
│ ├── lang/
│ │ ├── de/
│ │ ├── en/
│ │ │ ├── common.json
│ │ │ └── messages.js
│ │ ├── es-ES/
│ │ ├── fr/
│ │ ├── it/
│ │ ├── ja/
│ │ ├── ko/
│ │ ├── nl/
│ │ ├── pl/
│ │ ├── pt-BR/
│ │ ├── ru/
│ │ ├── sv-SE/
│ │ ├── tr/
│ │ ├── uk/
│ │ ├── zh-CN/
│ │ ├── zh-TW/
│ │ └── translations.json
│ ├── leaderboards/
│ │ └── activity.js
│ ├── logs/
│ │ └── templateEvents.js
│ └── nodes/
│ └── sendNotification.js
└── src/
├── clocks/
│ └── cleanup.js
├── commands/
│ └── template.js
├── events/
│ ├── messageCreate.js
│ └── interactionCreate.js
├── handlers/
│ └── Items.js
├── models/
│ └── Item.js
└── routes/
└── items/
└── route.jsDevelopment Workflow
- Database Schema: Define your database columns in
src/models/. When Medusa boots, it automatically alters database tables to match your schema. - Business Logic: Write reusable methods in
src/handlers/. Usethis.fail(statusCode, message)to bubble errors cleanly up to routes or command responses. - Discord Commands & Components: Expose user interactions in
src/commands/. Send interactive buttons, select menus, and modals using Discord.js builders withmedusa:<component>:<module>:<name>:<describer>custom IDs. - Gateway Interactions: Handle button clicks, dropdown selections, and modal submissions in
src/events/interactionCreate.js. - Dashboard Forms: Declare settings in
resources/config/. To show a live preview next to a config group, add a component inresources/dashboard/previews/, see Pages. - Custom Dashboard Views: Provide bespoke management pages in
resources/dashboard/pages/utilizing built-in shadcn/Tailwind UI components (Button,Select,Input,Switch,Badge,Card,Modal). - Localization: Define keys in
resources/lang/en/messages.jsand provide localized versions inresources/lang/translations.json.
Restart Medusa to compile and load your changes.