How shubham02022002/foretell works
Foretell is a virtual-credit binary prediction-market exchange. Traders discover markets, inspect probability/book activity, place or cancel orders, manage positions and wallet history, and follow trader standings; administrators create, close, resolve, or void markets. The README documents matching, escrow, settlement, candles, social features, notifications, and secured expiry handling. The map preserves these product branches, but several route implementations were not sampled: their links are shown only where the README or excerpt supports them. PostgreSQL access is represented as the shared persistence layer.
Main entry points: prisma.ts PostgreSQL via Prisma · market.ts Market lifecycle · page.tsx Market detail · orders.ts Order engine
Components 28
Trader experience
- Market discovery
app/markets/page.tsx - Market detail
app/markets/[slug]/page.tsx - Book and tape
components/order-book.tsx - Price charts
components/probability-chart.tsx - Market discussion
components/market-discussion.tsx - Portfolio
app/portfolio/page.tsx - Watchlist
app/watchlist/page.tsx - Market home
app/page.tsx
Market lifecycle
- Market routes
app/api/markets/route.ts - Market lifecycle
lib/exchange/market.ts - Expiry closing
app/api/cron/close-expired/route.ts
Trading engine
- Order routes
app/api/markets/[slug]/orders/route.ts - Order engine
lib/exchange/orders.ts - Binary matching
lib/exchange/matching.ts - Settlement math
lib/exchange/settlement.ts - Positions API
app/api/positions/me/route.ts - Wallet and ledger
app/api/wallet/route.ts
Accounts and community
- Sign-in and registration
components/auth-shell.tsx - Authentication
auth.ts - Account registration
app/api/auth/register/route.ts - Social and notifications
app/api/markets/[slug]/comments/route.ts - Leaderboard
app/leaderboard/page.tsx - Trader standings
lib/leaderboard.ts - Trader profiles
app/api/traders/[id]/route.ts
Administration
- Admin console
app/admin/page.tsx - Market administration
app/api/admin/markets/route.ts
Other components
- Trader
- PostgreSQL via Prisma
lib/prisma.ts
Connections 37
- Trader → Market discovery: browses
- Market discovery → Market routes: queries markets
- Market routes → Market lifecycle: gets market stats
app/api/markets/route.ts - Market routes → PostgreSQL via Prisma: reads markets
app/api/markets/route.ts - Market discovery → Market detail: opens market
- Market detail → Book and tape: renders tape
app/markets/[slug]/page.tsx - Market detail → Market discussion: renders discussion
app/markets/[slug]/page.tsx - Market detail → Price charts: renders chart
app/markets/[slug]/page.tsx - Market detail → Order routes: submits orders
app/markets/[slug]/page.tsx - Order routes → Order engine: executes orders
- Order engine → Binary matching: matches orders
lib/exchange/market.ts - Order engine → PostgreSQL via Prisma: persists fills
- Market lifecycle → Binary matching: aggregates book
lib/exchange/market.ts - Market lifecycle → Order engine: cancels orders
lib/exchange/market.ts - Market lifecycle → Settlement math: calculates payouts
lib/exchange/market.ts - Market lifecycle → PostgreSQL via Prisma: reads and updates
- Trader → Portfolio: reviews holdings
- Portfolio → Positions API: loads positions
- Positions API → PostgreSQL via Prisma: reads positions
app/api/positions/me/route.ts - Trader → Wallet and ledger: checks balance
- Wallet and ledger → PostgreSQL via Prisma: reads wallet
app/api/wallet/route.ts - Trader → Watchlist: tracks markets
- Trader → Sign-in and registration: creates account
- Sign-in and registration → Account registration: registers
- Account registration → PostgreSQL via Prisma: creates user
app/api/auth/register/route.ts - Authentication → PostgreSQL via Prisma: authenticates users
auth.ts - Trader → Leaderboard: checks standings
- Leaderboard → Trader standings: displays rankings
- Trader standings → PostgreSQL via Prisma: queries trade data
lib/leaderboard.ts - Trader → Trader profiles: views profile
- Trader profiles → Trader standings: gets standings
app/api/traders/[id]/route.ts - Trader profiles → PostgreSQL via Prisma: reads profile positions
app/api/traders/[id]/route.ts - Trader → Social and notifications: comments
- Admin console → Market administration: manages markets
app/admin/page.tsx - Market administration → Market lifecycle: creates markets
app/api/admin/markets/route.ts - Market administration → PostgreSQL via Prisma: writes markets
app/api/admin/markets/route.ts - Expiry closing → Market lifecycle: closes expired