hot-potato-client

Public
OVERVIEW.md

The Hot Potato client had to make one lesson work for both its teacher and its students.

The broader Hot Potato story began with a teacher's need and my interest in a substantial full-stack build. In this repository, the first hard problem was the interface: how could a teacher build a flexible lesson and have a student read the same content on a phone? A static form would not cover drawings, formulas, media, and different kinds of questions, so the editor grew into a document system with custom blocks.

One document, two ways to use it

Teacher tools edit a TipTap document; the student viewer renders that same structure. Question definitions and drawing state live in the document's nodes so saving, reopening, and viewing do not depend on a second hidden copy in React state. The teacher can bring in existing text, ask AI to suggest an outline or question, inspect a preview, and accept only what belongs in the lesson. The screen below shows that approval step in the authoring flow.

Hot Potato teacher AI draft preview in Thai before content is accepted into a lesson
Teacher authoring: AI proposes lesson structure for review before the teacher accepts it into the document.View source

The student side needed a different pace. Public lessons open without a sign-in wall, and the interface is Thai-first and phone-first. Students can answer several question types, receive feedback, and continue a conversation with the tutor. Streaming replies, follow-up suggestions, and optional account history make that conversation feel like part of the lesson rather than a separate AI page. The client sends requests to the companion server; it does not decide the trusted lesson text used by the tutor.

This repository owns the React interface, routes, state, editor, viewer, and browser-side API calls. The server owns persistence, access rules, and AI context. The useful result is a working two-sided experience; the client code and screenshots do not by themselves measure learning outcomes or usability with students.

README.md

Hot Potato

An AI-powered learning platform where teachers author interactive lessons and students learn with a personal AI tutor.

React TypeScript Vite Tailwind CSS

Express MongoDB Google Gemini

Showcase · Server Repository · Workspace Repository


Overview

Hot Potato is a full-stack learning platform designed for students who are far from good schools and reliable internet. Teachers — including non-technical ones — author rich lessons with embedded critical-thinking questions. Students read the lessons, answer the questions, and can freely ask an AI tutor (Google Gemini) anything about the content. The AI responds with warm, coaching-style feedback in Thai by default, rather than plain grading.

The deployable product is split across two repositories. This repository contains the web client; the separate workspace repository holds the cross-cutting architecture documentation.

Implementing a feature? Keep the root workspace repository alongside this repo. Its developer guidebook explains how client and server fit together, and its graphify-out/ knowledge graph connects UI, API, model, and tutor concepts across both codebases. Check that graph and the current source on both sides before changing an endpoint, lesson block, auth flow, or AI behavior.

RepositoryRoleStackHosted on
hot-potato-client (this repo)Web app — teacher editor + student viewer + AI chat surfacesReact 19, TypeScript, Vite 7, Tailwind CSS v4Vercel configuration
hot-potato-serverREST API — auth, lesson storage, student progress, the entire AI layerExpress 5, TypeScript, MongoDB (Mongoose 9), Google GeminiRender configuration

Two product principles shape the entire codebase:

  1. AI access is never rationed for real students — there are no per-student quotas. Rate limiting exists only to stop bots, with generous, environment-tunable thresholds.
  2. Anonymous users keep full access — reading lessons and using the AI tutor never requires an account. Logging in only adds persistence (answer history, chat history, tutor memory).

Use cases

The interface is Thai-first and can switch to English. These screenshots show a seeded guide lesson and demo accounts, captured with Playwright at 2× resolution. The landing screenshots were refreshed from the current running client with scripts/capture-readme-landing.mjs; the lesson and editor scenes come from scripts/capture-guide.mjs. Those older guide scenes should be recaptured after further UI changes. The in-app walkthroughs are at /guide/learning and /guide/creating when the client is running.

Current landing page with paths for students and teachers

Student: explore and read without signing in

  1. Open / and choose Start exploring, or go straight to /explore.
  2. Search by lesson title; switch between All, Bookmarked, and Recent. Bookmarks are stored on your device.
  3. Open a public lesson card. The viewer keeps the teacher's text, media, and embedded questions in reading order.
Explore lessonsRead a lesson
Explore with search and a bookmarked lessonLesson viewer on a phone

Student: answer questions and discuss the feedback

The lesson can contain multiple-choice, written-answer, drag-to-fill, and typed-fill questions. Submit your answer to get feedback; a written response is evaluated for reasoning. Follow-up suggestions and the question's conversation thread let you continue thinking through the same topic.

Choose an answerWrite an answerFill a blank
Multiple-choice questionWritten-answer questionDrag-to-fill question
AI feedback with suggested follow-up questions

Student: ask the tutor freely

Tap Ask AI in a lesson and ask a question in your own words. Replies stream into a chat grounded in the lesson, with suggested next questions. This also works anonymously; signing in adds server-side conversation history.

Ask about the lessonChoose a coaching style
Ask AI conversationTutor personality selector

Student: return to learning and set preferences

With an account, visit History to reopen lessons and Profile to view or erase tutor memory. Automatic memory updates are currently off by default on the server; the memory screen can still display existing data. Settings offers language, theme, and font-size controls.

Learning historyTutor memorySettings
Recently opened lessonsTutor memory cardLanguage and appearance settings

Teacher: create and write a lesson

  1. Sign in, open Create, and start a lesson.
  2. Write on the desktop editor canvas. Use the left rail for text, media, formulas, and questions; review the document and formatting controls alongside it.
  3. Add images or drawings and build a math expression visually when the lesson needs them.

Start a lesson:

Teacher Create page

Open the blank editor, then write and format content:

Blank lesson editor Lesson editor with content Text editing controls

Add media and formulas:

Image and media controls Math formula builder

Teacher: add questions and use the AI copilot

Add a question block from the editor rail and set its prompt, options, and guidance. The AI rail offers a workflow for outlining, drafting, improving text, generating questions, and reviewing the lesson. Generated material is previewed; it enters the document only when the teacher accepts it.

Build a question:

Question blocks in the editor Question creator form

Ask AI for a draft, then review its proposal:

AI tools grouped by writing step AI outline awaiting approval AI lesson review

Teacher: publish and share

Review the lesson, choose public, link-only, or private, and configure the tutor's per-lesson guidance. After publishing, copy or share the lesson link. A teacher can also add collaborators to help maintain a lesson.

Publish dialog and tutor settings Share controls after publishing

Features

For students

  • Interactive lesson viewer — rich text, images, tables, embedded YouTube, math formulas, and drawings, rendered read-only from the same document format the editor produces.
  • Five embedded question types — multiple choice, open-ended writing (AI-evaluated), fill-in-the-blank (choice and typed), and an embedded free-form AI tutor block.
  • Streaming AI tutor — answers stream token-by-token over SSE, render as safe markdown, and end with up to three tappable follow-up suggestion chips. Every question card supports a follow-up conversation thread.
  • Six tutor personalities — students pick the coaching style they like; the choice persists and is attached to every AI call.
  • Tutor memory controls — logged-in students can view and erase their sketch from the profile page. Automatic sketch updates and injection are disabled by default on the server; operators can enable them with AI_MEMORY_ENABLED=true.
  • No login wall — anonymous visitors can read every public lesson and use the AI tutor in full; conversation context is kept client-side and sent per request.
  • Answer persistence and history — answers autosave per block; recently opened lessons appear in the history page.

For teachers

  • Block-based lesson editor — built on TipTap 3 with custom node types: a resizable-image node, an embedded Fabric.js drawing canvas, a visual math-formula builder that serializes to LaTeX (rendered with KaTeX), and the five question blocks.
  • AI copilot inside the editor — a dedicated AI hub with eleven assistive actions: lesson outlining, section drafting, structure import, proofreading (six presets), question generation, guide-answer drafting, distractor suggestions, a lesson critic, and publish-metadata autofill. Every AI output goes through a preview → accept flow; nothing touches the document without explicit approval.
  • Per-lesson tutor controls — teachers configure the AI tutor's persona note, answer-directness, scope, and custom guidelines per lesson at publish time.
  • Access control — lessons can be public, link-only, or private, with collaborator support.
  • Image library — Cloudinary-backed upload and folder organization.

Platform & AI engine (server side)

  • One unified tutor endpoint — POST /api/chat/tutor serves four conversation modes (free chat, question feedback, writing evaluation, follow-up) with SSE streaming and a plain-JSON fallback.
  • Server-owned lesson context — the server loads and serializes the lesson for every AI call (cached), so the client never ships lesson text over the wire.
  • Model routing and resilience — lightweight tasks go to a fast Gemini model, coaching tasks to a stronger one; transient network failures are retried automatically.
  • Authentication — email/password (bcrypt) and Google Sign-In (verified Google Identity Services ID tokens with safe account auto-linking), JWT sessions, and role-based guards (admin / creator / learner).
  • Safe concurrent editing — lesson updates use optimistic concurrency; conflicting edits return 409 instead of silently overwriting.
  • Bilingual UI — Thai and English interface language, with Thai as the default AI output language.
  • Theming and performance — light/dark theme, app-wide font-size control, self-hosted fonts, route-level code splitting with heavy vendor libraries (TipTap, Fabric, KaTeX) in separate lazy chunks. The entry chunk stays around 138 kB gzipped.

