One definition.
A repository, written once in Rust.
Three interfaces.
An HTTP API, an OpenAPI document, and MCP tools for AI agents.
One rule guards all three.
A person or an AI agent: refused at the same line.
Build a new backend.
Three commands, then one file per model.
-
Create a Laravel for Rust app
laravel new my-api --rust -
Add Restify
cargo add laravel-restifyThen register it in
src/app.rs, inside.with_providers(..):providers.add(restify::Restify::new());. Its commands come with it. -
Brief your AI coding agent
laravel restify:installIt writes two skills into
.agents/skillsand.claude/skills, and lists them inAGENTS.md. An agent working in the app then knows how a repository is written, and where the guides for your version are.
One file per model.
What clients may send, what a response shows, what is related, and who may do what.
#[laravel::input(fills = Comment)]
#[validate(authenticated)]
#[derive(Schema)]
pub struct NewComment {
#[validate(required, exists(Post::id))]
pub post_id: i64,
#[validate(required, min_length(2))]
pub body: String,
}
impl Repository for CommentRepository {
type Model = Comment;
type Store = NewComment;
type Update = EditComment;
fn fields() -> Vec<Field<Comment>> {
vec![
Field::new(Comment::post_id).matchable(),
Field::new(Comment::body).searchable(),
Field::new(Comment::created_at),
]
}
const MCP: Option<McpTools> = Some(McpTools::INDEX.show(true));
fn related() -> Vec<Related<Comment>> {
vec![
Related::through::<UserRepository>(Comment::user, |comment| &comment.user),
Related::raw(Comment::post),
]
}
async fn authorize(action: Action, request: &Request, comment: Option<&Comment>) -> laravel::Result<()> {
match (action, comment) {
(Action::AllowRestify | Action::Index | Action::Store, _) => Ok(()),
(Action::Show, Some(comment)) => request.authorize(CommentPolicy::show, comment).await,
(Action::Update, Some(comment)) => request.authorize(CommentPolicy::update, comment).await,
(Action::Delete, Some(comment)) => request.authorize(CommentPolicy::delete, comment).await,
_ => Err(laravel::abort(403)),
}
}
}
The whole API, served.
No controllers and no routes to write. Register the repository, and it answers.
impl Repository for CommentRepository
HTTP JSON:API
GET /api/restify/commentsLists a page:?search=?post_id=?related=user,post?page=?perPage=GET /api/restify/comments/{id}Shows onePOST /api/restify/commentsCreates onePUT /api/restify/comments/{id}Changes one, checking every field’s rulesPATCH /api/restify/comments/{id}Changes the fields it sendsDELETE /api/restify/comments/{id}Deletes one
OpenAPI 3.1
laravel restify:openapiThe document of every endpoint, for API clients and SDK generators
MCP AI agents
comments-index-toolAn agent lists commentscomments-show-toolAn agent reads one, under the sameauthorize
Declare them, and the same file also serves bulk requests, actions and getters, nested routes and file uploads.
Move a PHP app.
Export it, import it, replay it until every answer matches.
-
Describe and record the PHP app
composer require --dev binarcode/laravel-restify-rust-migrate php artisan restify:rust-installYour AI coding agent can take it from there: type
/restify-migratein Claude Code. By hand,restify:exportdescribes the app andrestify:recordsaves what it really answers. -
Write the Rust app from it
laravel restify:import ../php-app/restify-manifest.jsonModels, repositories, fields, filters and routes, in Rust. What is code in PHP, such as the body of a policy, becomes a numbered task in
MIGRATION.mdfor your agent. -
Replay until it matches
cargo test --test restify_parityIt replays PHP’s recorded answers and names every difference. Green means the same API, on the same database, with the same tokens. The whole guide.
Recorded in PHP. Replayed in Rust.
41 recordings. 697 requests. The same answers, but for a short list of documented differences.
45 MiB
The whole server at its highest peak under load. A quarter of the code of the same endpoints written by hand, in the same memory.