← Back to projects

Full-Stack · Work in progress

Prediction Market Platform

Full-stack prediction market platform built for the Themeisle Internship Challenge 2026. React and TypeScript frontend, Bun and Elysia backend. Supports market creation, bet placement, real-time odds updates, leaderboard ranking, and automated payout calculation.

Demo accounts available — use alice, bob, charlie, diana, grace, or eve @demo.com with password: password123

Stack

  • React
  • TypeScript
  • Bun
  • Elysia
  • SQLite

Overview

  • REST API built with Elysia on Bun runtime — typed route definitions with schema validation at the handler level
  • Real-time odds updates via polling with SSE fallback; probability recalculated server-side on every bet
  • Market lifecycle management: creation, active betting, resolution, and automated payout distribution
  • Leaderboard with ranking derived from resolved market outcomes and cumulative profit/loss
  • API key authentication for programmatic market access alongside session-based browser auth

Screenshots

Prediction Market login screen

Authentication entry point. Session tokens are issued by the Elysia API and stored client-side; the React frontend redirects unauthenticated requests to this view.

1 / 6

Architecture

  • Backend: Elysia framework running on Bun — typed route handlers with built-in schema validation using Elysia's type system
  • Frontend: React with TypeScript, custom hooks for market state and polling-based live odds synchronisation
  • Persistence: SQLite via Bun's native SQLite bindings — single-file database appropriate for the current scale
  • Real-time: HTTP polling on the frontend; server-sent events as a lower-overhead alternative for odds streams
  • Auth: session tokens for browser clients, API keys for programmatic access — both validated in Elysia middleware
  • Probability model: simple constant-product market maker — recalculated on each bet, stored as a float in the market record

Engineering Challenges

  • Maintaining odds consistency under concurrent bets: SQLite write locks serialize conflicting transactions; at higher scale this would require a proper queue or optimistic locking strategy
  • Keeping the React frontend in sync with server state using polling: debounced interval fetches balance responsiveness against API load
  • Automated payout calculation on resolution: settlement runs as a single SQLite transaction to ensure all winners are credited atomically or not at all
  • Typed API contracts between Elysia and the React client without a code-generation step: shared TypeScript types in a common module ensure the frontend and backend agree on shape

What I'd improve

  • Replace polling with persistent WebSocket connections for lower-latency odds updates
  • Improve test coverage across API route handlers and probability calculation logic
  • Extract shared UI components into a dedicated internal package
  • Add market resolution dispute flow for contested outcomes

Links