Database Architecture
Beforehand uses Supabase (PostgreSQL) to store all off-chain data including user profiles, market metadata, communities, and social features.
Database Purpose
The database serves as:
- Metadata store: Market questions, descriptions, categories
- User management: Profiles, authentication, preferences
- Social layer: Comments, notifications, communities
- Voting system: Vote records, credibility scores
- Analytics: Views, engagement metrics
Key Design Principles
- Hybrid model: Critical financial data on-chain, metadata off-chain
- Real-time sync: Database stays synchronized with on-chain state
- Row-level security: Users can only access their own data
- Performance: Optimized queries for fast loading
Data Synchronization
The database doesn't duplicate on-chain data. Instead:
- Market status: Synced from contract state
- Positions: Calculated from token balances
- Pools: Read from contract, cached in database
- Resolution: Triggered by on-chain events
Core Data Models
- Profiles: User information and settings
- Markets: Market metadata and status
- Communities: Community data and memberships
- Votes: Voting records and outcomes
- Social: Comments, likes, notifications