# rocketpark/craft-mux architecture

> Architecture diagram of the GitHub repository rocketpark/craft-mux, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rocketpark/craft-mux
- Repository: https://github.com/rocketpark/craft-mux

## Overview

Mux for Craft CMS adds video upload, asset management, analytics, access controls, and developer-facing playback APIs to Craft. The principal workflow is an editor managing videos in Craft, with asset operations handled by plugin services and synchronized with Mux; webhook jobs process Mux updates. Other branches cover volume/folder organization, dashboard metrics, signed playback, GraphQL, fields, and templates. The graph follows documented capabilities and relationships shown in the excerpts or source index; unsampled subsystem internals and connections are not inferred.

Main entry points: [`src/services/Assets.php`](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Assets.php) (Asset service), [`src/elements/MuxAsset.php`](https://github.com/rocketpark/craft-mux/blob/craft-5/src/elements/MuxAsset.php) (Asset element), [`src/controllers/AssetsController.php`](https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/AssetsController.php) (Asset management), [`src/jobs/HandleMuxWebhookJob.php`](https://github.com/rocketpark/craft-mux/blob/craft-5/src/jobs/HandleMuxWebhookJob.php) (Webhook processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_management["Video management"]
  node_asset_ui["Asset management"]
  node_asset_element["Asset element<br/>[MuxAsset.php]"]
  node_asset_query["Asset query<br/>[MuxAssetQuery.php]"]
  node_asset_store[("Asset records<br/>[Assets.php]")]
  node_folders["Folder management<br/>[Folders.php]"]
  node_volumes["Volume management<br/>[Volumes.php]"]
  node_volume_model["Volume model<br/>[MuxVolume.php]"]
  node_folder_model["Folder model<br/>[MuxFolder.php]"]
end

subgraph group_integration["Mux integration"]
  node_asset_service["Asset service<br/>[Assets.php]"]
  node_webhook_route["Webhook endpoint"]
  node_webhook_job["Webhook processing"]
end

subgraph group_security["Playback security"]
  node_restrictions["Playback restrictions"]
  node_signed_keys["Signed keys<br/>[SignedKeys.php]"]
  node_jwt["JWT helper<br/>[JWT.php]"]
end

subgraph group_developer["Developer interfaces"]
  node_field["Asset field<br/>[MuxAsset.php]"]
  node_graphql["GraphQL API<br/>[MuxAsset.php]"]
  node_twig["Template variables"]
end

subgraph group_operations["Operations and analytics"]
  node_dashboard["Analytics dashboard<br/>[Data.php]"]
  node_data_api["Dashboard controller<br/>[DataController.php]"]
  node_settings["Plugin settings<br/>[Settings.php]"]
  node_console["Sync commands<br/>[SyncController.php]"]
end

node_editor(("Craft editor"))
node_mux["Mux video service"]

node_editor -->|"manages videos"| node_asset_ui
node_asset_ui -->|"handles assets"| node_asset_service
node_asset_service -->|"synchronizes assets"| node_mux
node_asset_service -->|"updates records"| node_asset_store
node_asset_element -->|"queries assets"| node_asset_query
node_asset_ui -->|"manages elements"| node_asset_element
node_editor -->|"organizes videos"| node_folders
node_editor -->|"organizes videos"| node_volumes
node_folders -->|"uses folder models"| node_folder_model
node_volumes -->|"uses volume models"| node_volume_model
node_folder_model -->|"resolves volume"| node_volumes
node_mux -->|"sends updates"| node_webhook_route
node_webhook_route -->|"queues processing"| node_webhook_job
node_webhook_job -->|"updates assets"| node_asset_service
node_webhook_job -->|"reads records"| node_asset_store
node_editor -->|"views metrics"| node_data_api
node_data_api -->|"fetches metrics"| node_dashboard
node_dashboard -->|"requests analytics"| node_mux
node_editor -->|"configures plugin"| node_settings
node_editor -->|"sets restrictions"| node_restrictions
node_editor -->|"manages keys"| node_signed_keys
node_asset_element -->|"creates playback tokens"| node_jwt
node_editor -->|"selects assets"| node_field
node_field -->|"selects elements"| node_asset_element
node_editor -->|"queries assets"| node_graphql
node_editor -->|"renders playback"| node_twig
node_editor -->|"runs synchronization"| node_console
node_console -->|"synchronizes assets"| node_asset_service

click node_asset_ui "https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/AssetsController.php"
click node_asset_element "https://github.com/rocketpark/craft-mux/blob/craft-5/src/elements/MuxAsset.php"
click node_asset_query "https://github.com/rocketpark/craft-mux/blob/craft-5/src/elements/db/MuxAssetQuery.php"
click node_asset_service "https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Assets.php"
click node_webhook_route "https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/WebhooksController.php"
click node_webhook_job "https://github.com/rocketpark/craft-mux/blob/craft-5/src/jobs/HandleMuxWebhookJob.php"
click node_asset_store "https://github.com/rocketpark/craft-mux/blob/craft-5/src/records/Assets.php"
click node_folders "https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Folders.php"
click node_volumes "https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Volumes.php"
click node_volume_model "https://github.com/rocketpark/craft-mux/blob/craft-5/src/models/MuxVolume.php"
click node_folder_model "https://github.com/rocketpark/craft-mux/blob/craft-5/src/models/MuxFolder.php"
click node_dashboard "https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Data.php"
click node_data_api "https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/DataController.php"
click node_settings "https://github.com/rocketpark/craft-mux/blob/craft-5/src/models/Settings.php"
click node_restrictions "https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/PlaybackRestrictions.php"
click node_signed_keys "https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/SignedKeys.php"
click node_jwt "https://github.com/rocketpark/craft-mux/blob/craft-5/src/helpers/JWT.php"
click node_field "https://github.com/rocketpark/craft-mux/blob/craft-5/src/fields/MuxAsset.php"
click node_graphql "https://github.com/rocketpark/craft-mux/blob/craft-5/src/gql/interfaces/elements/MuxAsset.php"
click node_twig "https://github.com/rocketpark/craft-mux/blob/craft-5/src/variables/MuxAssetBehavior.php"
click node_console "https://github.com/rocketpark/craft-mux/blob/craft-5/src/console/controllers/SyncController.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_asset_ui,node_asset_element,node_asset_query,node_asset_store,node_folders,node_volumes,node_volume_model,node_folder_model toneBlue
class node_asset_service,node_webhook_route,node_webhook_job toneAmber
class node_restrictions,node_signed_keys,node_jwt toneMint
class node_field,node_graphql,node_twig toneRose
class node_dashboard,node_data_api,node_settings,node_console,node_editor,node_mux toneIndigo
```

## Components

### Video management

- [Asset management](https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/AssetsController.php): `src/controllers/AssetsController.php`
- [Asset element](https://github.com/rocketpark/craft-mux/blob/craft-5/src/elements/MuxAsset.php): `src/elements/MuxAsset.php`
- [Asset query](https://github.com/rocketpark/craft-mux/blob/craft-5/src/elements/db/MuxAssetQuery.php): `src/elements/db/MuxAssetQuery.php`
- [Asset records](https://github.com/rocketpark/craft-mux/blob/craft-5/src/records/Assets.php): `src/records/Assets.php`
- [Folder management](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Folders.php): `src/services/Folders.php`
- [Volume management](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Volumes.php): `src/services/Volumes.php`
- [Volume model](https://github.com/rocketpark/craft-mux/blob/craft-5/src/models/MuxVolume.php): `src/models/MuxVolume.php`
- [Folder model](https://github.com/rocketpark/craft-mux/blob/craft-5/src/models/MuxFolder.php): `src/models/MuxFolder.php`

### Mux integration

- [Asset service](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Assets.php): `src/services/Assets.php`
- [Webhook endpoint](https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/WebhooksController.php): `src/controllers/WebhooksController.php`
- [Webhook processing](https://github.com/rocketpark/craft-mux/blob/craft-5/src/jobs/HandleMuxWebhookJob.php): `src/jobs/HandleMuxWebhookJob.php`

### Playback security

- [Playback restrictions](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/PlaybackRestrictions.php): `src/services/PlaybackRestrictions.php`
- [Signed keys](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/SignedKeys.php): `src/services/SignedKeys.php`
- [JWT helper](https://github.com/rocketpark/craft-mux/blob/craft-5/src/helpers/JWT.php): `src/helpers/JWT.php`

### Developer interfaces

- [Asset field](https://github.com/rocketpark/craft-mux/blob/craft-5/src/fields/MuxAsset.php): `src/fields/MuxAsset.php`
- [GraphQL API](https://github.com/rocketpark/craft-mux/blob/craft-5/src/gql/interfaces/elements/MuxAsset.php): `src/gql/interfaces/elements/MuxAsset.php`
- [Template variables](https://github.com/rocketpark/craft-mux/blob/craft-5/src/variables/MuxAssetBehavior.php): `src/variables/MuxAssetBehavior.php`

### Operations and analytics

- [Analytics dashboard](https://github.com/rocketpark/craft-mux/blob/craft-5/src/services/Data.php): `src/services/Data.php`
- [Dashboard controller](https://github.com/rocketpark/craft-mux/blob/craft-5/src/controllers/DataController.php): `src/controllers/DataController.php`
- [Plugin settings](https://github.com/rocketpark/craft-mux/blob/craft-5/src/models/Settings.php): `src/models/Settings.php`
- [Sync commands](https://github.com/rocketpark/craft-mux/blob/craft-5/src/console/controllers/SyncController.php): `src/console/controllers/SyncController.php`

### Other components

- **Craft editor**
- **Mux video service**

## Connections

- Craft editor → Asset management: manages videos
- Asset management → Asset service: handles assets (evidence: `src/controllers/AssetsController.php`)
- Asset service → Mux video service: synchronizes assets
- Asset service → Asset records: updates records (evidence: `src/services/Assets.php`)
- Asset element → Asset query: queries assets (evidence: `src/elements/MuxAsset.php`)
- Asset management → Asset element: manages elements (evidence: `src/controllers/AssetsController.php`)
- Craft editor → Folder management: organizes videos
- Craft editor → Volume management: organizes videos
- Folder management → Folder model: uses folder models
- Volume management → Volume model: uses volume models (evidence: `src/services/Volumes.php`)
- Folder model → Volume management: resolves volume (evidence: `src/models/MuxFolder.php`)
- Mux video service → Webhook endpoint: sends updates
- Webhook endpoint → Webhook processing: queues processing (evidence: `src/controllers/WebhooksController.php`)
- Webhook processing → Asset service: updates assets (evidence: `src/jobs/HandleMuxWebhookJob.php`)
- Webhook processing → Asset records: reads records (evidence: `src/jobs/HandleMuxWebhookJob.php`)
- Craft editor → Dashboard controller: views metrics
- Dashboard controller → Analytics dashboard: fetches metrics (evidence: `src/controllers/DataController.php`)
- Analytics dashboard → Mux video service: requests analytics (evidence: `src/services/Data.php`)
- Craft editor → Plugin settings: configures plugin
- Craft editor → Playback restrictions: sets restrictions
- Craft editor → Signed keys: manages keys
- Asset element → JWT helper: creates playback tokens (evidence: `src/elements/MuxAsset.php`)
- Craft editor → Asset field: selects assets
- Asset field → Asset element: selects elements (evidence: `src/fields/MuxAsset.php`)
- Craft editor → GraphQL API: queries assets
- Craft editor → Template variables: renders playback
- Craft editor → Sync commands: runs synchronization
- Sync commands → Asset service: synchronizes assets (evidence: `src/console/controllers/SyncController.php`)
