Skip to main content

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

  1. User creates market → Contract deployed on-chain
  2. Market metadata stored in database
  3. Trades execute on-chain → Position tokens minted
  4. Database syncs with on-chain state
  5. Resolution happens on-chain → Database updated
  6. Payouts distributed automatically