AndyL

AndyL

Apps under Umbrella Project vs Phoenix Contexts

Phoenix Contexts and Umbrella Apps seem to serve a similar purpose.

Can anyone give guidelines on when to use one vs the other?

Most Liked

hubertlepicki

hubertlepicki

Just a note for both of you: these are called umbrella projects. It still consists of multiple apps, that are sorta separated.

In fact, umbrella project is just a shared configuration + some sugar to allow running mix teasks from the top directory.

For the guidelines, I would say that if you have a Phoenix project, you want to have at least 2 apps in it (wrapped in an umbrella project or manually connected). One app is for the web UI, another one is for business logic, all your services etc. You might have another app for administrator panel UI too, so you end up with 2 UI apps (Phoenix) + one pure Elixir app (that has Ecto). You might also want to extract the database access layer to own app and move ecto there, but I do not think it’s required in most cases.

Then, whenever you have a fairly stand-alone part of the system, for example a set of functionality that handles file uploads and processing: it makes sense to make it another app.

The rule of thumb when asking “if this should be an app or a module/namespace/context”, is this for me: “is it possible I will need to replace this thing as a whole in the future”? For UI front-end that might be “yes”, as the big re-design might happen. I might want to run 2 of UI interfaces in parallel in fact for some time, so it makes a lot of sense to make it an app. I might want to migrate from AWS to Google Cloud, so my file uploads app might also need to be replaced. I might have more than one admin panels, or replace it with something else like an API etc.

BTW, an API app might be a good idea to have too. It’s likely the API and UI will live their lives in parallel, and you might do very well with having an ui, core, admin, uploads and api apps, for example.

15
Post #3
cmkarlsson

cmkarlsson

Umbrella apps is just a way to write OTP applications but in the same project. The alternative to umbrella apps is to have a regular OTP application but in a stand-alone repository. The other difference between a stand-alone OTP application and umbrella OTP application is that the umbrella applications are usually more coupled and depend on other applications in the umbrella. Therefore it is easier (according to some) from a project management point of view to have them all in the same project.

An OTP application is generally the same as a software library in another language, so they should have a clearly defined boundary to hide implementation. For erlang they also have their own supervision tree and can be started and stopped and upgraded as a unit (they don’t have to have a supervision tree, they can be a library as well).

Contexts are also a way to define clear boundaries between your code components. It is however orthogonal if they are in a separate OTP application or in the same.

Hence, a Context can be “moved” from one place or another if it makes sense from an OTP point of view. For example, initially you may have a module doing something like. Event.schedule_event(...). Event is a context. Then you grow your application and you add caching, notifications and other fancy stuff inside the Event context, so much that it warrants its own supervision tree. Then you can “move” this context to another OTP application, which can be an umbrella application.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement