Contexts [1] are not a standard nor Phoenix specific. All my Elixir projects that deal with data have contexts.
Context is the practice of creating a public API for your (database) models, opposite to having your controllers access directly your DB and database objects. Gives you better testability, better isolation, better code architecture.
def change_password(user_id, new_password):
# The Accounts module hides all the complexity and implementation details
user = Accounts.get_user_by_id(user_id)
Accounts.change_user_password(user, new_password)
render(password_changed.html, user)
That's really just it. It's a best practice which is prominent in the Ecto and Phoenix docs, but not necessarily applicable to those libraries only, or to Elixir only in fact.
Context is the practice of creating a public API for your (database) models, opposite to having your controllers access directly your DB and database objects. Gives you better testability, better isolation, better code architecture.
So instead of (in pseudocode):
you'd do: That's really just it. It's a best practice which is prominent in the Ecto and Phoenix docs, but not necessarily applicable to those libraries only, or to Elixir only in fact.1: https://hexdocs.pm/phoenix/contexts.html