Two Phoenix apps under umbrella project?

Hi all,

I’m building a simple site containing only frontend and separate admin panel. I’m not sure how to divide it properly.
The site and admin parts will use the same data underneath. Should I create two separate Phoenix apps under umbrella project? Or maybe I should deal with it in the router? Are there any guidelines how to approach this kind of cases?

Thanks,
Dawid

4 Likes

Will the admin panel be deployed on a separate server? If so, this may be a good reason to use a separate Phoenix app, with shared functionality in the umbrella app.

Will there be possibly multiple frontends with one admin panel managing them all? This may another reason to keep them separate.

As far as a simple web app goes, I would keep them in the same Phoenix application. If you find that later they need to be separated, it should be fairly straightforward if you have designed your modules and interfaces well.

4 Likes

@cichaczem, I have the same problem to solve.

I need site with modules (with its own web pages) connected, that I will be able to reuse on other sites later.

Modules, for example:

  • Authentication and authorization, connected to database.
  • E-shop, connected to database.

Also, I think it should be separate applications with different mix tasks for database creation and maybe even different databases (postgres and mongo).

2 Likes

@cichaczem, I am reading Part I: Going Deeper: The Request Pipeline in Programming Phoenix and seems that there is the answer.
Jose says that we can have separate applications running side by side. And this is described in Chapter 11.

3 Likes

After some thinking I decided my case doesn’t really fit the umbrella project apps idea. Both “apps” will share the same schemas. Both will work side by side and will be deployed to the same machine. Although they will be served from different subdomains. All this indicates the division should be handle in the app itself. Unless I’m wrong and there’s a better way of doing it.

@uranther Your comment help me clarify my thinking about umbrella apps. Thanks.

@dgamidov Yeah. I’ve read the book but example there is very different from mine. That’s why I wasn’t sure what’s better. Now I think it would bring more problems then solutions.

2 Likes

If you’re fine with serving both sites on the same port, using hostname to access on or another, you could replace the plug SomeRouter in your endpoint with a custom plug. That plug could forward to frontend or admin router based on the value of conn.host. So now you’re running two separate sites on the same port, and route based on a hostname.

The code resides in the same single OTP app, which might be fine for your case, since it seems there is some overlap. If you find these sites diverge a lot, you can always refactor to umbrella app later.

9 Likes

@cichaczem, I have made simple prototype of Phoenix application, which dependency is Phoenix application.
Authex is dependency of Lion.
Maybe you will find it useful.

2 Likes

I have a similar structure but I am getting an error saying:

Could not start application web: Web.start(:normal, ) returned an error: shutdown: failed to start child: Web.Endpoint

This is an umbrella project.

[Phoenix newbie here, but I’ve encountered something similar.]

Any chance you’re trying to run both endpoints on the same port? That’s not allowed. You would have to run each endpoint on its own port.

1 Like