# ed-watts-87/multiple-choice-quiz architecture

> Architecture diagram of the GitHub repository ed-watts-87/multiple-choice-quiz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ed-watts-87/multiple-choice-quiz
- Repository: https://github.com/ed-watts-87/multiple-choice-quiz

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        WCommon["webpack.common.js"]:::build
        WDev["webpack.dev.js"]:::build
        WProd["webpack.prod.js"]:::build
        Babel[".babelrc"]:::build
        TSConfig["tsconfig.json"]:::build
    end

    %% Data Layer
    subgraph "Data Layer"
        QJSON[(questions.json)]:::data
        AJSON[(answers.json)]:::data
    end

    %% Service Layer
    subgraph "Service Layer"
        ReqQ["requestQuestions.ts"]:::service
        ReqA["getAnswers.ts"]:::service
    end

    %% State Management (Redux)
    subgraph "State Management"
        Actions["actions.ts"]:::redux
        Reducers["reducers.ts"]:::redux
        ReducerTests["reducers.test.ts"]:::redux
        Store["Redux Store"]:::redux
    end

    %% UI Components
    subgraph "UI Components"
        IndexHTML["index.html"]:::ui
        IndexCSS["index.css"]:::ui
        IndexTSX["index.tsx"]:::ui
        QuestionCard["QuestionCard.tsx"]:::ui
        QuestionButtons["QuestionButtons.tsx"]:::ui
        QuestionsComp["Questions.tsx"]:::ui
        ReportCard["ReportCard.tsx"]:::ui
        ReportAnswers["ReportAnswers.tsx"]:::ui
        ErrorComp["Error.tsx"]:::ui
    end

    %% Build interactions
    WDev -->|"serves index.html"| IndexHTML
    WProd -->|"bundles app"| IndexTSX
    Babel -->|"transpile TSX"| IndexTSX
    TSConfig -->|"Type definitions"| IndexTSX

    %% UI startup flow
    IndexHTML -->|"loads script"| IndexTSX
    IndexCSS -->|"applies styles"| IndexTSX
    IndexTSX -->|"render App"| QuestionsComp

    %% Fetch questions flow
    QuestionsComp -->|"dispatch fetchQuestions"| Actions
    Actions -->|"thunk requestQuestions"| ReqQ
    ReqQ -->|"read questions.json"| QJSON
    QJSON -->|"return data"| ReqQ
    ReqQ -->|"dispatch success/error"| Actions
    Actions -->|"update state"| Reducers
    Reducers -->|"new state"| Store
    Store -->|"state read"| QuestionsComp
    QuestionsComp -->|"render UI"| QuestionCard
    QuestionsComp -->|"render UI"| QuestionButtons

    %% Fetch answers flow
    QuestionButtons -->|"dispatch fetchAnswers"| Actions
    Actions -->|"thunk getAnswers"| ReqA
    ReqA -->|"read answers.json"| AJSON
    AJSON -->|"return data"| ReqA
    ReqA -->|"dispatch success/error"| Actions
    Actions -->|"update state"| Reducers
    Reducers -->|"new state"| Store
    Store -->|"state read"| ReportCard
    Store -->|"state read"| ReportAnswers

    %% Error handling
    ReqQ -->|"on error dispatch setError"| Actions
    ReqA -->|"on error dispatch setError"| Actions
    Actions -->|"update error state"| Reducers
    Reducers -->|"new error state"| Store
    Store -->|"error flag"| ErrorComp

    %% Click Events
    click WCommon "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/webpack.common.js"
    click WDev "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/webpack.dev.js"
    click WProd "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/webpack.prod.js"
    click Babel "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/.babelrc"
    click TSConfig "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/tsconfig.json"
    click QJSON "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/mocks/questions.json"
    click AJSON "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/mocks/answers.json"
    click ReqQ "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/mocks/requestQuestions.ts"
    click ReqA "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/mocks/getAnswers.ts"
    click Actions "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/redux/actions.ts"
    click Reducers "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/redux/reducers.ts"
    click ReducerTests "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/redux/reducers.test.ts"
    click IndexHTML "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/index.html"
    click IndexCSS "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/index.css"
    click IndexTSX "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/index.tsx"
    click QuestionCard "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/QuestionCard/QuestionCard.tsx"
    click QuestionButtons "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/QuestionButtons/QuestionButtons.tsx"
    click QuestionsComp "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/Questions/Questions.tsx"
    click ReportCard "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/ReportCard/ReportCard.tsx"
    click ReportAnswers "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/ReportAnswers/ReportAnswers.tsx"
    click ErrorComp "https://github.com/ed-watts-87/multiple-choice-quiz/blob/master/src/Error/Error.tsx"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef redux fill:#D0FFD0,stroke:#333,stroke-width:1px
    classDef service fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef data fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef build fill:#E1BEE7,stroke:#333,stroke-width:1px
```
