The Peer Learning Platform uses PostgreSQL hosted on Supabase. This document outlines the core tables, their relationships, and the authentication flow.
erDiagram
PROFILES ||--o{ STUDY_SESSIONS : creates
PROFILES ||--o{ CHAT_MESSAGES : sends
STUDY_SESSIONS ||--o{ CHAT_MESSAGES : contains
PROFILES {
uuid id PK "Matches auth.users.id"
string username
string full_name
string avatar_url
string[] skills
int xp
int level
int streak_count
}
STUDY_SESSIONS {
uuid id PK
string title
string description
uuid creator_id FK
timestamp created_at
timestamp scheduled_for
string status
}
CHAT_MESSAGES {
uuid id PK
uuid session_id FK
uuid sender_id FK
string content
timestamp created_at
}
- User Sign Up/In: Handled via Supabase Authentication (Email/Password or OAuth).
- Profile Generation: A database trigger automatically creates a row in the
profilestable matching the newly created user'sauth.users.id. - Session Management: Supabase automatically handles JWT token issuance, refresh, and storage in the client.
- Row-Level Security (RLS): PostgreSQL RLS policies ensure that users can only access and modify their own data, or data in study sessions they are authorized to view.
Stores extended user information and gamification stats.
id: UUID (Primary Key, referencesauth.users.id)username: Textskills: Text Array (skills the user wants to learn or teach)xp: Integer (Experience points earned)level: Integer (Calculated level based on XP)
Represents collaborative learning rooms.
id: UUIDtitle: Textcreator_id: UUID (Referencesprofiles.id)status: Text (e.g., 'active', 'completed')
Stores all messages sent within study sessions.
id: UUIDsession_id: UUID (Referencesstudy_sessions.id)sender_id: UUID (Referencesprofiles.id)content: Text (Limited to 2000 chars)