Laravel inside Rust? I have a reason for that.
Daniel Reis

Daniel Reis @danielhe4rt

About: A Developer who likes to teach.

Location:
São Paulo
Joined:
Sep 13, 2020

Laravel inside Rust? I have a reason for that.

Publish Date: Feb 26 '24
126 11

What's up everyone!

I've been study Rust for the last couple of months and always trying to get closer of my actual stack which is around Laravel environment.

For me, as a PHP Developer, jump into Rust is a truly hard task since I never went to Functional Programming before, however I found a way to make this "easier".

Rust AFAIK

The whole ecosystem is made up of different packages and you should add it as you need it, unlike Laravel which has a really robust environment around the framework.

So my first impression was that I had to learn how to use the base packages:

  • Dotenvy
  • Chrono
  • Time
  • Uuid
  • and so on.

But when it comes to Web Development (API mostly) you have to choose an framework among many which is already there. Like:

  • Actix (currently using)
  • Axum (evaluating)
  • Rocket (people always tell me to not use it, still don't know why)

and none of them has the opinionated "structure" of Laravel, so I decided to create mine.

Laravel inside Rust

Why am I talking about Laravel? Because the "MVC" structure it gives us is elegant enough for small projects with Rust Web.

Things started to make sense when I coded Rust using the opinionated Laravel framework. Here's a structure of what I'm talking about:

./src
├── app.rs
├── config.rs
├── http
│   ├── controllers
│   │   ├── leaderboard_controller.rs
│   │   ├── mod.rs
│   │   └── submissions_controller.rs
│   ├── mod.rs
│   └── requests
│       ├── leaderboard_request.rs
│       ├── mod.rs
│       └── submission_request.rs
├── main.rs
├── models
│   ├── leaderboard.rs
│   ├── mod.rs
│   └── submission.rs
└── repositories
    ├── leaderboard_repository.rs
    ├── mod.rs
    └── submission_repository.rs
Enter fullscreen mode Exit fullscreen mode

This project is currently using:

and you can check my mess in this Pull Request

The question is: would be a good thing to follow this thoughts while working with Rust? The simplicity and good structure for maintaining is what I'm always looking in a project.

Also I'm thinking to write some series on how is my process migrating from PHP to Rust, would interest you read something like that?

Hope to see your thoughts here and thanks!

Comments 11 total

  • Anthony Vinicius
    Anthony ViniciusFeb 26, 2024

    Amazing post as always @danielhe4rt. Thanks for sharing your knowledge with us.

  • thalesmengue
    thalesmengueFeb 26, 2024

    What you have done is amazing, I always thought that laravel way to structure their modules is pretty organized and well structured, so, why not do this in another language if is well structured, right!?

    Great job, looking forward to see the next steps of the project!

  • Renato Teixeira
    Renato TeixeiraFeb 26, 2024

    really interesting! thanks for sharing!
    I'm starting to learn somethings about Laravel and it's curious to know that we can "copy" some structures... since I'm starting I don't know if Rust has its own structure but I think that if that's helping and working, there's no problem at all

    • Daniel Reis
      Daniel ReisFeb 26, 2024

      AFAIK, Rust developers doesn't like to opinionated in other developers Structures.

      However, there's plenty of Rust projects that you will look at the README and see something like "this is an opinionated structure using the framework X and Y tooling".

      I'm not a fan of copying things without know how it works behind the curtains, and that's why I'm following the Laravel structure.

  • Priscila Cabral
    Priscila CabralFeb 26, 2024

    Great article, Dan!

    What challenges did you face as a PHP developer transitioning to Rust, and how does incorporating Laravel into Rust development help address these challenges?

    • Daniel Reis
      Daniel ReisFeb 26, 2024

      First actual challenge was migrating to a heavy typed language. Rust doesn't allow you to do lazy typing like PHP.

      Also the immutability is a thing here. In PHP you can do whatever you want with the variables, in Rust, it must follow some patterns if you want to mutate it.

      The Laravel come when I need a more specific way to bring Web/Console/Database opinionated development, since I know each part of the framework not only in the "end user" side, but some internals as well.

  • Klecianny Melo
    Klecianny MeloFeb 26, 2024

    Excellent article @danielhe4rt ! Discovering new possibilities in technology is the action that opens up opportunities and universes for us as developers. Comparing what we are studying with what we already know is a good way to deeply understand the difference between the tools 😁

  • Leandro Proença
    Leandro ProençaFeb 26, 2024

    nice write-up! I miss a “one-person” framework in Rust too, I think such a project could make Rust more intuitive in the web scenario.

    have you seen loco.rs? it’s around this idea, heavily focused in the Rails way (which I think Laravel share some similarities)

  • Cherry Ramatis
    Cherry RamatisFeb 26, 2024

    nothing like a good old laravel architecture in every possible programming language

  • Patrica Johnson
    Patrica JohnsonMar 2, 2024

    Great job combining both the structues Rust & Laravel. Your proposed project structure looks clean and organized, Learn about Rust vs. PHP, Actix, and Charybdis ORM, switching from PHP to Rust, coding securely, setting up CI/CD, debugging tips, and managing databases. These resources are available on ProgrammingHomeworkHelp.com websites for all types of assignments, and projects. Hire their Assignment experts at +1(315)557-6473

  • SUMIT SHARMA
    SUMIT SHARMAApr 6, 2025

    I suddenly remembered about Adonisjs. Laravel in nodejs

Add comment