This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The Statamic Mux addon is a purpose-built integration between the Statamic CMS and the Mux video streaming and encoding platform. It enables content editors to upload and manage video content in a seamless workflow within the Statamic control panel while leveraging Mux's video processing and delivery capabilities in the background.
- Provide a seamless editing experience by mirroring local videos to Mux
- Simplify video embedding and rendering through Antlers frontend tags and official Mux web components
- Automated asset mirroring to Mux via background queue jobs
- Templating tags for frontend video rendering
- GraphQL API extensions for headless implementations
- Secure playback policy enforcement
- For Content Editors: Manage videos directly within the familiar Statamic control panel
- For Developers: Implement video playback with simple template tags
- For End Users: Experience fast-loading, adaptive video playback across all devices
- Content editor uploads video through Statamic's asset manager
- System automatically mirrors the asset to Mux (async job)
- Mux processes video for optimal delivery
- Playback IDs and metadata are stored with Statamic asset
- Developer implements templating tags in Antlers templates
- System generates appropriate embed code based on context
- Frontend visitors receive optimized video streams
The addon follows a service-oriented architecture with clear separation of concerns:
graph TD
UI[Control Panel UI] --> FT[Fieldtypes]
FT --> SERVICE[MuxService]
CLI[CLI Commands] --> SERVICE
SERVICE --> API[MuxApi]
API --> MUX[Mux Platform]
SERVICE --> JOBS[Queue Jobs]
JOBS --> API
- MuxService (
src/Mux/MuxService.php): Main service class that orchestrates all Mux operations including asset creation, deletion, and playback ID management. - MuxApi (
src/Mux/MuxApi.php): Wrapper around the Mux PHP SDK for API interactions. - MuxAsset (
src/Data/MuxAsset.php): Data class representing a Mux asset with an underlying local Asset. - ServiceProvider (
src/ServiceProvider.php): Registers all services, commands, fieldtypes, and tags with Laravel/Statamic.
- Actions Pattern: Complex operations are handled by dedicated Action classes in
src/Mux/Actions/ - Queue Integration: Heavy operations like asset upload/deletion are queued using
src/Jobs/ - Event System: Asset lifecycle events are fired for extensibility
- Hook System: Custom hooks are fired for extensibility during asset operations
Configuration is handled through config/mux.php with keys for:
- Mux API credentials (
token_id,token_secret) - Playback policies and signing keys
- Queue and webhook settings
- Videos uploaded to Statamic are detected by
MirrorFieldSubscriber - Assets are queued for upload to Mux via
CreateMuxAssetJob - Mux returns asset ID and playback IDs are generated
- Metadata is stored in Statamic's asset meta
- Templates can render videos using Mux tags
Tests use Pest framework with custom concerns in tests/Concerns/:
DealsWithAssets- Asset creation helpersExtendsAssetBlueprint- Blueprint extension utilitiesInteractsWithAntlersViews- Template testing helpers
Mock fixtures are stored in tests/__fixtures__/ for consistent testing.
- PHP 8.3+: Base language requirement
- Laravel 12+: Framework foundation
- Statamic 6+: CMS platform
- Mux PHP SDK: Official API client for Mux services
- Vue 3: Backend fieldtype components
- Vite: Asset building
- PHPStan: Static analysis
- Laravel Pint: Code formatting following Laravel style
composer analyse- Run PHPStan static analysiscomposer format- Format code with Laravel Pintcomposer lint- Check code formatting with Laravel Pintcomposer test- Run tests with Pestcomposer test:coverage- Run tests with coverage reportcomposer test:ci- Run tests with CI coverage output
npm run dev- Start Vite development servernpm run build- Build production assetsnpm run docs:dev- Run documentation development servernpm run docs:build- Build documentation
The addon provides three custom Artisan commands:
php artisan mux:mirror- Mirror assets to Muxphp artisan mux:prune- Delete orphaned assets on Muxphp artisan mux:upload- Upload specific assets to Mux
- Code Organization: Prefer trait-based composition over inheritance
- Naming Conventions:
Assetfor a file managed locally by StatamicMuxAssetfor a file uploaded to and streamed by MuxMuxPlaybackIdfor a unique playback ID allowing streaming from frontend componentsMuxprefix for all Mux-specific classes
- Avoid synchronous API calls in web requests
- Cache playback URLs when possible
- Use queue system effectively for background processing
- Consider storage implications of large video files
- Public playback IDs for open content
- Signed playback IDs with JWT tokens for restricted content
- Signed URLs with expiration timestamps
- Minimize configuration and implementation complexity for developers
- Provide flexible embedding options for different frontend scenarios
- Maintain performance through asynchronous processing
- Core infrastructure (API client, configuration, asset mirroring)
- Asset management with lifecycle events
- Frontend rendering with video, player, and embed tags
- Security with signed URLs and playback policies
- CLI commands for asset operations
- Replace original videos with short placeholder clip to optimize storage
- Expand test coverage for critical paths
- Control panel dashboard for Mux asset management
- List all Mux assets in a dedicated listing view
- Allow manual sync, deletion, and link to local assets