dusank/knapsack
Knapsack is a Laravel package for organizing applications into self-contained modules. It helps keep routes, views, config, migrations, and service providers grouped by module, making large Laravel codebases easier to structure, extend, and maintain.
map, filter, groupBy, reduce, zip, flatten, take/drop, chunk) over arrays, iterators, and generators. That's a meaningful slice of utility code we'd otherwise write, test, and own — directly relevant when scoping any feature that transforms large result sets.toArray(), we can ship feed ingestion, CSV/JSON exports, log triage, and report pre-aggregation as single-pass, constant-memory jobs instead of "needs a queue + chunking" architecture. This changes effort estimates, not just implementation style.foreach-filter-map-group chains are a cheap consolidation candidate — a small, well-understood diff rather than a rewrite.composer require and move on."Consider it when:
Generator/Iterator sources where array_map/array_filter would materialize too much.Look elsewhere when:
LazyCollection covers most of this natively, is maintained, and is already in the dependency tree.To executives: Knapsack is a small MIT-licensed PHP library for streaming data transformations. It lets us process large datasets in constant memory, which lowers infrastructure cost and unlocks ingestion and reporting features without new queue infrastructure. The trade-off is maintenance: last release was 2017 with essentially no downstream dependents, so we should treat it as code we adopt and own — vendor it, pin it, and cover it with our own tests. Net: low license cost, moderate ownership cost, clear win only where we have concrete streaming workloads. Recommend a short spike before committing.
To engineering: Lazy pipelines over iterables — Collection::fromArray() / fromGenerator(), then map / filter / groupBy / reduce / zip / flatten / chunk, evaluated on iteration or toArray(). Small API, fast ramp. Caveats: PHP 7-era, no upstream PHP 8 validation, no dependents to lean on, and any bug we hit is ours to fix. Plan to fork under our namespace, add PHPUnit coverage against our supported PHP versions, and keep it behind a thin internal adapter so we can swap to LazyCollection later without touching call sites.
How can I help you explore Laravel packages today?