rushing/laravel-data-schemas
Define structured data schemas in Laravel with a fluent API, helping you validate, cast, and transform data consistently across requests, models, and APIs. Lightweight, expressive, and easy to integrate.
spatie/laravel-data as the contract layer. The package only pays off if Data classes are already how boundary shapes are declared. That makes it the argument (and the payoff) for a doctrine: one declared class drives the schema, the API docs, and generated client types — rather than three hand-maintained copies that drift.Consider it when:
spatie/laravel-data. If Data classes aren't the pattern today, this has nothing to project — adoption cost is really the cost of migrating to Data classes, which is a much bigger decision.Look elsewhere (or build) when:
Recommendation: run a one-to-two-day spike on a real Data class with your nastiest rules (nested objects, enums, unions, nullables, examples, DB-backed rules like exists/unique). If the projection is faithful, adopt narrowly — AI tool schemas first, since the alternative there is manual drift. Otherwise, fork or walk away.
To executives: This is a small, MIT-licensed utility that turns our existing backend data definitions into JSON Schema — the format required for AI tool integrations, API documentation, and frontend validation. The strategic value isn't the package; it's that it makes "define the shape once, use it everywhere" actually enforceable, removing a recurring class of integration bugs and a parallel maintenance cost. It is early-stage software (single-digit stars, no dependents), so we should treat it as internalized code we can fork, not a vendor dependency: low cost, low lock-in, bounded scope, and no commitment until a short spike proves the output is exact.
To engineering: It projects declared spatie/laravel-data classes into JSON Schema, preserving validation attributes, descriptions, examples, and nullability. It deliberately does not infer shapes from arrays or docblocks — if a shape isn't a declared Data class, there is nothing to generate, so the discipline of declaring shapes is ours to enforce. It runs at build/CI time, not in the request path, so the integration is low-risk. Adopt only if we're already standardized on Data classes and need schema artifacts for AI tool definitions or frontend validators. Plan to vendor/fork it and own the generation path; wire a CI drift check so stale schemas fail loudly. Verify three things in the spike before committing: projection fidelity (attribute rules and rules(), nested/enum/union/nullable handling), how unrepresentable rules (exists, unique, closures) are surfaced rather than silently dropped, and the emitted JSON Schema draft. Fidelity of the projection is the one thing that matters — the rest we can absorb.
How can I help you explore Laravel packages today?