Back to skills
SKILL.md
Laravel Php To Rust
ASecurityPort existing Laravel PHP applications (laravel/laravel + laravel/framework) into official Laravel for Rust (laravel/rust + laravel/rust-framework) with full support for Inertia.js (React, Vue, Svelte) and decoupled frontends (Next.js, Nuxt, SvelteKit, standalone SPAs).
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added December 2, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add airshell/laravel-php-to-rust --skill laravel-php-to-rust --agent claude-codeAre you the author of Laravel Php To Rust?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/airshell-laravel-php-to-rust)---
name: laravel-php-to-rust
description: Port existing Laravel PHP applications (laravel/laravel + laravel/framework) into official Laravel for Rust (laravel/rust + laravel/rust-framework) with full support for Inertia.js (React, Vue, Svelte) and decoupled frontends (Next.js, Nuxt, SvelteKit, standalone SPAs).
---
# Laravel PHP → Laravel for Rust Migration Skill
## 1. Core Principles
- **Verify Against Installed Docs & Skills First:** `laravel/rust-framework` (`laravel-rust` crate) is in active `0.x` beta. Always consult this repository's built-in `.agents/skills/`, bundled Markdown framework docs, and `Cargo.toml` before generating code. Installed crate APIs always override assumptions from PHP Laravel.
- **Port in Vertical Slices:** Never rewrite an entire application at once. Port one complete vertical slice at a time:
`Database Schema & Model → Validation & Auth → Handler/Service → Route → Frontend Adapter → Feature Test`.
- **Preserve Existing Database Schema:** Map Rust models to existing production tables first (PostgreSQL, MySQL, or SQLite). Verify primary keys, foreign keys, indexes, enums, JSON columns, soft deletes, timestamps, and decimal precision before running any new migrations.
- **No Silent Lazy Loading:** Laravel for Rust never silently lazy-loads relationships on property access. Eager-load every required relation explicitly.
- **Strict Verification & Safety:**
- Never weaken, skip, or delete ported tests to make them pass.
- Avoid `unsafe` blocks unless explicitly approved by a human reviewer.
- Every completed slice must pass `cargo check`, `cargo test`, and `cargo fmt --check`.
---
## 2. Architecture Mapping (`laravel/laravel` → `laravel/rust`)
| Laravel PHP (`laravel/framework`) | Laravel for Rust (`laravel/rust-framework`) | Porting Notes |
| --- | --- | --- |
| `app/Models/*.php` (Eloquent) | `src/models/*.rs` (`#[model]` structs) | Explicit column types, `Option<T>` for nullable columns, `#[belongs_to]` / `#[has_many]`. No `$fillable` arrays. |
| `app/Http/Requests/*.php` | `#[laravel::input(fills = Model)]` structs | Use `#[validate(...)]` rules. Declare authorization explicitly on input structs so unauthorized inputs fail at compile time. |
| `app/Http/Controllers/*.php` | `src/http/handlers/*.rs` (`async fn`) | Return `laravel::Result<...>` with `?` propagation. Use typed extractors (`Authenticated`, `Valid<T>`, route-bound models). |
| `routes/web.php`, `routes/api.php` | `src/routes/*.rs` | Use compile-time route macros (`route!`, `redirect!`) rather than string route names. |
| `app/Http/Middleware/*.php` | Rust middleware layers | Explicitly map auth, rate limiting, CORS, and Inertia middleware. |
| `database/migrations/*.php` | Rust migrations (`db::migrations!`) | Compiled into the binary. Keep schema parity with existing PHP tables during parallel rollout. |
| `app/Jobs/*.php` / Events | Rust queue jobs / Durable Workflows | Use Rust queues (DB, Redis, SQS). Refactor multi-step delayed job chains into durable `async` Workflows where appropriate. |
| `app/Policies/*.php` | Authorization checks / input auth | Enforce policies explicitly in input structs or handlers. |
| Broadcasting (Reverb/Pusher) | Native Rust broadcasting (Reverb) | Preserve channel names, auth callbacks, and event payload shapes for frontend listeners. |
| `tests/Feature/*.php` (Pest/PHPUnit) | `tests/*.rs` (`#[laravel::test]`) | Mirror HTTP status codes, JSON/Inertia payloads, validation errors, and DB assertions 1-to-1. |
---
## 3. Frontend Integration Patterns
Identify the frontend stack before porting handlers and routes, then follow the corresponding pattern:
### A. Inertia.js Monolith (React, Vue, Svelte) — Built-In
Laravel for Rust ships with native Inertia support and Vite/TypeScript bundling.
- **Reuse existing frontend pages:** Keep `resources/js/pages/**/*` (`.tsx`, `.vue`, `.svelte`) and Inertia helpers (`Link`, `Form`, `useForm`, `InfiniteScroll`) intact with minimal or zero changes.
- **Render Inertia responses from handlers:**
```rust
use laravel::prelude::*;
pub async fn index() -> laravel::Result<inertia::Response> {
let posts = Post::query().with(Post::user).get().await?;
Ok(inertia::render("Posts/Index", props! { posts }))
}
```
- **Map Inertia v2 features:**
- `Inertia::defer(fn () => ...)` → `inertia::defer(async || ...)`
- `Inertia::lazy(...)` → `inertia::lazy(async || ...)`
- Shared props (`HandleInertiaRequests`) → Configure shared props in Rust Inertia middleware (authenticated user, flash messages, feature flags).
- Validation errors → `Valid<T>` failures populate Inertia's `errors` bag automatically via session flash.
- **64-bit integer safety:** Verify JavaScript ID handling; serialize large `i64` IDs consistently with legacy PHP if the frontend expects strings.
### B. Decoupled Meta-Frameworks & SPAs (Next.js, Nuxt, SvelteKit, Standalone React/Vue/Svelte)
When the frontend runs as a separate app consuming Laravel as an HTTP/JSON API:
- **Typed JSON DTOs:** Replace Eloquent `JsonResource` classes with `#[derive(Serialize)]` structs returned via `Ok(Json(dto))`.
- Match legacy JSON keys (`#[serde(rename_all = "snake_case")]` or `"camelCase"`) and data envelopes (`{ "data": ... }`) exactly so existing frontend clients do not break.
- **Next.js App Router / SSR Compatibility:**
- Preserve HTTP status codes (`200`, `201`, `204`, `401`, `403`, `422`) and caching headers (`Cache-Control`, `ETag`).
- Match Laravel PHP's `422 Unprocessable Entity` JSON structure (`{ "message": "...", "errors": { "field": ["..."] } }`) so existing form error handlers continue working unchanged.
- **Auth & CORS:**
- **Cookie/Session auth (Sanctum SPA mode with Next.js/Vue/React):** Configure strict CORS (`Access-Control-Allow-Credentials: true`, explicit allowed origins) and matching cookie domain/`SameSite` attributes.
- **Bearer token auth (Next.js BFF, mobile apps, external APIs):** Map Sanctum/Passport token middleware to Rust bearer-token auth extractors.
### C. Legacy Blade & Livewire
- **Blade views:** Port simple server-rendered Blade views to Laravel for Rust's template views, or migrate them to Inertia (React/Vue/Svelte).
- **Livewire components:** Do not attempt mechanical 1-to-1 translation. Refactor interactive Livewire components into Inertia pages (React/Vue/Svelte) backed by Rust handlers and `inertia::defer` / partial reloads.
---
## 4. Step-by-Step Porting Workflow
Execute these steps in order for every requested feature slice:
1. **Audit the PHP Slice**
- Read the PHP model(s), migration(s), Form Request(s), controller, policy, service classes, routes, frontend page/API consumer, and feature tests.
- Check `composer.json` dependencies used by the slice (e.g., Spatie packages, Cashier, Horizon). Consult `references/ecosystem-mapping.md` and flag missing or unstable Rust equivalents before writing code.
- Use `scripts/export-php-routes.sh` to generate a resumable, dependency-ordered `migration-manifest.json` (routes, models, migrations, and Composer package notes), and see `examples/posts-crud/README.md` for a golden vertical-slice reference.
2. **Port Models & Validation**
- Define `#[model]` structs and relationships in `src/models/`.
- Define `#[laravel::input]` structs with `#[validate(...)]` rules and authorization.
3. **Port Handlers, Services & Routes**
- Implement `async` handlers in `src/http/handlers/` and domain logic in service modules.
- Register routes in `src/routes/` with matching HTTP methods and middleware.
- Return `inertia::render(...)` + `props! { ... }` for Inertia apps, or `Json<Dto>` for Next.js/SPA APIs.
4. **Adapt Frontend (Minimal Changes Only)**
- Keep Inertia React/Vue/Svelte pages intact; adjust only prop shapes or route URLs if strictly needed.
- For Next.js/Nuxt/SvelteKit/SPA frontends, confirm response JSON shapes and `422` validation payloads match legacy PHP output.
5. **Port & Run Verification**
- Port PHPUnit/Pest feature tests to `#[laravel::test]`, covering happy paths, validation errors, authorization failures, and side effects.
- Run `cargo check`, `cargo test`, `cargo fmt --check`, and frontend typechecks (`tsc --noEmit` / `npm run typecheck`).
- Run `cargo audit` whenever introducing new third-party crates.
6. **Report Slice Status**
- List all created/modified Rust and frontend files.
- Document any behavioral differences, skipped Composer packages, or manual follow-up tasks.
---
## 5. Parallel Rollout & Strangler Fig Rules
- **Shared Database Safety:** When running PHP Laravel and Laravel for Rust side-by-side behind a reverse proxy, never duplicate destructive write operations during shadow testing. Run write comparisons against an isolated test database.
- **Incremental Cutover:** Route read-only and low-risk endpoints to Laravel for Rust first, verify response parity and metrics (latency, CPU, memory), then cut over write endpoints and background jobs.Files in this skill
- README.md
- SKILL.md
- rules/_sections.md
- rules/_template.md
- rules/app-cache-storage-http.md
- rules/app-config-env-container.md
- rules/app-console-logging-time.md
- rules/async-events-and-scheduling.md
- rules/async-jobs-and-queues.md
- rules/async-mail-notifications-broadcasting.md
- rules/auth-api-tokens.md
- rules/auth-guards-and-login.md
- rules/auth-passwords-verification.md
- rules/auth-policies.md
- rules/data-factories-seeders.md
- rules/data-migrations.md
- rules/data-models.md
- rules/data-queries.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.