# aayantasneem/quiz-game architecture

> Architecture diagram of the GitHub repository aayantasneem/quiz-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aayantasneem/quiz-game
- Repository: https://github.com/aayantasneem/quiz-game

## Overview

##### Main Components
a. User Interface (CLI) – handles input/output via the terminal.
b. Quiz Engine – core logic that drives question selection, shuffling, input validation, and score tracking.
c. Data Loader – reads quiz questions and answers from the CSV files in the `data/` directory.
d. Score Tracker – maintains the current score and produces the final result summary.
e. Result Presenter – shows correct answers and final score at the end.

##### Relationships and Data Flow
- The **User** (player) issues commands (start game, choose category, answer A/B/C/D).
- The **CLI** component captures that input and forwards it to the **Quiz Engine**.
- The **Quiz Engine** invokes the **Data Loader** to fetch and shuffle questions from `data/python_quiz.csv`, `data/math_quiz.csv`, or `data/sql_quiz.csv`.
- Each question → CLI → User’s answer → Quiz Engine → Input Validator → Score Tracker (updates score) → CLI (feedback).
- After all questions, the **Score Tracker** passes results to the **Result Presenter**, which outputs final score and the list of correct answers.

##### Architectural Patterns & Design Principles
- Single‐process, procedural flow with clear separation of concerns:
- I/O layer (CLI)
- Business logic layer (Quiz Engine & Score Tracker)
- Data access layer (CSV Data Loader)

##### Technologies & Libraries
- Runtime: **Python 3.10**
- File Handling: Python’s built-in `csv` module
- Data Structures: Lists & Dictionaries for question/answer storage
- Control Flow: Loops (`for`, `while`), Conditionals (`if/else`)

- Clear labels: “CLI Interface”, “Quiz Engine”, “Data Loader”, etc.
- External actors: “Player” on the far left.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actor
    Player["Player"]:::actor

    %% Layers
    subgraph "User Interface Layer"
        CLI["CLI Interface"]:::ui
    end

    subgraph "Core Logic Layer"
        Engine["Quiz Engine"]:::core
        Tracker["Score Tracker"]:::core
        Presenter["Result Presenter"]:::core
    end

    subgraph "Data Layer"
        Loader["Data Loader"]:::data
        subgraph "CSV Files" 
            PYCSV[("python_quiz.csv")]:::data
            MATHCSV[("math_quiz.csv")]:::data
            SQLCSV[("sql_quiz.csv")]:::data
        end
    end

    %% Flow
    Player -->|"start game / select category"| CLI
    CLI -->|"get_input()"| Engine
    Engine -->|"load_questions()"| Loader
    Loader -->|"read CSV"| PYCSV
    Loader -->|"read CSV"| MATHCSV
    Loader -->|"read CSV"| SQLCSV
    Engine -->|"validate_answer()"| Tracker
    Tracker -->|"update_score()"| Engine
    Engine -->|"end of quiz"| Presenter
    Presenter -->|"show_results()"| CLI
    CLI -->|"display to player"| Player

    %% Click events
    click CLI "https://github.com/aayantasneem/quiz-game/blob/main/quiz_game.py"
    click Engine "https://github.com/aayantasneem/quiz-game/blob/main/quiz_game.py"
    click Tracker "https://github.com/aayantasneem/quiz-game/blob/main/quiz_game.py"
    click Presenter "https://github.com/aayantasneem/quiz-game/blob/main/quiz_game.py"
    click Loader "https://github.com/aayantasneem/quiz-game/tree/main/data/"
    click PYCSV "https://github.com/aayantasneem/quiz-game/blob/main/data/python_quiz.csv"
    click MATHCSV "https://github.com/aayantasneem/quiz-game/blob/main/data/math_quiz.csv"
    click SQLCSV "https://github.com/aayantasneem/quiz-game/blob/main/data/sql_quiz.csv"

    %% Legend
    subgraph Legend
        LU["UI Module"]:::ui
        LC["Core Module"]:::core
        LD["Data Module"]:::data
        LA["Actor"]:::actor
        note["Rectangle = Module<br/>Cylinder = Data Store"] 
    end

    %% Styles
    classDef ui fill:#cce5ff,stroke:#005cbf,color:#005cbf;
    classDef core fill:#d4edda,stroke:#155724,color:#155724;
    classDef data fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef actor fill:#fff3cd,stroke:#856404,color:#856404;
```
