Medusa Examples

repository·main·Indexed 42 days ago

https://github.com/medusajs/examples

A collection of practical, real-world implementation examples for Medusa v2, including starters for Abandoned Cart and Agentic Commerce. These examples demonstrate how to extend Medusa using custom features, third-party integrations, scheduled jobs, subscribers, and module links.

Tokens
182.8K
Snippets
635
Records
745
Agent score
52%

What's inside Medusa Examples

  1. Overview of Medusa Next.js Starter features

    main

    The Medusa Next.js Starter is a performant storefront built with Next.js 15, Tailwind CSS, and TypeScript. It is designed to work with a Medusa commerce backend.

    Core Ecommerce Features:

    • Product Detail Page
    • Product Overview Page
    • Product Collections
    • Cart management
    • Checkout with Stripe
    • User Accounts
    • Order Details

    Next.js 15 Capabilities:

    • App Router
    • Next fetching/caching
    • Server Components
    • Server Actions
    • Streaming
    • Static Pre-Rendering
  2. Overview of Medusa Examples

    main

    This repository contains source code for various example projects built with Medusa v2. These examples demonstrate how to implement specific features, integrations, and storefront experiences using the Medusa platform.

    To use a specific example, navigate to its directory and read its local README.md file for detailed setup and usage instructions.

  3. What is Medusa

    main
    Medusa is an open-source set of commerce modules and tools designed to provide foundational commerce primitives. It allows developers to build advanced ecommerce stores, marketplaces, and other commerce applications without reinventing core logic. All modules are available via npm and can be customized to fit specific business needs.
  4. Overview of Invoice Generator features

    main

    The Invoice Generator example provides the following capabilities:

    • Automatic Invoice Generation: Generates PDF invoices automatically upon order placement.
    • Email Delivery: Automatically emails invoices to customers (requires a Notification Module Provider to be installed).
    • Admin Dashboard: Provides UI for managing invoice configurations and downloading invoices.
    • Store Customizations: Includes API routes for downloading invoices directly from the storefront.

    You can view the full API specification via this OpenAPI Spec file to import into tools like Postman.

  5. What is Medusa and its core concepts

    main

    Medusa is an open-source set of commerce modules and tools designed to provide foundational commerce primitives. It allows developers to build ecommerce stores, marketplaces, and other commerce-driven applications without implementing core logic from scratch. All modules are available via npm.

    Key architectural concepts include:

    • Commerce Modules: Specialized modules that handle core commerce logic.
    • Architecture: A modular system designed for customization and performance.

    For deep dives, refer to the Medusa Architecture and Commerce Modules documentation.

  6. Extend Medusa Admin with Widgets and Pages

    main

    You can extend the Medusa Admin dashboard by adding custom widgets and new pages. These customizations allow you to provide merchants with additional functionalities by interacting with your application's API routes.

    To implement these, you typically create React components and register them within the admin directory structure.

  7. Prerequisites for Sanity Integration

    main

    Before setting up the Sanity integration, ensure you have the following:

    • Node.js: v20 or higher
    • Git CLI
    • PostgreSQL
    • Sanity Project: A configured project at sanity.io.
    • CORS Configuration: You must add http://localhost:8000 to your Sanity project's CORS settings to allow requests from the local development environment.
  8. What is a Medusa Module?

    main
    A module is a package of reusable functionalities that can be integrated into a Medusa application without affecting the overall system. Modules can be created as part of a plugin and typically consist of a data model, a service containing business logic, and a module definition. They are registered in the application configuration and can be accessed via the dependency injection container (the req.scope).
  9. How to use a module via dependency injection

    main

    To use a module within the Medusa application (such as in API routes or workflows), you must resolve the module service from the Medusa container using its exported module name.

    Use req.scope.resolve(MODULE_NAME) where MODULE_NAME is the string constant exported by your module's index.ts.

    import { BLOG_MODULE } from "../../../modules/blog"
    
    // Inside an API route handler
    const blogModuleService = req.scope.resolve(BLOG_MODULE)
    const posts = await blogModuleService.listPosts()
  10. How module links work to associate data models

    main

    A module link creates an association between two data models belonging to different modules while preserving module isolation. This allows you to relate entities (like a product from the Product Module and a post from a custom Blog Module) without tightly coupling the modules themselves.

    To define a link, use the defineLink utility from @medusajs/framework/utils. You pass the linkable data models from each respective module as arguments.

    After defining your links in code, you must synchronize them with your database by running the Medusa migration command.

    import BlogModule from "../modules/blog"
    import ProductModule from "@medusajs/medusa/product"
    import { defineLink } from "@medusajs/framework/utils"
    
    export default defineLink(
      ProductModule.linkable.product,
      BlogModule.linkable.post
    )
  11. ACP Compatibility and Production Readiness for Agentic Commerce

    main

    This example implements the ACP 2026-04-17 Agentic Checkout and webhook schemas. Note the following implementation details and production requirements:

    CapabilityExample Implementation StatusProduction Requirement
    Product-feed generationsendProductFeed only logs the feed.Implement authenticated transport and delivery monitoring.
    Checkout session routesAuthentication is disabled in sample middleware.Enable and test bearer authentication.
    POST idempotencyRoutes pass key to workflow context.Enforce required, replay, in-flight, and payload-conflict behavior.
    Delegated paymentStripe example provided.Validate provider eligibility, failure recovery, and reconciliation.
    Order webhooksSchema-aligned payload example.Implement webhook delivery, retry, and monitoring.

    Security Checklist for Production:

    • Enable and test bearer authentication.
    • Enforce ACP version and idempotency behavior.
    • Implement secure transport for product feeds and webhooks.
    • Store and rotate signing secrets securely.
    • Validate all business scenarios (checkout, payment, order, refund, fulfillment).