Quizya - Comprehensive Project Architecture & Documentation
1. [Project Overview](#project-overview)
Quizya - Comprehensive Project Architecture & Documentation
๐ Table of Contents
- Project Overview
- Technology Stack
- Project Structure
- Database Architecture
- Authentication & Authorization
- API Routes
- Core Services
- Components & UI
- Data Flow & Interactions
- Key Features
- 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
| Role | Permissions |
|---|---|
| Teacher | Create exams, create questions, manage question bank, view own analytics, delete exams |
| Student | Take exams, view own results, browse public exams, access question bank (read-only) |
| Guest | Take 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: Paginationsearch: 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
| Package | Version | Purpose |
|---|---|---|
| next | 16.0.10 | Full-stack React framework |
| react | 19.2.0 | UI library |
| @supabase/supabase-js | 2.87.1 | Database & Auth client |
| @supabase/ssr | 0.8.0 | Server-side Supabase |
| tailwindcss | 4.1.9 | CSS utility framework |
| @radix-ui/ | Various | Accessible UI primitives |
| react-hook-form | 7.60.0 | Form state management |
| zod | 3.25.76 | TypeScript-first validation |
| recharts | 2.15.4 | React charting library |
| sonner | 1.7.4 | Toast notifications |
| next-themes | 0.4.6 | Theme management |
| lucide-react | 0.454.0 | Icon library |
| date-fns | 4.1.0 | Date 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
Design Document: BharatSeva AI
BharatSeva AI is a multi-agent orchestration system built on AWS using Amazon Bedrock Agents with Claude 3.5 Sonnet as the foundation model. The system deploys 10 AI agents (1 Master Orchestrator + 9 Specialist Agents) to assist India's informal sector workers in navigating government schemes across three domains: PM Vishwakarma (artisan credit), PMFBY (crop insurance), and BOCW (construction worker welfare).
OpenClaw Enterprise Transformation Plan
Transform OpenClaw from a single-user personal AI assistant into a **dual-mode platform** that is simultaneously:
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Daniel Sandner, for article on https://sandner.art/
Qwen3-TTS โ Model Reference
Models: `Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice` and `Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice`