ream88

ream88

Best Way to Structure Two Similar but Separate Phoenix Apps?

I have developed a management app and now want to create a separate front-end app that interacts with the same data. This new app needs to remain lightweight, avoiding unnecessary dependencies and assets. I’m currently facing challenges with:

  • Separation: Keeping the apps independent while avoiding duplicated configurations, such as Tailwind and custom Plugs.
  • Code Reuse: Preventing dependencies and logic from becoming out of sync or duplicated.
  • Maintainability: Striking the right balance between separation and shared code.

I’ve tried umbrella apps, a single app with multiple endpoints, and fully separated apps. However, each approach has trade-offs—either too much coupling or too much duplication. I still struggle with keeping shared logic in sync while maintaining separation.

Would love to hear how others have tackled this. And yes, I know I asked a similar question before… Sharing code across apps Pretty sure ChatGPT just reused my own question. Thanks!

Marked As Solved

ream88

ream88

I think I might have found a way that is feasible and also allows me to share most of the code base (including assets). I started using a custom ENV to change what routes are compiled and which processes are started. And after I got this working, I remembered that Nerves is using MIX_TARGET for configuring and compiling different apps out of one code base. It looks promising and I’m nearly done, maybe I will write a blog post once I got it working completely!

Also Liked

garrison

garrison

This is totally subjective and contextual. Personally when I hear “separate frontend for the same data” I think you should keep it all in the same codebase. You can always make it look to end users like it’s a different app (serve it from a different domain off the same server).

But there are some cases where that’s not true. For example if you want an “open source” part and a “proprietary” part like, say, Oban Pro.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey @ream88 to me these sorts of questions are best answered by looking at the people who are developing on them, rather than focusing on the “best” answer from a purely technical perspective. Specifically, I think you should structure the code in a way that mirrors who is ultimately responsible for each function.

If you have two distinct teams (even small teams of 1) and it’s common for features that you build for the user facing app to have 0 impact or require 0 changes to the backend app, then two distinct apps with perhaps some extracted functionality can work.

If however you have just a single team (or individual even) who is doing both, or features / PRs that you do for one often require a “paired” PR in the other, I would definitely do just a single application and use the Boundary — boundary v0.10.4 library to help delineate groups of functionality within the application.

dimitarvp

dimitarvp

Seems @benwilson512 beat me to it but IMO a single codebase + the Boundary library is your best bet. Keep it simple. The dev team can be trained.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement