Expand description
Laravel-to-Larust conversion tooling behind xr convert. Never wired
into larust-support’s facade - this is build-time/dev tooling, never a
generated app’s own runtime dependency, so it lives outside the “one
dependency surface” rule that governs everything apps depend on. See
docs/ARCHITECTURE.md’s “Laravel conversion” section for the two core
design decisions this whole crate is built around: third-party
(composer) packages are never auto-ported, and PHP business logic is
never auto-translated - only mechanically-regular structure is.
Modules§
- assets
- Copies the source Laravel app’s static asset files -
public/and the pre-buildresources/css/resources/jssource - into the converted project verbatim. Every converted Blade template already references these exact paths (/images/...,/css/app.css,/favicon.ico, …) unchanged (an asset path is a plain string literal, never PHP/Blade syntaxblade::exprwould translate), and Larust servespublic/directly at the URL root (ServeDirinlarust-core’sApplication) the same way Laravel’s own webserver docroot does - so without this phase, every converted page renders unstyled and imageless even though its own HTML is otherwise correct. - blade
resources/views/**/*.blade.php→resources/views/**/*.blade.xr. Seedocs/ARCHITECTURE.md’s “Laravel conversion” section for the whole-file (not per-item) safety rationale:crates/larust-macros/src/ view.rs’sview!macro consumes a template as one indivisible unit, so a bad directive or expression can’t be safely omitted mid-file - either the whole file translates cleanly, or none of it is trusted. That rationale still holds for most failures - seescan.rs’s own module doc comment for the one deliberate exception (a top-level@phpblock) and why it’s safe.- codegen
- Shared “write a generated file and wire it into the module tree”
primitives, used by both
xr make:*(larust-cli::generate) andxr convert(this crate’s own converters). Originally lived as private functions inlarust-cli::generate- moved here,pub, becauselarust-clidepends onlarust-convert(not the reverse), so a new crate generating controllers/models/etc. from a Laravel app couldn’t reach them as private functions in a crate that depends on it. One source of truth for the real edge-case handling here (rollback-on- failure, placeholder-collision guards) beats a second copy nothing keeps in sync. - composer
composer.json→ third-party package report. No PHP parsing needed here -composer.jsonis plain JSON, read withserde_json(already a workspace dependency).- config
config/*.php→config/app.rs(the framework’s own typed bootstrap fields) plusconfig/{file}.rs(everything else). Laravel’s config system takes an arbitrary set of dotted keys across many files; Larust’sConfig(crates/larust-core/src/config.rs) is a small, fixed, known struct - only [MAPPINGS]’s keys can become a typedConfigfield, soconvert(the narrower of this module’s two converters) really does have to name a key “no known Config field” and leave it out of that struct.- constructor_
props - Shared constructor-property extraction for
events.rs/jobs.rs- both a convertedEventand a convertedJobare simple field-only structs whose fields come from the Laravel class’s own constructor. Real Laravel code uses two styles, both detected here: modern constructor-promoted properties (public function __construct(public Order $order) {}) and the older explicit-property-plus-assignment style (public $order; public function __construct(Order $order) { $this->order = $order; }) - both produce the same flat field list. - controllers
app/Http/Controllers/*.php→ enriches Phase 1’s already-generatedtodo!()controller stubs (convert.rs’sgenerate_controller_stubs, driven byroutes::referenced_controllers) with each stubbed method’s original PHP body preserved as a comment - no logic translation, no smarter parameter typing (both explicitly out of scope, natural later enhancements). If the real source controller file doesn’t exist, or a specific stubbed method isn’t found in it, that method just gets Phase 1’s existing bare stub - this module only ever adds a comment, never removes Phase 1’s own guarantee that every referenced method compiles.- discover
- Recursive directory discovery - needed for the first time by Blade
(
resources/views/**nests arbitrarily); Phase 1/2a’s migrations/ config/requests directories are all flat (oneread_dircall each), so nothing before this needed it. - env
- Source Laravel app’s
.env→ the new Larust app’s.env. A plainKEY=VALUEtext format on both sides, so - unlikeconfig.rs’s PHP source - this needs no real parser, just line-oriented splitting. - events
app/Events/*.php→#[derive(Clone)] pub struct Name { pub field: Type, ... }-larust_events::Eventis a pure blanket impl overClone + Send + Sync + 'static, no derive macro, no required methods (verified againstcrates/larust-events/src/lib.rs), so a converted event needs nothing beyond a field-only struct matching the realPostCreatedshape. Fields come entirely fromconstructor_props::extract- whole-item safety, matching that module’s own rationale: an event’s field list has to be exactly right or not emitted at all, since it’s the whole struct.- jobs
app/Jobs/*.php→#[derive(Serialize, Deserialize)] pub struct Name { ... } impl Job for Name { const JOB_TYPE = "..."; async fn handle(&self) -> Result<(), AppError> { todo!() } }. Fields viaconstructor_props::extract, same whole-item safety asevents.rs.handle()’s original body preserved as a comment viaphp::body_as_comment- the same “preserve, never translate” treatment ascontrollers.rs/policies.rs.- livewire
- Reads two more mechanical things straight out of a Laravel Livewire
component’s own PHP source, beyond the route/mount shell
xr convert’s caller already builds around everylivewire_componentroute entry: - migrations
database/migrations/*.php(Schema::create/Schema::table+Blueprint) → Larust’s own migration format, which is raw SQL files (NNNN_snake_case_description.sql, applied in filename-sort order - seelarust_orm::migrate), not a DSL. Column-type mapping verified against the real files underdemo/database/migrations/.- models
app/Models/*.php→#[derive(Model)]structs, with relationships. Split intoschema(reads Phase 1’s own converted SQL - the authoritative field source),fields(SQL→Rust type mapping, whole-struct safety),relations(relationship detection + verified Laravel default-argument inference, per-attribute safety), andinferred_fields(the no-migration fallback - see its own doc comment) - mirroringlarust-macros’s ownmodel.rs/relations.rs/belongs_to_many.rssplit. Seedocs/ARCHITECTURE.md’s “Laravel conversion” section for the whole-struct-vs-per-attribute safety rationale.- php
- Thin wrapper over
tree-sitter/tree-sitter-php, shared by every converter module.tree-sitter-phpwas chosen (over the alternative crates surveyed -php-parser, a brand-new single-maintainer crate with no independent evidence backing its own claims, andphp-parser-rs, explicitly alpha) for its error-tolerant CST: a syntax-error-adjacent chunk of real-world PHP still parses into a walkable tree with a detectableERRORnode, rather than aborting the whole file - the right fit for a converter whose core rule is “never silently mistranslate.” - policies
app/Policies/*.php→impl Policy<User> for Model- mirrorsxr make:policy’s ownPOLICY_TEMPLATEexactly (all 5 abilities stubbedfalse, deny-by-default), with each Laravel ability method’s original body preserved as a comment above its stub, the same “preserve, never translate” treatment ascontrollers.rs.- report
CONVERSION_REPORT.md- the trust mechanism this whole tool is built around. Every item a converter touches lands in exactly one bucket below; nothing is silently dropped, nothing is silently guessed at. Expands onrust-laravel.md’s own two-bucket sketch (“Converted automatically” / “Requires manual review”) with a third bucket for third-party (composer) packages, split into the two-tier design agreed before this crate was built: packages with a hand-curated Larust equivalent, and packages with none (named, never guessed at).- requests
app/Http/Requests/*.php(aFormRequestsubclass’srules(): arraymethod) →#[derive(FormRequest)]+#[validate(...)](crates/larust-macros/src/form_request.rs).- routes
routes/web.php/routes/api.php→ Larust’sRoute::DSL (crates/larust-http/src/route.rs).