Skip to content

About

πŸ“š Next.js 16 platform for selling math courses, with a headless CMS, auth, video lessons, quizzes, LaTeX, interactive graphs, and an MCP server for AI-assisted content management.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

332 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js Math Course Platform

A modern full-stack Next.js 16 platform with CMS, auth, and Stripe integration - built to manage and sell online math courses with videos, quizzes, LaTeX, and interactive graphs.

GitHub code size in bytes GitHub created at GitHub last commit GitHub License

Tech Stack

Landing Lesson Lesson

Features

  • Full Authentication - powered by BetterAuth, featuring Google OAuth, Google One Tap, Passkeys, email verification & password reset via Resend. Includes Cloudflare Turnstile bot protection, block for disposable emails, last used method badge, session limits and rate limiting with Redis to prevent account sharing and abuse.
  • Admin CMS Dashboard - manage courses, lessons, and media directly through an integrated headless Payload CMS interface with drafts, version history, scheduled publishing via QStash job queues, and TOTP two-factor authentication.
  • Scheduled Course Publishing β€” automatically publish courses on schedule with failure detection and admin email alerts.
  • AI Feedback Classification β€” automatically classify lesson feedback by category, importance, sentiment, and spam using Jev by TypeSafe AI, with automatic retries.
  • MCP integration - a Model Context Protocol server lets AI clients like Claude draft, edit, and review lesson content directly against the CMS.
  • Stripe Payments - sell courses with one-time payments using Stripe Checkout.
  • Hybrid Lesson Delivery (SSR + SSG) - free lessons are pre-rendered for speed and SEO, while paid lessons use server-side rendering for secure, on-demand access.
  • Caching & Revalidation - lesson and enrollment data are cached for performance and automatically refreshed via Payload CMS hooks or Stripe webhook when content or access changes.
  • Media storage - dual-bucket setup on AWS S3 / Cloudflare R2: public assets (course posters, free lesson images) served directly from the CDN for speed, and protected assets (paid lesson images) served through presigned URLs restricted to enrolled users, both with auto-generated blur placeholders.
  • Mux Video Integration - video uploads through CMS and streaming; paid lessons use signed URLs restricted to enrolled users, free lessons stream publicly.
  • Rich Lesson Content - lessons are authored in Markdown with LaTeX math, interactive Desmos graphs, and custom elements like callout blocks, with settings like larger math font or colored symbols.
  • SEO Optimization - OG image generation, XML sitemap with per-lesson metadata (images, video thumbnails, duration, descriptions) for published free lessons.

Development

Clone the Repository

git clone https://github.com/maciekt07/nextjs-math-course
cd nextjs-math-course

Install Dependencies

pnpm install

Set Up Environment Variables

Create a .env.development file in the root directory. Use .env.example as a template. Environment variables are fully typed and validated for both dev and build. For production preview, use .env.production file.

Start Databases

Both PostgreSQL (for main app data) and MongoDB (for Payload CMS) run via Docker Compose

pnpm docker:dev

Tip

View Database with Drizzle Studio

pnpm db:studio

Apply Database Migrations

pnpm db:push

Run the Stripe webhook listener

pnpm stripe:webhook

Testing Payments

Use these Stripe test card details to simulate a successful payment:

  • Card Number: 4242 4242 4242 4242
  • Expiration Date: Any future date
  • CVC: Any 3-digit code

Run the App

Development mode:

pnpm dev

Production preview:

pnpm preview

The application should now be running at http://localhost:3000

Access Payload CMS Admin Panel

Once the app is running, you can access the CMS at:

http://localhost:3000/admin

  • Create your admin account on first visit

  • Use the panel to manage courses, lessons, and media

Preview Emails

Start the React Email preview server to view and test email templates locally:

pnpm email:dev

Set Up Upstash QStash (background jobs)

QStash periodically calls /api/cron/run, which triggers Payload's Jobs Queue for scheduled course publishing and feedback classification with Jev.

Start local QStash CLI:

pnpm qstash:dev

Register schedule against it:

pnpm qstash:schedules:dev

Usage

Using MCP Server

The CMS exposes an MCP server for managing lessons, chapters, and courses

1. Generate an API key

Go to /admin β†’ MCP β†’ API Keys β†’ Create New, enable the required collections/operations, save, and copy the generated key.

2. Connect your MCP client

Claude Code example:

claude mcp add --transport http Math-Course-CMS http://127.0.0.1:3000/api/mcp \
  --header "Authorization: Bearer MCP-USER-API-KEY"

Changes will be automatically saved as draft with version control.

Using Desmos Graphs

You can add interactive Desmos graphs directly in markdown lessons:

::desmos{url="https://www.desmos.com/calculator/your-graph-id"}
Desmos Graph

Note

By default, the embedded version displays only the graph. If you set noEmbed=true, it will open the full Desmos calculator with all its tools and controls.

::desmos{url="https://www.desmos.com/calculator/your-graph-id" noEmbed=true}

Using LaTeX in Markdown

You can include math expressions in your lessons using standard Markdown + LaTeX syntax:

Inline math: $E = mc^2$

Block math:

$$
f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}
$$

For more details, see the Markdown + LaTeX documentation

Using Mermaid Diagrams

You can add Mermaid diagrams directly in your markdown lessons:

```mermaid
flowchart TD
    A["Numbers"] --> B["Natural numbers"]
    A --> C["Integers"]
    A --> D["Rational numbers"]
    A --> E["Real numbers"]

    D --> F["$$\frac{a}{b}$$"]
    E --> G["Number line"]
```
Mermaid Diagram

Using Callout Blocks

You can highlight important content or tips using custom callout blocks like note, tip, important, warning, card.

:::note
This is a note
:::

:::tip{title="Remember"}
This is a tip with a custom title
:::
Callout block

Reordering Lessons

  1. Go to the Lessons collection in the CMS.
  2. In the top-right, open Filters β†’ Add Filter.
  3. Select course β†’ equals β†’ your course.
  4. Use drag-and-drop to reorder the filtered lessons.
Sort Filter

Performance

lighthouse

Math rendering

In paid lessons, math formulas are rendered lazily on the client as it scrolls into view, preventing main-thread blocking and avoiding FPS drops on long pages with many formulas. Free lessons are fully SSGed, which requires no special optimization and also benefits SEO.

Pages are also automatically split into semantic <section> tags. Each section uses content-visibility: auto, allowing the browser to skip rendering off-screen content until it is needed.

Credits

Illustrations used in this project are from Storyset, modified for personal use.

Made with ❀️ by maciekt07, licensed under MIT

About

πŸ“š Next.js 16 platform for selling math courses, with a headless CMS, auth, video lessons, quizzes, LaTeX, interactive graphs, and an MCP server for AI-assisted content management.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages