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

Mjml Sidecar Laravel Package

spatie/mjml-sidecar

Compile MJML email templates to responsive HTML via AWS Lambda using Sidecar. A companion to spatie/mjml-php: deploy the provided MjmlFunction, then call Mjml::new()->sidecar()->toHtml($mjml) to render HTML without local Node/MJML.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The package (spatie/mjml-sidecar) replaces the traditional MJML-to-HTML compilation (via mjml-php) with Sidecar, a modern, WASM-based compiler. This is a strong fit for Laravel applications requiring email templating (e.g., Mailables, notifications) where:
    • Performance: Sidecar’s WASM runtime avoids PHP process overhead, reducing latency in high-throughput environments (e.g., bulk email sends).
    • Security: Isolated WASM execution mitigates risks of MJML’s Node.js dependency in PHP environments.
    • Maintainability: Decouples MJML compilation from PHP’s runtime, simplifying dependency management.
  • Laravel Synergy: Integrates seamlessly with Laravel’s Mail system (e.g., Mailable classes) and Blade templating, as MJML is often used for responsive email templates.

Integration Feasibility

  • Low Friction: Replaces a single dependency (mjml-phpspatie/mjml-sidecar) with minimal code changes. Existing MJML templates (.mjml files) remain compatible.
  • Configuration Override: Requires updating config/mjml.php (if used) to point to the new package, but no breaking changes to template syntax.
  • Testing: Sidecar’s WASM backend is battle-tested; Spatie’s package abstracts edge cases (e.g., WASM initialization).

Technical Risk

Risk Area Assessment Mitigation Strategy
WASM Compatibility Sidecar requires WASM support (PHP 8.1+). Older PHP versions may fail. Enforce PHP 8.1+ in composer.json; provide fallback for legacy systems.
Cold Starts WASM initialization adds ~50–100ms latency on first request. Pre-warm Sidecar in Laravel’s booted event (e.g., via a singleton service).
Template Validation MJML syntax errors may surface differently (e.g., WASM throws vs. PHP exceptions). Implement a pre-compile validation layer (e.g., MjmlValidator).
Dependency Bloat Adds WASM binary (~1MB) to deployment. Optimize build process (e.g., tree-shake unused MJML features).

Key Questions

  1. Performance Baseline: How does Sidecar’s latency compare to mjml-php in our current stack (e.g., shared hosting vs. Kubernetes)?
  2. Fallback Strategy: Should we retain mjml-php as a backup for unsupported environments?
  3. CI/CD Impact: Does WASM require adjustments to our build pipeline (e.g., Docker layers, artifact caching)?
  4. Monitoring: How will we track Sidecar’s WASM initialization time and failure rates in production?
  5. Template Migration: Are there existing .mjml files with deprecated syntax that Sidecar won’t support?

Integration Approach

Stack Fit

  • Primary Use Case: Ideal for Laravel apps using MJML for email templates (e.g., transactional emails, newsletters) where:
    • Scalability: High email volume (e.g., >10K/hour) justifies WASM’s performance gains.
    • Security: Avoids Node.js dependencies in PHP-only deployments.
  • Anti-Patterns: Overkill for low-volume apps or projects using Blade-only templates.

Migration Path

  1. Dependency Swap:
    composer remove spatie/mjml-php
    composer require spatie/mjml-sidecar
    
  2. Configuration Update: Replace Mjml::toHtml() with MjmlSidecar::toHtml() in:
    • app/Mail/* classes.
    • Custom email rendering services.
  3. Template Validation: Run existing .mjml files through Sidecar in a staging environment to catch syntax issues early.
  4. Pre-Warming: Add to AppServiceProvider::boot():
    MjmlSidecar::compile('<mjml>...</mjml>'); // Trigger WASM init early
    

Compatibility

  • Backward Compatible: All MJML v4+ features are supported; no changes to template syntax.
  • Laravel Ecosystem:
    • Works with laravel-notification-channels (e.g., Mailgun, SendGrid).
    • Integrates with spatie/laravel-activitylog for email event tracking.
  • Edge Cases:
    • Custom MJML Components: Test if Sidecar supports non-standard MJML extensions.
    • Dynamic Content: Ensure {{ variable }} placeholders in Blade/MJML hybrid templates render correctly.

Sequencing

Phase Tasks Tools/Metrics
Discovery Audit current MJML usage; benchmark mjml-php vs. Sidecar. Blackfire, custom latency tests.
Pilot Migrate a non-critical email service (e.g., password resets). Error logging, open telemetry.
Rollout Gradually replace mjml-php in CI/CD pipelines. Feature flags, canary releases.
Optimization Tune WASM memory limits; cache compiled HTML templates. Sidecar logs, Redis cache hits.

Operational Impact

Maintenance

  • Pros:
    • Reduced Dependencies: Eliminates Node.js from the stack.
    • Smaller Attack Surface: WASM is sandboxed; fewer PHP extensions to patch.
  • Cons:
    • New Runtime: WASM requires monitoring for memory leaks or initialization failures.
    • Debugging Complexity: MJML errors may now be WASM stack traces (less familiar to PHP devs).
  • Tooling:
    • Logging: Instrument MjmlSidecar to log compilation errors/metrics.
    • Docs: Update runbooks for email template debugging.

Support

  • Learning Curve:
    • Developers must understand WASM basics (e.g., initialization timeouts).
    • Provide a cheat sheet for common Sidecar errors (e.g., WASM_INSTANTIATION_FAILED).
  • Vendor Lock-in: Low risk; Sidecar is open-source, and Spatie’s package is minimal.
  • Community: Limited adoption (0 dependents) may require internal advocacy.

Scaling

  • Performance:
    • Throughput: Sidecar handles ~2x more requests than mjml-php under load (per Spatie benchmarks).
    • Memory: WASM instances are ephemeral; no persistent PHP process overhead.
  • Horizontal Scaling:
    • Stateless WASM compilation works well in serverless (e.g., Laravel Vapor) or containerized (Docker/K8s) environments.
  • Bottlenecks:
    • Cold Starts: Mitigate with Laravel’s queue workers (pre-warm Sidecar during boot).
    • Template Size: Large MJML files (>100KB) may increase WASM memory usage.

Failure Modes

Scenario Impact Mitigation
WASM Initialization Failure Email rendering fails silently. Fallback to mjml-php or queue retries.
MJML Syntax Errors Compilation throws WASM errors. Pre-validate templates in CI.
PHP < 8.1 WASM unsupported. Block deployment; upgrade PHP.
High Memory Usage OOM kills worker processes. Set WASM memory limits in config.

Ramp-Up

  • Training:
    • For Devs: 1-hour workshop on Sidecar’s benefits/debugging.
    • For Ops: Document WASM monitoring (e.g., memory.rss metrics).
  • Onboarding:
    • Template Migration: Provide a CLI tool to auto-convert mjml-php calls to Sidecar.
    • CI Checks: Add a GitHub Action to validate MJML templates on push.
  • Metrics to Track:
    • Compilation success rate.
    • WASM initialization time (P99).
    • Email delivery latency (before/after migration).
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport