How episerver/cms-saas-vercel-demo works
Project type and purpose
• This is a monorepo hosting a full-stack web application demo site built in Next.js that uses Optimizely SaaS CMS as a headless content source. It also contains a CLI tool for scaffolding new sites (under packages/remkoj-optimizely-fx-nextjs-cli).
File structure
• Top-level:
• Yarn workspace configuration (.yarnrc.yml, .yarn/, package.json, tsconfig.json)
• apps/ – application code
– apps/frontend/ – the Next.js front-end
– apps/old_cms_types/ – legacy CMS type definitions (fallback code)
• packages/ – npm packages
– remkoj-optimizely-fx-nextjs-cli/ – a CLI for setting up Optimizely-One-Next.js projects
• docs/ and content-updates/ – documentation and data migrations
• Notice Next.js conventions in apps/frontend/src/app (file-based routing and API routes), GraphQL codegen config, PostCSS, Tailwind, ESLint, Prettier SDKs.
README for additional insights
• The front-end pulls content at build-time or run-time from the Optimizely Content Graph (GraphQL endpoint) using environment variables (OPTIMIZELY_CMS_URL, OPTIMIZELY_GRAPH_*).
• It’s deployed to Vercel (see vercel.json and README deploy instructions).
• It supports preview, static generation, client-side fetches, and on-page editing.
Main components of the system
a. Monorepo (Yarn workspaces)
b. CLI package (remkoj-optimizely-fx-nextjs-cli) – developer tool used locally at “build time” to scaffold new sites
c. Frontend application (apps/frontend)
• Next.js server (SSR/SSG) + React components
• File-based routing (src/app/[[...path]], API routes in src/app/api/...)
• GraphQL codegen & client (gql/, codegen.ts)
• Static assets (in public/)
• Styling (Tailwind in tailwind.config.ts, PostCSS, SCSS)
d. Optimizely CMS Content Graph (external GraphQL service)
e. Vercel (build pipeline & hosting)
f. Optional external services (e.g., Content Recommendations, Analytics integrations)
Relationships and interactions
• Build time:
• Developer invokes Yarn in root → installs workspaces → runs codegen in apps/frontend → Next.js build → output (static assets + serverless functions) → Vercel
• CLI package installed globally or via yarn workspace to scaffold new projects
• Runtime (user request flow):
1. Browser → Vercel Edge → Next.js serverless function (SSR/SSG) or static host
2. If SSR or fallback, Next.js calls GraphQL client → Optimizely CMS Content Graph → returns JSON content
3. Next.js renders page → HTML & JSON → Browser
4. In-page React components may fetch further dynamic data (search, “me”, preview) via built-in API routes → Next.js → CMS or other external services
5. Browser-side feature flags (via useFlag.ts) and analytics (“google-analytics.tsx”)
Architectural patterns and principles
• Monorepo with Yarn workspaces for code sharing
• File-based routing (Next.js app router) + API routes for serverless micro-endpoints
• GraphQL code generation for type-safe CMS queries
• Component-driven UI mapped to CMS content types (CMS components, experiences, media, page templates)
• Static & dynamic hybrid rendering (SSG with ISR, SSR for preview)
• Clear separation of concerns: components vs. layout vs. API vs. integrations