wolvcapital

WolvCapital Supabase Schema Documentation

This document describes the database schema for the WolvCapital investment platform, built on Supabase (PostgreSQL).

Overview

The schema is designed to support a comprehensive investment platform with user management, investment plans, transaction processing, and admin approval workflows.

Core Tables

1. user_profiles

Extends the default Supabase auth.users table with investment-specific profile information.

Key Features:

Important Fields:

2. investment_plans

Stores available investment products that users can invest in.

Key Features:

Important Fields:

3. transactions

Tracks all financial transactions in the platform.

Key Features:

Transaction Types:

4. user_investments

Tracks ongoing user investments in specific plans.

Key Features:

5. admin_approvals

Manages approval workflows for various platform actions.

Key Features:

Approval Types:

6. approval_history & approval_approvers

Supporting tables for detailed approval workflow tracking.

Views

user_portfolio

Complete investment portfolio view for users showing all investments with performance metrics.

transaction_summary

Aggregated transaction data by user and investment plan.

pending_approvals_summary

Admin dashboard view for managing pending approvals with urgency indicators.

investment_plan_performance

Performance analytics for investment plans.

user_activity_summary

Comprehensive user activity and portfolio overview.

Key Functions

Automated Functions

  1. handle_new_user(): Automatically creates user profile when user signs up
  2. handle_completed_investment(): Creates investment records when transactions complete
  3. handle_approval_status_change(): Processes approval workflow changes
  4. check_large_investment_approval(): Triggers approval for large investments

Utility Functions

  1. calculate_user_risk_score(user_id): Calculates user’s risk assessment score
  2. get_recommended_plans(user_id): Returns personalized investment recommendations
  3. get_user_investment_summary(user_id): User’s complete investment summary
  4. get_plan_statistics(): Platform-wide investment statistics

Security (Row Level Security)

Authentication-Based Access

Role-Based Permissions

Data Flow

Investment Process

  1. User creates investment transaction
  2. Large investments trigger automatic approval request
  3. Admin reviews and approves/rejects
  4. Approved transactions create user_investment records
  5. Investment plan statistics updated

KYC Process

  1. User uploads documents
  2. System creates KYC approval request
  3. Admin reviews documents
  4. Approval updates user profile KYC status

Performance Optimizations

Indexes

Computed Columns

Migration Files

  1. 20240917000001_create_user_profiles.sql - User profile management
  2. 20240917000002_create_investment_plans.sql - Investment products
  3. 20240917000003_create_transactions.sql - Transaction processing
  4. 20240917000004_create_admin_approvals.sql - Approval workflows
  5. 20240917000005_create_views_and_functions.sql - Views and utilities

Setup Instructions

  1. Initialize Supabase project
  2. Run migrations in order
  3. Load seed data for testing
  4. Configure environment variables
  5. Set up admin users with proper roles

API Integration

The schema is designed to work seamlessly with Supabase’s auto-generated APIs:

Monitoring and Analytics

Key metrics to track:

This schema provides a solid foundation for a scalable investment platform with proper security, performance, and regulatory compliance considerations.