Repository navigation
DATABASE
github-actions[bot] edited this page May 22, 2026
·
5 revisions
PersonalLearningPro uses a multi-database architecture optimized for different data access patterns:
- PostgreSQL: Primary transactional data store for users, workspaces, tenancy, billing, and sessions.
- MongoDB: Specialized store for tests, questions, and non-relational application state.
- Cassandra (Astra DB): High-performance message storage with automatic fallback to MongoDB.
PostgreSQL is the source of truth for all critical business logic and multi-tenancy.
Stores core identity and profile data.
-
id:bigserial(Primary Key) -
email:citext(Unique, case-insensitive) -
username:text(Unique) -
password_hash:text -
name:text -
display_name:text -
avatar:text -
email_verified:boolean(Default:false) -
role:text(student, teacher, admin, etc.) -
status:text(active, pending, suspended, rejected) -
onboarding_complete:boolean -
created_at:timestamptz -
last_login_at:timestamptz
Core multi-tenancy containers.
-
id:bigserial(Primary Key) -
name:text -
slug:text(Unique, URL-friendly) -
type:text(business, school, personal) -
description:text -
owner_id:bigint(Referencesusers.id) -
members:bigint[](Array of user IDs for fast filtering) -
created_at:timestamptz
Join table linking users to workspaces with specific roles.
-
id:bigserial(Primary Key) -
workspace_id:bigint(Referencesworkspaces.id) -
user_id:bigint(Referencesusers.id) -
role:text(owner, admin, member) -
status:text(active, pending, suspended) -
created_at:timestamptz
Secure invitation tokens for joining workspaces.
-
id:bigserial(Primary Key) -
workspace_id:bigint(Referencesworkspaces.id) -
email:citext -
name:text -
role:text -
kind:text(business_member, student) -
token_hash:text(Unique, SHA-256 hash of random token) -
status:text(pending, accepted, expired) -
expires_at:timestamptz
Server-side session management for local auth.
-
id:bigserial(Primary Key) -
user_id:bigint(Referencesusers.id) -
refresh_token_hash:text(Unique) -
device_info:text -
ip_address:inet -
expires_at:timestamptz
Test definitions created by teachers.
{
id: number,
title: string,
description: string,
subject: string,
class: string,
teacherId: number,
totalMarks: number,
duration: number,
testDate: Date,
status: enum, // draft | published | completed
createdAt: Date
}Individual questions belonging to tests.
{
id: number,
testId: number,
type: enum, // mcq | short | long | numerical
text: string,
options: mixed,
correctAnswer: string,
marks: number,
order: number,
aiRubric: string
}High-performance message storage partitioned by channel.
CREATE TABLE messages (
channel_id text,
message_id text,
author_id bigint,
content text,
type text,
file_url text,
is_pinned boolean,
created_at timestamp,
PRIMARY KEY (channel_id, message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);-
Auth Bridge: All authentication now happens via PostgreSQL. The
firebaseUidfield is deprecated and kept only for backward compatibility. - Search: Critical entities (Users, Workspaces) are stored in PostgreSQL for relational queries, while flexible content (Tests, Questions) remains in MongoDB.
-
Caching: Frequently accessed session data is cached in memory, but backed by the PostgreSQL
sessionstable.
- PostgreSQL: Standard WAL-based backups (Point-in-time recovery).
- MongoDB: Atlas automated snapshots.
- Cassandra: Astra DB built-in backups.