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 clipboard
smoothstep) 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 Sellerstatus reflected in storefronts. - Multi-storefront filtering: Seamlessly filter the entire tree by Sales Channel (Copy to clipboard
All 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:
- 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 Pagelink opening Copy to clipboard/app/categories/:idin a separate tab when desired.
- 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 clipboard
Q Search), pagination, and batch assignment.
- Storefronts & Media:
- Multi-sales channel visibility checkboxes (Copy to clipboard
Monfil Store, Copy to clipboardSuperpunch, etc.). - Native Drag-and-Drop Media Upload: Integrated with Medusa v2's native File Module (Copy to clipboard
sdk.admin.upload.create). - Visual Gallery Manager: Image preview cards, delete actions, and one-click Copy to clipboard
β Thumbnaildesignation. - Direct External URL Input: Fallback support for external CDN, Cloudinary, or DAM image links.
- Multi-sales channel visibility checkboxes (Copy to clipboard
- 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 clipboard
A -> A) or cyclic loops (Copy to clipboardA -> B -> C -> A).
π¦ Installation
Install the package in your Medusa backend project:
12345npm install @hectasquare/medusa-plugin-category-tree# orpnpm add @hectasquare/medusa-plugin-category-tree# oryarn 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):
12345678module.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:
- Admin UI Page & Sidebar Item: Registered under Copy to clipboard
/app/category-treewith a folder tree icon. - Backend API Endpoints: Under Copy to clipboard
/admin/category-treesupporting 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 clipboard
category.metadata.ordered_product_ids: string[] - Copy to clipboard
category.metadata.product_ranks: Record<string, number> - Copy to clipboard
category.metadata.top_sellers: string[]
Storefront 2 Priority Showcase Example
In your storefront API or data layer (e.g. Next.js App Router):
12345678910111213// Inspect category metadata for top commercial sellersconst topSellerIds = category.metadata?.top_sellers || []if (topSellerIds.length > 0) {// Fetch top seller products and place them first in designated orderconst { 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 duplicatesreturn [...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:
- Native Medusa File Module Pipeline:
- Uploads execute via Medusa v2's native SDK (Copy to clipboard
sdk.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 clipboard
medusa-config.jsand returns the CDN URL.
- Uploads execute via Medusa v2's native SDK (Copy to clipboard
- 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 clipboard
category.metadata:
- Stores all gallery assets and active thumbnail directly inside Medusa's native Copy to clipboard
123456789{"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 clipboard
product_category_imageexposing Copy to clipboard/admin/categories/:category_id/images), the plugin detects this endpoint and automatically synchronizes both the custom relation and metadata!
- If your backend has extended the Medusa framework with a custom Category Media module (e.g., custom DML model Copy to clipboard
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
1234567891011121314151617181920// medusa-config.jsmodule.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 URLaccess_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
123456789// medusa-config.jsoptions: {file_url: process.env.R2_PUBLIC_URL, // e.g. https://pub-xxxx.r2.dev or custom domainaccess_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)
1234567891011// medusa-config.jsoptions: {file_url: process.env.MINIO_PUBLIC_URL, // e.g. http://localhost:9000/my-bucketaccess_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:9000additional_client_config: {forcePathStyle: true, // Required for MinIO},}
DigitalOcean Spaces
123456789// medusa-config.jsoptions: {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
1234567891011121314151617181920medusa-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:
1234# In the plugin directorypnpm build# ornpm 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
