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
Accountsregister_userlogin_userupdate_user_profile
Merchantsregister_merchantupdate_merchant_profile
Option 2
Accountsregister_userregister_merchant
Authenticationlogin_user
Profilesupdate_user_profileupdate_merchant_profile
or maybe other options?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 9 of 9 Posts
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
MerchantsalsoUsers? DoesMerchantuse a different schema thanUser? Answering those questions might help you decide which functions belong to the same context and which don’t.sammkj
If
Merchantsare notUsers(two different schema), does it still make sense to use option 2? In my mind, anAccountis an account on a given app. The account could be of typeUserorMerchant.AstonJ
Also check out these threads:
wmnnd
Since there will probably be additional
Merchantfunctions in the future, Option 1 seems quite reasonable.Since
Usersare also going to be their own thing, an additionalUserscontext might also be a good idea.And one more thing: Maybe consider renaming
UserstoCustomersin order to be clearer when it comes to the wording.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
@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
Nice talk
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
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
corecontext (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.