Overview
Icon for Category Tree

Category Tree

Drag-and-drop category tree in the Admin

@hectasquare/medusa-plugin-category-tree

An enterprise-grade, AAA interactive Category Tree, Mind Map & Category Detail Hub plugin for Medusa v2 Admin.

Inspired by modern visual and canvas tools like Figma, Miro, Linear, and NotebookLM, this plugin transforms Medusa's standard nested category list into a fluid, 60fps pan/zoom node canvas with branch-specific harmonic color coding, left-edge tier level indicators, sibling superscript rankings, and an all-in-one Category Detail Hub with product ranking and commercial top seller management.

🌟 Why This Plugin?

In high-volume e-commerce stores with hundreds or thousands of categories across multiple sales channels and brands:

  • Standard nested tables and indent lists quickly become unwieldy, difficult to scan, and prone to navigation fatigue.
  • Re-parenting or reordering categories through repeated modal dropdowns is slow, error-prone, and provides no immediate visual feedback.
  • Managing products, rankings, and commercial visibility required constantly hopping back and forth between administrative screens.

With this plugin:

  • Zero backend contamination: Lives entirely inside an external npm plugin (Copy to clipboard@hectasquare/medusa-plugin-category-tree). Your backend core remains pristine.
  • Bird’s-eye hierarchy visualization: Instant visual comprehension of your entire category taxonomy with orthogonal connections (Copy to clipboardsmoothstep) and branch-specific harmonic colors.
  • Hierarchical Centered Layout: Clean Buchheim/Walker-style tree geometry centering parents directly over children without cross-canvas wire tangle.
  • Interactive drag-and-drop reparenting: Connect and restructure categories directly on the canvas with real-time topological cycle protection.
  • Category Detail Hub: Complete 4-tab slide-over hub replacing the need to visit legacy pagesβ€”edit metadata, manage products, rank items, and configure storefronts in one place.
  • Product Ranking & Top Commercial Sellers: Reorder sibling products directly with interactive controls and star items with Copy to clipboard⭐ Top Seller status reflected in storefronts.
  • Multi-storefront filtering: Seamlessly filter the entire tree by Sales Channel (Copy to clipboardAll Storefronts, Copy to clipboardMonfil, Copy to clipboardSuperpunch, etc.).
  • Atomic batch updates: Stage moves visually on canvas and commit them in a single transactional request with automatic rollback.

πŸš€ Key Features

πŸ—‚οΈ All-in-One Category Detail Hub

Clicking the edit pencil icon on any node opens a wide slide-over hub featuring 4 dedicated workspaces:

  1. General & Ranking:
    • Title, Handle, Description, and Active / Internal toggles.
    • Sibling category rank ordering (Copy to clipboard↑ Earlier, Copy to clipboard↓ Later, Copy to clipboardTop (#0)).
    • Direct Copy to clipboardβ†— Open Full Page link opening Copy to clipboard/app/categories/:id in a separate tab when desired.
  2. Products Management:
    • Full product listing with thumbnail, title, collection, variant count, and status badges.
    • Sibling Product Ranking: Dynamic rank numbering (Copy to clipboard#1, Copy to clipboard#2, Copy to clipboard#3...) with interactive Copy to clipboardβ–² Move Up and Copy to clipboardβ–Ό Move Down buttons.
    • ⭐ Top Commercial Seller: One-click toggle marking priority commercial showcase products.
    • Remove Products: Individual removal or multi-select bulk remove.
    • Full-Screen FocusModal: Direct parity with Medusa's legacy Add Products modal with full-width table, search (Copy to clipboardQ Search), pagination, and batch assignment.
  3. Storefronts & Media:
    • Multi-sales channel visibility checkboxes (Copy to clipboardMonfil Store, Copy to clipboardSuperpunch, etc.).
    • Native Drag-and-Drop Media Upload: Integrated with Medusa v2's native File Module (Copy to clipboardsdk.admin.upload.create).
    • Visual Gallery Manager: Image preview cards, delete actions, and one-click Copy to clipboardβ˜… Thumbnail designation.
    • Direct External URL Input: Fallback support for external CDN, Cloudinary, or DAM image links.
  4. YouTube Videos:
    • Multi-video demonstration manager with real-time thumbnail preview cards and quick remove actions.

🎨 Branch-Specific Harmonic Color Coding

  • Every major branch receives a distinct harmonic color (Emerald, Indigo, Amber, Rose, Cyan, Violet, Pink, Lime, Sky, Orange) assigned deterministically from its top-level root ancestor.
  • Vertical left-edge tier indicator bars and connecting orthogonal edge lines inherit the branch color, making complex multi-level trees effortless to scan visually.

🌳 Dual-Mode Visual Layout Engine

  • Vertical Tree (Top-to-Bottom): Clustered hierarchical layout centering parents cleanly over children.
  • Horizontal Mind Map (Left-to-Right): Lateral branching layout (Linear/Miro style) ideal for wide root catalogs.
  • Recalculates dynamically with sub-millisecond responsiveness.

β›Ά Box / Marquee Multi-Selection

  • Click and drag anywhere on the canvas to marquee-select multiple nodes at once (Copy to clipboardβ›Ά Box Select).
  • Move entire subtrees or selected clusters in unison.

🏷️ Left-Edge Tier Level Indicators & Superscript Ranks

  • Tier 1 (Root): Single vertical bar in branch accent.
  • Tier 2 (Sub): Dual vertical bars with high-contrast spacing.
  • Tier 3 (Sub-Sub): Triple vertical bars.
  • Sibling Superscripts: Numbers (Copy to clipboardΒΉ, Copy to clipboardΒ², Copy to clipboardΒ³, Copy to clipboard⁴, Copy to clipboardⁿ) representing the category's display rank among siblings.

πŸ“‚ NotebookLM-Style Subtree Collapse

  • Expand or collapse individual subtrees with a single click.
  • Collapsed nodes show an indicator badge (e.g., Copy to clipboard[ β–Έ 4 sub ]).
  • Quick actions in the floating dock to expand or collapse all nodes or selective subtrees.

πŸ›‘οΈ Topological Cycle Protection

  • Real-time client-side and server-side cycle detection.
  • Completely prevents accidental self-parenting (Copy to clipboardA -> A) or cyclic loops (Copy to clipboardA -> B -> C -> A).

πŸ“¦ Installation

Install the package in your Medusa backend project:

npm install @hectasquare/medusa-plugin-category-tree
# or
pnpm add @hectasquare/medusa-plugin-category-tree
# or
yarn add @hectasquare/medusa-plugin-category-tree

βš™οΈ Configuration

Register the plugin in your backend's Copy to clipboardmedusa-config.js (or Copy to clipboardmedusa-config.ts):

module.exports = defineConfig({
plugins: [
{
resolve: "@hectasquare/medusa-plugin-category-tree",
options: {},
},
],
})

When you start your Medusa backend (Copy to clipboardnpx medusa develop or Copy to clipboardpnpm dev), the plugin automatically injects:

  1. Admin UI Page & Sidebar Item: Registered under Copy to clipboard/app/category-tree with a folder tree icon.
  2. Backend API Endpoints: Under Copy to clipboard/admin/category-tree supporting atomic reorders, rank shifts, and category creations.

πŸ›’ Storefront Integration (Product Ranking & Top Sellers)

The plugin persists category-scoped ranking and top seller configuration into Copy to clipboardcategory.metadata:

  • Copy to clipboardcategory.metadata.ordered_product_ids: string[]
  • Copy to clipboardcategory.metadata.product_ranks: Record<string, number>
  • Copy to clipboardcategory.metadata.top_sellers: string[]

Storefront 2 Priority Showcase Example

In your storefront API or data layer (e.g. Next.js App Router):

// Inspect category metadata for top commercial sellers
const topSellerIds = category.metadata?.top_sellers || []
if (topSellerIds.length > 0) {
// Fetch top seller products and place them first in designated order
const { products: topProducts } = await getProductsList({
queryParams: { id: topSellerIds },
})
topProducts.sort((a, b) => topSellerIds.indexOf(a.id) - topSellerIds.indexOf(b.id))
// Fill remaining slots from the general category pool without duplicates
return [...topProducts, ...otherCategoryProducts]
}

☁️ Media Upload & Storage Provider Compatibility

The plugin's Category Detail Hub features a unified media uploader and gallery manager. To ensure zero vendor lock-in, file handling is 100% storage-provider agnostic:

  1. Native Medusa File Module Pipeline:
    • Uploads execute via Medusa v2's native SDK (Copy to clipboardsdk.admin.upload.create({ files })), routing directly to Copy to clipboardPOST /admin/uploads.
    • Your backend delegates the upload to whichever File Module Provider is configured in Copy to clipboardmedusa-config.js and returns the CDN URL.
  2. Direct External URL / CDN Fallback:
    • If your assets are hosted on an external DAM, Cloudinary, Imgix, or third-party S3 bucket, you can simply paste the image URL directly into the uploader and click Add.

πŸ’‘ Category Media in Medusa v2: Native vs. Plugin Architecture

In core Medusa v2, products have native media tables (Copy to clipboardproduct_images), but Copy to clipboardproduct_category does not have a native images relationship out of the box.

To solve this universally without imposing mandatory database migrations on standard Medusa stores, this plugin employs an adaptive hybrid architecture:

  • Universal Metadata Mode (Zero Config / Out of the Box):
    • Stores all gallery assets and active thumbnail directly inside Medusa's native Copy to clipboardcategory.metadata:
{
"metadata": {
"image_url": "https://cdn.store.com/category-thumb.webp",
"images": [
{ "id": "img_01", "url": "https://cdn.store.com/hero.webp", "type": "thumbnail" },
{ "id": "img_02", "url": "https://cdn.store.com/banner.webp", "type": "image" }
]
}
}
  • Zero backend code or database migrations required. Any standard Medusa v2 installation supports this immediately.
  • Custom Backend Module Mode (Optional Extended Architecture):
    • If your backend has extended the Medusa framework with a custom Category Media module (e.g., custom DML model Copy to clipboardproduct_category_image exposing Copy to clipboard/admin/categories/:category_id/images), the plugin detects this endpoint and automatically synchronizes both the custom relation and metadata!

Configuring S3-Compatible Storage in Medusa v2

Because Medusa abstracts storage through Copy to clipboard@medusajs/medusa/file-s3, you can seamlessly route category media to AWS S3, Cloudflare R2, MinIO, or DigitalOcean Spaces by adjusting Copy to clipboardmedusa-config.js:

AWS S3

// medusa-config.js
module.exports = defineConfig({
modules: [
{
resolve: "@medusajs/medusa/file",
options: {
providers: [
{
resolve: "@medusajs/medusa/file-s3",
id: "s3",
options: {
file_url: process.env.MEDUSA_FILE_URL, // CDN or bucket public URL
access_key_id: process.env.S3_ACCESS_KEY_ID,
secret_access_key: process.env.S3_SECRET_ACCESS_KEY,
region: process.env.S3_REGION,
bucket: process.env.S3_BUCKET,
},
},
],
},

Cloudflare R2

// medusa-config.js
options: {
file_url: process.env.R2_PUBLIC_URL, // e.g. https://pub-xxxx.r2.dev or custom domain
access_key_id: process.env.R2_ACCESS_KEY_ID,
secret_access_key: process.env.R2_SECRET_ACCESS_KEY,
bucket: process.env.R2_BUCKET_NAME,
endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
region: "auto",
}

MinIO (Self-Hosted S3)

// medusa-config.js
options: {
file_url: process.env.MINIO_PUBLIC_URL, // e.g. http://localhost:9000/my-bucket
access_key_id: process.env.MINIO_ROOT_USER,
secret_access_key: process.env.MINIO_ROOT_PASSWORD,
bucket: process.env.MINIO_BUCKET,
endpoint: process.env.MINIO_ENDPOINT, // e.g. http://127.0.0.1:9000
additional_client_config: {
forcePathStyle: true, // Required for MinIO
},
}

DigitalOcean Spaces

// medusa-config.js
options: {
file_url: `https://${process.env.DO_SPACES_BUCKET}.${process.env.DO_SPACES_REGION}.digitaloceanspaces.com`,
access_key_id: process.env.DO_SPACES_KEY,
secret_access_key: process.env.DO_SPACES_SECRET,
bucket: process.env.DO_SPACES_BUCKET,
endpoint: `https://${process.env.DO_SPACES_REGION}.digitaloceanspaces.com`,
region: process.env.DO_SPACES_REGION,
}

πŸ—οΈ Architecture & Project Structure

medusa-plugin-category-tree/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ admin/
β”‚ β”‚ β”œβ”€β”€ index.tsx # Medusa Admin SDK registration
β”‚ β”‚ β”œβ”€β”€ routes/category-tree/ # Route /app/category-tree
β”‚ β”‚ └── components/category-tree/
β”‚ β”‚ β”œβ”€β”€ category-tree-canvas.tsx # Interactive canvas & marquee selection
β”‚ β”‚ β”œβ”€β”€ category-node.tsx # Node card with tier bars & ranks
β”‚ β”‚ β”œβ”€β”€ custom-edge.tsx # Orthogonal edge matching branch color
β”‚ β”‚ β”œβ”€β”€ canvas-dock.tsx # Floating glassmorphic dock
β”‚ β”‚ β”œβ”€β”€ tier-bars.tsx # Branch-colored tier bars
β”‚ β”‚ β”œβ”€β”€ edit-category-drawer.tsx # 4-tab Category Detail Hub
β”‚ β”‚ β”œβ”€β”€ category-products-manager.tsx # Products table, ranking & FocusModal
β”‚ β”‚ β”œβ”€β”€ create-category-drawer.tsx # Slide-over subcategory creator
β”‚ β”‚ └── lib/
β”‚ β”‚ β”œβ”€β”€ layout-engine.ts # Buchheim/Walker centered tree engine
β”‚ β”‚ └── tree-state.ts # Palette, tiers, ranks, & cycle checks
β”‚ β”œβ”€β”€ api/admin/category-tree/ # Server route handlers
β”‚ └── workflows/ # Atomic reorder workflows
β”œβ”€β”€ package.json

πŸ› οΈ Development & Building

To build the plugin for distribution:

# In the plugin directory
pnpm build
# or
npm run build

This compiles TypeScript definitions and JavaScript bundles into Copy to clipboard.medusa/server/.

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to open an issue or pull request on our repository.

πŸ“„ License

Apache License 2.0 Β© HectaSquare Team

You may also like

Browse all integrations

Build your own

Develop your own custom integration

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?