Architecture

The two halves communicate over a REST API. The client attaches a JWT Bearer token to every request through a single configured Axios instance; AI replies stream back over Server-Sent Events. In production the client is a static SPA on Vercel, the API runs on Render, data lives in MongoDB Atlas, images in Cloudinary, and AI inference on Google Gemini.

Client (this repository)

src/
├── App.tsx              # router + route guards (the page map)
├── main.tsx             # React root
├── index.css            # Tailwind v4 entry + theme tokens
├── pages/               # one component per route (all lazy-loaded except Landing)
├── layouts/             # AppLayout — shared chrome via <Outlet/>
├── components/
│   ├── ui/              # shadcn/ui primitives
│   ├── editor/          # the lesson editor: TipTap + Fabric + question blocks
│   │   ├── extensions/  # custom nodes (questions, canvas, image) + tutorApi.ts
│   │   ├── ai/          # teacher AI copilot surfaces
│   │   └── FormulaBlock/ # visual math builder → LaTeX
│   └── *.tsx            # TopNav, route guards, ThemeToggle, ...
├── stores/              # Zustand global state (auth, content, answers, ...)
├── hooks/               # Fabric canvas hooks
├── lib/                 # axios instance, creator API bridge, cloudinary, utils
└── types/               # shared TypeScript types

Key design decisions:

  • Single API bridge per AI surface. All student-facing AI calls go through src/components/editor/extensions/tutorApi.ts (callTutor / callTutorStream), and all teacher-copilot calls through src/lib/creatorApi.ts. Streaming falls back to plain JSON transparently if SSE fails before the first token.
  • The TipTap document is the single source of truth. All editor block data — canvas drawings, question definitions, formulas — lives in node attributes and serializes with the document.
  • Route guards, not scattered checks. ProtectedRoute (hard redirect), RequireLogin (soft inline prompt), and PublicRoute (bounce authenticated users) wrap routes declaratively in App.tsx.
  • Auth token lives in one store. The Axios instance reads the token from the Zustand auth store outside React and reacts to the server's structured 401 contract by logging out and redirecting only on protected paths.

Server (hot-potato-server)

An MVC-structured Express 5 + TypeScript service: route → auth middleware → controller → Mongoose model, with cross-cutting logic (lesson serialization, AI persona building, retries, observability) in a services layer. The API surface in one glance:

GroupBase pathWhat it covers
Auth/api/authRegister, login, Google Sign-In, token recheck, change password
Content/api/contentCreate / load / update / delete / search lessons, access control
Answers/api/content-answerPer-student answer maps, single and bulk save
AI chat/api/chatThe unified tutor endpoint + student tutor-memory
Teacher copilot/api/creatorOne endpoint, eleven authoring actions
Users/api/usersProfile read/update, admin user list
History/api/historyRecently visited lessons
Media/api/categories, /api/imagesCloudinary image library + folders
Status/api/statusPublic aggregated health check + admin diagnostics

The full per-endpoint reference, data model, AI integration internals, and security notes live in the server README.

Tech stack

LayerTechnology
Frontend coreReact 19, TypeScript, Vite 7
StylingTailwind CSS v4 (CSS-first config), shadcn/ui (Radix primitives), lucide-react, sonner
Client stateZustand (global stores), TanStack Query (server state)
Routing / HTTPReact Router 7, Axios
Rich text & canvasTipTap 3 (+ tiptap-markdown), Fabric.js 7, KaTeX, react-markdown + remark-gfm
BackendNode.js, Express 5, TypeScript
DatabaseMongoDB with Mongoose 9
AIGoogle Gemini via @google/genai (fast + tutor model routing)
AuthJWT, bcrypt, Google Identity Services (@react-oauth/google + google-auth-library)
MediaCloudinary (unsigned upload)
TestingVitest + happy-dom (client), Vitest + Supertest + mongodb-memory-server (server)
DeploymentVercel (client), Render (server), MongoDB Atlas

Getting started

Running the whole platform locally takes two terminals: one for the API, one for the web app.

Prerequisites

  • Node.js 20.19+ (or 22.12+) and npm
  • A MongoDB database — a free MongoDB Atlas cluster works, or a local instance
  • A Google Gemini API key — free from Google AI Studio
  • A Cloudinary account (cloud name + unsigned upload preset) for image uploads
  • Optional: a Google OAuth Web client ID (Google Cloud Console) to enable Sign in with Google

1. Set up the server

git clone https://github.com/Jakkarin-Promsee/hot-potato-server.git
cd hot-potato-server
npm install

Create hot-potato-server/.env:

PORT=5000
MONGO_URI=mongodb+srv://<user>:<pass>@<cluster>/<db>
JWT_SECRET=replace-with-a-long-random-string
JWT_EXPIRES_IN=7d
GEMINI_API_KEY=your-gemini-api-key
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_UPLOAD_PRESET=your-unsigned-preset

# Optional
GOOGLE_CLIENT_ID=your-google-oauth-client-id   # enables POST /auth/google
CORS_ORIGINS=http://localhost:5173             # unset = open (dev only)
AI_OUTPUT_LANGUAGE=thai                        # or "english"

Optional tuning knobs (AI model selection, rate limits, memory cadence) are documented in the server README.

Start the API:

npm run dev      # → http://localhost:5000

Verify it is up: GET http://localhost:5000/ returns a health string, and GET http://localhost:5000/api/status/all returns an aggregated systems check.

2. Set up the client

git clone https://github.com/Jakkarin-Promsee/hot-potato-client.git
cd hot-potato-client
npm install

Create hot-potato-client/.env. Only VITE_-prefixed variables are exposed to the browser:

VITE_API_URL=http://localhost:5000
VITE_CLOUDINARY_CLOUD_NAME=your-cloud-name
VITE_CLOUDINARY_UPLOAD_PRESET=your-unsigned-preset
VITE_GOOGLE_CLIENT_ID=your-google-oauth-client-id   # optional
VariableRequiredDescription
VITE_API_URLyesBase URL of the server API (no trailing slash)
VITE_CLOUDINARY_CLOUD_NAMEyesCloudinary account name — use the same account as the server
VITE_CLOUDINARY_UPLOAD_PRESETyesCloudinary unsigned upload preset
VITE_GOOGLE_CLIENT_IDnoGoogle OAuth Web client ID; when unset, the Google Sign-In button is hidden. Use the same client ID as the server's GOOGLE_CLIENT_ID, with http://localhost:5173 registered as an authorized origin

Start the web app:

npm run dev      # → http://localhost:5173

3. Try it

Open http://localhost:5173. Stay anonymous to explore a public lesson and use its AI tutor. To create a lesson, register or sign in, then open Create. The tutor needs the server's GEMINI_API_KEY.

Available scripts

ScriptDescription
npm run devStart the Vite dev server
npm run buildProduction build → dist/
npm run previewServe the production build locally
npm run lintRun ESLint
npm testRun the Vitest suite (happy-dom, offline)

Server-side scripts (test suite, live AI smoke tests, admin promotion) are listed in the server README.

Testing

Both halves ship offline test suites — no network, no real database, no API key needed:

  • Client: Vitest + happy-dom. Tests live next to the code they cover (src/**/__tests__/) — stores, axios helpers, route guards, editor bridges, AI copilot surfaces, and page-level tests.
  • Server: Vitest + Supertest with an in-memory MongoDB and a mocked Gemini client, covering every endpoint group plus prompt builders and retry logic.
npm test         # in either repository

Deployment

HalfPlatformConfiguration
ClientVercelBuild npm run build, output dist/. vercel.json rewrites all paths to index.html for SPA routing. Set the VITE_* variables in the dashboard with VITE_API_URL pointing at the production API.
ServerRenderBuild npm install && npm run build, start npm start. Set every server .env variable in the dashboard, including CORS_ORIGINS with the client's production origin.

Cold starts: on Render's free tier the API sleeps when idle, so the first request after a pause takes several seconds on top of normal AI latency. The client accounts for this with loading states throughout.

RepositoryDescription
hot-potato-serverExpress 5 + TypeScript REST API: auth, lesson storage, student progress, and the Gemini AI integration — full API reference in its README

Author

Jakkarin Promsee — Computer Engineering, KMUTT

License

Original code and documentation authored by Jakkarin Promsee are licensed under the MIT License. Third-party code, assets, datasets, and other materials are not covered by this license; their original terms apply.