openapi: 3.1.0 info: title: Api version: 0.1.0 description: BBPW Football Prediction Platform API servers: - url: /api description: Base API path tags: - name: health - name: auth - name: users - name: matches - name: predictions - name: leaderboard - name: friends - name: notifications - name: rewards - name: admin paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" /auth/register: post: operationId: register tags: [auth] summary: Register a new user (username + 4-digit PIN) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RegisterInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "400": description: Bad request content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" "409": description: Username taken content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/login: post: operationId: login tags: [auth] summary: Login with username and 4-digit PIN requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginInput" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "401": description: Invalid credentials content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/logout: post: operationId: logout tags: [auth] summary: Logout current user responses: "200": description: Logged out content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /auth/me: get: operationId: getMe tags: [auth] summary: Get current authenticated user responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/User" "401": description: Not authenticated content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /users: get: operationId: listUsers tags: [users] summary: List all users (admin only) responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/User" /users/search: get: operationId: searchUsers tags: [users] summary: Search users by username parameters: - in: query name: q schema: type: string required: true responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/User" /users/{userId}: get: operationId: getUser tags: [users] summary: Get a user profile parameters: - in: path name: userId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/UserProfile" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" patch: operationId: updateUser tags: [users] summary: Update user (admin or self) parameters: - in: path name: userId schema: type: integer required: true requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UserUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/User" delete: operationId: deleteUser tags: [users] summary: Delete a user (admin only) parameters: - in: path name: userId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /users/{userId}/predictions: get: operationId: getUserPredictions tags: [users] summary: Get prediction history for a user parameters: - in: path name: userId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/PredictionWithMatch" /matches: get: operationId: listMatches tags: [matches] summary: List matches (filter by status) parameters: - in: query name: status schema: type: string enum: [upcoming, live, completed, all] responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Match" post: operationId: createMatch tags: [matches] summary: Create a match (admin only) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MatchInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Match" /matches/today: get: operationId: getTodayMatches tags: [matches] summary: Get today's matches responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Match" /matches/{matchId}: get: operationId: getMatch tags: [matches] summary: Get a single match with prediction stats parameters: - in: path name: matchId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/MatchDetail" patch: operationId: updateMatch tags: [matches] summary: Update a match (admin only) parameters: - in: path name: matchId schema: type: integer required: true requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MatchUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/Match" delete: operationId: deleteMatch tags: [matches] summary: Delete a match (admin only) parameters: - in: path name: matchId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /matches/{matchId}/result: post: operationId: declareResult tags: [matches] summary: Declare match result and settle predictions (admin only) parameters: - in: path name: matchId schema: type: integer required: true requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ResultInput" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SettlementResult" /predictions: get: operationId: getMyPredictions tags: [predictions] summary: Get my predictions responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/PredictionWithMatch" post: operationId: placePrediction tags: [predictions] summary: Place a prediction on a match requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/PredictionInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Prediction" "400": description: Bad request (already predicted, match started, etc.) content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /leaderboard: get: operationId: getLeaderboard tags: [leaderboard] summary: Get global leaderboard parameters: - in: query name: sortBy schema: type: string enum: [coins, accuracy, wins] - in: query name: limit schema: type: integer responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/LeaderboardEntry" /friends: get: operationId: getFriends tags: [friends] summary: Get my friends list responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Friend" /friends/requests: get: operationId: getFriendRequests tags: [friends] summary: Get pending friend requests responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/FriendRequest" post: operationId: sendFriendRequest tags: [friends] summary: Send a friend request requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/FriendRequestInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/FriendRequest" /friends/requests/{requestId}: patch: operationId: respondFriendRequest tags: [friends] summary: Accept or decline a friend request parameters: - in: path name: requestId schema: type: integer required: true requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/FriendRequestResponse" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /friends/{friendId}: delete: operationId: removeFriend tags: [friends] summary: Remove a friend parameters: - in: path name: friendId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /notifications: get: operationId: getNotifications tags: [notifications] summary: Get my notifications responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Notification" /notifications/{notificationId}/read: post: operationId: markNotificationRead tags: [notifications] summary: Mark a notification as read parameters: - in: path name: notificationId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /notifications/read-all: post: operationId: markAllNotificationsRead tags: [notifications] summary: Mark all notifications as read responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /rewards/daily: post: operationId: claimDailyReward tags: [rewards] summary: Claim daily login reward responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/DailyRewardResult" "400": description: Already claimed today content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /admin/stats: get: operationId: getAdminStats tags: [admin] summary: Get platform-wide admin statistics responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/AdminStats" /admin/users/{userId}/coins: patch: operationId: setUserCoins tags: [admin] summary: Set a user's coin balance (admin only) parameters: - in: path name: userId schema: type: integer required: true requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CoinUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/User" /admin/users/{userId}/toggle-admin: patch: operationId: toggleAdmin tags: [admin] summary: Toggle admin status for a user (admin only) parameters: - in: path name: userId schema: type: integer required: true responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/User" components: schemas: HealthStatus: type: object properties: status: type: string required: - status ErrorResponse: type: object properties: error: type: string required: - error SuccessResponse: type: object properties: success: type: boolean message: type: string required: - success RegisterInput: type: object properties: username: type: string minLength: 3 maxLength: 30 pin: type: string pattern: "^[0-9]{4}$" required: - username - pin LoginInput: type: object properties: username: type: string pin: type: string rememberMe: type: boolean required: - username - pin AuthResponse: type: object properties: user: $ref: "#/components/schemas/User" token: type: string required: - user - token User: type: object properties: id: type: integer username: type: string avatarUrl: type: ["string", "null"] coins: type: integer wins: type: integer losses: type: integer accuracy: type: number rank: type: ["integer", "null"] isAdmin: type: boolean createdAt: type: string format: date-time lastLoginAt: type: ["string", "null"] format: date-time lastDailyRewardAt: type: ["string", "null"] format: date-time badges: type: array items: type: string required: - id - username - coins - wins - losses - accuracy - isAdmin - createdAt - badges UserProfile: type: object properties: user: $ref: "#/components/schemas/User" recentPredictions: type: array items: $ref: "#/components/schemas/PredictionWithMatch" leaderboardRank: type: ["integer", "null"] friendStatus: type: ["string", "null"] enum: [none, friends, pending_sent, pending_received, "null"] required: - user - recentPredictions UserUpdate: type: object properties: username: type: string minLength: 3 maxLength: 30 avatarUrl: type: ["string", "null"] isAdmin: type: boolean coins: type: integer Match: type: object properties: id: type: integer league: type: string leagueLabel: type: string homeTeam: type: string awayTeam: type: string homeScore: type: ["integer", "null"] awayScore: type: ["integer", "null"] kickoffAt: type: string format: date-time status: type: string enum: [upcoming, live, completed, cancelled] result: type: ["string", "null"] enum: [home, draw, away, "null"] totalPool: type: integer predictionCount: type: integer createdAt: type: string format: date-time required: - id - league - leagueLabel - homeTeam - awayTeam - kickoffAt - status - totalPool - predictionCount - createdAt MatchDetail: type: object properties: match: $ref: "#/components/schemas/Match" userPrediction: $ref: "#/components/schemas/Prediction" homeVotes: type: integer drawVotes: type: integer awayVotes: type: integer totalStaked: type: integer required: - match - homeVotes - drawVotes - awayVotes - totalStaked MatchInput: type: object properties: league: type: string leagueLabel: type: string homeTeam: type: string awayTeam: type: string kickoffAt: type: string format: date-time required: - league - leagueLabel - homeTeam - awayTeam - kickoffAt MatchUpdate: type: object properties: league: type: string leagueLabel: type: string homeTeam: type: string awayTeam: type: string kickoffAt: type: string format: date-time status: type: string enum: [upcoming, live, completed, cancelled] ResultInput: type: object properties: result: type: string enum: [home, draw, away] homeScore: type: integer awayScore: type: integer required: - result - homeScore - awayScore SettlementResult: type: object properties: match: $ref: "#/components/schemas/Match" winnersCount: type: integer losersCount: type: integer totalPool: type: integer payoutPerWinner: type: integer required: - match - winnersCount - losersCount - totalPool - payoutPerWinner Prediction: type: object properties: id: type: integer userId: type: integer matchId: type: integer prediction: type: string enum: [home, draw, away] stake: type: integer payout: type: ["integer", "null"] outcome: type: ["string", "null"] enum: [win, loss, pending, "null"] createdAt: type: string format: date-time required: - id - userId - matchId - prediction - stake - createdAt PredictionInput: type: object properties: matchId: type: integer prediction: type: string enum: [home, draw, away] stake: type: integer minimum: 10 required: - matchId - prediction - stake PredictionWithMatch: type: object properties: prediction: $ref: "#/components/schemas/Prediction" match: $ref: "#/components/schemas/Match" required: - prediction - match LeaderboardEntry: type: object properties: rank: type: integer user: $ref: "#/components/schemas/User" coins: type: integer wins: type: integer accuracy: type: number required: - rank - user - coins - wins - accuracy Friend: type: object properties: id: type: integer user: $ref: "#/components/schemas/User" friendedAt: type: string format: date-time required: - id - user - friendedAt FriendRequest: type: object properties: id: type: integer fromUser: $ref: "#/components/schemas/User" toUser: $ref: "#/components/schemas/User" status: type: string enum: [pending, accepted, declined] createdAt: type: string format: date-time required: - id - fromUser - toUser - status - createdAt FriendRequestInput: type: object properties: toUserId: type: integer required: - toUserId FriendRequestResponse: type: object properties: action: type: string enum: [accept, decline] required: - action Notification: type: object properties: id: type: integer userId: type: integer type: type: string enum: [prediction_won, prediction_lost, friend_request, match_reminder, daily_reward, system] title: type: string message: type: string isRead: type: boolean createdAt: type: string format: date-time required: - id - userId - type - title - message - isRead - createdAt DailyRewardResult: type: object properties: coinsAwarded: type: integer newBalance: type: integer streak: type: integer required: - coinsAwarded - newBalance - streak AdminStats: type: object properties: totalUsers: type: integer totalMatches: type: integer activeMatches: type: integer totalPredictions: type: integer totalCoinsInCirculation: type: integer recentActivity: type: array items: $ref: "#/components/schemas/ActivityItem" required: - totalUsers - totalMatches - activeMatches - totalPredictions - totalCoinsInCirculation - recentActivity ActivityItem: type: object properties: type: type: string description: type: string timestamp: type: string format: date-time required: - type - description - timestamp CoinUpdate: type: object properties: coins: type: integer minimum: 0 required: - coins