A prediction market backend built with TypeScript, Express.js, Prisma, and PostgreSQL.
- JWT-based authentication
- User registration and login
- User profile management
- Balance tracking
- Leaderboard system
- Create and update prediction markets (admin only)
- Binary outcome markets (YES/NO)
- Market categories (Sports, Esports)
- Market search by title
- Lock betting before resolution
- Resolve markets with outcome
- Place bets on market outcomes
- Dynamic odds calculation based on betting pool
- Automatic payout distribution on market resolution
- Betting history tracking
- Track all financial transactions
- Transaction types: BET_PLACED, BET_WON, DEPOSIT, WITHDRAW
- Transaction history per user
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: PostgreSQL with Prisma ORM
- Validation: Zod
- Authentication: JWT (jsonwebtoken)
- Security: bcrypt for password hashing
POST /api/v1/users/signup- Register new userPOST /api/v1/users/signin- User loginGET /api/v1/users/me- Get current userGET /api/v1/users/leaderboard- Get winning leaderboard
POST /api/v1/markets/create- Create market (admin)PUT /api/v1/markets/update/:id- Update market (admin)GET /api/v1/markets/getallmarkets- List all marketsGET /api/v1/markets/getmarket/:id- Get market by IDGET /api/v1/markets/openmarkets- Get open marketsGET /api/v1/markets/getmarketsbycatagory/:category- Filter by categoryGET /api/v1/markets/search?title=- Search marketsPOST /api/v1/markets/lockbets/:id- Lock market (admin)POST /api/v1/markets/resolvemarket/:id- Resolve market (admin)
POST /api/v1/bets/placebets- Place a betGET /api/v1/bets/getallbets- Get user's betsGET /api/v1/bets/getallbetsmarket/:id- Get user's bets for a market
GET /api/v1/transactions/getalltransactions- Get user's transactions
- Install dependencies:
npm install- Set up environment variables in
.env:
DATABASE_URL="postgresql://user:password@localhost:5432/polymarket"
JWT_SECRET="your-secret-key-min-32-chars"
PORT="3005"
- Run database migrations:
npx prisma migrate dev- Build and run:
npm run build
npm run dev- User: Stores user accounts with email, password, balance
- Market: Prediction markets with outcomes, odds, and metadata
- Bets: User bets with amount, outcome choice, and locked-in odds
- Transactions: Financial transaction history
- Initial user balance: 10,000 units
- Odds calculation: Dynamic based on total betting pool
- Market outcomes: Binary (YES/NO)
- All monetary values in smallest unit (cents)