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

Recurr Laravel Package

simshaun/recurr

PHP library for RFC5545 RRULE recurrence rules. Build rules from strings or fluent setters, then transform them into DateTime occurrences via transformers. Useful for calendars and recurring events with time zone support.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Integration: The package is PHP-native and Composer-compatible, making it a seamless fit for Laravel applications. It aligns well with Laravel’s dependency injection and service container patterns, especially for domain logic involving recurring events (e.g., calendars, subscriptions, or scheduled tasks).
  • Domain Alignment: Ideal for use cases requiring RRULE (RFC 5545) parsing/generation, such as:
    • Calendar systems (e.g., event recurrence).
    • Subscription billing (e.g., monthly/yearly charges).
    • Scheduled notifications or reminders.
  • Laravel-Specific Synergies:
    • Can integrate with Laravel’s Carbon (via \DateTime compatibility) for timezone-aware operations.
    • Works alongside Laravel’s scheduling (e.g., Artisan::schedule) or queue workers for time-based jobs.
    • Compatible with Eloquent models for storing recurrence rules in databases (e.g., recurrence_rule column as JSON/text).

Integration Feasibility

  • Low Friction: Minimal boilerplate—just composer require simshaun/recurr and instantiate the Rule/Transformer classes.
  • Flexible Input/Output:
    • Accepts RRULE strings (e.g., "FREQ=MONTHLY;COUNT=12") or programmatic builders (fluent methods like setFreq()).
    • Outputs RecurrenceCollection (Doctrine ArrayCollection subclass) with DateTime objects, enabling easy iteration or storage.
  • Database Storage: Rules can be serialized as strings (e.g., json_encode($rule->getString())) or stored as objects (e.g., using Laravel’s Encrypter for sensitive rules).

Technical Risk

  • Edge Cases:
    • Monthly Recurrence Quirks: Default behavior skips invalid dates (e.g., Jan 31 → Feb 28/29). Requires explicit configuration (enableLastDayOfMonthFix()) for edge cases. Mitigation: Document and test edge cases early.
    • Performance: Virtual limit (default 732 recurrences) prevents infinite loops but may need adjustment for long-term rules (e.g., yearly events over decades). Mitigation: Use ArrayTransformerConfig to set custom limits or lazy-load recurrences.
    • Timezones: Requires explicit timezone handling (e.g., new \DateTimeZone('UTC')). Mitigation: Enforce timezone consistency in Laravel config (e.g., config('app.timezone')).
  • Testing:
    • Unit Tests: Package includes tests, but Laravel-specific integrations (e.g., with Eloquent or queues) will need additional test coverage.
    • Edge Cases: Validate with:
      • Leap years (e.g., Feb 29 recurrence).
      • DST transitions (timezone-aware rules).
      • Mixed timezones (e.g., rule created in UTC but executed in EST).
  • Dependencies:
    • No hard dependencies beyond PHP 7.4+, but Laravel’s Carbon could replace \DateTime for consistency (requires minor wrapper).

Key Questions

  1. Use Case Scope:
    • Will this power user-facing calendars (high visibility for errors) or backend systems (e.g., billing)?
    • Are there custom RRULE extensions needed beyond RFC 5545?
  2. Performance:
    • What’s the expected maximum recurrence count (e.g., 100 vs. 10,000 events)?
    • Will recurrences be pre-generated (e.g., cached in DB) or dynamically computed (e.g., on-demand)?
  3. Data Storage:
    • How will rules be stored? As raw strings, objects, or normalized data (e.g., freq, interval, until)?
    • Need for versioning if rules evolve (e.g., migrating from COUNT=12 to UNTIL=...)?
  4. Laravel-Specific:
    • Should rules be scoped to tenants (e.g., multi-tenant SaaS)?
    • Integration with Laravel Notifications, Tasks, or Events (e.g., RecurrenceGenerated event)?
  5. Localization:
    • Need for human-readable text (e.g., "Every 2nd Tuesday") in multiple languages? If so, ensure translations are bundled or extensible.

Integration Approach

Stack Fit

  • Core Laravel Components:
    • Eloquent Models: Store recurrence rules as JSON/text in DB (e.g., recurrence_rule column).
    • Carbon: Replace \DateTime with Carbon for Laravel-native timezone handling (requires minimal wrapper).
    • Queues/Jobs: Use for generating recurrences asynchronously (e.g., GenerateRecurrencesJob).
    • Events: Trigger events for recurrence generation/updates (e.g., RecurrenceGenerated, RecurrenceUpdated).
    • API Resources: Expose filtered recurrences via API (e.g., startsBetween for date-range queries).
  • Third-Party Synergies:
    • Laravel Calendar: Integrate with packages like spatie/laravel-calendar for UI.
    • Billing: Pair with spatie/laravel-invoices for subscription management.
    • Scheduling: Use with laravel-scheduler for time-based tasks.

Migration Path

  1. Proof of Concept (PoC):
    • Implement a single model (e.g., Event) with recurrence support.
    • Test RRULE parsing/generation and edge cases (e.g., monthly rules on Jan 31).
  2. Core Integration:
    • Database Schema: Add recurrence_rule column (text/json) to relevant tables.
    • Model Accessors: Add methods like:
      public function getRecurrences(): RecurrenceCollection {
          $rule = new Rule($this->recurrence_rule, $this->start_date);
          return (new ArrayTransformer())->transform($rule);
      }
      
    • Service Layer: Create a RecurrenceService to centralize logic (e.g., filtering, generation).
  3. Performance Optimization:
    • Caching: Cache generated recurrences (e.g., Redis) if computation is expensive.
    • Lazy Loading: Use generators or cursors for large recurrence sets.
  4. UI/UX:
    • Admin Panel: Add recurrence rule editor (e.g., dropdown for FREQ, inputs for COUNT/UNTIL).
    • Frontend: Use API endpoints to fetch filtered recurrences (e.g., /events?start_after=2023-01-01).

Compatibility

  • Laravel Versions: Compatible with Laravel 8+ (PHP 7.4+). For Laravel 7, may need to polyfill DateTime methods.
  • PHP Extensions: No special extensions required (pure PHP).
  • Timezones: Ensure Laravel’s app.timezone matches the package’s timezone (or override per rule).
  • Database: Works with any Laravel-supported DB (MySQL, PostgreSQL, etc.). For large datasets, consider full-text search on serialized rules.

Sequencing

  1. Phase 1: Core Logic
    • Implement Rule/Transformer in a service layer.
    • Store rules as JSON in DB.
  2. Phase 2: API/Querying
    • Add API endpoints to fetch recurrences (e.g., filtered by date range).
    • Integrate with Eloquent scopes (e.g., Event::whereRecurrenceStartsBetween(...)).
  3. Phase 3: UI/UX
    • Build admin interface for rule creation/editing.
    • Add frontend components to display recurrences (e.g., calendar views).
  4. Phase 4: Optimization
    • Add caching for frequent queries.
    • Implement background jobs for generating large recurrence sets.

Operational Impact

Maintenance

  • Dependencies:
    • Monitor for breaking changes in the package (low risk; MIT license, active repo).
    • Pin version in composer.json (e.g., ^2.0) to avoid surprises.
  • Testing:
    • Unit Tests: Add tests for Laravel-specific integrations (e.g., model accessors, API responses).
    • Integration Tests: Test recurrence generation with edge cases (e.g., DST, leap years).
    • End-to-End: Validate full workflow (e.g., create rule → generate events → display in UI).
  • Documentation:
    • Internal docs for:
      • Common RRULE patterns (e.g., "How to set up a yearly event on the last Friday of the month").
      • Edge cases (e.g., "Handling Jan 31 monthly recurrences").
      • API usage (e.g., "Fetching recurrences for a date range").

Support

  • Debugging:
    • Logs: Log RRULE strings and generated recurrences for auditing.
    • Validation: Add input validation for RRULE strings (e.g., reject malformed rules early).
  • User Errors:

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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
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