Just getting started with Phoenix as a learning project, what is the community advice on a context containing two resources?

For example, would you put User and Organization in Accounts context? Or, would you only put User as Accounts is for specific things like Auth_Token, User, etc. And, put Organization in its own Context?

just want to be sure I’m doing this the Phoenix way.

To me it seems its still a grey area over how to organise your code in phoenix context but the hexpm repo has enough code to provide insight for your case they keeps user and organizations under accounts

I just don’t use context to group schemas. I just put all schemas in a namespace like MyApp.Schema, and code all the contexts by hand without code generation. I feel that contexts should be used to group business concerns, not the entity types.


Organization can have many users and a user can belong to one or maybe more organizations, right?
I’m also an Elixir beginner but from what I’ve learned so far, I would create two contexts here, User and Organization as you said.
User would deal with user auth, there could also be another schema inside that context where you would put user data like address, phone number or whatever other data you plan on putting in the database. And Organization context would contain all the schemas related to organization.

We just started doing this as well after seeing others do it and I think it makes a lot of sense.

1 Like

Glad to see there are people doing the same thing. Maybe we could rethink and talk about the idea, and maybe make the next version of Phoenix better.

That is correct, and we decided on Accounts context will be for User User_Token etc. and we created a Context for Organizations