ream88

ream88

Hi everyone,

I’m working on a well-established Phoenix application that has grown quite a bit, and I now need to create a separate Phoenix app to act as a back office for managing the data and operations of the main app. The existing app has a lot of schemas and helper functions that I’d like to reuse in this new back office application to avoid duplicating code.

What I’m trying to achieve:

• Set up a new Phoenix app for back office functionality.
Reuse existing schema files (and some helper functions) from the main app in this new app.
• I don’t want to create an umbrella app or move things into a standalone library.
• I’m considering using git sparse-checkout to manage only the parts of the codebase I need in the back office app, but I’m not sure if this is the best approach. I know that mix has support for it, however while testing my back office app wasn’t able to find modules defined in the other app.

What is the best approach here?

Showing Posts 1 to 10

Sorc96

Sorc96

We’ve done someting like this at work with a Ruby app. We used a git submodule for the common parts, but eventually realized that we were basically reimplementing a package manager using git.

If I was to do this again, I would first seriously consider keeping everything as one application. If that got ruled out, I would probably make a regular library from the common code, so that it would be managed the same way as all other libraries.

But then it’s important to be very careful about what this common code depends on. Our apps share some dependencies that are really only needed by one of them, but the submodule was pulled out ad hoc without anyone puting in the effort to really make it reusable, so it’s kind of a mess.

D4no0

D4no0

I don’t know if you want to introduce complexity from git into your codebase, I personally wouldn’t consider this as a viable option.

Depending on how your projects are organized, I would recommend to have the shared code separated in a library, but in the same repo (a monorepo that hosts both the projects and the library). In this way you can use the option of local dependency and not worry about maintaining separate variants for the library codebase and version them:

defp deps do
  [
    {:local_dependency, path: "path/to/local_dependency"}
  ]
end
cmo

cmo

If you must split it off, then +1 to path dependencies in a monorepo. You would end up with applications like app, app_back_office, app_common and app_web_common. Check out [workspace] for working with a monorepo.

dimitarvp

dimitarvp

Monorepo with different applications – not an umbrella. And path dependencies.

Though I’m curious why making a library out of the common code is not an option.

al2o3cr

al2o3cr

TBH I don’t understand the anti-umbrella vibes; the alternatives suggested all sound like umbrellas with extra steps :man_shrugging:

dimitarvp

dimitarvp

You are more regular here than me, you are telling me you don’t remember the objective arguments against them?

TBF I don’t remember them but I’ve tried umbrellas, the whole package, from ideation to deployment and they had drawbacks I was not willing to live with. And other people expressed the same and made lists. I did not save those lists but again, there were good reasons.

Though in this case of this thread in particular, I don’t get the anti-library sentiment more.

D4no0

D4no0

From the experience I’ve had, umbrella projects bring in more problems than they solve. Starting from configuration handling to OOM issues when fetching dependencies for multiple umbrella projects.

The idea of umbrella projects is to have separated OTP apps and that is a hard requirement only for a very few specific projects.

al2o3cr

al2o3cr

More like “didn’t particularly pay attention to”. You can find folks who’ll decry the use of ANYTHING - even if statements! - and I wasted waaaaaaay too much time arguing with that sort in Rails-land.


I’ve seen an umbrella solve OP’s specific problem very efficiently - the system was one that coordinated delivery companies (+ drivers) and stores. The key problem the umbrella solved was keeping UIs for different audiences entirely separated; apps were roughly like:

  • core: giant ball of DB schemas + business logic
  • store_web: UI for stores to use to submit & track delivery requests
  • driver_web: UI for drivers to use when making deliveries. Mobile-first, designed to tolerate drivers losing network connectivity intermittenttly
  • dispatcher_web: UI for the dispatchers to manage their driver’s work and check status

We didn’t do anything fancy for deployment like splitting subparts (for instance, deploying core + store_web separately) but the built-in boundary checking means we could.

This setup really showed its benefit when Bigco asked us for a new interface that would let Bigco management admin all of their stores. It found a straightforward home as a new bigco_admin_web, with a separate asset pipeline so BigCo could have their logo plastered on everything.

Another nice momement was when we needed to add SAML as a login option, but only for stores. This involved “splitting” the login form to ask for email first, and then either prompt for password or redirect to the IdP. Since each audience has its own _web, it was straightforward to modify only the one for stores.

None of these are strictly “only umbrella could do this”; a team with sufficient organization and discipline could accomplish the same thing all wedged into one Phoenix app, the same way a team like that could make a well-factored Rails monolith. Here in the real world, IMO the umbrella helped us keep things organized despite the hectic schedule of a startup.

ream88

ream88 OP

I think I need to provide more information. My goal was to find a quick and easy way to test if a back office app is feasible. I planned to launch it on fly.io without a public IP, making it accessible only via Wireguard. In the past, I’ve worked with various solutions you mentioned: monorepos, umbrella apps, and shared libraries. However, none of these solutions are simple enough for a quick Sunday afternoon hackathon. They all require structuring the code in a way that feels like premature optimization. And it is mind-boggling to me that something so simple is this hard in Elixir.

I currently have a proof of concept running with this in my mix.exs: {:app, github: "repo/app", sparse: "lib/shared", app: false, compile: false}. Then, I run Code.compile_file("deps/app/lib/shared/file.ex") to make it available.

D4no0

D4no0

If you want a quick and dirty way, can’t you just add an option to your main app to not start the application tree and just use it as a library from the thing you are currently building?

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
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
spammy
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
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
subsaharancoder
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New

Other Trending Topics Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
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
ausimian
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews