Phoenix phx.gen.auth for umbrella app, how to: mix phx.gen.auth Accounts User users

Hi all,

I have a clean umbrella project structured like this:

  • apps/data → Ecto + Data.Repo

  • apps/core → business logic

  • apps/admin → Phoenix app (without its own Repo)

How can I configure the umbrella project so that I can run
mix phx.gen.auth Accounts User users
inside the admin app?

elixir 1.19, phoenix 1.18.

IIRC there are 2 ways you can do this:

  1. Navigate to the child project and run the Mix task from there: cd apps/admin && mix phx.gen.auth Accounts User users

  2. Run the Mix task from the parent project: mix cmd --app admin mix phx.gen.auth Accounts User users

EDIT: Just realized you were asking about configuration, not the specific command. :upside_down_face:

The generators are not meant to handle every use case. As you noted, they either assume no umbrella, or the default umbrella with one “core” app including the database and one web app. So if you want to use phx.gen.auth, I think my approach would be to generate a fresh umbrella project and then copy over the modules to the right part and find+replace the module names as necessary…

Personally, I wouldn’t separate core from data, but that’s a different topic :smiley:

I had a memory of this being the case, but I wasn’t sure.

One workaround was to generate a non-umbrella project, generate the files in that, then move them to your umbrella project.

I might be out of line here, but I understand that the general consensus is that umbrellas are not the best tool for code organization, but are more intended for building heterogenous releases, where you might need app A and B for environment X, but you need app B and C in environment Y.

@newbie2 You may want to look into using a tradational Elixir/Phoenix application, then use a tool like Boundary to enforce cross-domain hygiene (or whatever the proper term is).

I have also seen and contributed to serious efforts to introduce various boot-time flags / variables that made the app look like something very different depending on that input.

Not super idiomatic, many would say, but it worked well, we just had to have a good discipline. Lint by lint, regex rule by regex rule, we got there. It worked great.

I don’t deny that umbrellas can do the same but they gave me enough WTFs back in the day for me to remember not wanting to risk with them again. Maybe it’s a skill issue but I’d be okay with that as well. I don’t aim to know 100% of everything in Elixir.

And yeah Boundary is great. I love it and used it many times now (ironically never in my OSS work but so far I have not needed it there).

1 Like