How harshyadav812/nextjs-ecommerce-store works
Project type and purpose
• This is a full-stack, multi-tenant e-commerce marketplace built with Next.js 15 (App Router), Payload CMS, tRPC, MongoDB, and Stripe.
• Vendors get isolated “stores” under subdomains; customers browse, add to cart, and checkout.
File structure
• src/app/(app): public storefront pages (home, auth, library, tenants’ store fronts)
• src/app/(payload): Payload CMS admin UI and GraphQL/REST playground under /admin and /api
• src/collections: Payload collection schemas (Users, Products, Orders, Tenants, etc.)
• src/modules: feature modules (auth, products, checkout, tenants, library, categories, reviews, tags) each exposing tRPC procedures and UI components
• src/trpc: tRPC server setup, client, routers, and initialization
• src/lib & src/hooks: shared utilities (Stripe helper, access control, custom hooks)
• API routes:
• /api/stripe/webhooks – Stripe webhook receiver
• /api/trpc – tRPC endpoint
• /api/graphql – Payload CMS GraphQL API
• Middleware.ts supports multi-tenant context and auth
README for additional insights
• Multi-tenancy with complete data isolation per vendor
• Type-safe API via tRPC, prefetching and SSR in Next.js, N+1 query optimization
• Stripe payment flow with platform fee and vendor payout
• Tech stack confirms Next.js (React), Payload CMS, tRPC, MongoDB, Stripe
a. Main components
• Web Client (Next.js App Router) – SSR & CSR, React components
• State & Data Layer – TanStack Query, Zustand
• API Layer –
◦ tRPC server (procedures in src/modules/*/server)
◦ Payload CMS API (collections in src/collections, payload.config.ts)
◦ Stripe Webhooks handler (/api/stripe/webhooks)
• Database – MongoDB
• External Services – Stripe (payments, webhooks)
• Admin Panel – Payload CMS UI under /admin
b. Relationships & interactions
• User → Next.js pages → data fetch via tRPC calls or direct Payload GraphQL/REST
• tRPC server → calls business logic (modules/*/server/procedures) → reads/writes MongoDB
• Checkout flow: Next.js client invokes Stripe Checkout Session → redirect to Stripe → success/failure → Stripe Webhook → Next.js API writes Order to DB and triggers notifications
• Admin user → Payload CMS UI → CRUD on collections → MongoDB
c. Architectural patterns & principles
• Multi-tenant isolation: context determined from subdomain/slug (middleware.ts)
• Modular monolith: feature-based modules with clear separation (auth, products, checkout, tenants, etc.)
• Type-safe end-to-end: shared types between frontend and tRPC backend
• Server Components for SSR, Client Components for interactive UI
d. Key technologies & frameworks
• Next.js App Router, React Server/Client Components
• tRPC 11 for API
• Payload CMS 3 for headless CMS and admin
• MongoDB for persistence
• Stripe for payments
• TanStack Query & Zustand for client-side state and caching
• Tailwind CSS for styling
Elements
• Admin panel separately under “Payload CMS UI”