✦ QuizBuddy
CLASSROOM DOCUMENTATION · QUIZBUDDY V1.3.1

Built it. Here's how it works.

Two ways to learn about the project: a quick teaching presentation or a technical walkthrough for your instructor.

🎤 Simple presentation🧩 Technical documentation
PRESENTATION TRACK

Show and tell in 14 clear steps

Read these in order while demonstrating the website.

01

The idea

QuizBuddy is a friendly AI-powered quiz game. Anyone can explore a subject, choose a difficulty and play a ten-question multiple-choice quiz. No account is required.

02

What the visitor sees

The homepage introduces Pip, our cartoon guide. Large colourful buttons, clear progress and easy reading make the experience welcoming on desktop and phone.

03

Choose any topic

Type a topic such as Light, Animals or Python. An optional name personalises the result. Greetings, symbols and suspicious instructions receive helpful fallback messages.

04

Pick one difficulty

Beginner is designed for younger learners, Intermediate for growing confidence and Advanced for deeper knowledge. Each level contains exactly ten questions.

05

Answer and learn

Every question has four choices: A, B, C and D. A visitor can move backward, change an answer or skip. The screen shows progress from 1 to 10.

06

Receive results

The server—not the browser—keeps the answer key. At submission, the server grades answers, shows a score out of ten and explains the correct answers.

07

Explain the subject

After completing the quiz, press Explain Topic for five to ten simple-English sentences. This uses AI unless a prepared offline explanation is available.

08

AI from several providers

The administrator can save API credentials and select a model from OpenRouter, OpenAI, Groq, Claude or Gemini. Only one provider is active at a time.

09

Switch without deleting

Save a second key, test it and then activate it when ready. Existing saved provider keys and choices remain; a separate Disconnect action removes one connection.

10

Keep costs visible

The admin dashboard records app-side AI requests, input/output tokens and estimated US-dollar usage. Model prices can come from the provider or entered rates.

11

Pause online generation

Manual Pause AI—or an app usage limit—switches new quizzes to eight prepared subjects. Pip gently offers the offline adventures. Saved API keys are not deleted.

12

Control and security

The password-protected admin studio manages keys, models, modes, quotas, results and password changes. API keys remain encrypted on the server.

13

What we built

One public website, a Bun/TypeScript backend, persistent data storage on Railway, secure admin sessions and a custom HTTPS domain: quizbuddy.app.

14

The lesson learned

This project demonstrates frontend design, APIs, provider compatibility, server validation, persistence, security, cost monitoring and safe offline fallbacks.

INSTRUCTOR TRACK

Technical reference

Architecture, API communication, backend rules, security, data and limitations as implemented.

01. Architecture & hosting

The deployed application is a single Railway Function using Bun and TypeScript. It serves static HTML/CSS/JavaScript assets and JSON endpoints from the same service. A persistent Railway volume holds its JSON state file. The database is not yet PostgreSQL; it is a small demonstration design. The application uses quizbuddy.app with HTTPS, and the Railway service URL remains a fallback.

02. Visitor journey

The homepage offers an optional display name and a free-text subject. Topic validation accepts normal learning subjects and redirects greetings, unsupported characters or prompt-injection-like messages. Visitors choose Beginner, Intermediate or Advanced, receive exactly 10 questions with four distinct choices, select or revise answers, then submit and receive a grade and short explanations.

03. Question generation & quality

The backend sends a narrowly defined system instruction to the selected provider and requests JSON containing exactly ten questions, four answer options, a zero-based correct answer index and one short explanation. It validates structure, uniqueness and answer-index ranges. Structural validation does not prove every AI-generated fact is correct; educational material still warrants checking.

04. Server-side scoring

The public quiz-generation endpoint returns question text and options but not correct answers. The server stores the answer key with an opaque quiz ID. Submitting ten answer positions computes a score out of ten and returns the correct-answer review. Previously submitted quizzes cannot be scored a second time, and old quiz IDs expire.

05. Offline examination library

When AI is paused, eight subjects are available: Light, Mathematics, Animals, Geography, Space, History, English and Computers. Each has Beginner, Intermediate and Advanced sets with ten questions each. These are preloaded questions, not new AI generations. Prepared explanations are available for offline subjects. Other subjects are unavailable while offline.

06. AI providers & API compatibility

OpenAI, Groq and OpenRouter share an OpenAI-style chat-completions structure, with some provider differences. Anthropic Claude and Google Gemini use their own native endpoints and adapters. The application converts the same internal quiz request into the appropriate provider format, reads each provider's response and returns a common structure to the frontend.

07. Administrator workflows

Sign in at /admin with the administrator password. Save each provider's API key and model separately, load model options where the provider allows, and use Test Connection (a billable AI request) before Activate. Activating a provider does not erase any other saved key. Disconnect removes a key from QuizBuddy, not from the upstream provider.

08. Secrets & authentication

The app stores API keys encrypted with AES-256-GCM using a server-side environment key. Admin passwords are protected with scrypt-derived password hashes; login uses HttpOnly, Secure, SameSite=Strict cookies and an expiring server-side session. Admin routes require authentication. Same-origin checks guard state-changing requests. These are demonstration-grade controls, not a full enterprise security review.

09. Usage, budgets & fallbacks

A global daily AI-request counter includes quiz-generation calls, AI subject explanations and AI connection tests. The default daily cap is 60. There is also an IP-based rolling-hour cap of 8 quiz attempts per visitor, including offline quizzes. A configurable monthly USD spending guard uses app-side estimated request costs; it is not a guaranteed provider billing cap. When caps prevent online generation, the application switches to offline mode and displays a friendly visitor message. Manual resume is required.

10. Pricing accuracy & limits

Actual token usage comes from the provider's response when available. OpenRouter may return a provider-reported request cost. For Claude and Gemini, pricing can use selected published reference rates or administrator-supplied rates. Cache and thinking tokens receive specific handling where available. Price catalog entries may become stale and external projects sharing the key are not included. The dashboard clearly represents application-side costs, not the provider's final invoice.

11. Data model & retention

The persistent JSON state includes app settings, encrypted provider keys, quiz instances, completed results, admin sessions, rate limits and usage records. Results retain the optional visitor name. Current retention is bounded in code: results are capped, usage history is capped, and old quiz instances and sessions are pruned. A production multi-user product should migrate to a relational database with user-specific access controls.

12. API route map

GET /api/health and GET /api/settings expose public status. POST /api/quiz creates a quiz; POST /api/quiz/submit grades answers; POST /api/quiz/explain provides a lesson. Under authenticated /api/admin: session/login/logout, settings, provider save/activate/disconnect, models, test, mode, usage, usage.csv, password and results. The documentation page contains no keys or private data.

13. Known limitations & next steps

There is no visitor registration, no user-specific login, no guaranteed plagiarism or factuality check, and no provider-level billing reconciliation. IP-based hourly limits may count multiple people on one Wi-Fi as one visitor. Model prices and the offline library are controlled by application code. Reasonable future upgrades include verified billing reconciliation, per-user accounts, more offline content and automated regression tests.