# mushaf-khalil/quizvendor_webtechnologies architecture

> Architecture diagram of the GitHub repository mushaf-khalil/quizvendor_webtechnologies, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mushaf-khalil/quizvendor_webtechnologies
- Repository: https://github.com/mushaf-khalil/quizvendor_webtechnologies

## Overview

##### Project type and purpose
- QuizVendor is a full-stack web application whose main goal is to let educators and learners generate, take, and review AI-powered quizzes.
- The front end is a set of static HTML/CSS/JS pages; the back end is PHP scripts interacting with a MySQL database and the OpenAI API.

##### File structure
- A “php/” directory contains all REST-style endpoints:
- db.php (DB connection)
- signup.php, login.php, logout.php, check_session.php (user auth)
- create_quiz.php (AI quiz generation + persistence)
- submit_quiz.php (quiz submission, grading, persistence)
- get_history.php (fetch user’s quiz history)
- Root folder holds individual HTML pages (index.html, getstarted.html, dashboard.html, create_quiz_page.html, takeQuiz.html, history.html, etc.) that call the PHP endpoints via fetch.

##### README for additional insights
- The system uses XAMPP (Apache + PHP + MySQL) in development; production would swap in a proper LAMP/LEMP stack.
- OpenAI’s GPT-3.5 Turbo provides the quiz content.
- A session mechanism in PHP + client-side JS ensures page-level protection.
- MySQL tables: users, quizzes, questions, choices, quiz_attempts, user_answers.

a. Main components:
- Browser / Frontend (HTML/CSS/JS)
- PHP application server (REST endpoints)
- MySQL database
- External service: OpenAI API
b. Relationships / interactions:
1. User’s browser sends HTTP requests (via fetch) to the PHP endpoints.
2. PHP endpoints read/write to MySQL over a secure connection.
3. create_quiz.php proxies requests to the OpenAI API, parses responses, then persists quiz metadata & questions in MySQL.
4. PHP returns JSON to the browser; the front end renders dynamic quiz content or history.
c. Architectural patterns / design principles:
- Layered architecture:
1. Presentation layer (HTML/JS)
2. Application layer (PHP controllers)
3. Persistence layer (MySQL)
- RESTful endpoints for CRUD operations and AI integration.
- Session management for authentication and authorization.
d. Key technologies:
- Frontend: HTML5, CSS3, Vanilla JavaScript (ES6 fetch)
- Backend: PHP 8.x, session cookies
- Database: MySQL (InnoDB, foreign keys)
- External API: OpenAI GPT-3.5 Turbo

##### Elements
- Blue rectangles for frontend components
- Green rectangles for backend/PHP services

##### Detailed breakdown of key interactions
- User clicks “Generate Quiz”:
[Browser: create_quiz_page.html + JS] → POST fetch to create_quiz.php →
- OpenAI responds with quiz JSON → create_quiz.php writes to MySQL (quizzes, questions, choices) →
- create_quiz.php returns quiz (without answers) to browser → JS renders quiz.
- User submits answers:
[Browser] → POST fetch to submit_quiz.php →
- submit_quiz.php writes to quiz_attempts & user_answers, reads correct answers →
- Calculates score → returns result JSON → JS displays results.
- User views history:
[Browser] → GET fetch to get_history.php →
- get_history.php queries quiz_attempts & quizzes → returns JSON → JS populates history.html table.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client Side"
        direction TB
        Browser["Browser"]:::frontend
        Presentation["Presentation Layer\nHTML/CSS/JS"]:::frontend
        Assets["Static Assets\n(Images/Icons)"]:::frontend
    end

    %% Server Side
    subgraph "Server Side"
        direction TB
        subgraph "REST API"
            direction TB
            DBConn["db.php\n(DB Connection)"]:::backend
            Signup["signup.php"]:::backend
            Login["login.php"]:::backend
            Logout["logout.php"]:::backend
            SessionCheck["check_session.php"]:::backend
            CreateQuiz["create_quiz.php"]:::backend
            SubmitQuiz["submit_quiz.php"]:::backend
            GetHistory["get_history.php"]:::backend
        end
        MySQL["MySQL Database"]:::db
        OpenAI["OpenAI GPT-3.5 Turbo"]:::api
    end

    %% Interactions
    Browser -->|"loads pages"| Presentation
    Presentation -->|"fetch assets"| Assets

    Browser -->|"POST /php/signup.php\n(JSON)"| Signup
    Signup -->|"writes user"| MySQL
    Signup -->|"JSON response"| Browser

    Browser -->|"POST /php/login.php\n(JSON)"| Login
    Login -->|"reads user"| MySQL
    Login -->|"set session Cookie"| Browser

    Browser -->|"GET /php/check_session.php"| SessionCheck
    SessionCheck -->|"validate session"| MySQL
    SessionCheck -->|"JSON auth status"| Browser

    Browser -->|"POST /php/create_quiz.php\n(JSON)"| CreateQuiz
    CreateQuiz -->|"reads/writes quiz data"| MySQL
    CreateQuiz -->|"API Key + prompt"| OpenAI
    OpenAI -->|"JSON quiz"| CreateQuiz
    CreateQuiz -->|"JSON quiz"| Browser

    Browser -->|"POST /php/submit_quiz.php\n(JSON answers)"| SubmitQuiz
    SubmitQuiz -->|"writes attempts & answers\nreads correct answers"| MySQL
    SubmitQuiz -->|"JSON result"| Browser

    Browser -->|"GET /php/get_history.php"| GetHistory
    GetHistory -->|"queries attempts & quizzes"| MySQL
    GetHistory -->|"JSON history"| Browser

    %% Click Events
    click Presentation "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/*.html"
    click Assets "https://github.com/mushaf-khalil/quizvendor_webtechnologies/tree/main/QuizVendor/ASSETS/"
    click DBConn "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/db.php"
    click Signup "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/signup.php"
    click Login "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/login.php"
    click Logout "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/logout.php"
    click SessionCheck "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/check_session.php"
    click CreateQuiz "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/create_quiz.php"
    click SubmitQuiz "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/submit_quiz.php"
    click GetHistory "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/QuizVendor/php/get_history.php"
    click README "https://github.com/mushaf-khalil/quizvendor_webtechnologies/blob/main/README.md"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef db fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef api fill:#e2d1f9,stroke:#333,stroke-width:1px
```
