Hi, I’ve been developing a project for a few months and since the beginning i’ve been paying attention to the design of my code, writing it modular, well separated and those kind of things, but it’s been growing and i’m missing something I dont really know what. I’m often kind of lost of what a module or service returns, you now like when a module calls a module that calls a module that calls another module, and I caught myself open a few archives to check the returns. I think what is missing for me it’s some kind of architecture guide, something like interfaces to know exactly what x or y returns, so I’m here asking for some general or personal resources into that.
To give an example, I have the a controller that at some point calls another module
defp handle_answer(%{"payload" => payload, "status" => status, "meta" => meta}) when is_boolean(status) do
case status do
true -> handle_paid_pix(payload)
false -> handle_failure_pix(payload, meta)
end
end
defp handle_answer(_), do: {:error, FE.initerror("validation", "invalid payload")}
defp handle_paid_pix(payload), do: TransactionRealm.handle_pix_paid(payload)
defp handle_failure_pix(payload, meta), do: TransactionRealm.handle_pix_failed(payload, meta)
but then in this module I got more calls to another modules
def handle_pix_paid(payload) do
PixTransaction.handle_pix_paid(payload)
end
def handle_pix_failed(payload, meta) do
PixTransaction.handle_failure_pix(payload, meta)
end
def handle_pix_paid(payload) do
with {:ok, _} <- MnesiaPendingContractsDomain.update_payment_status({:payload, payload, :pix_paid}),
{:ok, _} <- EctoContractsDomain.update_payment_status({:payload, payload, :pix_paid}) do
:ok
else
{:error, _} = error -> error
end
end
def handle_failure_pix(payload, meta) do
with {:ok, _} <- MnesiaPendingContractsDomain.update_contract_meta({:payload, payload, meta}) do
:ok
else
{:error, _} = error -> error
end
end
I dont know if its on my mind but really feels like a terrible spagetthi code terrible typed and error prone. As I said at the beginnig designing that way was no problem, but i’m really a constraint that ties my code which makes it cohesive and well-fitted. Sorry if it’s a very abstract question, I tried to explain it as best I could.