This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MatchBox is a Python desktop application that automates OBS scene switching and match video clipping for FIRST Tech Challenge (FTC) robotics events. It connects to the FTC scoring system via WebSocket, controls OBS via WebSocket, and serves clipped match videos via HTTP with mDNS discovery.
Install dependencies:
pip install -r requirements.txtRun the GUI application:
python matchbox.pyRun in CLI mode:
python matchbox-cli.py --ftc-host <host> --event-code <code>Build standalone executables:
python build.pyNote: There is no test suite.
Type checking:
basedpyright matchbox.py matchbox-cli.py matchbox-sync.py build.py web_api/ local_video_processor.pyThe project uses basedpyright in strict mode. When writing or modifying code:
- Avoid
Anytypes — useobject,dict[str, object], orcast()instead - Annotate class attributes, function parameters, and return types
- Use
_ =for intentionally unused call results - Prefix unused variables with
_(e.g.,_dirs) - Use
from __future__ import annotationswithTYPE_CHECKINGimports to avoid circular imports at runtime
matchbox.py - Main application containing:
MatchBoxConfig- Configuration dataclass for all settingsMatchBoxCore- Application controller handling WebSocket connections, OBS control, and video processing orchestrationMatchBoxGUI- Tkinter GUI with sv-ttk theming
matchbox-cli.py - Command-line interface alternative to the GUI
matchbox-sync.py - Standalone rsync daemon for syncing match clips to a remote server
local_video_processor.py - Video clipping engine that uses ffmpeg subprocess calls to extract match segments from OBS recordings
web_api/ - Web server components:
handler.py- HTTP request handler with REST API routes, admin UI static file serving, and session-cookie authenticationwebsocket_server.py- WebSocket server for real-time log streaming, status updates, and OBS WebSocket proxyws_tunnel_client.py- WebSocket tunnel client that connects to a relay server for remote access
web_admin/ - Static HTML/CSS/JS for the browser-based admin dashboard (served by handler.py at /admin/)
pi-server/relay_server.py - Relay server (designed to run on a VPS/Pi) that bridges remote browser clients to MatchBox instances via WebSocket tunneling
FTC Scoring WebSocket → MatchBoxCore → OBS Scene Switch
↓
Match Start Event
↓
LocalVideoProcessor (delayed)
↓
ffmpeg Clip Extraction
↓
match_clips/<event_code>/
↓
HTTP Server (mDNS: ftcvideo.local)
- Main thread: Tkinter GUI event loop
- Background thread: asyncio event loop for WebSocket monitoring
- Web server: ThreadingHTTPServer with multi-threaded request handling
- WebSocket server: Separate daemon thread with its own asyncio event loop
- mDNS: Separate daemon thread for Zeroconf registration
- Local access: Admin UI served at
/admin/, API at/api/, clip downloads at/ - Remote access: WS tunnel client connects to relay server; relay proxies HTTP/WS requests back through the tunnel
- Authentication: HMAC-signed session cookies (
mb_session), 24h expiry. Two-tier: instance password (per-instance) and admin password (hardcoded hash viaADMIN_SALT/ADMIN_HASH). Localhost requests bypass auth (for tunnel-proxied requests). - WebSocket paths:
/ws/logs(log streaming),/ws/status(status updates),/ws/obs(OBS WebSocket proxy)
- Uses
obs-websocket-pyfor OBS control with fallback methods for older API versions - Custom HTTP handler implements Range requests for progressive video playback
- Configuration stored as JSON (
matchbox_config.json) with CLI args taking priority - Version derived from git tags via setuptools-scm
- Admin password hash generated via
generate_admin_hash.py
PyInstaller builds configured in matchbox.spec:
- Downloads platform-specific ffmpeg binaries automatically
- Produces standalone executables for Windows, macOS, and Linux
- CI/CD via GitHub Actions (
.github/workflows/pyinstaller.yml)