How ed-watts-87/multiple-choice-quiz works
Project Type and Purpose
• This is a single-page application (SPA) built with React and Redux in TypeScript.
• Purpose: present a multiple-choice food quiz, collect answers, show results, and handle errors—all in the browser using mock data.
File-Structure Highlights
• src/index.tsx + index.html + index.css: App entry point, global styles, and HTML template.
• src/QuestionCard, QuestionButtons, Questions: core UI components to display questions and choices.
• src/ReportCard, ReportAnswers: UI components to show results.
• src/Error/Error.tsx: centralized error-display component.
• src/mocks: mock data (questions.json, answers.json) and service layer (requestQuestions.ts, getAnswers.ts) with tests.
• src/redux/actions.ts & reducers.ts (+ tests): Flux pattern for state transitions, actions for fetching questions/answers.
• webpack.{common,dev,prod}.js + tsconfig.json + .babelrc: build and bundling configuration.
Core Components
a. Frontend UI Layer
• React Components:
• QuestionCard & QuestionButtons (question display + selection)
• Questions (orchestrates fetching & rendering)
• ReportCard & ReportAnswers (results view)
• Error (global error fallback)
b. State Management
• Redux Store
• Actions: fetchQuestions, fetchAnswers, setError
• Reducers: update state (questions, answers, loading, error flags)
c. Service Layer (API abstraction)
• requestQuestions.ts & getAnswers.ts simulate HTTP calls to /questions and /answers using mock JSON.
d. Data Layer
• mocks/questions.json, mocks/answers.json: mock datasets.
e. Build/Deployment
• Webpack Dev Server (serves the SPA on localhost)
• Webpack Production Bundle (build pipeline)
Relationships & Data Flow
• At startup, Questions component dispatches fetchQuestions action → Redux Thunk (in requestQuestions) → loads questions.json → dispatches success or error → Redux store updated → Questions reads state and renders QuestionCard.
• On answer selection, dispatch fetchAnswers → getAnswers → update store → Report components render final report.
• Error component listens to error slice in store and overlays UI on any API failure.
• Webpack Dev Server serves index.html → index.tsx → ReactDOM.render(App).
Architectural Patterns & Principles
• Component-based UI (React)
• Unidirectional data flow (Flux/Redux)
• Separation of concerns: UI vs. state vs. service vs. data
• Mock API layer to decouple frontend from real backend
• Type safety with TypeScript definitions (typings.d.ts)
• Test-driven bits: unit tests for mocks and reducers
Final Recommendations
• Review with the team to confirm completeness—don’t forget the error path and test artifacts.