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.
Two ways to learn about the project: a quick teaching presentation or a technical walkthrough for your instructor.
Read these in order while demonstrating the website.
Architecture, API communication, backend rules, security, data and limitations as implemented.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.