giusdp

giusdp

I was wondering if it’d make sense and how feasible it is to have a multi-tenant project composed of 2 phoenix apps.

One app is just an API with ash_json_api to serve the end-users, and the other is a dashboard on top of the same database, for the tenants.
The dashboard app with a AshAuthentication set up for the main users (magic link login) and the API app another AshAuthentication setup with email/password.

Both apps use the same database with schema-based multitenancy, but the dashboard also operates on the public schema for the main users (for user creation and login).

This way I could cleanly separate the 2 sides of the system, but then it’d be a mess having to keep in sync the shared domain and resources. In one I’d have to put json api routes and in the other no.

I bet there is something I’m missing and I could be able to derive the 2 apps from the same resources. Right now it’s one single otp_app that offers both json api routes and html dashboard routes. One problem is that Ash authentication is picking up both the main-user and end-user resources when accessing the dashboard (it shows both magic link and email/pass at login, and the conn has both current_user and current_end_user).

I’d like to avoid that. Also what if I need to start scaling and replicate the API? The dashboard side won’t need to scale up, probably , while the api side might receive a lot of traffic. For instance I could have 1 single user that in turn has 1 million end-users. The dashboard is used by 1 and the api is used by 1 million.

So, my question is basically how to organize such project. Would it be possible to separate the project into a multi app monorepo project or an umbrella project where I have:

  • 1 otp_app with all the shared domain and resource (with both dashboard-specific actions and json api routes);
  • 1 app for the dashboard with the router for the dashboard routes + the main accounts domain and resource with ash authentication on top;
  • 1 app for the API which has a very simple router to just redirect to the AshJsonApi Router in the shared app, plus its own end-user domain+resource with another ash authentication.

I didn’t try anything yet and it might be a silly idea that won’t work. I’d like to know from more experienced people how to organize a project like that with ash.

Showing Posts 1 to 5

zachdaniel

zachdaniel

Creator of Ash

We often don’t tend to split Ash apps up in that way, but there shouldn’t be any reason you can’t do it :slight_smile:

As for the question about it displaying bot h user resources, IIRC there is an option you can use to restrict which user resources get their authentication strategies displayed. pretty sure its an option in the router code.

giusdp

giusdp OP

@zachdaniel could you point me to the docs where I can restrict the user resources in the router? I can’t manage to find how to do it :frowning:

zachdaniel

zachdaniel

Creator of Ash

Looks like you’re right, and there is not a way to manually select the resources. I don’t have time to fully test this out myself, but I’ve pushed the changes required to support this to a branch, the PR is here: improvement: allow setting a subset of resources on sign in by zachdaniel · Pull Request #593 · team-alembic/ash_authentication_phoenix · GitHub

You would use this as sign_in_route ...., resources: [A.Specific.Resource]

giusdp

giusdp OP

Awesome! I think it will be a nice addition. I believe I saw around the forum other people needing something like this, too. I’ll try the branch out as soon as I can

giusdp

giusdp OP

I finally had the time to try the branch out and works as expected :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews