Back to .md Directory

Quizya - Comprehensive Project Architecture & Documentation

1. [Project Overview](#project-overview)

May 2, 2026
0 downloads
1 views
ai
View source

Quizya - Comprehensive Project Architecture & Documentation

๐Ÿ“‹ Table of Contents

  1. Project Overview
  2. Technology Stack
  3. Project Structure
  4. Database Architecture
  5. Authentication & Authorization
  6. API Routes
  7. Core Services
  8. Components & UI
  9. Data Flow & Interactions
  10. Key Features
  11. Development Setup

๐ŸŽฏ Project Overview

Quizya is a modern, full-stack online examination platform built with Next.js 16 and React 19. It enables teachers to create, manage, and administer exams with advanced features like proctoring, guest access, real-time analytics, and question banking.

Core Purpose

  • For Teachers: Create exams, manage questions, monitor student performance, view analytics
  • For Students: Take exams in real-time, receive immediate feedback, access results
  • For Guests: Join exams using room codes without authentication
  • For Admins: Manage users, view system-wide analytics, manage settings

Key Highlights

  • Real-time exam administration with guest access support
  • Advanced proctoring capabilities (tab switching detection, fullscreen exit detection)
  • Comprehensive question banking system
  • Multi-role support (teacher, student)
  • Responsive dark/light theme
  • Server-side rendering with Next.js App Router

๐Ÿ› ๏ธ Technology Stack

Frontend

  • Framework: Next.js 16.0.10 (React 19.2.0)
  • Styling:
    • Tailwind CSS 4.1.9 with PostCSS 8.5
    • Custom Neumorphism (Neu) design system
    • Shadcn/ui components with Radix UI primitives
  • UI Libraries:
    • Radix UI (30+ component primitives)
    • Lucide React (icons)
    • Sonner (toast notifications)
    • React Hook Form (form validation)
    • Recharts (data visualization)
    • Embla Carousel (carousel)
  • State Management:
    • React Context API (AuthProvider)
    • Custom hooks (useAuth, useExams, useGuestExamAccess)
  • Themes: next-themes (light/dark/system)

Backend & Database

  • Runtime: Node.js (Next.js Server Components & API Routes)
  • Database: Supabase PostgreSQL
  • Auth: Supabase Authentication (Email/Password + Google OAuth)
  • ORM: Supabase JS Client (direct SQL queries)
  • Security: Row Level Security (RLS) policies

Development Tools

  • TypeScript: 5.x (strict mode enabled)
  • Package Manager: pnpm
  • Linting: ESLint
  • Form Validation: Zod + React Hook Form
  • Icons: Lucide React (454 icons)

Deployment

  • Hosting: Vercel
  • Analytics: Vercel Analytics
  • Database: Supabase Cloud
  • CDN: Vercel Edge Network

๐Ÿ“ Project Structure

v2-quizya/
โ”œโ”€โ”€ app/                              # Next.js App Router directory
โ”‚   โ”œโ”€โ”€ api/                          # API Routes (Backend endpoints)
โ”‚   โ”‚   โ”œโ”€โ”€ auth/                     # Authentication endpoints
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ login/                # POST: User login
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ signup/               # POST: User registration
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ logout/               # POST: User logout
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ google/               # GET: Google OAuth
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ callback/             # GET: OAuth callback
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ me/                   # GET: Current user info
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ verify-email/         # POST: Email verification
โ”‚   โ”‚   โ”œโ”€โ”€ exams/                    # Exam management endpoints
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ route.ts              # GET: List exams | POST: Create exam
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [id]/                 # Dynamic exam routes
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ route.ts          # GET/PUT/DELETE: Exam CRUD
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ ...               # Nested exam operations
โ”‚   โ”‚   โ”œโ”€โ”€ exam/                     # Exam taking/session endpoints
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ guest-join/           # POST: Guest joins exam
โ”‚   โ”‚   โ”œโ”€โ”€ public-exams/             # Public exam discovery
โ”‚   โ”‚   โ”œโ”€โ”€ analytics/                # Analytics endpoints
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/            # Overall dashboard stats
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ teacher/              # Teacher-specific analytics
โ”‚   โ”‚   โ””โ”€โ”€ sessions/                 # Exam session management
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ auth/                         # Authentication pages
โ”‚   โ”‚   โ”œโ”€โ”€ login/                    # Login page
โ”‚   โ”‚   โ”œโ”€โ”€ signup/                   # Registration page
โ”‚   โ”‚   โ””โ”€โ”€ setup/                    # Initial setup/onboarding
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ dashboard/                    # Main dashboard
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx                  # Dashboard home
โ”‚   โ”‚   โ”œโ”€โ”€ exams/                    # Exam management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx              # Exams list
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ [id]/                 # Exam detail & edit
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ new/                  # Create new exam
โ”‚   โ”‚   โ”œโ”€โ”€ question-bank/            # Question bank management
โ”‚   โ”‚   โ”œโ”€โ”€ analytics/                # Analytics views
โ”‚   โ”‚   โ””โ”€โ”€ settings/                 # User settings
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ exam/                         # Exam taking interface
โ”‚   โ”‚   โ””โ”€โ”€ take/                     # Exam taking page
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ join/                         # Guest join exam
โ”‚   โ”œโ”€โ”€ public-exams/                 # Browse public exams
โ”‚   โ”œโ”€โ”€ results/                      # View exam results
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ layout.tsx                    # Root layout (Auth + Theme providers)
โ”‚   โ”œโ”€โ”€ page.tsx                      # Landing page
โ”‚   โ””โ”€โ”€ globals.css                   # Global styles
โ”‚
โ”œโ”€โ”€ components/                       # Reusable React components
โ”‚   โ”œโ”€โ”€ ui/                           # Shadcn/Neumorphism UI components
โ”‚   โ”‚   โ”œโ”€โ”€ neu-button.tsx            # Custom Neu button
โ”‚   โ”‚   โ”œโ”€โ”€ neu-card.tsx              # Custom Neu card
โ”‚   โ”‚   โ”œโ”€โ”€ neu-input.tsx             # Custom Neu input
โ”‚   โ”‚   โ”œโ”€โ”€ neu-modal.tsx             # Custom Neu modal
โ”‚   โ”‚   โ”œโ”€โ”€ neu-timer.tsx             # Exam timer component
โ”‚   โ”‚   โ”œโ”€โ”€ neu-progress.tsx          # Progress bar
โ”‚   โ”‚   โ”œโ”€โ”€ neu-toast.tsx             # Toast notifications
โ”‚   โ”‚   โ”œโ”€โ”€ proctoring-badge.tsx      # Proctoring status indicator
โ”‚   โ”‚   โ”œโ”€โ”€ room-code-widget.tsx      # Room code display
โ”‚   โ”‚   โ”œโ”€โ”€ sortable-question.tsx     # Draggable question component
โ”‚   โ”‚   โ”œโ”€โ”€ theme-toggle.tsx          # Dark/light mode toggle
โ”‚   โ”‚   โ”œโ”€โ”€ credential-input.tsx      # Masked credential input
โ”‚   โ”‚   โ”œโ”€โ”€ password-strength.tsx     # Password strength meter
โ”‚   โ”‚   โ””โ”€โ”€ ...                       # Other Radix-based components
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ auth/                         # Authentication components
โ”‚   โ”‚   โ”œโ”€โ”€ auth-login.tsx            # Login form component
โ”‚   โ”‚   โ”œโ”€โ”€ auth-signup.tsx           # Signup form component
โ”‚   โ”‚   โ””โ”€โ”€ protected-route.tsx       # Route protection wrapper
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ dashboard/                    # Dashboard components
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard.tsx             # Main dashboard container
โ”‚   โ”‚   โ”œโ”€โ”€ exams-list.tsx            # Exams list view
โ”‚   โ”‚   โ”œโ”€โ”€ exam-results.tsx          # Exam results display
โ”‚   โ”‚   โ”œโ”€โ”€ exam-taking.tsx           # Active exam interface
โ”‚   โ”‚   โ”œโ”€โ”€ question-bank-list.tsx    # Question bank list
โ”‚   โ”‚   โ”œโ”€โ”€ analytics-dashboard.tsx   # Analytics visualization
โ”‚   โ”‚   โ”œโ”€โ”€ settings-dashboard.tsx    # Settings UI
โ”‚   โ”‚   โ””โ”€โ”€ student-performance.tsx   # Performance charts
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ exam-students/                # Exam-related student components
โ”‚   โ”‚   โ”œโ”€โ”€ exam-results.tsx          # Student exam results
โ”‚   โ”‚   โ””โ”€โ”€ guest-join-form.tsx       # Guest join form
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ landing/                      # Landing page components
โ”‚   โ”‚   โ”œโ”€โ”€ hero-section.tsx          # Hero banner
โ”‚   โ”‚   โ”œโ”€โ”€ features-section.tsx      # Features showcase
โ”‚   โ”‚   โ”œโ”€โ”€ header.tsx                # Navigation header
โ”‚   โ”‚   โ””โ”€โ”€ footer.tsx                # Page footer
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ debug/                        # Debug/testing components
โ”‚   โ”‚   โ””โ”€โ”€ supabase-test.tsx         # Supabase connectivity test
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ theme-provider.tsx            # Next-themes provider wrapper
โ”‚   โ””โ”€โ”€ toast-container.tsx           # Toast notifications container
โ”‚
โ”œโ”€โ”€ lib/                              # Core logic & utilities
โ”‚   โ”œโ”€โ”€ supabase/                     # Supabase configuration
โ”‚   โ”‚   โ”œโ”€โ”€ client.ts                 # Browser Supabase client
โ”‚   โ”‚   โ”œโ”€โ”€ server.ts                 # Server Supabase client (SSR)
โ”‚   โ”‚   โ””โ”€โ”€ middleware.ts             # Auth middleware
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ services/                     # Business logic services
โ”‚   โ”‚   โ”œโ”€โ”€ exams.ts                  # Exam CRUD operations
โ”‚   โ”‚   โ”œโ”€โ”€ exam-sessions.ts          # Exam session management
โ”‚   โ”‚   โ”œโ”€โ”€ questions.ts              # Question CRUD
โ”‚   โ”‚   โ”œโ”€โ”€ question-bank.ts          # Question bank operations
โ”‚   โ”‚   โ””โ”€โ”€ profiles.ts               # User profile operations
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ hooks/                        # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ use-auth.tsx              # Auth context & hook
โ”‚   โ”‚   โ”œโ”€โ”€ use-exams.ts              # Exam data hook
โ”‚   โ”‚   โ””โ”€โ”€ use-guest-exam-access.ts  # Guest access hook
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ types/                        # TypeScript type definitions
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts                  # Exported types
โ”‚   โ”‚   โ””โ”€โ”€ database.ts               # Supabase database types (auto-generated)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ utils/                        # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ guest-session.ts          # Guest session utilities
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ utils.ts                      # General utility functions
โ”‚
โ”œโ”€โ”€ public/                           # Static assets
โ”‚   โ”œโ”€โ”€ icon-light-32x32.png
โ”‚   โ”œโ”€โ”€ icon-dark-32x32.png
โ”‚   โ”œโ”€โ”€ icon.svg
โ”‚   โ””โ”€โ”€ apple-icon.png
โ”‚
โ”œโ”€โ”€ supabase/                         # Database migrations & config
โ”‚   โ”œโ”€โ”€ schema.sql                    # Main database schema
โ”‚   โ”œโ”€โ”€ config.toml                   # Supabase config
โ”‚   โ”œโ”€โ”€ migration-guest-access.sql    # Guest access migration
โ”‚   โ”œโ”€โ”€ verify-guest-setup.sql        # Guest setup verification
โ”‚   โ””โ”€โ”€ migrations/
โ”‚       โ””โ”€โ”€ 20241213000001_create_user_settings.sql
โ”‚
โ”œโ”€โ”€ styles/                           # Global styles
โ”‚   โ””โ”€โ”€ globals.css                   # Tailwind + custom styles
โ”‚
โ”œโ”€โ”€ postcss.config.mjs                # PostCSS configuration
โ”œโ”€โ”€ tailwind.config.js                # Tailwind CSS configuration
โ”œโ”€โ”€ tsconfig.json                     # TypeScript configuration
โ”œโ”€โ”€ next.config.mjs                   # Next.js configuration
โ”œโ”€โ”€ components.json                   # Shadcn/ui configuration
โ”œโ”€โ”€ package.json                      # Dependencies & scripts
โ”œโ”€โ”€ pnpm-lock.yaml                    # Dependency lock file
โ””โ”€โ”€ README.md                         # Project documentation

๐Ÿ—„๏ธ Database Architecture

Database Schema

1. User Roles Enum

CREATE TYPE user_role AS ENUM ('teacher', 'student');

2. Profiles Table

Stores user profile information.

CREATE TABLE profiles (
    id UUID PRIMARY KEY (references auth.users),
    email TEXT UNIQUE NOT NULL,
    full_name TEXT,
    avatar_url TEXT,
    role user_role DEFAULT 'student',
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);

Purpose: User identity and role management

3. Exams Table

Main exam container.

CREATE TABLE exams (
    id UUID PRIMARY KEY,
    title TEXT NOT NULL,
    description TEXT,
    duration_minutes INTEGER NOT NULL,
    total_questions INTEGER NOT NULL,
    passing_score INTEGER NOT NULL,
    is_public BOOLEAN DEFAULT false,
    is_active BOOLEAN DEFAULT true,
    room_code TEXT UNIQUE,
    proctoring_enabled BOOLEAN DEFAULT false,
    shuffle_questions BOOLEAN DEFAULT false,
    show_results_immediately BOOLEAN DEFAULT true,
    created_by UUID REFERENCES profiles(id),
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);

Purpose: Exam metadata and configuration

4. Questions Table

Individual exam questions.

CREATE TABLE questions (
    id UUID PRIMARY KEY,
    exam_id UUID REFERENCES exams(id),
    question_text TEXT NOT NULL,
    question_type question_type,  -- 'multiple_choice', 'true_false', 'short_answer', 'essay'
    options JSONB,                  -- Array of options (for multiple choice)
    correct_answer TEXT NOT NULL,
    points INTEGER DEFAULT 1,
    order_index INTEGER NOT NULL,   -- Question ordering
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);

Purpose: Exam questions and answers

5. Exam Sessions Table

Student exam attempt records.

CREATE TABLE exam_sessions (
    id UUID PRIMARY KEY,
    exam_id UUID REFERENCES exams(id),
    student_id UUID REFERENCES profiles(id),
    guest_name TEXT,               -- For guest students
    guest_email TEXT,              -- For guest students
    is_guest BOOLEAN DEFAULT false,
    started_at TIMESTAMP,
    submitted_at TIMESTAMP,
    score DECIMAL(5,2),
    total_points INTEGER,
    status session_status,         -- 'not_started', 'in_progress', 'completed', 'abandoned'
    answers JSONB,                 -- Student answers { question_id: answer }
    proctoring_data JSONB,         -- Suspicious activity logs
    created_at TIMESTAMP,
    updated_at TIMESTAMP,
    CONSTRAINT unique_exam_participant UNIQUE(exam_id, student_id, guest_email)
);

Purpose: Track exam attempts, scores, and student answers

6. Question Bank Table

Reusable question library.

CREATE TABLE question_bank (
    id UUID PRIMARY KEY,
    title TEXT NOT NULL,
    description TEXT,
    subject TEXT,
    difficulty_level difficulty_level,  -- 'easy', 'medium', 'hard'
    question_text TEXT NOT NULL,
    question_type question_type NOT NULL,
    options JSONB,
    correct_answer TEXT NOT NULL,
    explanation TEXT,               -- Answer explanation
    tags TEXT[],                    -- For categorization
    created_by UUID REFERENCES profiles(id),
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);

Purpose: Reusable question library for creating exams

Database Indexes

CREATE INDEX idx_exams_created_by ON exams(created_by);
CREATE INDEX idx_exams_room_code ON exams(room_code);
CREATE INDEX idx_questions_exam_id ON questions(exam_id);
CREATE INDEX idx_questions_order ON questions(exam_id, order_index);
CREATE INDEX idx_exam_sessions_exam_id ON exam_sessions(exam_id);
CREATE INDEX idx_exam_sessions_student_id ON exam_sessions(student_id);
CREATE INDEX idx_exam_sessions_status ON exam_sessions(status);
CREATE INDEX idx_question_bank_created_by ON question_bank(created_by);
CREATE INDEX idx_question_bank_subject ON question_bank(subject);
CREATE INDEX idx_question_bank_difficulty ON question_bank(difficulty_level);
CREATE INDEX idx_question_bank_tags ON question_bank USING GIN(tags);

Row Level Security (RLS) Policies

All tables have RLS enabled with role-based access control:

Profiles:

  • Public profiles viewable by everyone
  • Users can only insert/update their own profile

Exams:

  • Public exams viewable by everyone
  • Only teachers can create exams
  • Teachers can only update/delete their own exams

Questions:

  • Viewable by exam creators or students taking the exam
  • Teachers manage questions for their exams

Exam Sessions:

  • Students can only view their own sessions
  • Teachers can view sessions for their exams

Question Bank:

  • Users can only view/manage their own questions
  • Support for sharing questions (future enhancement)

๐Ÿ” Authentication & Authorization

Authentication Flow

1. Email/Password Authentication

User Input (Email + Password)
    โ†“
POST /api/auth/signup or /api/auth/login
    โ†“
Supabase Auth API
    โ†“
JWT Token + Refresh Token (stored in httpOnly cookies)
    โ†“
Create/Update profiles table entry
    โ†“
Redirect to dashboard

2. Google OAuth

User clicks "Sign in with Google"
    โ†“
GET /api/auth/google (redirect to Google)
    โ†“
Google OAuth flow
    โ†“
GET /api/auth/callback (handle callback)
    โ†“
Create Supabase user + profile
    โ†“
Redirect to dashboard

3. Guest Access (No Authentication)

Guest provides email/name
    โ†“
POST /api/exam/guest-join with room code
    โ†“
Create temporary exam_sessions entry (is_guest=true)
    โ†“
No authentication required
    โ†“
Access exam temporarily

Authorization Levels

RolePermissions
TeacherCreate exams, create questions, manage question bank, view own analytics, delete exams
StudentTake exams, view own results, browse public exams, access question bank (read-only)
GuestTake public exams with room code (no authentication needed)
Admin(Future) Manage users, view system analytics, manage platform settings

Auth Context (useAuth Hook)

interface AuthContextType {
  user: User | null;                    // Current user
  profile: Profile | null;              // User's profile data
  loading: boolean;
  signIn(email, password): Promise;     // Login
  signUp(email, password, name, role): Promise;  // Register
  signOut(): Promise;                   // Logout
  refreshProfile(): Promise;            // Reload profile
}

Token Management

  • JWT tokens stored in httpOnly cookies (secure, XSS-protected)
  • Refresh tokens handled automatically by Supabase
  • Session persistence across browser reloads
  • Automatic logout on token expiration

๐Ÿ”Œ API Routes

Authentication Routes

POST /api/auth/signup

Purpose: User registration Request:

{
  "email": "user@example.com",
  "password": "SecurePass123!",
  "fullName": "John Doe",
  "role": "teacher" // 'teacher' or 'student'
}

Response: { user, session } or error Auth: Public

POST /api/auth/login

Purpose: User login Request:

{
  "email": "user@example.com",
  "password": "SecurePass123!"
}

Response: { user, session } or error Auth: Public

POST /api/auth/logout

Purpose: User logout Auth: Protected (requires authentication)

GET /api/auth/me

Purpose: Get current authenticated user Response: { user, profile } Auth: Protected

GET /api/auth/google

Purpose: Google OAuth initiation Auth: Public

GET /api/auth/callback

Purpose: Handle Google OAuth callback Auth: Public

POST /api/auth/verify-email

Purpose: Verify email address Auth: Public

Exam Management Routes

GET /api/exams

Purpose: List user's exams with pagination Query Params:

  • page: Page number (default: 1)
  • limit: Items per page (default: 10) Response:
{
  "data": [{ id, title, duration_minutes, ... }],
  "pagination": { page, limit, total, pages }
}

Auth: Protected

POST /api/exams

Purpose: Create new exam Request:

{
  "title": "Math Final Exam",
  "description": "...",
  "duration_minutes": 120,
  "total_questions": 50,
  "passing_score": 70,
  "is_public": false,
  "proctoring_enabled": true,
  "shuffle_questions": true
}

Response: Created exam object Auth: Protected (teacher only)

GET /api/exams/[id]

Purpose: Get single exam with questions Response:

{
  "id": "...",
  "title": "...",
  "questions": [{ id, question_text, options, ... }]
}

Auth: Protected

PUT /api/exams/[id]

Purpose: Update exam Request: Partial exam object Response: Updated exam Auth: Protected (exam creator only)

DELETE /api/exams/[id]

Purpose: Delete exam Auth: Protected (exam creator only)

Question Management Routes

POST /api/exams/[id]/questions

Purpose: Add question to exam Request:

{
  "question_text": "...",
  "question_type": "multiple_choice",
  "options": ["A", "B", "C", "D"],
  "correct_answer": "A",
  "points": 2,
  "order_index": 1
}

Auth: Protected (exam creator only)

PUT /api/exams/[id]/questions/[qid]

Purpose: Update question Auth: Protected (exam creator only)

DELETE /api/exams/[id]/questions/[qid]

Purpose: Delete question Auth: Protected (exam creator only)

Exam Session Routes

POST /api/exam/guest-join

Purpose: Guest joins exam with room code Request:

{
  "roomCode": "EXAM123",
  "guestName": "John",
  "guestEmail": "john@example.com"
}

Response: Exam session object Auth: Public

GET /api/sessions/[id]

Purpose: Get exam session details Response: Session with answers and score Auth: Protected

PUT /api/sessions/[id]

Purpose: Update exam session (submit answers) Request:

{
  "answers": { "question_id": "answer_text" },
  "status": "completed",
  "submitted_at": "2024-12-14T..."
}

Auth: Protected/Guest

Analytics Routes

GET /api/analytics/dashboard

Purpose: Get teacher's dashboard analytics Response:

{
  "totalExams": 15,
  "activeExams": 3,
  "totalSessions": 250,
  "avgScore": 78.5,
  "completionRate": 92,
  "recentExams": [...]
}

Auth: Protected (teacher only)

GET /api/analytics/teacher

Purpose: Detailed teacher analytics Response: Graphs data, performance metrics Auth: Protected (teacher only)

Public Exams Routes

GET /api/public-exams

Purpose: Browse public exams Query Params:

  • page: Pagination
  • search: Search by title Response: List of public exams Auth: Public

Settings Routes

GET /api/settings/profile?userId=[id]

Purpose: Get user profile Auth: Public (profile is public)

PUT /api/settings/profile

Purpose: Update user profile Request:

{
  "full_name": "...",
  "avatar_url": "...",
  "role": "..."
}

Auth: Protected (own profile only)

GET /api/settings/preferences

Purpose: Get user preferences Auth: Protected

PUT /api/settings/preferences

Purpose: Update user preferences Auth: Protected


๐Ÿ”ง Core Services

Exam Service (lib/services/exams.ts)

createExam(exam: ExamInsert): Promise<Exam>
  โ†’ Insert new exam into database
  โ†’ Called from: Dashboard "Create Exam" button

getExam(examId: string): Promise<Exam>
  โ†’ Fetch single exam metadata
  โ†’ Called from: Exam detail page

getExamWithQuestions(examId: string): Promise<ExamWithQuestions>
  โ†’ Fetch exam + all questions (with ordering)
  โ†’ Called from: Exam editing, exam taking

getUserExams(userId: string): Promise<Exam[]>
  โ†’ Fetch all exams created by user
  โ†’ Called from: Dashboard exams list

getPublicExams(): Promise<Exam[]>
  โ†’ Fetch all public exams
  โ†’ Called from: Public exams browse page

updateExam(examId: string, updates: ExamUpdate): Promise<Exam>
  โ†’ Update exam metadata
  โ†’ Called from: Exam edit form

deleteExam(examId: string): Promise<boolean>
  โ†’ Soft/hard delete exam
  โ†’ Called from: Dashboard delete action

Exam Session Service (lib/services/exam-sessions.ts)

createExamSession(session: ExamSessionInsert): Promise<ExamSession>
  โ†’ Create new exam attempt record
  โ†’ Called from: Exam start (student or guest)

getExamSession(examId, studentId?, guestEmail?): Promise<ExamSession>
  โ†’ Fetch existing session
  โ†’ Supports both authenticated and guest lookups

updateExamSession(sessionId, updates): Promise<ExamSession>
  โ†’ Update session (add answers, change status)
  โ†’ Called from: Question submission, exam completion

startExamSession(...): Promise<ExamSession>
  โ†’ Initialize session with started_at timestamp
  โ†’ Marks status as 'in_progress'

submitExamSession(sessionId, answers): Promise<ExamSession>
  โ†’ Submit final answers
  โ†’ Calculate score
  โ†’ Mark status as 'completed'
  โ†’ Called from: "Submit Exam" button

getExamSessions(examId): Promise<ExamSession[]>
  โ†’ Get all sessions for exam (teacher view)
  โ†’ Called from: Analytics dashboard

calculateSessionScore(session, questions): number
  โ†’ Compare student answers to correct answers
  โ†’ Sum points from correct answers

Question Service (lib/services/questions.ts)

createQuestion(question: QuestionInsert): Promise<Question>
  โ†’ Add question to exam
  โ†’ Auto-increment order_index

updateQuestion(questionId, updates): Promise<Question>
  โ†’ Edit question details

deleteQuestion(questionId): Promise<boolean>
  โ†’ Remove question from exam

getExamQuestions(examId): Promise<Question[]>
  โ†’ Fetch all questions in order
  โ†’ Called from: Exam display, analytics

reorderQuestions(examId, questionIds[]): Promise<boolean>
  โ†’ Reorder questions via drag-drop
  โ†’ Called from: Question editor

Question Bank Service (lib/services/question-bank.ts)

createBankQuestion(question: QuestionBankInsert): Promise<QuestionBank>
  โ†’ Create reusable question in bank

getUserBankQuestions(userId): Promise<QuestionBank[]>
  โ†’ Fetch user's question bank

searchBankQuestions(userId, filters): Promise<QuestionBank[]>
  โ†’ Filter by subject, difficulty, tags
  โ†’ Called from: Question bank browser

addBankQuestionToExam(bankQuestionId, examId): Promise<Question>
  โ†’ Copy question from bank to exam
  โ†’ Called from: Exam editor "Add from bank" button

Profile Service (lib/services/profiles.ts)

createProfile(profile: ProfileInsert): Promise<Profile>
  โ†’ Create profile on signup

getProfile(userId): Promise<Profile>
  โ†’ Fetch user profile

updateProfile(userId, updates): Promise<Profile>
  โ†’ Update user profile info

getUserByEmail(email): Promise<Profile | null>
  โ†’ Find user by email (for sharing, etc.)

Supabase Client Setup

Browser Client (lib/supabase/client.ts)

createBrowserClient(url, anonKey)
  โ†’ Used in client components
  โ†’ Has limited access (public/personal data only)
  โ†’ Handles RLS policies

Server Client (lib/supabase/server.ts)

createServerClient(url, anonKey, { cookies })
  โ†’ Used in server components & API routes
  โ†’ Can access more data (with proper RLS)
  โ†’ Manages session cookies

๐ŸŽจ Components & UI

Component Architecture

Neumorphism Design System

All custom Neu components follow a soft, 3D aesthetic:

  • Soft shadows and highlights
  • Rounded corners
  • Neutral color palette
  • Touch-friendly sizing

UI Component Hierarchy

ui/
โ”œโ”€โ”€ neu-card.tsx           (Card container with header/content)
โ”‚   โ”œโ”€โ”€ NeuCard
โ”‚   โ”œโ”€โ”€ NeuCardHeader
โ”‚   โ”œโ”€โ”€ NeuCardTitle
โ”‚   โ””โ”€โ”€ NeuCardContent
โ”œโ”€โ”€ neu-button.tsx         (Button with multiple variants)
โ”œโ”€โ”€ neu-input.tsx          (Text input field)
โ”œโ”€โ”€ neu-modal.tsx          (Dialog/modal overlay)
โ”œโ”€โ”€ neu-progress.tsx       (Progress bar)
โ”œโ”€โ”€ neu-timer.tsx          (Countdown timer for exams)
โ”œโ”€โ”€ neu-toast.tsx          (Toast notifications)
โ”œโ”€โ”€ proctoring-badge.tsx   (Proctoring status indicator)
โ”œโ”€โ”€ room-code-widget.tsx   (Room code display/copy)
โ”œโ”€โ”€ sortable-question.tsx  (Draggable question component)
โ”œโ”€โ”€ theme-toggle.tsx       (Dark/light mode switcher)
โ”œโ”€โ”€ credential-input.tsx   (Password/secret input field)
โ”œโ”€โ”€ password-strength.tsx  (Password strength meter)
โ””โ”€โ”€ [radix-ui components]  (Dialog, Select, Tabs, etc.)

Dashboard Components

Dashboard.tsx (Main Container)

- Fetches user exams via useExams hook
- Displays exam statistics (total, active, sessions, avg score)
- Shows exams list with pagination
- Actions: Create, Edit, Delete, View, Copy link
- Navigation: To new exam, question bank, analytics, settings

ExamsList.tsx

- Lists user's exams in grid/list view
- Shows:
  - Exam title & duration
  - Question count
  - Public/Private status
  - Room code (if applicable)
  - Last updated date
- Actions per exam: View, Edit, Share, Delete

ExamResults.tsx

- Displays exam attempt details
- Shows:
  - Student name
  - Score & percentage
  - Time taken
  - Pass/Fail status
  - Question-by-question review
  - Answer comparison
- Export/Print options

ExamTaking.tsx

- Main exam interface for taking exams
- Features:
  - Timer countdown
  - Question navigator/switcher
  - Answer tracking
  - Progress indicator
  - Proctoring status badge
  - Submit button with warning
- Proctoring events logged:
  - Tab switches
  - Window blur
  - Fullscreen exit
  - Copy/paste attempts

AnalyticsDashboard.tsx

- Displays charts using Recharts:
  - Student performance distribution
  - Score trends over time
  - Question difficulty analysis
  - Class average vs individual
  - Completion rate
  - Most difficult questions

StudentPerformance.tsx

- Shows performance metrics:
  - Total exams attempted
  - Average score
  - Completion rate
  - Performance trends

Authentication Components

AuthLogin.tsx

- Email/Password form
- "Sign in with Google" button
- Form validation with Zod
- Error handling & display
- "Forgot password?" link
- "Don't have account?" โ†’ signup link

AuthSignup.tsx

- Email, Password, Full Name, Role (Teacher/Student) fields
- Password strength indicator
- Terms & conditions checkbox
- Email verification (optional)
- "Already have account?" โ†’ login link

ProtectedRoute.tsx

- Wrapper component for protected pages
- Checks if user is authenticated
- Redirects to login if not
- Handles loading states

Landing Page Components

HeroSection.tsx

- Hero banner with CTA buttons
- "Get Started" โ†’ Signup
- "Learn More" โ†’ Features
- Key benefits/highlights

FeaturesSection.tsx

- Feature cards:
  - Exam creation
  - Student management
  - Analytics
  - Proctoring
  - Question banking
  - Guest access

Header.tsx (Navigation)

- Logo & branding
- Navigation links (Home, Features, Pricing, etc.)
- Auth buttons (Login/Signup or Dashboard link)
- Dark/Light theme toggle
- Mobile menu (hamburger)

Footer.tsx

- Links sections (Product, Company, Legal)
- Social media links
- Copyright notice

๐Ÿ”„ Data Flow & Interactions

High-Level Application Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        LANDING PAGE                         โ”‚
โ”‚  (Hero, Features, CTA buttons โ†’ Login/Signup)              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ†“
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚   AUTHENTICATION CHOICE    โ”‚
              โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
              โ”‚ โ”‚ Email/Pw โ”‚  โ”‚ Google   โ”‚โ”‚
              โ”‚ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ†“             โ†“
           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ”‚  Create/Validate User       โ”‚
           โ”‚  (Supabase Auth API)        โ”‚
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ†“
           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ”‚  Create Profile Entry       โ”‚
           โ”‚  (profiles table)           โ”‚
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ†“
           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ”‚    DASHBOARD (Teacher)      โ”‚
           โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
           โ”‚  โ”‚ - View own exams         โ”‚
           โ”‚  โ”‚ - View analytics         โ”‚
           โ”‚  โ”‚ - Create new exam        โ”‚
           โ”‚  โ”‚ - Manage question bank   โ”‚
           โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ†“         โ†“         โ†“          โ†“             โ†“
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ Create โ”‚ โ”‚Edit โ”‚ โ”‚Delete  โ”‚ โ”‚ Publish โ”‚ โ”‚Analyticsโ”‚
    โ”‚ Exam   โ”‚ โ”‚Exam โ”‚ โ”‚Exam    โ”‚ โ”‚ Exam    โ”‚ โ”‚         โ”‚
    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”ฌโ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚        โ”‚        โ”‚           โ”‚         โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚        โ”‚           โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚      exams TABLE (INSERT/UPDATE/DELETE)โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          STUDENT/GUEST TAKES EXAM                           โ”‚
โ”‚                                                             โ”‚
โ”‚  Student View:                                             โ”‚
โ”‚  1. Dashboard โ†’ Public Exams                              โ”‚
โ”‚  2. Select exam โ†’ Start exam                              โ”‚
โ”‚  3. Fetch exam_sessions (or create new)                   โ”‚
โ”‚  4. Display questions from exam_sessions.answers          โ”‚
โ”‚  5. Track proctoring events                               โ”‚
โ”‚  6. Submit answers โ†’ Update exam_sessions.answers         โ”‚
โ”‚  7. Calculate score โ†’ Update exam_sessions.score          โ”‚
โ”‚  8. View results                                          โ”‚
โ”‚                                                             โ”‚
โ”‚  Guest View:                                              โ”‚
โ”‚  1. /join page with room code input                       โ”‚
โ”‚  2. POST /api/exam/guest-join                             โ”‚
โ”‚  3. Same flow as student (no authentication)              โ”‚
โ”‚                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Exam Creation Flow

Teacher clicks "Create Exam"
    โ†“
/dashboard/exams/new page loads
    โ†“
Form: Title, Duration, PassingScore, etc.
    โ†“
POST /api/exams
    โ†“
INSERT into exams table
    โ†“
Get exam ID back
    โ†“
Redirect to /dashboard/exams/[id]
    โ†“
Teacher can add questions
    โ†“
For each question:
  - POST /api/exams/[id]/questions
  - INSERT into questions table
  - Assign order_index
    โ†“
Teacher clicks "Publish"
    โ†“
UPDATE exams SET is_public = true, is_active = true
    โ†“
Generate room_code (unique)
    โ†“
Exam ready for students/guests

Exam Taking Flow (Student)

Student in dashboard
    โ†“
Clicks "Take Exam"
    โ†“
Navigates to /exam/take/[examId]
    โ†“
ExamTaking component loads
    โ†“
GET /api/exams/[id]/questions
    โ†“
Fetch all questions from database
    โ†“
Display first question
    โ†“
Student answers question
    โ†“
Answer stored in component state (not yet saved)
    โ†“
Student clicks "Next" or "Submit"
    โ†“
On Submit:
  - POST /api/sessions
  - CREATE exam_sessions record
  - UPDATE with answers JSONB
  - UPDATE with submitted_at timestamp
    โ†“
Server calculates score:
  - Compare each answer to correct_answer
  - Sum points for correct answers
    โ†“
UPDATE exam_sessions.score
UPDATE exam_sessions.status = 'completed'
    โ†“
Redirect to /results/[sessionId]
    โ†“
Display results page with score & review

Data Access Patterns

Read Exam (Teacher)

useAuth() โ†’ user.id
  โ†“
useExams() โ†’ fetchExams()
  โ†“
GET /api/exams?page=1
  โ†“
SELECT * FROM exams WHERE created_by = user.id
  โ†“
RLS: created_by = auth.uid() โœ“
  โ†“
Return list of exams

Read Questions (Student)

ExamTaking component loads
  โ†“
GET /api/exams/[id]/questions
  โ†“
SELECT * FROM questions WHERE exam_id = [id]
  โ†“
RLS: Check if exam is public OR created_by = auth.uid()
  โ†“
Return questions array (ordered by order_index)

Submit Exam (Guest)

Guest joins with room code
  โ†“
POST /api/exam/guest-join
  {roomCode, guestName, guestEmail}
  โ†“
CREATE exam_sessions
  is_guest = true
  guest_email = provided email
  student_id = NULL
  โ†“
Guest takes exam (no auth check)
  โ†“
PUT /api/sessions/[id]
  {answers, status: 'completed'}
  โ†“
RLS: Allow if session.is_guest = true OR session.guest_email = provided
  โ†“
Calculate & save score

Real-time Features

Timer (Exam Duration)

ExamTaking component:
  - useEffect: setInterval every 1000ms
  - Decrement timeRemaining
  - Warning at 5 minutes
  - Auto-submit at 0 seconds

Proctoring Events

ExamTaking component:
  - onBlur: Detect window blur (tab switch)
  - onfullscreenchange: Detect fullscreen exit
  - oncontextmenu: Prevent right-click
  - Events stored in proctoring_data JSONB
  - Badge shows warning to student
  - Teacher can review events in results

Auto-save (Optional)

ExamTaking component:
  - onChange on answer field
  - Debounced PUT /api/sessions/[id]/answers
  - Updates exam_sessions.answers JSONB
  - User can see "Saved" indicator

โœจ Key Features

1. Exam Management

  • โœ… Create exams with custom duration, passing score
  • โœ… Add multiple question types (MC, T/F, Short Answer, Essay)
  • โœ… Reorder questions via drag-drop
  • โœ… Publish/Unpublish exams
  • โœ… Generate unique room codes for guest access
  • โœ… Bulk import questions from question bank
  • โœ… Clone exams
  • โœ… Schedule exams (future feature)

2. Question Types

  • โœ… Multiple Choice: 4-5 options, single correct
  • โœ… True/False: Binary choice
  • โœ… Short Answer: Keyword matching or manual grading
  • โœ… Essay: Manual grading by teacher
  • โณ Matching: Match columns (future)
  • โณ Fill in Blank: Fill blanks in text (future)

3. Question Bank

  • โœ… Organize questions by subject & difficulty
  • โœ… Tag questions for easy filtering
  • โœ… Search & filter
  • โœ… Reuse questions across exams
  • โœ… Share questions with colleagues (future)
  • โœ… Include answer explanations

4. Exam Taking

  • โœ… Timer with countdown
  • โœ… Question navigator (jump to question)
  • โœ… Progress indicator
  • โœ… Flag for review
  • โœ… Question review before submit
  • โœ… Auto-save answers
  • โœ… Guest access with room code
  • โณ Section-based exams (future)

5. Proctoring

  • โœ… Tab switching detection
  • โœ… Window blur detection (focus loss)
  • โœ… Fullscreen exit detection
  • โœ… Prevent right-click/inspect element
  • โœ… Suspicious activity log
  • โœ… Teacher can review violations
  • โณ Webcam monitoring (future)
  • โณ Screen recording (future)
  • โณ AI-based cheating detection (future)

6. Analytics & Reporting

  • โœ… Dashboard with key metrics (total exams, active exams, avg score)
  • โœ… Exam-specific analytics (attempt count, score distribution)
  • โœ… Question analytics (difficulty analysis, discrimination index)
  • โœ… Student performance trends
  • โœ… Performance by question
  • โœ… Export results to CSV
  • โณ Custom reports (future)
  • โณ Predictive analytics (future)

7. Student Features

  • โœ… Take exams in real-time
  • โœ… Immediate feedback (optional)
  • โœ… View results & score
  • โœ… Review answered questions
  • โœ… View answer explanations
  • โœ… Attempt history
  • โณ Practice mode (future)

8. User Management

  • โœ… Role-based access (Teacher/Student)
  • โœ… User profiles with avatar
  • โœ… Email verification
  • โœ… Password reset
  • โœ… Google OAuth login
  • โณ LDAP/SSO integration (future)
  • โณ Bulk user import (future)

9. UI/UX

  • โœ… Responsive design (mobile, tablet, desktop)
  • โœ… Dark/Light theme
  • โœ… Neumorphism design system
  • โœ… Accessibility features (ARIA labels, keyboard nav)
  • โœ… Toast notifications
  • โœ… Loading skeletons
  • โœ… Smooth animations & transitions

10. Security

  • โœ… Row-level security (RLS) on all tables
  • โœ… JWT authentication with httpOnly cookies
  • โœ… HTTPS enforced (Vercel)
  • โœ… SQL injection prevention (Supabase)
  • โœ… CSRF protection
  • โœ… Rate limiting (future)
  • โœ… 2FA authentication (future)

๐Ÿš€ Development Setup

Prerequisites

  • Node.js 18+ / pnpm
  • Supabase account (database + auth)
  • Google OAuth credentials (optional)
  • Vercel account (for deployment, optional)

Environment Variables

# .env.local
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

# Optional
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com

Installation

cd v2-quizya
pnpm install

Database Setup

# Create Supabase project
# Run schema migrations
pnpm supabase db push

# OR run SQL manually in Supabase SQL editor
# supabase/schema.sql

Running Locally

# Development server
pnpm dev

# Open http://localhost:3000

Building

# Build for production
pnpm build

# Start production server
pnpm start

Linting

# Check for linting errors
pnpm lint

Deployment

# Deploy to Vercel (connected to GitHub)
# Every push to main branch auto-deploys

# OR manual deployment
vercel --prod

๐Ÿ“Š Component Interaction Diagram

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        app/layout.tsx                              โ”‚
โ”‚  (RootLayout - Global Providers)                                   โ”‚
โ”‚  โ”œโ”€ ThemeProvider (next-themes)                                    โ”‚
โ”‚  โ”œโ”€ AuthProvider (use-auth context)                                โ”‚
โ”‚  โ””โ”€ Toaster (sonner notifications)                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ†“            โ†“            โ†“               โ†“                  โ†“
Landing      Auth Pages   Dashboard      Exam Pages         Results
(/)          (/auth/*)   (/dashboard)    (/exam/*)          (/results)
โ”‚            โ”‚            โ”‚               โ”‚                  โ”‚
โ”œโ”€Header     โ”œโ”€AuthLogin  โ”œโ”€Dashboard    โ”œโ”€ExamTaking      โ”œโ”€ExamResults
โ”œโ”€Hero       โ”œโ”€AuthSigup  โ”œโ”€ExamsList    โ”œโ”€QuestionNav     โ”œโ”€ScoreDisplay
โ”œโ”€Features   โ””โ”€Protected  โ”œโ”€Analytics    โ”œโ”€Timer            โ””โ”€ReviewAnswers
โ”œโ”€Footer        Route     โ”œโ”€Settings     โ””โ”€ProctorBadge
โ””โ”€ -          โ”‚           โ””โ”€QuestBank
              โ”‚
         useAuth hook โ”€โ”€โ”€โ”€โ”
                          โ”‚
                    Supabase Auth API
                    (/api/auth/*)
                          โ”‚
                    Supabase Client
                          โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”
                    โ†“           โ†“
              Profiles       Auth.users
              (RLS)          (Supabase)
              

Dashboard Flow:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ useExams() โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ /api/exams   โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ exams table โ”‚
โ”‚ (hook)     โ”‚       โ”‚ (GET/POST)   โ”‚       โ”‚ (RLS)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”‚
    โ”œโ”€โ–ถ ExamsList โ”€โ”€โ–ถ [Edit/Delete exams]
    โ”œโ”€โ–ถ Analytics โ”€โ”€โ–ถ /api/analytics/dashboard
    โ””โ”€โ–ถ Settings โ”€โ”€โ–ถ /api/settings/profile


Exam Taking Flow:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ExamTaking.tsx   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - useEffect:     โ”‚  GET /api/exams/[id]  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   fetchExam()    โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ questions   โ”‚
โ”‚ - Questions loop โ”‚                        โ”‚ table (RLS) โ”‚
โ”‚ - Timer          โ”‚                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ - ProctorBadge   โ”‚
โ”‚ - onBlur/Focus   โ”‚
โ”‚ - onContextMenu  โ”‚
โ”‚ - setInterval    โ”‚
โ”‚ - onChangeโ†’      โ”‚  PUT /api/sessions    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   saveAnswers()  โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ exam_sessions โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ”‚ table (RLS)   โ”‚
    โ”‚                                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”œโ”€ proctoring_data logged
    โ””โ”€ On submit: Calculate score

๐Ÿ”— Key Dependencies & Their Roles

PackageVersionPurpose
next16.0.10Full-stack React framework
react19.2.0UI library
@supabase/supabase-js2.87.1Database & Auth client
@supabase/ssr0.8.0Server-side Supabase
tailwindcss4.1.9CSS utility framework
@radix-ui/VariousAccessible UI primitives
react-hook-form7.60.0Form state management
zod3.25.76TypeScript-first validation
recharts2.15.4React charting library
sonner1.7.4Toast notifications
next-themes0.4.6Theme management
lucide-react0.454.0Icon library
date-fns4.1.0Date utilities

๐Ÿ“ Summary

Quizya is a comprehensive, modern exam platform with:

  • Frontend: Next.js 16, React 19, Tailwind CSS with custom Neumorphism design
  • Backend: Supabase (PostgreSQL + Auth)
  • Architecture: Server-side rendering with client components, API routes, custom hooks
  • Security: Row-level security, JWT auth, httpOnly cookies
  • Features: Exam management, question banking, real-time taking, proctoring, analytics
  • Scalability: Indexed database queries, pagination, caching strategies
  • Developer Experience: TypeScript, ESLint, component-based architecture

The system is designed for teachers to create and manage exams, for students to take exams in real-time, and for guests to participate with minimal friction. All interactions flow through Supabase with enforced security policies at the database level.

Related Documents