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

Osmose Laravel Package

agog/osmose

Osmose is a Laravel package for elegantly filtering Eloquent queries via dedicated filter classes. Generate filters with an artisan command, define rules in a residue() array, and apply them with sieve() using built-in direct, callback, and relationship drivers.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Eloquent-Centric: Perfectly aligned with Laravel’s Eloquent ORM, leveraging query builders natively. Reduces boilerplate for common filtering patterns (e.g., direct column filters, relationship joins, callbacks).
  • Separation of Concerns: Encapsulates filtering logic in dedicated Filter classes, decoupling business rules from controllers. Follows Laravel’s service-layer patterns.
  • Extensibility: Supports custom drivers (e.g., DirectFilter, CallbackFilter, RelationshipFilter) and allows for future additions via the OsmoseFilterInterface.
  • Global Functionality: The osmose() helper reduces verbosity for simple use cases, though explicit sieve() calls offer more control.

Integration Feasibility

  • Low Friction: Composer install + Artisan command (osmose:make-filter) scaffolds filters in seconds. Minimal configuration required for basic use.
  • Laravel Ecosystem Compatibility:
    • Works seamlessly with Laravel’s request validation (e.g., validate input before filtering).
    • Integrates with API resources (e.g., Resource::collection()) and pagination (->paginate()).
    • Supports Laravel’s caching (e.g., cache filtered query results).
  • PHP 8+ Support: Leverages modern PHP features (e.g., typed properties, named arguments), reducing compatibility risks in new Laravel projects.

Technical Risk

  • Learning Curve: Developers unfamiliar with Laravel’s query builder or filter patterns may need training. The residue()/bound() methods require understanding of rule syntax.
  • Performance Overhead:
    • Relationship Filters: May introduce N+1 query risks if not optimized (e.g., with() eager loading).
    • CallbackFilters: Custom logic could lead to inefficient queries if not benchmarked (e.g., complex where clauses).
    • Mitigation: Profile queries with Laravel Debugbar or Xdebug; use ->toSql() to inspect generated SQL.
  • Version Lock-In: Breaking changes in v3.0.0 (PHP 8, namespace shifts) may require updates. Monitor changelog for deprecations.
  • Edge Cases:
    • Null/Empty Requests: bound() rules always execute, which may conflict with optional filters.
    • Date Handling: Carbon dependency adds complexity for time-zone-aware queries (e.g., created_at ranges).
    • Mitigation: Test with edge cases (e.g., ?gender= or ?role= with no value).

Key Questions

  1. Filter Granularity:
    • Should filters be model-specific (e.g., UserFilter, ProductFilter) or domain-agnostic (e.g., AdminFilter for all admin queries)?
    • Tradeoff: Granularity improves reusability but increases scaffolding effort.
  2. Performance SLAs:
    • Are there queries where filtering must complete in <100ms? If so, benchmark RelationshipFilter with large datasets.
  3. Custom Drivers:
    • Will the team need to extend the package (e.g., add a FullTextFilter for search)? If so, evaluate maintainability of the Driver interface.
  4. Testing Strategy:
    • How will filters be tested? Unit tests for residue() logic vs. integration tests for query correctness?
    • Recommendation: Use Laravel’s QueryBuilder assertions (e.g., expectsQuery() in Pest).
  5. Documentation Gaps:
    • Are there undocumented limitations (e.g., nested relationship filters, orm-specific quirks)?
    • Action: Review GitHub issues (e.g., #42 on date ranges).

Integration Approach

Stack Fit

  • Laravel Projects: Ideal for any Laravel 9+ app using Eloquent. Avoid if using raw PDO or non-Laravel PHP.
  • API-First Apps: Excels at standardizing API query params (e.g., /users?role=admin&status=active).
  • Admin Panels: Reduces backend logic in controllers (e.g., replace if ($request->has('gender')) with GenderFilter).
  • Non-Laravel PHP: Not applicable; tightly coupled to Laravel’s request handling and Eloquent.

Migration Path

Phase Action Tools/Commands
Assessment Audit existing filters (e.g., manual where clauses in controllers). Search for ->where( in codebase.
Scaffolding Generate filter classes for critical models. php artisan osmose:make-filter UserFilter
Incremental Replace one controller’s filtering logic at a time. Start with high-impact endpoints (e.g., dashboards).
Global Adopt osmose() helper for simple cases (e.g., public APIs). Publish config if using custom namespaces.
Optimization Profile and optimize slow filters (e.g., add with() for relationships). Laravel Debugbar, Xdebug.

Compatibility

  • Laravel Versions: Tested with Laravel 9+ (PHP 8+). Avoid Laravel 8 or older due to PHP 7 deprecation.
  • Eloquent Features:
    • Works with relationships (belongsTo, hasMany, belongsToMany).
    • Supports accessors/mutators (filters operate on raw DB columns).
    • Soft Deletes: Respects deleted_at if the model uses it.
  • Third-Party Conflicts:
    • Request Validation: Combine with Laravel’s FormRequest for input validation before filtering.
    • API Packages: Conflicts unlikely, but test with tools like spatie/laravel-api or fractal.
  • Database: Agnostic (MySQL, PostgreSQL, SQLite). No raw SQL dependencies.

Sequencing

  1. Start with DirectFilters: Replace simple where clauses (e.g., ?status=active).
  2. Add RelationshipFilters: Handle complex joins (e.g., filtering users by their roles.name).
  3. Implement CallbackFilters: For custom logic (e.g., ?search=term with full-text search).
  4. Adopt bound(): Enforce mandatory filters (e.g., admin-only queries).
  5. Global osmose(): Shortcut for low-complexity endpoints.

Operational Impact

Maintenance

  • Pros:
    • Centralized Logic: Filters live in App\Http\Filters, reducing controller bloat.
    • Reusability: Share filters across APIs, admin panels, and CLI commands.
    • Type Safety: PHP 8 typing reduces runtime errors (e.g., residue() must return array).
  • Cons:
    • Filter Bloat: Overuse of CallbackFilter can scatter logic across many files.
    • Testing Overhead: Each filter requires unit/integration tests for edge cases (e.g., empty requests).
  • Best Practices:
    • Naming: Use PascalCase for filters (e.g., ActiveUserFilter).
    • Documentation: Add PHPDoc to residue() explaining available query params.
    • Deprecation: Monitor for breaking changes (e.g., v3.0.0’s namespace shift).

Support

  • Debugging:
    • Query Inspection: Use ->toSql() or dd($filter->sieve(Model::class)->getQuery()).
    • Request Dumping: Log $request->all() before filtering to verify input.
    • Common Issues:
      • Filter Not Applying: Check residue() keys match request params exactly (case-sensitive).
      • Performance Issues: Profile with DB::enableQueryLog().
  • Community:
    • Limited Activity: 47 stars, infrequent updates. Rely on GitHub issues for support.
    • Alternatives: Consider spatie/laravel-query-builder if osmose lacks features.
  • Error Handling:
    • Graceful Degradation: Wrap sieve() in try-catch for invalid inputs.
    • Validation: Pair with Laravel’s validation (e.g., Rule::in(['admin', 'user']) for role params).

Scaling

  • Performance:
    • Large Datasets: Use ->cursor() for pagination or ->chunk() for batch processing.
    • Caching: Cache filtered results (e.g., Cache::remember('filtered_users', 5, fn() => $filter->sieve(User::class)->get())).
    • Database Indexes: Ensure filtered columns (e.g., gender, role_id) are indexed.
  • Concurrency:
    • Thread Safety: Filters are stateless; safe for queue workers or concurrent API requests.
    • Rate Limiting: Combine with Laravel’s throttling for public APIs (e.g.,
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.
terminal42/code-quality-tools
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