This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
For documentation content guidelines (adding/editing docs), see content/README/AGENTS.md.
This is the Superwall documentation site built with Next.js, Fumadocs, and deployed to Cloudflare Pages. The site serves SDK documentation for multiple platforms (iOS, Android, Flutter, Expo) along with dashboard guides and integration documentation.
# First-time setup: build documentation files
bun run build
# Start development server at http://localhost:8293
bun run dev
# Clear Next.js cache if needed
rm -rf .next
# Clear build cache
bun run clear:cache# Build for production
bun run build
# Deploy to staging
bun run deploy:staging
# Deploy to production
bun run deployCRITICAL: DO NOT EVER DEPLOY WITHOUT CHECKING WITH THE USER
# Generate AI-optimized markdown files
tsx scripts/generate-llm-files.ts
# Generate standard markdown files
tsx scripts/generate-md-files.ts
# Copy documentation images
bun run copy:docs-images
# Watch for image changes during development
bun run watch:imagesThe documentation follows a strict source-to-output pipeline:
- Source files:
/content/docs/**/*.mdx(ALWAYS edit here) - Processing: Build scripts + remark plugins transform content
- Generated output:
/public/**/*.md(NEVER edit - auto-generated)
CRITICAL: Always edit files in /content/docs/, NEVER in /public/. The /public/ directory contains auto-generated files that will be overwritten during build.
The site uses a sophisticated system to serve documentation for multiple SDKs from shared and platform-specific content:
- Platform folders:
/content/docs/{ios,android,flutter,expo}/ - Shared content:
/content/shared/contains reusable MDX files - SDK filtering:
remark-sdk-filterplugin removes platform-specific content blocks during build - SDK selector pattern:
/docs/sdk/*routes redirect to platform-specific pages (e.g.,/docs/sdk/quickstart/install→/docs/ios/quickstart/install)
Content processing happens through a series of custom remark plugins (defined in source.config.ts):
remark-image-paths- Resolves and processes image paths (runs first)remark-follow-export- Handles exported content referencesremark-include(fumadocs) - Processes file includes from shared contentremark-directive- Parses custom directive syntax (e.g.,:::expo)remark-tabs-syntax- Transforms tab syntax for multi-platform coderemark-code-language- Detects and sets code block languagesremark-codegroup-to-tabs- Converts code groups to tabbed interfacesremark-sdk-filter- Removes non-matching SDK-specific blocks (runs last)
The order matters - image path resolution must happen before other transformations.
- Structure: Each folder can have a
meta.jsonfile defining navigation order and hierarchy - Pages without catch-all: If
meta.jsondoesn't include"...", every page must be explicitly listed - Nested navigation: Related APIs can be grouped as nested objects (e.g.,
PaywallOptionsunderSuperwallOptions) - Auto-generation: Pages are generated based on file structure + meta.json configuration
- File references: Use relative paths without extensions (e.g.,
"guides/my-guide"not"guides/my-guide.mdx")
- Configuration:
redirects-map.tsdefines URL redirects - Types:
folderRedirectsMap- Redirects from root to folder pathsfileRedirectsMap- File-to-file redirects (e.g., legacy SDK installation paths)externalRedirectsMap- External URL redirects
- Processing:
next.config.tsgenerates redirect rules from these maps during build - Note: Changes to redirects require rebuild to take effect
- Platform: Cloudflare Pages via OpenNext.js adapter (
@opennextjs/cloudflare) - Environments: Production and staging
- Build process:
bun run build:cfcreates Cloudflare-compatible output - Webpack customization:
next.config.tsincludes aliases to replace eval-based components (not allowed on Cloudflare Workers) - Base path: All routes are prefixed with
/docs(configured in next.config.ts)
source.config.ts- Fumadocs configuration and remark plugin chainnext.config.ts- Next.js config, redirects, webpack aliases, basePath (/docs)redirects-map.ts- URL redirect mappings (exported as const objects)tsconfig.json- TypeScript config with path aliases (@/*→src/*).env.example- Environment variable templates
src/app/layout.config.tsx- Site layout, navigation, theme configurationsrc/lib/source.ts- Documentation source configuration and SDK iconssrc/mdx-components.tsx- Custom MDX component overridessrc/app/(docs)/[[...slug]]/page.tsx- Dynamic route handler for all doc pages
plugins/remark-sdk-filter.ts- Removes SDK-specific blocks (directive:::expoor JSX<div sdk="expo">)plugins/remark-tabs-syntax.ts- Processes custom tab syntaxplugins/remark-code-language.ts- Detects code block languagesplugins/remark-image-paths.ts- Resolves image paths for buildplugins/remark-follow-export.ts- Handles content exportsplugins/remark-codegroup-to-tabs.ts- Converts code groups to tabs
scripts/generate-title-map.ts- Creates title lookup map for pagesscripts/generate-llm-files.ts- Generates AI-optimized documentationscripts/generate-md-files.ts- Converts MDX to plain markdownscripts/copy-docs-images.cjs- Copies images from content to publicscripts/watch-docs-images.ts- Watches for image changes during devscripts/clear-cache.ts- Clears build cache
When adding new documentation pages:
- Create the
.mdxfile in the appropriate/content/docs/subdirectory - Update the corresponding
meta.jsonfile in the same folder to include the new page in navigation - Use relative paths without file extensions in
meta.json(e.g.,"guides/my-new-guide") - Group related APIs as nested objects when appropriate
- Run
bun run buildto generate output files and verify
Each SDK follows a standard structure:
content/docs/{sdk}/
├── quickstart/ # Getting started guides
├── guides/ # Conceptual docs and tutorials
│ ├── advanced/ # Advanced topics (collapsed in nav with meta.json)
│ └── ...
└── sdk-reference/ # API reference (one MDX per public symbol)
See .env.example for required environment variables:
SEARCH_MODE- Toggle between 'fumadocs' (default) or 'rag' (uses external AI search at mcp.superwall.com)NEXTJS_ENV- Development or production- Integration keys for Slack, Mesh, Unify, RB2B, Pylon (optional for local dev)
- Dev server port: 8293 (configured in package.json dev:next script)
- Changes requiring rebuild: Redirects, remark plugin modifications, meta.json changes, image additions
- Auto-reload: Content changes in
/content/docs/rebuild automatically during dev - Image handling: Images in
/content/docs/images/are copied to/public/during build - Component customization: Add custom components to
src/components/and reference in MDX - Turbo cache: Build uses Turbo for caching and optimization
@/*maps tosrc/*@/.sourcemaps to.source/index.ts(generated by Fumadocs)
- Check for syntax errors in
.mdxfiles - Verify
meta.jsonfiles are valid JSON - Ensure all pages in meta.json exist as files
- Run
bun run buildto see detailed error messages
- Clear cache:
rm -rf .next - Run full rebuild:
bun run build - Check for port conflicts (port 8293)
- Verify node_modules are installed
- Verify Cloudflare configuration in wrangler.jsonc
- Check build logs in deployment dashboard
- Ensure all environment variables are set
- Verify redirects-map.ts exports are valid