hubertlepicki
Avoiding circular dependencies between 2 umbrella Phoenix applications using each other's routers
So I have the umbrella project that consists of user_interface and admin applications. I want to display some links from user_interface back to appropriate admin panel section when logged in user is admin. And I also want to display links to public facing URLs in user_interface, from within admin_panel.
As you can guess I am creating circular dependency here. One application has to be compiled before the other, so I think I need to decouple these.
As far as I see it, I have the options to:
- move the routes resolution to runtime. I think either exposing GenServers with registered names on each end that expose underlying router functions will do, or I an use :erlang.apply
- use dependency injection where I would figure out the appropriate router module at run time
- hardcode the URLs

Any other ideas? What do you think would be best?
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










Marked As Solved
Gazler
In this instance, I’d probably hard-code the URLs on the basis that they are acting as 2 independent systems. I’d probably configure the base url for each so that it can be easily changed.
Assuming the admin interface is running on port 5000 and the web interface on 4000, then I’d configure it like:
Then have a module like:
If I was paranoid about these going out of sync then I’d have a 3rd application that is just for testing, that includes both applications as a dependency and assert the urls match.
This would ensure that things work even if you deploy your admin interface independently from the web interface e.g.
admin.myapp.comAlso Liked
josevalim
Agreed. Cyclic dependencies should be avoided and it is very likely you are going to run into issues, such as xref warnings. Ideally you would want to move this behind a configuration and have a explicit dependency from a → b or b → a, but not both ways (which is not even possible Mix-wise).
If you expecting too many options, then it likely means you have an artificial boundary between your applications and they should likely stick together.
michalmuskala
For me this is a similar case to having, for example, front-end URLs on back-end in a SPA application (for example a URL in an email).
My preferred way of dealing with things like that is through configuration, similar to a way that @Gazler showed. Alternatively, you could have the configuration keep an MFA you’d call at runtime to produce the link. This, of course, also has the disadvantage of not being checked at compile-time, similar to other dynamic functions.
benwilson512
It’s this assumption that is the issue. Build a release with just your admin app in it. It’s only going to have the admin app and the code from the admin apps dependencies. It isn’t going to have any code from the user_interface app.