For engineers and recruiters
How KidLearn is built
The stack and the alternatives it beat, the architecture, how AI content is kept behind a human, and how it is tested and shipped. Every claim links to the document it comes from.
The stack
One choice per layer. Each tab says what was picked, why, what it costs, and what it beat.
Next.js 16 with the App Router, React 19 and Tailwind CSS v4.
- Why
- Phones and tablets come first, so pages are built mobile-first. Design tokens live in CSS variables, which lets the kid theme and the parent theme share one set of components and swap at runtime without a line of theme logic in JavaScript.
- What it costs
- Every route is rendered on demand, because the root layout reads the language cookie on the server. That trades static caching for a Bangla visitor never seeing a flash of English.
- What else was considered
- A plain Vite single-page app (no server rendering, so a slow phone sees a blank screen longer) and Remix (fewer people know it, and Vercel hosts Next.js with no configuration).
Express 5 in TypeScript (ESM), one module per domain.
- Why
- A small, explicit REST API that is easy to read top to bottom. Every route that takes input checks it with the same Zod schemas that generate its OpenAPI document, and a test fails if any live route is missing from that document.
- What it costs
- Express brings no structure of its own, so the conventions (routes, schema, service, middleware per module) are written down and enforced in review rather than by the framework.
- What else was considered
- NestJS (more ceremony than a two-person API needs), Next.js route handlers (would tie the API to the web host and leave nothing for the planned mobile app to call) and tRPC (TypeScript-only, so no contract for a non-TypeScript client).
PostgreSQL through Prisma 6, with JSONB for lesson content.
- Why
- The family, progress and publishing data is relational and needs transactions and foreign keys. Lesson and quiz payloads change shape as new activity types arrive, so they live in versioned JSONB columns checked by Zod. Row-level security is on for every table, so Supabase's public Data API cannot reach around the server.
- What it costs
- Prisma cannot type a JSONB column, so every payload is parsed at the edge of the service that reads it. Prisma's generated client also has to be built before the server type-checks.
- What else was considered
- MongoDB (would give up the transactions that award stars and delete a family in one step) and Drizzle (closer to SQL, but Prisma's migrations and schema file were the better fit for a schema that changes often).
better-auth: Google sign-in for parents, email and password for admins.
- Why
- Parents never create a password, and Google handles account recovery. Admins cannot sign up at all: the only way to create one is a seed script run on the server. An admin session ends 12 hours after sign-in however active it is, while a parent's slides for 30 days.
- What it costs
- Parents without a Google account cannot sign in. Account linking is switched off on purpose, so a Google sign-in on an admin's address can never inherit the admin account.
- What else was considered
- Auth.js (built around Next.js, but the sessions belong to the Express API) and a hosted service such as Clerk or Auth0 (a monthly bill and child-adjacent data held by a third party).
Cloudinary, uploaded straight from the browser with a signed request.
- Why
- The API signs an upload and the browser sends the file directly to Cloudinary, so no image or audio clip passes through the API's memory. Cloudinary resizes and serves images from its CDN, and the free plan covers the expected traffic.
- What it costs
- Another vendor with its own dashboard and keys, and a URL format the app depends on.
- What else was considered
- Amazon S3 with CloudFront (cheaper at scale, but image resizing would have to be built) and Supabase Storage (fewer vendors, but no on-the-fly transformations on the free tier).
Vercel for the web app; one EC2 instance running Docker Compose behind Caddy for the API (planned).
- Why
- The production and development APIs run side by side on one Graviton instance in Mumbai, close to Bangladesh. Caddy handles TLS and is the only process listening on the public ports. The estimated cost for both environments is about $14.08 a month.
- What it costs
- One instance is one point of failure, and there is no autoscaling. That is accepted for now: rollback is one command, and the database lives elsewhere.
- What else was considered
- ECS or App Runner behind a load balancer (the load balancer alone would cost more each month than the instance) and running the API on Vercel too (long AI generation requests and the weekly report job do not fit serverless limits).
Architecture
The shape of the system: how the code is organised, how a request travels, and the rules that keep content and rewards honest.
One pnpm workspace built with Turborepo: two apps and six packages.
- Why
- Types, strings, design tokens and the database client are shared, so a change to an API contract breaks the web app's type-check in the same pull request. Dependencies point one way: apps import packages, never the reverse.
- What it costs
- One lockfile and one CI job for everything, so a slow test anywhere slows every pull request.
packages/uiis web-only by decision, because its Radix primitives need a browser DOM. - What else was considered
- Separate repositories for web and API (contracts would drift between releases) and Nx (more features than two apps need).
The browser calls the API directly, with an httpOnly session cookie on the API's own origin.
- Why
- There is no proxy in between. Express refuses any state-changing request from an origin other than the web app's, guards such as
requireParentandrequireAdmincheck the session before a handler runs, andrequireConsentholds back child data until a parent has agreed. Prisma is the only way into the database. - What it costs
- The web app and the API need CORS and a cookie set up carefully across two hostnames, and the web app has exactly one allowed origin per environment.
- What else was considered
- Proxying every call through Next.js (one more hop and a second place to get auth wrong) and tokens in local storage (readable by any script on the page).
Activities and quizzes are versioned JSONB payloads, drawn by generic engines in the web app.
- Why
- Drag and drop, tracing, matching, puzzles and quiz questions are each described by a payload with a
schemaVersion. One set of Zod schemas inpackages/typeschecks a payload when an admin saves it, when an AI drafts it, and when the app reads it. A new lesson is data, not code, and goes live without a deploy. - What it costs
- A new kind of activity still needs code: a schema and an engine. Older payloads have to be migrated as they are read, so every write can stay strict.
- What else was considered
- A React component per lesson (every lesson would need a deploy) and a headless CMS (no way to check that a lesson actually plays).
AI content
AI drafts lessons, stories, quizzes, narration and pictures. It reaches a child only after a person approves it.
Two doors in, one gate out.
- Why
- AI content enters through Gemini, run by KidLearn, or through an admin's own assistant over MCP. Both doors share the same prompts, the same Zod schemas and the same save path, and both end in the same review queue. Every generation keeps an audit trail: inputs, prompts, raw attempts, token use, who asked and who approved.
- What it costs
- Two code paths to keep consistent. Sharing the rule book, the schemas and the persistence keeps the difference to who writes the JSON.
- What else was considered
- Gemini only (admins with their own subscription would be limited to a small daily budget) and MCP only (admins without an AI subscription could not generate anything).
Door 1: a Generate button in the CMS that calls Gemini with KidLearn's key.
- Why
- Gemini returns structured JSON that is checked against the same Zod schema the game engines read. A first attempt that fails validation is retried once with the errors as feedback; a second failure ends the job. Daily budgets per kind of job keep the bill predictable.
- What it costs
- The admin waits while the model works, because jobs run in the request rather than on a queue. A busy day hits the budget and has to wait for tomorrow.
- What else was considered
- A job queue with workers (more infrastructure than three jobs a day need) and free-form text parsed afterwards (content the engines could not trust).
Door 2: KidLearn is an MCP server, and an admin's own assistant writes the drafts.
- Why
- Admins already pay for Claude, Cursor or Gemini CLI, and in a chat they can ask for changes before submitting. The assistant runs the model on the admin's subscription, so KidLearn holds no text-model key for this door. An admin signs the assistant in with a personal token that can write drafts and nothing else: it can never approve, publish, edit or delete.
- What it costs
- KidLearn cannot configure an outside model's safety filters or its Bangla, so for this door the human reviewer is the only safety gate KidLearn controls.
- What else was considered
- OAuth for MCP clients (not yet supported by the desktop clients admins use) and one shared API key (no way to tell who submitted a draft or to revoke one person).
Narration from Google Cloud Text-to-Speech, illustrations from Gemini's image model, both made on the server.
- Why
- One voice per language keeps narration consistent. Recurring characters keep their look through written character sheets added to every illustration prompt. Media is generated on the server even for MCP drafts, so the server never fetches an image from an address an outside model chose.
- What it costs
- Character sheets are text, so a character can still drift between pictures, and the reviewer catches it. Pictures need a Gemini key or a manual upload.
- What else was considered
- Accepting image URLs from MCP clients (opens the server to request forgery) and recording narration by hand (slow for two languages).
Nothing an AI makes reaches a child until an admin approves it.
- Why
- Every generator writes
draftrows, and a job can only end asawaiting_revieworfailed. Approving checks for blockers, then walks the content topublished. The publish check itself refuses AI content without an approved job, even through the ordinary CMS. Child and parent data never reaches a model. - What it costs
- Content arrives only as fast as people can review it.
- What else was considered
- Automatic publishing behind safety filters (for children aged three to six, a filter is not enough on its own).
Safety by design
- No social features
- No chat, no messages and no public profiles. Nobody can contact a child.
- No way out of the child's screens
- The child's screens contain no external links, and a test fails if one appears, even inside a lesson title written in the CMS.
- Consent before profiles
- The server refuses to create a child profile or record progress until a parent has given consent.
- No family data in AI prompts
- Prompts carry curriculum text and the admin's request, nothing else. A test asserts that no MCP tool can read child, parent, progress or account data.
- Full deletion
- Deleting an account erases everything about the family in one database transaction. There is no soft delete and no grace period.
Quality and shipping
How a change is checked before it merges, and how it reaches production.
Biome for lint and formatting, TypeScript in strict mode everywhere.
- Why
- One fast tool lints, formats and sorts imports across the whole repository, so there is no ESLint and Prettier configuration to keep in step.
tsctype-checks every package with no implicit any. - What it costs
- Biome has fewer rules and plugins than ESLint, and it does not catch Tailwind class issues; the editor's Tailwind extension does.
- What else was considered
- ESLint with Prettier (two tools, two configurations, and several times slower on a monorepo).
Vitest in every package, contract checks on every route, and a real Postgres for what a stub cannot prove.
- Why
- Every successful response in a route test is checked against its published schema with
assertContract. Cascades, unique constraints and the status check on related rows run against a real database in*.db.test.tssuites, which refuse any database not named*_test. - What it costs
- Most server suites stub Prisma for speed, so they need care to stay honest; the rules for a new stubbed suite are written down.
- What else was considered
- Only end-to-end browser tests (slow and flaky as the main suite) and a mocked database everywhere (would miss the constraints the data depends on).
GitHub Actions, one required job called gates.
- Why
- On every pull request and every push to
mainordev: install from the lockfile, lint, build, type-check, the tests with coverage, and the real-database suites against a Postgres service. Both branches require a pull request and a greengates. - What it costs
- Coverage is reported but deliberately not gated on a threshold, so it relies on review.
- What else was considered
- Several smaller jobs (more parallel, but more places to read when something fails) and a coverage gate (encourages tests written for the number).
Images tagged by commit, a deploy script with health gates, and migrations only on request.
- Why
- One image serves both environments, configured at runtime.
deploy.shwaits for the healthcheck and a database read before it counts a deploy as good, and remembers the last good tag for rollback. Database migrations run only when the deploy asks for them, so a schema change is a decision, not a side effect of a restart. - What it costs
- Deploys are run by hand for now; a GitHub Actions deploy pipeline is specified but not yet built.
- What else was considered
- Kubernetes (far more than one instance needs) and running migrations on every start (one bad restart could change the schema).
Read further
- Requirements and architecture (opens in a new tab)
- How AI is integrated (opens in a new tab)
- Content authoring playbook (opens in a new tab)
- Database design (opens in a new tab)
- Design system (opens in a new tab)
- User journeys and manual (opens in a new tab)
- Engineering standards (opens in a new tab)
- Deployment guide (opens in a new tab)
- Operations runbook (opens in a new tab)
- Mobile app plan (opens in a new tab)