An AI tutor for learning to code: ask questions, practise tasks in a real editor and see your progress. Built as an Honours research project on AI-assisted programming learning.
Live demo · What it does · How a message is answered · Run it locally
I built Programming Helper AI for my BSc (Hons) Computing Honours project at Glasgow Caledonian University. The question behind it: does an AI assistant that is limited to programming, and paired with structured practice, help people learn to code? The app is the study instrument: participants take a pre-assessment, learn with the assistant and the tasks, then take a post-assessment, and their interactions are collected anonymously with consent.
- Programming-only assistant. Questions are checked before they reach the model; off-topic ones get a short redirect instead of an API call.
- Answers that read well. Headings, numbered steps, bullets, inline code and code blocks are rendered as React elements, so model output is never parsed as HTML.
- Research by design. Consent before participation, anonymous identifiers, pre- and post-assessments and an admin dashboard for the study. See docs/RESEARCH_ETHICS.md.
- Guard rails. Per-user rate limits stored in PostgreSQL, a 7-day cache of AI responses, a strict Content-Security-Policy and Clerk authentication.
flowchart LR
U["Chat UI<br/>(React 19)"] -- "tRPC chat.sendMessage" --> R{"Rate limit<br/>(PostgreSQL)"}
R --> V{"Programming<br/>question?"}
V -- no --> X["Short redirect,<br/>no API call"]
V -- yes --> C{"Cached answer?<br/>(7 days)"}
C -- hit --> A["Answer"]
C -- miss --> O["OpenAI<br/>(OPENAI_MODEL)"]
O --> A
A --> S[("Session, message and<br/>anonymous stats in PostgreSQL")]
S --> U
The model is set in one place (OPENAI_MODEL, default gpt-5.6-terra), so moving to a new model is a configuration change.
| Layer | Tech |
|---|---|
| Frontend | Next.js 15 (App Router), React 19, TypeScript, Tailwind CSS 4, TanStack Query, Monaco Editor |
| API | tRPC 11 with Zod validation |
| Data | PostgreSQL, Prisma 6 |
| AI | OpenAI API |
| Auth | Clerk |
| Tests and CI | Jest and React Testing Library; GitHub Actions runs lint, type-check and tests on every push |
| Deployment | Vercel |
You need: Node.js 20+, PostgreSQL, and keys for OpenAI and Clerk.
git clone https://github.com/Bogdusik/Programming-Helper-AI.git
cd Programming-Helper-AI
npm install
cp .env.example .env.local # fill in DATABASE_URL, OPENAI_API_KEY and the Clerk keys
npm run db:push # create the schema
npm run db:init-rate-limits
npm run dev # http://localhost:3000npm test # Jest
npm run type-check # TypeScriptEnvironment variables
DATABASE_URL="postgresql://user:password@localhost:5432/programming_helper_ai"
OPENAI_API_KEY="sk-..."
# OPENAI_MODEL="gpt-5.6-terra" # optional override
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_..."
CLERK_SECRET_KEY="sk_..."
NEXT_PUBLIC_APP_URL="http://localhost:3000"Never hardcode secrets; keep them in .env.local locally and in Vercel's Environment Variables in production.
Deploying to Vercel
- Import the repo in Vercel (branch
main). - Add the environment variables above under Settings → Environment Variables.
- Run
npm run db:pushagainst the productionDATABASE_URLwheneverprisma/schema.prismachanges. - If cloning fails with "There was a permanent problem cloning the repo", see docs/VERCEL_DEPLOYMENT.md.
Project structure
Programming-Helper-AI/
├── app/ # Next.js App Router: chat, tasks, task/[id], stats, admin, settings, legal pages
│ └── api/trpc/ # tRPC endpoint
├── components/ # ChatBox, Message, TaskCodeEditor, ProgressDashboard, ResearchConsent, …
├── lib/ # trpc.ts (router), openai.ts, prompts, programming-validator, db, rate limits
├── prisma/ # schema.prisma, seed
├── __tests__/ # component, lib and API tests
├── docs/ # API documentation, research ethics, deployment notes, README media
└── postman/ # Postman collection
Security notes
- All
@trpc/*packages are kept at 11.8.0+ for the prototype-pollution fix flagged by Snyk. - The app stays on Next.js 15 until
@clerk/nextjssupports Next.js 16; the related Snyk finding is ignored in.snykwith an expiry.
- End-to-end type safety: tRPC and Prisma give one set of types from the database to the React components.
- Building on an LLM API: prompts that keep the assistant on topic, caching and rate limits to control cost, and keeping the model choice configurable after a model was retired.
- Research ethics in software: consent flows, anonymous identifiers and data that can be withdrawn.
- Testing a UI that renders model output: component tests that check formatting and that HTML in an answer stays text.


