Skip to Content

Data Models

Actual Supabase Database Schema

This ER diagram shows the ACTUAL tables and relationships currently implemented in the Earna AI Supabase database with Row Level Security (RLS).

Core Entities:

EntityDescriptionPrimary Storage
auth.usersSupabase Auth usersSupabase Auth Schema
usersPlatform user profilesSupabase Public Schema
chatsAI chat conversationsSupabase with RLS
messagesChat messagesSupabase with RLS
projectsMulti-model projectsSupabase with RLS
chat_attachmentsFile attachmentsSupabase Storage

Data Volume Estimates:

  • Users: ~100,000 (target)
  • Chat Sessions: ~500,000/month
  • Messages: ~5,000,000/month
  • Tool Calls: ~2,000,000/month
  • Credit Profiles: ~100,000
  • Credit Scores: ~200,000/month
  • Improvement Plans: ~50,000/month

Supabase Database Architecture

This section details the Supabase-specific implementation and features used in the Earna AI platform.

Supabase Services Used:

ServicePurposeImplementation
DatabasePostgreSQL 15Core data storage with RLS
AuthUser authenticationEmail/password, OAuth providers
StorageFile storageDocument uploads, reports
RealtimeLive updatesChat messages, notifications
Edge FunctionsServerless computeAI processing, webhooks
VectorEmbeddingspgvector for semantic search

Supabase Configuration:

// Supabase Client Configuration import { createClient } from '@supabase/supabase-js' const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY export const supabase = createClient(supabaseUrl, supabaseAnonKey, { auth: { autoRefreshToken: true, persistSession: true, detectSessionInUrl: true }, realtime: { params: { eventsPerSecond: 10 } }, db: { schema: 'public' } }) // Supabase Admin Client (Server-side) const supabaseAdmin = createClient( supabaseUrl, process.env.SUPABASE_SERVICE_ROLE_KEY, { auth: { autoRefreshToken: false, persistSession: false } } )

Database Extensions:

  • uuid-ossp: UUID generation
  • pgcrypto: Encryption functions
  • pg_stat_statements: Query performance
  • pgvector: Vector similarity search
  • pg_trgm: Text similarity search

Credit Analysis Data Model

This ER diagram shows the Canadian credit analysis data model for credit score tracking and improvement planning.

Credit Data Entities:

EntityDescriptionEncryption
CreditProfileUser credit identityPII encrypted
CreditReportBureau credit reportsEncrypted at rest
TradeLineCredit accountsEncrypted
PaymentHistoryPayment recordsEncrypted
PublicRecordBankruptcies, liensEncrypted
CreditInquiryCredit checksAudit trail
InquiryImpactInquiry effectsEncrypted
ScoreSimulationWhat-if scenariosEncrypted
SimulationActionSimulated actionsEncrypted
SimulationResultProjected outcomesEncrypted

Credit Score Factors (Canadian):

  • Payment History: 35%
  • Credit Utilization: 30%
  • Length of Credit History: 15%
  • Types of Credit: 10%
  • New Credit Inquiries: 10%

Banking Integration Data Model

This section details the data model for Plaid banking integration and financial analysis.

Banking Data Entities:

EntityDescriptionUpdate Frequency
PlaidConnectionUser’s Plaid linkOn demand
BankAccountLinked bank accountsDaily sync
TransactionAccount transactionsReal-time webhook
TransactionCategorySpending categoriesPer transaction
BalanceCurrent balancesDaily
BalanceHistoryHistorical balancesDaily snapshot
SpendingAnalysisSpending patternsWeekly/Monthly
SpendingCategoryCategory breakdownPer analysis
CreditUtilizationCredit card usageDaily

Plaid Data Scope:

  • Transactions: 2 years history
  • Balances: Real-time
  • Account details: On connection
  • Identity: Optional verification
  • Liabilities: Credit cards, loans

AI SDK v5 Message Types

This section documents the AI SDK v5 message type system used throughout the application.

AI SDK v5 Type Definitions:

// From @ai-sdk/react export interface UIMessage { id: string; role: 'user' | 'assistant' | 'system'; parts: UIMessagePart[]; } export type UIMessagePart = | TextUIPart | ToolInvocationUIPart | ImageUIPart | FileUIPart | ReasoningUIPart; export interface TextUIPart { type: 'text'; text: string; } export interface ToolInvocationUIPart { type: 'tool-invocation'; toolInvocation: ToolInvocation; } // From @ai-sdk/ui-utils export interface Message { id: string; content: string; role: 'user' | 'assistant' | 'system' | 'data'; createdAt?: Date; experimental_attachments?: Attachment[]; parts?: UIMessagePart[]; toolInvocations?: ToolInvocation[]; } export interface Attachment { name: string; contentType: string; url: string; }

Role Types:

  • user: Messages from the user
  • assistant: AI model responses
  • system: System prompts and instructions
  • data: Data-only messages (Message type only)
Last updated on