dogweather

dogweather

Wanted: examples of well organized Phoenix LiveView apps

I feel lost in my Phoenix LiveView code base. Coming from Rails, I can’t find anything. But I also have no confidence that I’m got it organized according to best practices.

For example, where should the template for a certain page or route be? Should it be in a .heex file, or in .ex? When is one usually chosen over the other?

Are there any good examples out there of some full Phoenix LiveView apps that I can learn from?

Marked As Solved

pdgonzalez872

pdgonzalez872

I’d try running some generators and only steering away from that if you have very good reason to do so. It’s a great starting point, everyone will know where things go.

mix phx.gen.live Accounts User users name:string age:integer and so forth. Contexts are a thing, once you start, it’s very foreign to not think about problems that way.

Also Liked

sodapopcan

sodapopcan

I have your last post about this in mind and mostly balked at replying as it becomes a bit of an exhausting discussion where many people have Opions :tm: (and oh boy do I ever have Opinions :tm: myself!) For me, the best part of Rails and the worst part of Phoenix is that Rails is opinionated and Phoenix is not. Of course many people see Phoenix’s lack of opinion—atedness(?) as a good thing, but it does leave a lot of people lost.

All that is to say that the closest thing we have to best practices in Phoenix is the guides. I’d say that the most controversial part is contexts and what I’m assuming is giving you trouble in finding stuff. Oddly enough they are supposed to make that easier :sweat_smile: I love contexts and were a big part of the attraction for me. Contexts are loosely based on Bounded Contexts from Domain Driven Design. I say loosely because you are free to use them in a way that doesn’t conform to DDD’s idea, but you can absolutely use them as such! DDD is one of those things like Agile and TDD that you either buy into or you don’t. I’m personally a big fan (or parts of it at least, and I could go more into that) but of course you are not bound to it.

Even though it pains me personally to say this (:zany_face:) if you’re missing Rails then throwing all your schemas in a MyApp.Schemas namespace is perfectly acceptable. You could forgo contexts completely and add repo functions to your schemas like MyApp.User.save(user). Even Ash optionally supports this (though it would be MyApp.Accounts.User.save(user)) On the other hand, the last big Rails project I worked on used bounded contexts and it was great so, ya :slight_smile:

Asking for “well organized based on best practices” Phoenix project is a bit of a loaded question so I’d say refine it to “well organized” you’ll more likely get many different answers :smiley:

But as far what Chris was thinking in terms of context, I’d suggest at least reading about DDD’s bounded contexts if you’re curious. The neat thing about DDD is that it isn’t one of those prescriptive things where it claims you need to follow all of its advice exactly—it’s a HUGE book that openly says: “Here are a whole bunch of fleshed out ideas, maybe you want to use some of them.” It even puts a whole bunch of paragraphs throughout the book in bold text and suggests that only reading those paragraphs is perfectly acceptable to get a lot out of it.

PS I neglected your specific question to ramble:

Templates can go in either .heex or in render functions it’s totally up to you. The only metric I’ve ever heard anyone use is that they put it in a .heex file “when it gets too big.” Personally, I always put it in a render no matter how big it is.

sodapopcan

sodapopcan

Naw, heex is heex whether it’s in a .heex file or ~H sigil!

I hear you on the making things easier to find. How you name LiveViews etc is another thing that you’ll see all sorts of different advice on. While it can vary per project, I’m generally looking for home/index_live.ex if I want something on the home page.

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement