sammkj

sammkj

I’m a bit confused about what context really is after reading the Phoenix Context Guide. From the guide, it seems like Accounts context deals with everything related to users (registration, authentication, etc.). But aren’t those supposed to be its own contexts? So which of the following is the right way to define context?

Option 1

  • Accounts
    • register_user
    • login_user
    • update_user_profile
  • Merchants
    • register_merchant
    • update_merchant_profile

Option 2

  • Accounts
    • register_user
    • register_merchant
  • Authentication
    • login_user
  • Profiles
    • update_user_profile
    • update_merchant_profile

or maybe other options?

Showing Posts 1 to 9

wmnnd

wmnnd

You’re right, depending on the structure of your application it might make sense to draw different lines between the contexts. Since it is just a question of how you want to organize your application, it doesn’t really matter as long as the way you split your contexts is reasonable and understandable.

In the example you give, I would also say: It depends.
It depends on what the individual functions do. I. e.: Are Merchants also Users? Does Merchant use a different schema than User? Answering those questions might help you decide which functions belong to the same context and which don’t.

sammkj

sammkj OP

If Merchants are not Users (two different schema), does it still make sense to use option 2? In my mind, an Account is an account on a given app. The account could be of type User or Merchant.

AstonJ

AstonJ

Also check out these threads:

:023:

wmnnd

wmnnd

Since there will probably be additional Merchant functions in the future, Option 1 seems quite reasonable.
Since Users are also going to be their own thing, an additional Users context might also be a good idea.
And one more thing: Maybe consider renaming Users to Customers in order to be clearer when it comes to the wording.

jwipeout

jwipeout

it seems to me option 2 makes more sense because it will keep the context small. I am still unclear if we are suppose to keep our contexts from growing out of control with a huge amount of functions being placed in them? Anyone know the answer? @chrismccord

In rails i would abstract methods out of the model into small service objects, but I am still unclear what path we are recommended to take.

EssenceOfChaos

EssenceOfChaos

@sammkj - There is no “right” or “wrong” way to build your application. It ultimately comes down to whatever makes the most sense to you for your specific use case. You’re already on the right track by considering your application structure beforehand, a benefit of Phoenix’s contexts.

As to your question regarding the two options, the second option does look better. The contexts are simply a formality that encourage name-spacing and allow you to write decoupled code. By starting to develop with contexts in mind you’re setting yourself up for easier refactoring in the future. So, if you should choose option 1 or 2 today and in the future change your mind, you’ll be able to restructure the application without much hassle.

nsin08

nsin08

Nice talk

sic

sic

Contexts are basically features of your app.

Or practically, a business activity.

For example, in a FinTech company, one of it’s activities/services is offering loans to its clients.

Being a tech company, they want to automate it. So they ask the dev team to build a functionality to automatically send loans to clients.

LoanOffer now could be your context (translated from a business activity to a feature of their webapp)

In that activity you could guess now that the collaborator objects (Schemas) would be Loan, Client, Disbursement (for wiring the money), etc.

Another example is Facebook’s bookmarks. That is a feature right? In that context you have the Post itself, BookmarkGroup (videos, articles to watch later), etc. You get the point.

Also in scrum teams, you can also map the epics as being the contexts in your app. Cause epics are basically features of an app.

LostKobrakai

LostKobrakai

To be honest I feel this is putting to much into the idea of phoenix contexts. While phoenix had to come of with some form of contexts to be able to provide generators for them I feel the idea is much broader: Do not put business logic in your web layer, but create an plain elixir setup of modules with functions for it.

Not being more concrete allows for everyone doing phoenix to decide what makes most sense for their project. People can go a hardcode hexagonal arch. route with all sorts of layers and abstractions or have a single core context (when the business domain is not to complex). It however also has the downside of not being super obvious to beginners, as they cannot be guided to a one-size-fits-all solution and possibly need external/additional knowledge.

— All posts loaded —

Where Next? Top

Trending in Questions Top

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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews