deby22

deby22

Mayby its not a Elixir/Phoenix problem, but i have it in Elixir project, so i think this is right place for this question.

So. I have a project build from 3 services. All build on Elixir/Phoenix
Frontend → just for test. In the future will be rewritten to React probably
Auth → module for authenticate. based on guardian
Core → whole system. Including REST API and Console Admin.

And now i have few question.
First one is how to deal with multi services data. I mean for example register form. One of required field is for example your favourite food. Another is your weight. That fields doesn’t fit to Auth module.

So i decided to build system like this
Front (html) send request to Front Controller
Front Controller send request via Tesla to Core Service
Core Service prevalidate fields and then send request to Auth Service
Auth Service validate own fields (like password), and if everything is OK, save new user and send back info do Core Service.
Corve Service save other fields including uuid given from the Auth system

Is this correct way to to this?

Front --> Core(pre validation) --> Auth(validation and save) --> back to Care(save) --> back to Front with succes message.

There is few issue. First one, how to deal with validation of another system. For example password field. Core doesnt have to know anything about password. But if i don’t validate this field user won’t know that password is invalid unitl i ask Auth for it.

Another solution is send request from front to both services. But what if one of them have invalid data? It should like below?

# register_controller.ex
  def register(conn, params) do
    with  {:ok, validated_client_params} <- API.Core.validate(params),
            {:ok, validated_user_params} <- API.Auth.Core.validate(params),
            {:ok, client} <- API.Core.create_client(validated_client_params),
            {:ok, user} <- API.Auth.create_client(validated_user_params) do
            render("submit.html", client: client, user: user)
    end
  end

But there is 4 request to do simple thing like create new user. SLA of this solution is terrible.


Second question is related of this topic.
What if i have many fields on form but they are from different bounded_context in my backend?
Like i said before i have AUTH like another service (security policy)
In Core i have few bounded context.

  • Client for basic information about client
  • Limits for restrict acces to resources
  • Foods for food catalog
  • Diet for create new diet plan based on foods and related to clients or dietician.

So how should i implement it if on register form i have to put field from diet context, like → prefered diet, or mentioned favourite food, to better target diet advertisement?

I’m thinking about register scope/controller/view. This is only virtual scope. By virtual i mean only in web parts. This concept won’t appear in my contexts.

It could looks like this

# web/api/register.ex
  def register_controller(conn, params) do
     with {:ok, client} <- Clients.create(params),
             {:ok, food_preferences} <- Foods.create_if_not_exist(params),
             {:ok, diet_mentor} <- Diet.related_dietician_mentor(params),
             {:ok, diet_preferences} <- Diet.create_diet_preferences(params) do
                conn |> ...
   end
 end

# clients.ex
def create(params), do: Client.changeset(params) |> Repo.insert()

# foods.ex
def create_if_not_exist(params), do: ...

If anyone need to change the same field in the future i have to add another controller but now in separated bounded_context. registration context is just for keep whole process consist and isolatet from external word. I mean Front apps shouldn’t know which fields are related to which bounded context. Core could save all of this fields to keep “copy” but source of true is bounded context which update state.

Thanks for any advice!
Mayby there is easier way to do that?

Any good books/wideos to read/watch. On Elixir ofc.

I watched this wideo twice: https://youtu.be/l3VgbSgo71E
I think its pretty good, but still i don’t know how to deal with this concept in practice :expressionless:

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
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
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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 &amp; 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