Baseball Scoreboard App | Reddit for Developers
close

Readme

MLB Baseball Scorecard App

A Reddit Devvit app that creates interactive baseball scorecards with live game data, comprehensive statistics, and play-by-play analysis.

Architecture

Core Components

  • src/main.tsx - Devvit app configuration, settings, and entry point
  • src/app.tsx - Main fetching logic, scheduled jobs, and post rendering
  • src/forms/GameSelectionForm.tsx - Date/game selection forms and post creation workflow
  • src/phases/ - Game phase-specific components (pregame, postgame)
  • src/utils/gameParsers.ts - SportsRadar API data normalization and parsing
  • src/types/game.ts - TypeScript interfaces for game data structures

Data Flow

  1. User selects date → fetches MLB schedule from SportsRadar API
  2. User selects game → creates Reddit post with loading state
  3. Fetches boxscore + extended summary data → stores in Redis
  4. Renders interactive scorecard with live updates via scheduled jobs

Setup

Prerequisites

  • Reddit Devvit CLI installed
  • SportsRadar API key (trial account sufficient)

Installation

npm install

Configuration

  1. Set SportsRadar API key in Devvit settings:
devvit settings set sportsradar-api-key YOUR_API_KEY
  1. Deploy to Reddit:
devvit upload

API Integration

SportsRadar Endpoints Used

  • GET /mlb/trial/v8/en/games/{year}/{month}/{day}/schedule.json - Daily game schedule
  • GET /mlb/trial/v8/en/games/{gameId}/boxscore.json - Current game state
  • GET /mlb/trial/v8/en/games/{gameId}/extended_summary.json - Detailed statistics

Data Caching Strategy

  • Schedule data cached by date: schedule_{year}_{month}_{day}
  • Boxscore data cached by game ID: boxscore_{gameId}
  • Extended summary cached by game ID: extended_summary_{gameId}
  • All caches include timestamps for TTL management

Key Features

Live Game Updates

  • Scheduled job runs every 2 seconds for live games, 300 seconds for closed games
  • Updates score, inning, outs, base runners
  • Refreshes team statistics and play-by-play data

Comprehensive Statistics

  • Batting: AB, R, H, RBI, BB, SO, LOB, AVG, OBP, SLG, OPS
  • Pitching: IP, H, R, ER, BB, K, HR, PC-ST, ERA
  • Fielding: DP, E, PB with player breakdowns
  • Advanced: RISP, 2-out RBI, game scores, pitch types

Interactive UI

  • Tabbed interface for different data views
  • Pagination for player lists and play-by-play
  • Team switching between home/away
  • Progressive cumulative statistics

Development

Project Structure

src/
├── main.tsx                # Devvit app entry point and configuration
├── app.tsx                 # Main fetching logic and scheduled jobs
├── forms/
│   └── GameSelectionForm.tsx  # Date/game selection forms
├── phases/
│   ├── pregame/
│   │   ├── pregame.tsx     # Pregame voting and countdown
│   │   └── LineupsTab.tsx  # Player lineups and stats
│   └── postgame/
│       ├── postgame.tsx    # Final score and team stats
│       ├── BoxScoreTab.tsx # Detailed player statistics
│       └── PlayByPlayTab.tsx # Play-by-play with pagination
├── utils/
│   └── gameParsers.ts      # API data normalization
├── types/
│   └── game.ts            # TypeScript interfaces
└── assets/
    ├── bases.ts           # Base runner images
    └── logos/mlb.ts       # Team logo URLs

Deployment

Production Checklist

  • [ ] npm i
  • [ ] SportsRadar API key configured

About this app