Database Schema
MongoDB collections and data models used in BetterLearn.
🗂️ Collections Overview
users
User profiles, settings, credits
quizzes
Generated quizzes
collections
Quiz collections
files
Uploaded files metadata
generations
AI tool generations
libraryitems
Saved library content
rooms
Study rooms
credittransactions
Credit history
👤 Users Collection
User Schema
{
clerkId: String, // Clerk user ID
email: String,
name: String,
imageUrl: String,
credits: Number, // Available credits
role: String, // 'user' | 'admin'
settings: {
theme: String,
notifications: Boolean
},
createdAt: Date,
updatedAt: Date
}
📝 Quizzes Collection
Quiz Schema
{
userId: ObjectId,
title: String,
description: String,
questions: [{
question: String,
type: String, // 'multiple_choice' | 'true_false' | 'short_answer'
options: [String],
correctAnswer: String | Number,
explanation: String
}],
settings: {
difficulty: String,
questionCount: Number,
timer: Number
},
sourceFile: String,
collectionId: ObjectId,
createdAt: Date
}
⚡ Generations Collection
Generation Schema
{
userId: ObjectId,
toolId: String, // Tool identifier
toolName: String,
input: Object, // Tool input parameters
output: String, // Generated content
creditsUsed: Number,
createdAt: Date
}
🏠 Rooms Collection
Room Schema
{
userId: ObjectId, // Creator
name: String,
description: String,
code: String, // Join code
tools: [String], // Assigned tool IDs
students: [{
name: String,
email: String,
joinedAt: Date
}],
isActive: Boolean,
createdAt: Date
}
⚙️ Site Settings Collection
Site Settings Schema
{
siteName: String,
siteDescription: String,
logo: String,
favicon: String,
primaryColor: String,
freeCredits: Number, // Credits for new users
footerText: String,
socialLinks: Object,
updatedAt: Date
}
💳 Pricing Plans Collection
Pricing Plan Schema
{
name: String,
credits: Number,
price: Number,
currency: String,
features: [String],
isPopular: Boolean,
isActive: Boolean,
stripePriceId: String,
createdAt: Date
}
🔍 Indexes
Recommended indexes for performance:
db.users.createIndex({ clerkId: 1 }, { unique: true })
db.users.createIndex({ email: 1 })
db.quizzes.createIndex({ userId: 1 })
db.quizzes.createIndex({ collectionId: 1 })
db.generations.createIndex({ userId: 1, createdAt: -1 })
db.rooms.createIndex({ code: 1 }, { unique: true })