In short: move all db interactions from the context file to the repository and call it inside the context.
Please let me know what do you think about it! Is it fine or you can a better approach?
Like @theangryangel said, take a look at defdelegate though personally I think that defdelegate should only be used to delegate t methods and functions from external packages.
Example
defmodule Novistore.Accounts.Authentication do
@moduledoc """
Authentication
"""
@doc """
Check the password against the password_hash
"""
defdelegate check_password(password, password_hash), to: Comeonin.Bcrypt, as: :checkpw
@doc """
Dummy check password
"""
defdelegate dummy_check_password, to: Comeonin.Bcrypt, as: :dummy_checkpw
@doc """
Hash the password
"""
defdelegate hash_password(password), to: Comeonin.Bcrypt, as: :hashpwsalt
end
The above example allows me to switch out Bcrypt for Aragon2 in the future (if needed) without having to refactor the entire app.