Laravel inside Rust? I have a reason for that.

Daniel Reis - Feb 26 - - Dev Community

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!

. . . . . . . . . . . . . . . . . .