Ecto is not your how to do it well?

I’ve come across a number of opinions in the Elixir community talking about how your domain model and your database models are best kept separate (ex: Dave Thomas and Lance Halvorsen). This is great since I’ve run into that issue in previous programming environments (Python + SQLAlchemy).

At some point, though you need to make your application’s state persistent. Can anyone point me to resources about how to do this (presumably with Ecto) in a way that preserves separation of concerns?


Hello, welcome to the forum.

I think it should be

  • Phoenix is not your application for Lance Halvorsen
  • No Ecto, because never Ecto for Dave Thomas

Which is not the same as Ecto is not your app.

In the first option, it just says your web part is not your business part.
The second is more do not develop around DB.

When You start a new project, there will a separation between Business and Web.

Ecto is in the Business part. Contexts create boundaries.

1 Like

Thanks for the quick reply! “Ecto is in the business part” is helpful. Are there any example repos, posts, or books that anyone can point me to, though?

1 Like

Maybe this

Or search about contexts… this has been widely commented.

1 Like

There is also a chapter on application design in the Ecto Book :003: Funnily enough, I posted about it last night in the Ecto Book Club thread: (you might also find this discussion interesting: Discussion: Don't add a database layer to your Phoenix application)

Ecto follows the Repository Pattern which helps separate the pure from the impure and Phoenix encourages working with Contexts, which is made easy by Ecto. The Ecto book says Phoenix Contexts were inspired by the concept of bounded contexts as described in the Domain Driven Design book.

Also, @sasajuric just posted a new package today Boundaries - enforcing boundaries in Elixir projects which may also be of interest.

If you haven’t read it, I highly recommend the Ecto Book - it’s so easy to read as the examples are clear and easy to follow. Check out my interim review here :smiley: