Skip to content

About

LearnToCode — interactive HTML learning app with Better Auth

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LearnToCode

An interactive web app for learning HTML by building — gamified lessons, mini-games, instant feedback, and Byte, a terminal-style coding companion that reacts to your progress.

Built with Next.js 16 (App Router) · React 19 · TypeScript · TailwindCSS 4 · Framer Motion · Zustand and authenticated with Better Auth (email/password + GitHub).


Features

  • Interactive HTML lessons (teach → play → challenge → complete)
  • Mini-games and coding challenges with live preview
  • Byte — a terminal companion that gives smart hints, fun facts, and mentor tips
  • Email/password + GitHub auth via Better Auth
  • Progress, streaks, XP, and achievements (persisted locally in the browser)
  • Premium glassmorphism UI

Prerequisites

  • Node.js 20+
  • npm

Getting Started (local dev)

  1. Install dependencies:

    npm install
  2. Configure environment variables. Copy the example and edit as needed:

    cp .env.example .env.local

    .env.local is git-ignored. The dev defaults work out of the box with a local SQLite database.

  3. Create the local database tables:

    node scripts/init-db.mjs
  4. Run the dev server:

    npm run dev

    Open http://localhost:3000.

Testing note: .env.local ships with NEXT_PUBLIC_DISABLE_AUTH=true so you can click through the app without signing in. Never enable this in production.


Authentication (Better Auth)

  • Server instance: src/lib/auth.ts
  • API handler: src/app/api/auth/[...all]/route.ts (toNextJsHandler)
  • Client: src/lib/auth-client.ts (signIn, signUp, signOut, useSession)
  • Route protection: src/middleware.ts (checks the Better Auth session cookie) and src/components/auth/AuthGuard.tsx

Database

The app uses the Kysely adapter and picks the database by environment:

Environment Database Driver
Development SQLite (dev.db) better-sqlite3
Production PostgreSQL pg

DATABASE_URL selects the connection. In dev it is file:./dev.db; in production it is a Postgres connection string (e.g. from Neon/Supabase).


Production Deployment

1. Create the production database

Provision a Postgres database (Neon, Supabase, Railway, etc.) and create the Better Auth tables:

DATABASE_URL=postgres://user:pass@host:5432/db npx tsx scripts/init-db-postgres.mjs

(Or paste the SQL from that script into your Postgres console.)

2. Set environment variables

On your host (Vercel / Railway / Fly), set:

Variable Example Notes
BETTER_AUTH_SECRET openssl rand -base64 32 output Required. Strong random string.
BETTER_AUTH_URL https://your-domain.com Server base URL (no trailing slash).
NEXT_PUBLIC_BETTER_AUTH_URL https://your-domain.com Client base URL.
DATABASE_URL postgres://... Postgres connection string.
NEXT_PUBLIC_DISABLE_AUTH false Must be false in production.
GITHUB_CLIENT_ID optional For GitHub sign-in.
GITHUB_CLIENT_SECRET optional For GitHub sign-in.

⚠️ Never set NEXT_PUBLIC_DISABLE_AUTH=true in production — it disables all auth gating.

3. Deploy

  • Vercel: import the repo, set the env vars above, deploy. (Postgres is required — SQLite does not persist on Vercel's filesystem.)
  • Railway / Fly.io / Render: these provide a persistent filesystem, so you can also keep SQLite if you prefer — just keep DATABASE_URL="file:./dev.db" and run node scripts/init-db.mjs as a build/start step.
npm run build
npm run start

Project Structure

src/
  app/                 # Next.js App Router pages + API routes
    api/auth/[...all]  # Better Auth handler
    auth/              # login / register pages
    lesson/ course/ dashboard/ profile/ settings/ onboarding/
  components/
    auth/              # AuthGuard, AuthSessionSync
    byte/              # Byte terminal companion
    brand/             # BrandLogo (uses /logo-icon.svg)
  lib/
    auth.ts            # Better Auth server instance (Kysely adapter)
    auth-client.ts     # Better Auth React client
  store/               # Zustand store (progress, achievements, Byte settings)
  data/                # Static course / lesson / challenge content
  middleware.ts        # Route protection via session cookie
scripts/
  init-db.mjs          # SQLite table creation (dev)
  init-db-postgres.mjs # Postgres table creation (prod)

Scripts

Command Description
npm run dev Start dev server
npm run build Production build
npm run start Start production server
npm run lint ESLint

License

MIT

About

LearnToCode — interactive HTML learning app with Better Auth

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages