dopatraman

dopatraman

Renaming the root folder from `lib` to `app` -- is this a bad convention?

The standard project structure is something like this:

~/
  lib/
    app/
      data/
      service/
    web/
       controllers/
       endpoint.ex
    application.ex
  test/

I’d like to rename the top directory to app instead of lib – to me it just makes sense that the top level folder is the application, and lib (library modules) are underneath it.

The Elixir community seems opinionated about this, so I wanted to start a discussion about it. What are some arguments against doing this?

Most Liked

josevalim

josevalim

Creator of Elixir

Previously Phoenix did put things in the “app” directory and many complained that “Phoenix was leading people away from Elixir conventions” or that “building a Phoenix application should not be different than any other Elixir codebase”.

It is one of the discussions that could go in loops forever, especially as it is an easy topic to get sidetracked with. So my recommendation would be to stick with the current conventions. If you really want to change it, do it in your mix.exs.

Once you choose a directory, you can do whatever structure you want inside that directory. It doesn’t have to be only my_app and my_app_web, feel free to create directories for other needs. I personally go with similar approach to @LostKobrakai (my_app, my_app_lib, my_app_web, etc).

lawik

lawik

Nerves Core Team

I don’t care if the folder is named lib or app. It could be named “stuff” honestly, but that would have more people dissatisfied. What I do care about is that there is a strong convention that is consistently used. When I pick up a project I can immediately find my way. The lib name is probably not perfect but it absolutely works well in my book.

pedromtavares

pedromtavares

If you plan on ever working with other people, I’d suggest against doing something like this. Code needs to ultimately follow a pattern so collaborators can have the lowest possible cognitive load when reading it, breaking a core convention like this because of a personal opinion is not worth it on the long run.

Where Next?

Popular in Discussions Top

vans163
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
sashaafm
I’m trying to evaluate the best combo/stack for a BEAM Web app. Right now I’m exploring Yaws a bit, after having dealt with Phoenix for a...
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54250 245
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127536 1222
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement