# naveengehu/quiz_port architecture

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

- Interactive diagram: https://gitdiagram.com/naveengehu/quiz_port
- Repository: https://github.com/naveengehu/quiz_port

## Overview

##### Project Type and Purpose
- QuizPort is a full-stack, web-based quiz application that demonstrates internal data structures (hash tables, arrays/linked lists) for efficient question lookup, storage, and randomization.
- The existing file tree shows a static “frontend” (HTML/CSS/JS) and a collection of monolithic PHP scripts under “server.”

##### High-Level Architecture Overview
a. Client Layer (Presentation Tier)
b. Application Layer (Backend Services)
c. Data Layer (Persistence and Cache)

##### Main Components
a. Client Layer
- Browser-based SPA pages (login, registration, dashboard, test creation/taking)
- app.js orchestrates UI logic, stores session info in LocalStorage, and calls REST endpoints.
- Responsive UI (HTML5, CSS3, possibly a UI framework like Bootstrap or Vue/React)
b. Application Layer
We replace the unstructured PHP scripts with separate, well-scoped service modules. Each module is a PHP class or microservice, exposing RESTful endpoints via an API Gateway (e.g., Slim Framework or Laravel API routes).
1. API Gateway / Router
– Central entry point for all REST calls
– Authenticates token/session, routes to service controllers
2. User Management Service
– Endpoints: /register, /login, /logout, /validateSession
– Responsibilities: credential hashing, JWT/session issuance, session validation
3. Quiz Management Service
– Endpoints: /questions, /createTest, /getTestKeys
– Internally loads question metadata into:
- Hash Tables (O(1) lookup by ID)
- Arrays or Linked Lists for sequencing & randomization
– Supports CRUD on question bank
4. Attempt Evaluation Service
– Endpoint: /submitTest
– Validates answers against keyed data structures, calculates score
5. Leaderboard/Analytics Service
– Endpoints: /leaderboard, /stats
– Aggregates results, computes rankings, trend analytics
c. Data Layer
- Primary Database (MySQL/PostgreSQL)
– Tables: users, questions, tests, submissions, scores
- Cache Layer (Redis or Memcached)
– Caches hot question data and leaderboard results
- File Storage (if media questions): S3 or local FS

##### Relationships and Data Flows
1. Browser → API Gateway: Authenticate & fetch question list
2. API Gateway → Appropriate Service Module
3. Service Module ↔ Database / Cache for read/write
4. Service Module returns JSON responses to Client
5. Client updates UI, persists tokens in LocalStorage

##### Architectural Patterns and Principles
- Layered Architecture: separation of concerns between Presentation, Application, and Data
- Modular Services: each business function in its own bounded context
- Dependency Injection / Inversion of Control in PHP services (using a framework)
- Caching for performance, database normalization for integrity
- Statelessness: backend services treat each request independently (facilitates scaling)

##### Technologies and Frameworks
- Client: Vanilla JS or modern framework (React/Vue/Angular), Bootstrap/CSS3
- Backend: PHP 7+ with a micro-framework (Slim, Lumen, Laravel API)
- DB: MySQL/PostgreSQL
- Cache: Redis
- Authentication: JWT or PHP sessions stored in Redis
- REST over HTTPS

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Client Layer
  subgraph "Client Layer"
    direction TB
    Index["index.html"]:::client
    LoginStu["loginpageforstudent.html"]:::client
    LoginTea["loginpageforteacher.html"]:::client
    RegStuPage["registrationpageforstudent.html"]:::client
    RegTeaPage["registrationpageforteacher.html"]:::client
    DashStu["studentdashboard.html"]:::client
    DashTea["teacherdashboard.html"]:::client
    CreatePage["testcreatingpage.html"]:::client
    TakePage["testtakingpage.html"]:::client
    ResultPage["resultviewingpage.html"]:::client
    Style["style.css"]:::client
    App["app.js"]:::client
  end

  %% Application Layer
  subgraph "Application Layer"
    direction TB
    APIGW["API Gateway / Router"]:::service

    subgraph "User Management Service"
      direction TB
      RegStuSrv["register_student.php"]:::service
      RegTeaSrv["register_teacher.php"]:::service
      FetchStu["fetch_dbstudent.php"]:::service
      FetchTea["fetchdb_teacher.php"]:::service
    end

    subgraph "Quiz Management Service"
      direction TB
      FetchQ["fetch_question.php"]:::service
      CreateTest["create_test.php"]:::service
      GetKeys["getTestKeys.php"]:::service
      MapKey["map_test_key.php"]:::service
    end

    subgraph "Attempt Evaluation Service"
      direction TB
      SubmitTest["submit_test.php"]:::service
      CheckSub["check_submission.php"]:::service
    end

    subgraph "Leaderboard/Analytics Service"
      direction TB
      FetchMarks["fetch_marks.php"]:::service
    end
  end

  %% Data Layer
  subgraph "Data Layer"
    direction TB
    DB[(Primary Database)]:::data
    Cache((Redis Cache)):::data
    Conn["conn.php"]:::data
  end

  %% Flows
  App -->|"REST API"| APIGW
  APIGW -->|"auth/routes"| RegStuSrv
  APIGW --> RegTeaSrv
  APIGW -->|"routes"| FetchStu
  APIGW --> FetchTea

  APIGW --> FetchQ
  APIGW --> CreateTest
  APIGW --> GetKeys
  APIGW --> MapKey

  APIGW --> SubmitTest
  APIGW --> CheckSub

  APIGW --> FetchMarks

  RegStuSrv --> Conn
  RegTeaSrv --> Conn
  FetchStu --> Conn
  FetchTea --> Conn

  FetchQ --> Cache
  FetchQ --> DB
  CreateTest --> DB
  GetKeys --> Cache
  GetKeys --> DB
  MapKey --> DB

  SubmitTest --> DB
  SubmitTest --> Cache
  CheckSub --> DB

  FetchMarks --> DB
  FetchMarks --> Cache

  %% Click Events
  click Index "https://github.com/naveengehu/quiz_port/blob/main/frontend/index.html"
  click LoginStu "https://github.com/naveengehu/quiz_port/blob/main/frontend/loginpageforstudent.html"
  click LoginTea "https://github.com/naveengehu/quiz_port/blob/main/frontend/loginpageforteacher.html"
  click RegStuPage "https://github.com/naveengehu/quiz_port/blob/main/frontend/registrationpageforstudent.html"
  click RegTeaPage "https://github.com/naveengehu/quiz_port/blob/main/frontend/registrationpageforteacher.html"
  click DashStu "https://github.com/naveengehu/quiz_port/blob/main/frontend/studentdashboard.html"
  click DashTea "https://github.com/naveengehu/quiz_port/blob/main/frontend/teacherdashboard.html"
  click CreatePage "https://github.com/naveengehu/quiz_port/blob/main/frontend/testcreatingpage.html"
  click TakePage "https://github.com/naveengehu/quiz_port/blob/main/frontend/testtakingpage.html"
  click ResultPage "https://github.com/naveengehu/quiz_port/blob/main/frontend/resultviewingpage.html"
  click Style "https://github.com/naveengehu/quiz_port/blob/main/frontend/style.css"
  click App "https://github.com/naveengehu/quiz_port/blob/main/frontend/app.js"

  click APIGW "https://github.com/naveengehu/quiz_port/blob/main/server/JsonResponse.php"

  click RegStuSrv "https://github.com/naveengehu/quiz_port/blob/main/server/register_student.php"
  click RegTeaSrv "https://github.com/naveengehu/quiz_port/blob/main/server/register_teacher.php"
  click FetchStu "https://github.com/naveengehu/quiz_port/blob/main/server/fetch_dbstudent.php"
  click FetchTea "https://github.com/naveengehu/quiz_port/blob/main/server/fetchdb_teacher.php"

  click FetchQ "https://github.com/naveengehu/quiz_port/blob/main/server/fetch_question.php"
  click CreateTest "https://github.com/naveengehu/quiz_port/blob/main/server/create_test.php"
  click GetKeys "https://github.com/naveengehu/quiz_port/blob/main/server/getTestKeys.php"
  click MapKey "https://github.com/naveengehu/quiz_port/blob/main/server/map_test_key.php"

  click SubmitTest "https://github.com/naveengehu/quiz_port/blob/main/server/submit_test.php"
  click CheckSub "https://github.com/naveengehu/quiz_port/blob/main/server/check_submission.php"

  click FetchMarks "https://github.com/naveengehu/quiz_port/blob/main/server/fetch_marks.php"

  click Conn "https://github.com/naveengehu/quiz_port/blob/main/server/conn.php"

  %% Styles
  classDef client fill:#cce5ff,stroke:#333,stroke-width:1px
  classDef service fill:#d4edda,stroke:#333,stroke-width:1px
  classDef data fill:#fff3cd,stroke:#333,stroke-width:1px
```
