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

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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

We're in Beta

About us Mission Statement