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 Chunky Laravel Package

netipar/laravel-chunky

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Design: Aligns well with Laravel’s ecosystem (e.g., EventServiceProvider, Broadcasting). Enables seamless integration with existing job queues (e.g., AssembleFileJob) and real-time updates via Laravel Echo.
  • Chunked Uploads: Solves a critical pain point for large-file handling (e.g., video, datasets) in web apps, where traditional single-file uploads fail due to timeout/connection issues.
  • Framework Agnosticism: Frontend clients (Vue/React/Alpine/Livewire) decouple upload logic from backend, reducing frontend-backend coupling.

Integration Feasibility

  • Laravel 11/12/13 Compatibility: Minimal friction for adoption in modern Laravel apps. PHP 8.2+ requirement ensures compatibility with recent Laravel versions.
  • Database Dependency: Uses migrations for tracking uploads/batches, requiring a database (no major issue for Laravel apps).
  • Queue-Dependent: AssembleFileJob must run on a queue worker (not sync), which is standard practice for Laravel but requires infrastructure setup.

Technical Risk

  • Locking Mechanism: Relies on Cache::lock() for concurrency control. Misconfiguration (e.g., using file driver) could lead to race conditions. Requires Redis/Memcached/DB for production.
  • Storage Overhead: Temporary chunks stored in storage/app/chunky/temp/ until assembly. Large-scale deployments need sufficient disk space or a dedicated staging directory.
  • Frontend Complexity: Framework-specific clients (Vue/React/Alpine) introduce minor learning curves for teams unfamiliar with the package’s API.
  • Broadcasting: Real-time updates require Laravel Echo + WebSocket server (e.g., Pusher, Ably). Not critical but adds operational complexity.

Key Questions

  1. Scalability Needs:
    • How many concurrent uploads/batches are expected? (Affects queue worker sizing and lock contention.)
    • Is Redis/Memcached feasible for locking, or will a DB-based solution (e.g., database lock driver) be required?
  2. Storage Strategy:
    • Where will chunky.staging_directory point? Cloud storage (e.g., S3) or local disk? Does it need to handle files larger than /tmp?
  3. Security/Compliance:
    • Are there restrictions on file types/sizes? (Package supports validation via chunky.metadata.max_keys and chunky.max_files_per_batch.)
    • How will upload ownership/authentication be enforced? (Default: auth user_id == upload user_id. Custom Authorizer may be needed.)
  4. Observability:
    • Are metrics (e.g., chunky.metrics.*) required for monitoring? If so, is Datadog/Prometheus integrated?
  5. Frontend Stack:
    • Which frontend framework(s) will use the package? (Vue/React/Alpine/Livewire all supported, but Livewire may require additional Blade/Livewire setup.)
  6. Failure Modes:
    • How will failed uploads be handled? (Retries via autoRetry/maxRetries in frontend clients.)
    • Is cleanup (chunky:cleanup) critical, or can expired uploads be manually managed?

Integration Approach

Stack Fit

  • Backend: Native Laravel integration (routes, events, jobs, migrations). Works alongside existing Laravel features like Sanctum/Passport for auth, Echo for broadcasting, and Horizon for queue monitoring.
  • Frontend:
    • Vue/React/Alpine: Drop-in composables/hooks with minimal boilerplate. Leverage existing build tools (Vite/Webpack).
    • Livewire: Zero npm dependency; uses Alpine.js under the hood. Integrates with Livewire’s event system (#[On]).
  • Infrastructure:
    • Queue: Requires a queue worker (e.g., Redis, database) for AssembleFileJob. Avoids sync driver.
    • Cache: Redis/Memcached recommended for locking. Fallback to DB if needed.
    • Storage: Supports local disk or cloud (e.g., S3 via Laravel Filesystem). Temporary chunks stored in storage/app/chunky/temp/.

Migration Path

  1. Backend Setup:
    • Install via Composer: composer require netipar/laravel-chunky.
    • Publish config: php artisan vendor:publish --tag=chunky-config.
    • Run migrations: php artisan migrate.
    • Configure auth middleware (e.g., Sanctum) in chunky.routes.middleware.
  2. Frontend Integration:
    • Install framework-specific package (e.g., npm install @netipar/chunky-vue3).
    • Replace existing upload logic with useChunkUpload/useBatchUpload composables.
    • For Livewire, add <livewire:chunky-upload /> to Blade templates.
  3. Queue/Worker:
    • Ensure AssembleFileJob runs on a queue worker (not sync). Test with php artisan queue:work.
  4. Testing:
    • Validate chunked uploads with large files (e.g., 100MB+) over unstable networks.
    • Test edge cases: paused/resumed uploads, cancellations, batch failures.

Compatibility

  • Laravel Ecosystem:
    • Works with Sanctum/Passport for auth, Echo for broadcasting, and Horizon for queue monitoring.
    • Supports Laravel’s Filesystem (local/cloud storage).
  • Frontend Frameworks:
    • Vue 3.4+, React 18/19, Alpine.js 3+, Livewire 3+. No major conflicts with existing setups.
  • Legacy Systems:
    • If using older Laravel versions (<11), may require minor adjustments (e.g., event binding syntax).

Sequencing

  1. Phase 1: Backend Integration
    • Configure routes, middleware, and queue workers.
    • Set up event listeners (e.g., UploadCompleted).
  2. Phase 2: Frontend Adoption
    • Replace single-file uploads with chunked uploads in critical flows (e.g., user avatars, document submissions).
    • Gradually migrate batch uploads for multi-file scenarios.
  3. Phase 3: Observability
    • Enable metrics (chunky.metrics.*) and monitoring.
    • Schedule cleanup (php artisan chunky:cleanup).
  4. Phase 4: Optimization
    • Tune chunk_size, max_concurrent, and max_retries based on performance data.
    • Adjust chunky.staging_directory for large files.

Operational Impact

Maintenance

  • Backend:
    • Minimal maintenance for core package. Focus on:
      • Monitoring queue workers (AssembleFileJob failures).
      • Rotating chunky.staging_directory storage (if using local disk).
      • Updating the package during minor releases (check UPGRADE.md).
    • Custom event listeners or authorizers may require updates if business logic changes.
  • Frontend:
    • Framework-specific clients are stable but may need updates if the core package changes.
    • Livewire components are self-contained; Alpine.js/Vue/React clients require occasional dependency updates.

Support

  • Troubleshooting:
    • Chunk Failures: Check chunky.lock_driver (Redis recommended), network stability, and disk space.
    • Assembly Failures: Monitor queue workers for AssembleFileJob exceptions. Verify file permissions in chunky.staging_directory.
    • Auth Issues: Ensure chunky.routes.middleware includes proper auth (e.g., Sanctum).
    • Broadcasting Issues: Validate Laravel Echo setup and WebSocket server connectivity.
  • Logs:
    • Package logs upload events to Laravel’s default log channel. Enable debug logging in config/chunky.php if needed.
    • Frontend errors (e.g., API 4xx/5xx) can be caught via onError callbacks.

Scaling

  • Horizontal Scaling:
    • Stateless backend (except for chunk storage). Scale queue workers and app servers independently.
    • Distribute chunky.staging_directory across servers if using local storage (e.g., via shared network storage or cloud sync).
  • Performance Tuning:
    • Adjust chunk_size (default: 5MB) based on network conditions and file types.
    • Increase max_concurrent in frontend clients for faster uploads (trade-off: higher server load).
    • Optimize AssembleFileJob for large files (e.g., use faster storage backends like S3).
  • Load Testing:
    • Simulate concurrent uploads to validate queue performance and lock contention.
    • Monitor chunky.metrics.* for bottlenecks (e.g., chunk upload rate, assembly time).

Failure Modes

Failure Scenario Impact Mitigation
Queue worker crashes Unassembled chunks; incomplete uploads Use supervisor (e.g., Supervisor, Kubernetes) to restart workers.
Disk full in staging_directory Upload failures Set chunky.staging_directory to a monitored cloud storage or larger disk.
Redis/Memcached
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.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium