Emily

Emily

Umbrella projects vs. stand alone apps as a dependency

I’m going through Dave Thomas’s video course, “Elixir For Programmers”. In the course he talks about decoupling & maintaining that decoupling.

He recommends seperate apps over an umbrella project.

What he says makes a lot of sense, but I believe there must have been a lot of thought going into the umbrella project design.

I don’t have enough programming experience to comment & would like to hear the counter arguments.

(For more context, a “rant” quote from Dave:)

A Personal Rant About Kitchen Sink Web Apps
When you create a new Phoenix application, you end up with over 7,000 files spread over more than 1,000 directories—a total of about 45Mb.

Now most of these are not part of Phoenix itself—they are third party dependencies. In fact, over 90% of this is JavaScript.

But, ignoring all this, we’re still faced with the potential for another kind of bloat. Although Phoenix 1.3 is better in this regard than its predecessors, it still tempts developers to include their application code alongside the Phoenix code, either directly or as a so-called umbrella app.

Part of this temptation is the directory structure itself. Why is there a separate web subdirectory under gallows if we aren’t supposed to put non-web code somewhere?

Part of the temptation is also the fact that the ecto database interface code is included by default in every new Phoenix app. A pure web interface has no need of a database—all persistence work should be performed in services.

I strongly suggest you fight the temptation to stick everything in the Phoenix app. As we’ve been building our hangman game, we’ve been working hard to build code into separate, well defined applications. We’ll continue to do this as we add Phoenix integration.

If, in some future app, you fall victim to the pressure to put all your code into a single Phoenix basket, then it isn’t a disaster. But, when you finish, look at the result and ask yourself if it might be better structured as a set of isolated components.

Most Liked

michalmuskala

michalmuskala

Yup, config handling is different because of how it is generated. It’s nothing inherent, though, if you look at the config files (and the config_path: "../../config" setting in mix.exs), you’ll see you can easily change how it works to have a per-app config.

hubertlepicki

hubertlepicki

Biggest difference lies in how the umbrella apps are generated, and in fact their configs. So in umbrella project all the relevant config files from all the apps will be loaded, i.e. config is shared by default.

When you build the project from multiple independent apps, you can either do that, or not. For example, I can have separate config/test.exs for each app, so I can test those in isolation (and even in parallel), mock some stuff in ui app and hit the database in db app (or other way around, as I please).

So the biggest advantage of not having umbrella project is that you don’t share the same config across all apps and it’s up to you how you configure it all.

mkaszubowski

mkaszubowski

@hubertlepicki Can you elaborate a bit on how umbrella project is making it harder to deploy your applications separately?

In my experience there’s no much difference between keeping the applications as an umbrella or as completely different projects. If you keep respect the boundaries between the applications, I think the only difference in that umbrella project lets you run mix tasks for everything at once which is really convenient for running tests.

One problem we had with umbrellas is that because they are compiled into one directory, they allow you to call functions from other applications without explicitly declaring dependencies in the mix.exs file. This is a big problem because you may even create a circular dependencies if you aren’t careful. To prevent this, we decided to build and test every application separately. Fortunately, we can do this on CI.

I guess the key is to keep the applications separated and decoupled. The way you do it - may it be an umbrella project or a set of independent applications in separate repositories - is not much of a difference.

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
cvkmohan
The upcoming Phoenix 1.6 release looks very interesting. Became a habit to watch the commits - and - what they are bringing in. phx.gen...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New

Other popular topics Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement