Sanjibukai

Sanjibukai

Elixir with Ecto (and Phoenix without Ecto)?

Hello everybody,

Tl;Dr: How to decouple the “web interface” from the “business logic” when a database is involved.

I watched the following talk from 2016 given by Lance Halvorsen https://www.youtube.com/watch?v=lDKCSheBc-8 about “Phoenix is not your application”.

I don’t know if this is something rather accepted in Elixir/Phoenix communities or if it’s only the thought of the speaker.. But I couldn’t agree more with this statement.
Particularly coming from Rails where Rails is considered your application (to quote DHH).. Which I never really agree with that.

I even heard about not using at all Ecto within Phoenix apps (applying --no-ecto) and letting a regular Elixir app taking care of the business logic. An example I heard is from the course Elixir for Programmers by Dave Thomas. But it seems (I didn’t took the course yet) that in this case the business logic doesn’t use a database.
And I somehow understand how the Phoenix web app will communicate with the Elixir “domain” app using OTP.

But, I wonder if this approach is still applicable to application that have a business logic that actually uses a database.
And so, if Ecto is intended to be used solely with Elixir? I mean without Phoenix..
Or put it in another way I want to know if Phoenix is doing a lot under the hood in using Ecto.

But I also took a look at the following talk from 2017 given by Chris McCord https://www.youtube.com/watch?v=tMO28ar0lW8 where he explains how Phoenix from 1.3 is distinguishing the web part (the web interface) from the logic/domain part.

So I wanted to ask you, Elixir/Phoenix folks, what’s the best approach you’ve experienced?

I’m asking this question in the context of an application that could become relatively large and complex regarding the logic/domain..

I’ve already had a bad experience with Rails working with large applications (very probably also because of a bad design too) and I really love the approach of having applications completely decoupled regarding the web interface and the business logic.

I hope this makes sense and I’m sorry if it’s rather confusing and also for the bad English..

Most Liked

outlog

outlog

No, we just tend to mix them all up - call the DB directly in controllers/channels etc. - have business logic in controllers/channels etc. etc.

It makes good sense to keep them seperate - say in MyApp(ecto and business logic) and MyAppWeb(phoenix that calls MyApp for data and data processing)

this is a great talk on DDD - but also look into various materials on using “Contexts” search this forum etc.

ps: in a large app you might even see multiple Phoenix apps..

ityonemo

ityonemo

I have deployed elixir with no Phoenix or ecto, elixir with ecto and plug and no Phoenix. I’m currently deploying elixir with a phoenix admin panel, and a json API in plug (no ecto)… It all depends on what you need.

Where Next?

Popular in Questions Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement