php/src/Core/Cdn/CLAUDE.md
Snider 1d8a202bdf feat: add CLAUDE.md to all 21 CorePHP subsystems
Agent-readable documentation for every Core subsystem, extracted
from 530 PHP source files. Each CLAUDE.md documents key classes,
public API, patterns, and integration points.

Highlights discovered:
- Actions: #[Scheduled] attribute system wires to Laravel scheduler
- Bouncer Gate: training mode with #[Action] attributes (CoreGO pattern)
- Config: hierarchical scope (global→workspace→user) with version diffs
- Crypt: LthnHash = QuasiSalt from dAppServer, ported to PHP
- Database: Kahn's algorithm topological seeder sorting via attributes
- Events: 12 lifecycle events with HasEventVersion forward compat
- Front: 78 blade components + programmatic Component for MCP/agent UI
- Headers: DetectDevice identifies 14 in-app browser platforms
- Input: 9-step pre-boot sanitisation pipeline
- Lang: TranslationMemory with fuzzy matching + TMX import/export
- Mail: EmailShield with 100k+ disposable domain blocking
- Search: 7-source unified search with privacy-aware IP hashing
- Storage: Redis circuit breaker (Closed/Open/Half-Open)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-29 13:24:07 +01:00

2.5 KiB

Cdn

BunnyCDN integration with vBucket workspace isolation and storage offloading.

What It Does

Unified CDN and object storage layer providing:

  • BunnyCDN pull zone operations (purge, stats)
  • BunnyCDN storage zone operations (upload, download, list, delete)
  • Context-aware URL building (CDN, origin, private, signed)
  • vBucket-scoped paths using LthnHash for tenant isolation
  • Asset pipeline for processing and offloading
  • Flux Pro CDN delivery
  • Storage offload migration from local to CDN

Key Classes

Class Purpose
Boot ServiceProvider registering all services as singletons + backward-compat aliases to App\ namespaces
BunnyCdnService Pull zone API: purgeUrl(), purgeUrls(), purgeAll(), purgeByTag(), purgeWorkspace(), getStats(), getBandwidth(), listStorageFiles(), uploadFile(), deleteFile(). Sanitises error messages to redact API keys
BunnyStorageService Direct storage zone operations (separate from pull zone API)
CdnUrlBuilder URL construction: cdn(), origin(), private(), apex(), signed(), vBucket(), vBucketId(), vBucketPath(), asset(), withVersion(), urls(), allUrls()
StorageUrlResolver Context-aware URL resolution
FluxCdnService Flux Pro component CDN delivery
AssetPipeline Asset processing pipeline
StorageOffload (service) Migrates files from local storage to CDN
StorageOffload (model) Tracks offloaded files in DB
Cdn (facade) Cdn::purge(...) etc.
HasCdnUrls (trait) Adds CDN URL methods to Eloquent models

Console Commands

  • cdn:purge -- Purge CDN cache
  • cdn:push-assets -- Push assets to CDN storage
  • cdn:push-flux -- Push Flux Pro assets to CDN
  • cdn:offload-migrate -- Migrate local files to CDN storage

Middleware

  • RewriteOffloadedUrls -- Rewrites storage URLs in responses to CDN URLs
  • LocalCdnMiddleware -- Serves CDN assets locally in development

vBucket Pattern

Workspace-isolated CDN paths using LthnHash::vBucketId():

cdn.example.com/{vBucketId}/path/to/asset.js

The vBucketId is a deterministic SHA-256 hash of the domain name, ensuring each workspace's assets are namespaced.

Integration

  • Reads credentials from ConfigService (DB-backed config), not just .env
  • Signed URLs use HMAC-SHA256 with BunnyCDN token authentication
  • Config files: config.php (CDN settings), offload.php (storage offload settings)
  • Backward-compat aliases registered for all App\Services\* and App\Models\* namespaces