System Overview
Beforehand is a full-stack prediction market platform built with a hybrid on-chain and off-chain architecture.
High-Level Architecture
The platform combines:
- On-chain: Market contracts, position tokens, and resolution logic
- Off-chain: User profiles, communities, voting, and social features
This hybrid approach balances security (critical financial operations on-chain) with flexibility (rich metadata and social features off-chain).
Core Components
Smart Contracts
Markets are deployed as individual smart contracts. Each market has:
- YES and NO position tokens (yUSDC/nUSDC)
- Pool tracking for each side
- Resolution logic
Database
Supabase PostgreSQL stores:
- User profiles and authentication
- Market metadata and status
- Community data and memberships
- Voting records and credibility scores
- Social features (comments, notifications)
Frontend
React application that:
- Connects to user wallets via Privy
- Displays markets and trading interface
- Manages state with React Query
- Syncs on-chain and off-chain data
Data Flow
- User creates market → Contract deployed on-chain
- Market metadata stored in database
- Trades execute on-chain → Position tokens minted
- Database syncs with on-chain state
- Resolution happens on-chain → Database updated
- Payouts distributed automatically