pyrech/gcode-estimator
Estimate 3D print duration and filament consumption directly from G-code files with this PHP library. Parse toolpaths, feed rates, and extrusion data to provide accurate time and material usage estimates for your app.
Architecture fit. pyrech/gcode-estimator is a headless, framework-agnostic PHP library whose single responsibility is parsing a G-code file and deriving filament length, weight, and cost. That is a clean fit as a leaf dependency inside a Laravel application: no service provider, no config publishing, no global state, no framework baggage. It slots into a "quoting / estimation" bounded context and is easy to hide behind our own interface (FilamentEstimator contract) so the rest of the application never imports vendor classes directly.
The trade-off is that being framework-agnostic means we own all the glue: the service container binding, configuration (filament diameter, density, price per kg, currency, waste factor), input validation, file lifecycle, persistence of results, and error semantics. None of that ships with the package, and it is where most of the real product logic lives. The package computes a number; the business computes a price.
Integration feasibility. Technically high: it is a Composer package, installable in minutes, with no infrastructure footprint. Commercially/ecosystem-wise it is weak — 15 stars, a 0.569 health score, and a last release of 2020-02-23 means it has not tracked PHP 7.4 → 8.x evolution or any G-code dialect changes in roughly five years. We should treat it as a reference implementation we can vendor and patch, not a strategic dependency.
Technical risk.
composer.json PHP constraint, possible deprecated syntax (dynamic properties, ${} interpolation, each()-era patterns), and no guarantee it installs cleanly on PHP 8.2/8.3.M82/M83), firmware retraction (G10/G11), volumetric extrusion (M200), G92 resets, and multi-extruder/tool-change (T0/T1) handling all affect the result. A parser that silently ignores a construct produces a plausible but wrong number — the most dangerous failure class for a cost/quotation feature.Key questions (resolve before committing):
require constraints?cost computed — does it take a price-per-kg input and return a currency-agnostic number, or does it hard-code assumptions?gcodestat, Python gcode-parser) we should benchmark against?Stack fit. Additive and low-ceremony: composer require pyrech/gcode-estimator, bind it in a small EstimationServiceProvider, and expose one application-level service (PrintEstimator) that accepts an uploaded file plus a FilamentProfile value object (diameter, density, price, currency) and returns a typed Estimate DTO. The rest of the app depends on the DTO, never the vendor API.
Migration path. No data migration is required — this is a new capability. If we currently estimate via slicer UI screenshots or manual math, run shadow mode: compute both the legacy figure and the package figure for 20–50 historical jobs, plot the delta, and only cut over when the variance is inside an agreed tolerance (e.g., ±5% on weight). If we already use CuraEngine CLI, keep it as the fallback for files the package fails to parse.
Compatibility. Verify the package's PHP constraint against our runtime before anything else. If it declares <8.0, options are: (a) pin an older PHP for a queue-only worker container, (b) fork and bump the constraint, patching deprecations — the parsing surface is small enough that this is a day or two of work, or (c) skip the package and write the parser in-house against a well-tested grammar. Option (b) is usually the right default, but it must be an explicit, resourced decision, not a surprise in sprint.
Sequencing.
PrintEstimator contract and DTO; implement the vendor adapter; add unit tests with golden files.EstimatePrintJob on a dedicated queue with a memory limit and timeout; results persisted and cached by file hash so re-quotes are free.Maintenance. The package is effectively a maintenance orphan. Budget for a named owner and an annual (or per-PHP-minor) compatibility review. Pin the exact version in composer.json; never float it. Expect to carry a fork or a patch set. The code surface is small, so the ongoing cost is low — but it is nonzero and permanent, which must be stated up front rather than discovered later.
Support. Community-only, no SLA, no CVE feed. Internal runbook must cover: how to reproduce a failed parse, where golden files live, and the escalation path to the fork owner.
Scaling. Parsing is CPU- and I/O-bound and single-file-linear; it scales horizontally by adding queue workers, not by adding app servers. Enforce a max file size and per-job memory limit, run estimation asynchronously, and cache aggressively by content hash — the same file re-quoted should never be parsed twice. At typical volumes (hundreds to low thousands of files/day) this is a handful of workers.
Failure modes.
Ramp-up. A competent Laravel developer can integrate this in roughly half a day; a hardened, tested, queued version is 2–3 days including golden-file fixtures. The real learning curve is domain knowledge, not code: filament density and diameter tolerances, spool tare weight, purge/prime and raft/skirt consumption, waste factor, and how slicer-reported estimates differ from measured spool loss. Allocate time with someone who actually runs the printers — that is where estimation accuracy, and therefore product credibility, is won or lost.
How can I help you explore Laravel packages today?