How yuangwei/payload-ecommerce works
Project type and purpose
• This is a full-stack, server-rendered React application built with Next.js (App Router).
• It embeds Payload CMS as a headless content management system, mounting its admin UI at /admin and its REST/GraphQL API under a catch-all API route.
File structure
• Top-level directories/files of interest:
• app/ – Next.js App Router directory.
– app/page.tsx – main public-facing page.
– app/admin/ – Payload admin UI.
– app/api/[...slug]/route.ts – catch-all Next.js API route that initializes Payload.
• payload.config.ts – Payload CMS configuration (collections, database).
• collections/ – Payload collection definitions (e.g., users.ts).
• next.config.ts, tsconfig.json – Next.js and TypeScript config.
• Patterns: a single Next.js serverless entrypoint hosting both public pages and the CMS API/admin UI.
README
• Confirms a Next.js 13 project scaffolded via create-next-app.
a. Public Frontend (Next.js SSR/SSG)
b. Payload CMS Server (mounted in the API route)
c. Payload Admin UI (served at /admin)
d. Database (e.g., MongoDB or PostgreSQL)
e. External/Hosting (Vercel Serverless Functions, CDN for public/ assets)
Relationships and data flows
• Public User → HTTP GET / or other page routes → Next.js Server
→ (during SSR/SSG) calls Payload CMS Server → Database → returns content → Next.js renders HTML → Public User.
• Admin User → navigates to /admin → Next.js serves static admin UI → Admin UI calls Payload CMS Server via REST/GraphQL → Database reads/writes → Admin UI updates.
• Build/Deploy pipeline (Vercel) picks up next.config.ts, environment variables, and deploys serverless functions for app/api/[...slug].
Architectural patterns/design principles
• Headless CMS pattern: content is managed and exposed via a decoupled API.
• Server-side rendering (SSR) and static generation in Next.js for public pages.
• Single codebase for both front and back, with serverless functions hosting the CMS API.
• Separation of concerns:
• Presentation layer (React components in app/)
• Data layer (Payload collections + database)
• Integration layer (Next.js API route for Payload)
Relevant technologies/frameworks
• Next.js 13 (App Router, server components)
• React + TypeScript
• Payload CMS (with payload.config.ts + collections/)
• Tailwind CSS (tailwind.config.ts)
• Vercel (serverless hosting)
• MongoDB or PostgreSQL (configured via environment variables)
• Public Browser / User Agent
• Next.js App Server (App Router)
• Public Page Components (app/page.tsx, other routes)
• Admin UI Static Assets (app/admin/*)
• Payload CMS API (Next.js Serverless Function at app/api/[...slug])
• Database (MongoDB/PostgreSQL)
• Vercel (Hosting & Serverless Execution)
• Page requests
• Data fetch (SSR)
• Admin UI API calls
• Database read/write
• Optional: CDN for public/ assets, environment variables store