Multi-Tenant E-Commerce with Platform Fees
A modern e-commerce platform built with Next.js, Payload CMS, and Stripe, featuring multi-tenant architecture and platform fees capabilities.
Features
- ๐ฌ Multi-tenant architecture
- ๐ Vendor subdomains
- ๐จ Custom merchant storefronts
- ๐ณ Stripe Connect integration
- ๐ฐ Automatic platform fees
- โญ Product ratings & reviews
- ๐ User purchase library
- ๐งโ๐ผ Role-based access control
- ๐ ๏ธ Admin dashboard
- ๐งพ Merchant dashboard
- ๐งฑ Payload CMS backend
- ๐๏ธ Category & product filtering
- ๐ Search functionality
- ๐ผ๏ธ Image upload support
- โ๏ธ Built with Next.js 15
- ๐จ TailwindCSS V4 styling
- ๐ ShadcnUI components
Prerequisites
- Node.js 18+ or Bun 1.0+
- MongoDB Atlas account
- Stripe account
- Vercel account (for Blob storage)
Getting Started
Installation
Using Bun (Recommended)
# Clone the repository
git clone https://github.com/code-with-antonio/next15-multitenant-ecommerce.git
cd multitenant-ecommerce
# Install dependencies
bun install
# Copy environment variables
cp .env.example .env
Using npm
# Clone the repository
git clone https://github.com/code-with-antonio/next15-multitenant-ecommerce.git
cd multitenant-ecommerce
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
Using yarn
# Clone the repository
git clone https://github.com/code-with-antonio/next15-multitenant-ecommerce.git
cd multitenant-ecommerce
# Install dependencies
yarn install
# Copy environment variables
cp .env.example .env
Environment Variables
Update the .env file with your configuration:
# Database
DATABASE_URI=your_mongodb_uri
PAYLOAD_SECRET=your_payload_secret
# Global
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_ROOT_DOMAIN=localhost:3000
NEXT_PUBLIC_ENABLE_SUBDOMAIN_ROUTING=false
# Stripe
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
# Vercel Blob
BLOB_READ_WRITE_TOKEN=your_vercel_blob_token
Subdomain Routing Configuration
The platform supports wildcard subdomain routing, allowing each vendor to have their own unique subdomain (e.g., vendorname.yourdomain.com). This feature is controlled by the NEXT_PUBLIC_ENABLE_SUBDOMAIN_ROUTING environment variable.
Development
By default, subdomain routing is disabled in development (NEXT_PUBLIC_ENABLE_SUBDOMAIN_ROUTING="false"), and all stores are accessed through routes like:
http://localhost:3000/tenants/[tenant-slug]
Production
To enable subdomain routing in production:
-
Configure your DNS provider with a wildcard subdomain record:
*.yourdomain.com โ your-vercel-deployment.vercel.app -
Update your environment variables:
NEXT_PUBLIC_ROOT_DOMAIN=yourdomain.com NEXT_PUBLIC_ENABLE_SUBDOMAIN_ROUTING="true"
Once enabled, stores will be accessible through their unique subdomains:
https://tenantslug.yourdomain.com
Notes
- Make sure your hosting provider (e.g., Vercel) supports wildcard subdomains
- Each subdomain will automatically serve the corresponding store's content
- SSL certificates should be configured to support wildcard subdomains
- The main marketplace will remain accessible at your root domain
Database Setup
# Using Bun
bun run db:fresh
bun run db:seed
# Using npm
npm run db:fresh
npm run db:seed
# Using yarn
yarn db:fresh
yarn db:seed
Development
# Using Bun
bun run dev
# Using npm
npm run dev
# Using yarn
yarn dev
Open http://localhost:3000 with your browser to see the result.
Available Scripts
dev- Start development serverbuild- Build for productionstart- Start production serverlint- Run ESLintgenerate:types- Generate Payload CMS typesdb:fresh- Reset and migrate databasedb:seed- Seed database with initial data