Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Themer Laravel Package

alizharb/laravel-themer

Enterprise-grade theme management for Laravel. Create, clone, activate, and safely delete themes with per-theme Vite builds, NPM workspaces, asset shortcuts, view overrides, and Livewire 4 support. Includes metadata, wizards, and fast production caching.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Zero-IO Production Cache: The new bootstrap/cache/themes.php cache eliminates filesystem scans in production, aligning with Laravel’s optimized bootstrapping. This reduces cold-start latency and improves scalability for high-traffic applications.
  • Vite Native Integration: Replaces legacy symlink workarounds with direct Vite hooks, ensuring seamless compatibility with modern asset pipelines. This simplifies theme development and eliminates manual configuration for @vite tags.
  • PreviewTheme Middleware: Adds a secure, query-param-based preview system (e.g., ?preview_theme=slug), useful for admin dashboards or internal tools. Requires careful handling of signed URLs to avoid CSRF risks.
  • System Event Hooks: Extends theme.json to trigger Artisan commands (e.g., after_activate), enabling workflow automation (e.g., seeding data post-theme activation). Risk of command injection if not sanitized.
  • Safe Mode Fallback: Mitigates theme boot failures by silently falling back to a default theme, improving stability. May mask underlying issues if over-reliant on this safety net.
  • Laravel 13 Support: Early compatibility ensures future-proofing but may introduce edge cases if Laravel 13’s bootstrapping changes (e.g., service provider ordering).

Integration Feasibility

  • Core Laravel Services:
    • ThemeManager: Centralized logic for theme resolution, now optimized with zero-IO caching. Override via ThemeManager::macro().
    • PreviewTheme Middleware: Insert into middleware stack for preview routes (e.g., Route::middleware(['preview_theme'])->group(...)).
    • Event Hooks: Define in theme.json:
      {
        "hooks": {
          "after_activate": ["php artisan db:seed --class=EcommerceSeeder"]
        }
      }
      
    • Vite Integration: Replace mix-manifest.json logic with @vite directives in Blade:
      @vite(['resources/themes/current/css/app.css'])
      
  • Database Agnostic: Schema migrations automated via theme:upgrade, but custom theme.json hooks may require manual validation for non-MySQL databases.
  • Asset Pipeline: Vite-native integration simplifies theming but requires:
    • Theme-specific Vite config (e.g., vite.config.js per theme).
    • Build directory isolation (e.g., public/themes/{slug}/assets).

Technical Risk

  • Zero-IO Cache Invalidation: Manual cache clearing (php artisan theme:cache) may be needed after theme updates. Risk of stale themes if not automated (e.g., via theme-updated events).
  • Vite Hooks Complexity: Native Vite integration assumes Laravel’s Vite plugin. Conflicts may arise with custom Vite setups (e.g., multi-project builds).
  • Event Hook Security: theme.json hooks execute arbitrary commands. Validate inputs and restrict to trusted themes.
  • Safe Mode Overhead: Fallback mechanism adds complexity to debugging. Log failed themes for postmortems.
  • Laravel 13 Edge Cases: Potential breaking changes in:
    • Service provider boot order.
    • Vite asset pipeline (e.g., new useBuildDirectory behavior).
  • Preview Middleware: Query params (preview_theme) may conflict with existing routing logic. Use middleware groups or custom prefixes.

Key Questions

  1. Cache Invalidation: How are bootstrap/cache/themes.php and Blade/X-Cache invalidated post-theme update? Are there event listeners (e.g., ThemeUpdated)?
  2. Vite Isolation: Can multiple themes share Vite builds, or is a per-theme Vite config required? How are shared dependencies (e.g., @alpinejs) handled?
  3. Hook Sanitization: Are theme.json hooks sanitized to prevent command injection? Example: after_activate: ["rm -rf /"].
  4. Preview Security: How are signed URLs for PreviewThemeMiddleware generated and validated? Is CSRF protection included?
  5. Multi-Tenant: Does PreviewThemeMiddleware support tenant-aware previews (e.g., ?preview_theme=slug&tenant=acme)?
  6. Legacy Themes: How are themes created pre-v1.3.0 migrated to the new theme.json hooks system? Is backward compatibility guaranteed?
  7. Testing: Are there built-in test helpers for:
    • Cache validation?
    • Vite asset isolation?
    • Hook execution (e.g., assertThemeHookExecuted())?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Core: Zero-IO cache and ThemeManager integrate natively with Laravel’s service container and bootstrapping.
    • Vite: Native hooks replace legacy asset pipelines, requiring Vite 4+ and Laravel’s Vite plugin.
    • Livewire: Untested with new Vite integration. May need @vite directives in Livewire components.
    • APIs: Preview middleware enables theme previews via API routes (e.g., GET /api/themes/preview?slug=admin).
  • PHP Extensions: No changes; still requires fileinfo and mbstring.
  • Frontend: Mandates Vite for theme assets. Legacy Mix users must migrate or use symlinks as a fallback.

Migration Path

  1. Discovery:
    • Audit existing theme.json or custom theme configs for hooks/commands.
    • Identify Vite/Mix usage in themes (replace with @vite directives).
  2. Pilot Phase:
    • Install v1.3.0: composer require alizharb/laravel-themer:^1.3.
    • Run php artisan theme:upgrade to migrate legacy themes.
    • Test theme:lint and theme:dev wizards for DX improvements.
  3. Core Integration:
    • Replace manual Vite builds with @vite tags in Blade/Livewire.
    • Implement PreviewThemeMiddleware for admin previews:
      Route::middleware(['preview_theme'])->group(function () {
          Route::get('/admin', AdminController::class);
      });
      
    • Configure theme.json hooks for automation (e.g., post-activation seeding).
  4. Asset Pipeline:
    • Migrate to per-theme Vite configs (e.g., resources/themes/admin/vite.config.js).
    • Update vite.config.js to support theme isolation:
      export default defineConfig({
        build: {
          outDir: `../../public/themes/${process.env.THEME_SLUG}/assets`,
        },
      });
      
  5. Validation:
    • Test zero-IO cache with php artisan theme:cache and verify production boot times.
    • Validate Vite asset paths in preview mode.
    • Audit hook executions for security/command injection.

Compatibility

  • Laravel Versions: Officially supports 11/12/13. For Laravel 10:
    • Downgrade Vite hooks manually (not recommended).
    • Patch ThemeManager to bypass zero-IO cache.
  • PHP Versions: Still PHP 8.2+. No changes.
  • Package Conflicts:
    • Vite Plugins: Conflicts with custom Vite plugins. Use vite.config.js merge strategies.
    • Middleware: PreviewThemeMiddleware may clash with auth middleware. Order matters (e.g., run after auth but before global middleware).
    • Artisan Hooks: Concurrent theme.json hooks could cause race conditions. Use queues for long-running commands.
  • Database: theme:upgrade handles schema changes, but custom theme.json hooks may need manual validation for SQLite/PostgreSQL.

Sequencing

  1. Phase 1: Cache & DX (2–3 days)
    • Enable zero-IO cache (php artisan theme:cache).
    • Test theme:lint and wizards in development.
  2. Phase 2: Vite Migration (3–5 days)
    • Replace Mix with @vite directives.
    • Configure per-theme Vite builds.
  3. Phase 3: Preview & Hooks (3–4 days)
    • Implement PreviewThemeMiddleware for admin routes.
    • Define theme.json hooks (e.g., after_activate).
  4. Phase 4: Security & Validation (2–3 days)
    • Audit hook sanitization.
    • Test preview mode with signed URLs.
  5. Phase 5: Legacy Support (2–3 days)
    • Backward-compatibility for pre-v1.3.0 themes.
    • Deprecate old asset pipeline logic.

Operational Impact

Maintenance

  • Updates:
    • Monitor for Laravel 13 breaking changes (e.g., Vite integration).
    • Pin Vite/Laravel versions to avoid auto-updates during critical phases.
  • Dependencies:
    • Use replace in composer.json for internal forks if needed (e.g., custom hook sanitization).
    • Document Vite version compatibility (e.g., "Tested with Vite 4.0+").
  • Debugging:
    • Log theme cache misses/hits in app/Exceptions/Handler.php.
    • Add health checks for:
      • `GET /health/themes
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor