Skip to content

Database‐Models

Veerendra Kumar edited this page Jun 5, 2026 · 1 revision

Database Schemas & Data Model Definitions

NQTCoder uses four primary MongoDB collections to manage users, coding challenges, submissions, and proctored test sessions.


1. User Schema (models/User.js)

Stores user profiles, credential hashes, email verification details, and practice stats.

Field Name Type Description
username String (Required, Unique) User's unique handle.
email String (Required, Unique) User's email address (Google or local credentials).
password String Bcrypt hash of password (absent for Google OAuth).
role String ('user' or 'admin') Access permissions role. Defaults to 'user'.
isVerified Boolean Account validation status. Blocked from logging in if false.
otpCode String Active 6-digit verification OTP.
otpExpires Date Verification OTP timestamp expiration (10 minutes duration).
solvedQuestions Array [Schema.Types.ObjectId] List of successfully solved question references.
solvedCount Object Counts of solved challenges categorized by difficulty.

2. Question Schema (models/Question.js)

Holds coding challenge details, constraints, metadata, and the test case arrays.

Field Name Type Description
title String (Required) The title of the programming challenge.
description String (Required) Markdown string outlining problem parameters and instructions.
inputFormat String Description of expected standard input formatting.
outputFormat String Description of expected console output formatting.
constraints String Code constraints (e.g. constraints on execution space or variable sizes).
difficulty String ('Easy', 'Medium', 'Hard') Question difficulty category.
topic String Tag categorization (e.g. Arrays, Recursion).
company Array [String] Recruitment companies using this problem (e.g. TCS, Wipro).
testCases Array [Object] Test cases with structure: input (String), output (String), and isPrivate (Boolean). Hidden test cases are marked isPrivate: true.
timerEnabled Boolean Enables a countdown timer inside the coding workspace.
timerDuration Number Active duration in minutes for the workspace timer.

3. Submission Schema (models/Submission.js)

Tracks logs of compilations and submissions.

Field Name Type Description
user Schema.Types.ObjectId (Required) Reference to the submitting user profile.
question Schema.Types.ObjectId (Required) Reference to the challenge being solved.
code String (Required) Code source text submitted by the user.
language String ('cpp', 'java', 'python') Chosen programming language.
status String Output verdict (e.g., Accepted, Wrong Answer, Runtime Error, Compilation Error).
runtime Number Execution time in milliseconds.
error String Detailed compiler console output (if compilation failed).
testCasesPassed Number Count of total test cases successfully passed.
totalTestCases Number Total test cases compiled against (visible + hidden).

4. MockTest Schema (models/MockTest.js)

Controls proctored assessments, warning stats, and time-out conditions.

Field Name Type Description
user Schema.Types.ObjectId Reference to the participating student.
q1 Schema.Types.ObjectId Reference to the first coding challenge.
q2 Schema.Types.ObjectId Reference to the second coding challenge.
q1Code / q2Code String Active source code state for question 1 and 2.
q1Language / q2Language String Selected compilation language.
q1Status / q2Status String Progress status ('not_started', 'started', 'submitted').
tabSwitchesCount Number Counter tracking window focus losses. Auto-submits test at 3.
status String Overall test session state ('active', 'completed').

Clone this wiki locally