This is the Cloudflare Worker backend for the Key Quest Kids application. It provides a RESTful API for managing lessons and phrases, with AI-powered content generation.
- Lessons Management: Create and retrieve typing lessons
- Phrases Management: Add and retrieve phrases for each lesson
- AI-Powered Generation: Generate lesson content and phrases using Workers AI
- D1 Database: Persistent storage using Cloudflare D1
GET /api/lessons- Get all lessons (optionally filtered by difficulty)- Query params:
?difficulty=beginner|intermediate|advanced
- Query params:
GET /api/lessons/:id- Get a specific lesson by IDPOST /api/lessons- Create a new lesson- Body:
{ "title": string, "description?": string, "content": string, "difficulty?": "beginner"|"intermediate"|"advanced" }
- Body:
GET /api/lessons/:id/phrases- Get all phrases for a lessonPOST /api/lessons/:id/phrases- Add a new phrase to a lesson- Body:
{ "text": string, "difficulty?": "beginner"|"intermediate"|"advanced" }
- Body:
POST /api/generate/phrase- Generate a phrase using AI- Body:
{ "prompt?": string, "difficulty?": "beginner"|"intermediate"|"advanced", "maxLength?": number }
- Body:
POST /api/generate/lesson- Generate lesson content using AI- Body:
{ "topic": string, "difficulty?": "beginner"|"intermediate"|"advanced" }
- Body:
- Node.js 16+
- npm or pnpm
- Cloudflare Wrangler CLI (
npm install -g wrangler)
-
Install dependencies:
npm install
-
Log in to Cloudflare:
wrangler login
-
Create a new D1 database:
wrangler d1 create key-quest-kids-db
Update the
wrangler.jsoncfile with the database ID. -
Run database migrations:
wrangler d1 migrations apply key-quest-kids-db --local
-
Start the development server:
npm run dev
-
Apply migrations to production:
wrangler d1 migrations apply key-quest-kids-db
-
Deploy the worker:
npm run deploy
DB- D1 database binding (automatically configured inwrangler.jsonc)AI- Workers AI binding (automatically configured inwrangler.jsonc)