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

Sidecar Shiki Laravel Package

spatie/sidecar-shiki

Run Shiki syntax highlighting on AWS Lambda via Sidecar from your Laravel app—no Node.js or Shiki dependencies on your server. Install the package, configure Sidecar, register the HighlightFunction, and render highlighted code fast and consistently.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: Ideal for Laravel applications requiring serverless syntax highlighting (e.g., code blocks in documentation, IDE-like previews, or CMS-generated content). Leverages Shiki (a modern, high-performance syntax highlighter) via Sidecar (AWS Lambda integration), eliminating Node.js dependency on the server.
  • Decoupling: Enables offloading CPU-intensive tasks (e.g., parsing/rendering code snippets) to Lambda, improving core application performance.
  • Extensibility: Compatible with Laravel’s service container for dependency injection (e.g., wrapping Shiki calls in a facade/service). Can integrate with queue workers (e.g., spatie/laravel-queueable-sidecar) for async processing.

Integration Feasibility

  • Low Friction: Minimal setup—requires only:
    • AWS Lambda configuration (Sidecar handles the rest).
    • Laravel package installation (composer require spatie/sidecar-shiki).
    • Environment variables for AWS credentials (Sidecar-managed).
  • Language Agnostic: PHP/Laravel acts as a client; Shiki runs in Lambda, abstracting Node.js entirely.
  • Blade/Template Support: Easily embed syntax-highlighted code in views via Blade directives or helper methods (e.g., @highlight('php', $code)).

Technical Risk

  • AWS Dependency: Requires Lambda setup (cost, IAM roles, region constraints). May introduce latency if Lambda is remote.
  • Cold Starts: Sidecar/Lambda cold starts could delay highlighting for sporadic requests. Mitigate via provisioned concurrency or caching (e.g., Redis).
  • Error Handling: Network/Lambda failures must be gracefully handled (e.g., fallback to static highlighting or retries).
  • Shiki Versioning: Relies on Sidecar’s Shiki version. Major updates may require testing for breaking changes.

Key Questions

  1. Performance: What’s the acceptable latency for highlighting? Can caching (e.g., Redis) reduce Lambda invocations?
  2. Cost: How often will highlighting be used? Lambda costs could scale with usage (e.g., $0.20 per 1M requests).
  3. Fallback Strategy: What if Lambda fails? Static highlighting or client-side JS (e.g., Prism.js) as backup?
  4. Security: Are AWS credentials securely managed? Use Laravel’s env() or Vault for sensitive data.
  5. Testing: How will you test Lambda integration locally? Tools like SAM CLI or LocalStack may help.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Seamless integration with:
    • Blade templates (custom directives or helpers).
    • API routes (return highlighted JSON for SPAs).
    • Queue jobs (async processing for large code blocks).
  • Sidecar Compatibility: Works with any Laravel app using Sidecar’s PHP client (no Node.js required).
  • Alternatives Considered:
    • Prism.js: Client-side, but increases bundle size and lacks server-side control.
    • Highlight.js: Server-side PHP ports exist but may lag Shiki’s features.
    • Self-hosted Shiki: More control but higher maintenance (Node.js, Docker, etc.).

Migration Path

  1. Phase 1: Proof of Concept
    • Install package: composer require spatie/sidecar-shiki.
    • Configure AWS Lambda via Sidecar (follow Sidecar docs).
    • Test basic highlighting in a Blade view or API endpoint.
  2. Phase 2: Integration
    • Create a service class to wrap Shiki calls (e.g., app/Services/CodeHighlighter.php).
    • Add caching (e.g., spatie/laravel-cache) for frequent requests.
    • Implement error handling (e.g., retry logic, fallbacks).
  3. Phase 3: Optimization
    • Monitor Lambda costs/metrics (CloudWatch).
    • Optimize payload size (e.g., compress code snippets before sending to Lambda).
    • Explore provisioned concurrency if latency is critical.

Compatibility

  • Laravel Versions: Tested with Laravel 8+ (PHP 8.0+). Backward compatibility may require adjustments for older versions.
  • Shiki Themes: Supports all Shiki themes. Theme switching can be dynamic via config.
  • Code Languages: Full Shiki language support (e.g., PHP, JavaScript, Markdown). Custom languages may need Sidecar configuration.

Sequencing

  1. Prerequisites:
    • AWS account with Lambda permissions.
    • Sidecar installed (composer require hammerstonedev/sidecar).
  2. Core Integration:
    • Deploy Lambda function (Sidecar handles the rest).
    • Configure Laravel to call Sidecar (e.g., via HTTP client).
  3. Advanced:
    • Add caching (Redis).
    • Implement queue jobs for async processing.
    • Set up monitoring (e.g., track Lambda errors).

Operational Impact

Maintenance

  • Dependencies:
    • Sidecar: Monitor for updates (e.g., new Shiki versions).
    • AWS Lambda: Patch runtime (e.g., Node.js version) if Sidecar requires it.
    • Laravel Package: Minimal maintenance (MIT license, active repo).
  • Logging:
    • Use Laravel’s logging + CloudWatch for Lambda invocations.
    • Log errors (e.g., failed requests, timeouts) to debug issues.
  • Updates:
    • Test Shiki major updates in staging (breaking changes possible).

Support

  • Troubleshooting:
    • Lambda Errors: Check CloudWatch logs for Sidecar failures.
    • Network Issues: Verify VPC/configuration if Lambda is private.
    • Caching Issues: Clear cache (e.g., php artisan cache:clear) if highlights stale.
  • Documentation:
    • Package README is clear, but internal docs should cover:
      • AWS setup steps.
      • Error handling workflows.
      • Performance tuning (e.g., caching strategies).
  • Vendor Lock-in: Low risk—Sidecar is open-source, but AWS-specific.

Scaling

  • Horizontal Scaling:
    • Lambda auto-scales with request volume (no manual intervention).
    • Monitor concurrency limits (default: 1,000 per region).
  • Cost Optimization:
    • Caching: Reduce Lambda invocations for repeated requests.
    • Payload Size: Compress code snippets to minimize Lambda runtime.
    • Reserved Concurrency: Limit costs if usage is predictable.
  • Performance Bottlenecks:
    • Cold Starts: Mitigate with provisioned concurrency.
    • Payload Size: Large code blocks may increase latency (test thresholds).

Failure Modes

Failure Scenario Impact Mitigation
Lambda timeout Highlighting fails for long snippets Increase timeout or split into chunks.
AWS outage All highlighting disabled Fallback to static highlighting.
Network issues (VPC/Lambda) Intermittent failures Retry logic + circuit breaker.
Shiki version incompatibility Highlighting breaks Test updates in staging.
Cache corruption Stale highlights Cache invalidation strategy.

Ramp-Up

  • Developer Onboarding:
    • 1-2 hours: Basic setup (Lambda, package install).
    • 4-8 hours: Integration with Blade/API + error handling.
    • 1 day: Caching, async processing, and monitoring.
  • Key Skills Needed:
    • Laravel service containers, Blade templates.
    • Basic AWS Lambda/Sidecar configuration.
    • PHP error handling and logging.
  • Training Materials:
    • Create a runbook with:
      • Step-by-step AWS/Lambda setup.
      • Example Blade/API usage.
      • Debugging guide for common failures.
  • Adoption Risks:
    • Complexity: AWS setup may slow initial adoption. Mitigate with a pre-configured Terraform/CDK template.
    • Latency: Cold starts could frustrate users. Pre-warm Lambdas or use caching.
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