How theleejungyan/mathquiz works
Project type and purpose
• This is a front-end single-page application (SPA) built with React and TypeScript.
• Purpose: present multiple-choice math questions (from a local JSON file), let users answer them, and display a score summary.
• Deployed on Vercel; uses Vite as its build tool.
File structure
• Top‐level config/build files:
– package.json / package-lock.json (dependencies, scripts)
– vite.config.ts (Vite build config)
– tailwind.config.js / postcss.config.js (styling setup)
– tsconfig*.json (TypeScript settings)
– vercel.json (deployment settings)
• Public assets:
– public/ (favicon, static files)
• Source code in src/:
– src/main.tsx: app entry point (mounts React)
– src/router.tsx: React Router setup (routes → HomePage, Quiz)
– src/pages/: page components (HomePage.tsx, Quiz.tsx)
– src/components/: UI‐level atoms/molecules (DialogBox, Button, ProgressBar, etc.)
– src/components/ui/: headless UI primitives (input, label, alert-dialog)
– src/global/: shared types (dataType.ts, type.ts)
– src/hook/: custom hooks (useIdentifyChange)
– src/lib/: utility functions (utils.ts)
– src/json/quiz.json: the quiz questions data store
– src/assets, src/images, src/fonts, src/css: static assets and styles
README for additional insights
• Confirms that quiz.json is the source of questions, and dataType.ts defines the structure.
• Technologies: React, TypeScript, Vercel.
Main components and their interactions
a. User’s Browser (Client)
b. React Application
– Entry point: main.tsx
– Router: defines the navigation between HomePage and Quiz pages
– Pages: fetch/ load data, manage high-level state per route
– Components: present UI, dialogs, progress bar, with UI primitives under components/ui
– Hooks & Utils: useIdentifyChange manages state transitions (e.g. current question), utils.ts has helper functions (e.g. shuffle questions)
– Data Layer: quiz.json is read (imported) at build time or fetched at runtime
– Styles: Tailwind CSS + custom CSS (src/css/quiz.css, index.css)
c. Build & Deployment
– Vite: development server and bundler (build pipeline)
– Vercel: hosting platform that serves the static build output
Relationships & data flow:
1. On load, Browser → index.html → main.tsx mounts React app
2. Router reads URL → renders HomePage or Quiz page
3. Quiz page loads quiz.json (via import/fetch) → state initialized (global types)
4. User interactions in Components → triggers Hooks & Utils → updates React state
5. React re-renders components showing next question / score dialog → user sees results
6. Build pipeline (Vite) bundles code + assets → deployed to Vercel → served to users
Architectural patterns & design principles
• Component-based decomposition (atoms → molecules → pages)
• Single source of truth for question data (quiz.json + TypeScript types)
• Unidirectional data flow (React state → UI)
• Separation of concerns: UI primitives, business logic (utils/hooks), data types