Actix-web: Is there any document on how to structure actix applicaiton.

Created on 20 Apr 2020  路  11Comments  路  Source: actix/actix-web

I have worked in fat and thin both frameworks. I feel actix comes somewhere in between.

It is not fat like Ruby on Rails. And also not thin like Sanatra. It is some where in between.

My question is how creators of Actix like to arrange or architect their application. Project or folder structure. Or something totally else.

I know actix is very flexible. but that also comes with problem of choosing how to do things.

I hope I m not asking question at wrong place. if that is the case please direct me to right place.

Most helpful comment

One more interesting thing about having recommended best practice is that soon after that we could start building tools for generating some part of code based on some inputs, or some basic application templates or similar. It for sure can not generate a production-ready application, nut it should not for sure (what we would do for a living than :D), but it could make some basic structure that could save some time and typing... at least for some standard tasks... I hope that this has some sense :)

All 11 comments

If you've not found it yet, the examples repo attempts to display best practices. Most examples are focussed and single file but there are a few (eg. simple_auth_server) that span multiple files you can reference.

The readme on that repo also has a bunch of community examples.

In general, actix-web aims to be flexible enough to support many project layouts.

@robjtede thanks for reply. I did found it. And question is because of that only. As many community example are bending actix in all direction. It did show the potential but also add to confusion for new comer like me.

@kunjee17 I have found this blog very useful for beginners (myself included). It extracts model, routes and similar into separate modules and for me that looks good enough... but I'm a beginner too... I will also submit PR for examples later today or tomorrow with an example of how to use sqlx with actix-web using a similar organization... I hope this could helo little :)

@zmilan this is what I was looking for. Or may be very near to it. Thanks man for sharing.

I m keeping this issue open, if someone else like to share any update. Else authors please feel free to close it.

@kunjee17 you are welcome... I supposed that it could be useful since I'm in similar situation, and I was very happy when I have found this blog :)

Will leave open for a week or so, if you have any thoughts on best structure for getting going or other beginners recommendations we could add to the website for instance please feel free to share :)

@robjtede I have also found this youtube channel useful for beginners

About structure for most applications that I have planned to build structure from example above is totally good.

src

  • main.rs
  • module1

    • mod.rs

    • model.rs - DB model

    • routes.rs - end points under /module1

  • module2

    • mod.rs

    • model.rs - DB model

    • routes.rs - end points under /module2

  • module...

Issue with this is that when you open multiple files with same name inside IDE it could be hard to find which one belongs to which module (until you check path).

Anyway, I will also be happy to get some feedback on this structure or to see some framework best practice. I also like that actix-web is really flexible but with this kind of flexibility comes issues with choosing right/ the best way to do it... so from my point of view I would like to see actix-web flexible as it is now, but with some community chosen best practice which you can follow if you don't have specific requirements...

One more interesting thing about having recommended best practice is that soon after that we could start building tools for generating some part of code based on some inputs, or some basic application templates or similar. It for sure can not generate a production-ready application, nut it should not for sure (what we would do for a living than :D), but it could make some basic structure that could save some time and typing... at least for some standard tasks... I hope that this has some sense :)

@zmilan regarding the structure you suggested. I totally in favor of that. Most modern IDEs can figure it out files based on history. But I do have trick to solve this problem. Instead of model.rs I go for personModel.rs . So, it is more easier to search in different text editors and IDEs.

@robjtede We should have some guide lines around best or recommended structure as well. If as framework we can't have then it would be great to have something like awesome-actix page. (I am managing awesome-fable ). It will seriously help other community members as well. Examples are good thing but not every person like to start from code. My 2 cents.

@kunjee17 yes I agree, if you not use exact same names in all modules, each editor will handle it properly and in open tab will display something that is more recognizable than if each has same name

@robjtede I guess we can close this issue. Please do the honors. And also let us know if we can help to add this things to documents if that is good idea.

Was this page helpful?
0 / 5 - 0 ratings