jan-swiatek

jan-swiatek

Hi,

I’m learning Phoenix for a while and I don’t get the differences between MVC and LiveView. When should I use which, or how to mix them properly? Can you give me some examples as well?

Showing Posts 1 to 9

tfwright

tfwright

This seems like a strange question, assuming you mean Model/View/Controller, since the latter is a general pattern for building software and LiveView is a very specific framework for rendering HTML server-side. The default Phoenix code structure already encourages a sort of MVC structure by encouraging you to keep business logic (Model) in contexts, and providing a template system so you can keep your mark up (View) separate from your event handlers (Controller). So really it’s only left to us as Phoenix LiveView users to try and respect the boundaries the framework has already put in place, and not put functions that generate HTML in contexts, or general business logic in specific live views, etc…

If you provide some more specific examples of things you’re confused about, maybe we can give you more specific pointers.

jan-swiatek

jan-swiatek OP

Thanks for the explanation.

I follow “Phoenix LiveView Pro” from The Pragmatic Studio. As far as I know, now I’m using LiveView for all stuff. They mentioned that there is a possibility to use LiveView only when it’s necessary using live_render() (I assume that I should use traditional MVC instead of LiveView and live macros). Which approach is better or when to use them? Please correct me if I’m wrong.

cmo

cmo

It depends.

I assume when you say MVC you mean something along the lines of the stateless HTTP request-response type of web. Plain old Phoenix gives you that. You click something, send a request to the server and it loads a new page.

LiveView maintains a connection between the server and the client over WebSockets. This allows the server to push events to the client. There are other things that you get with LiveView but this is the core difference.

tfwright

tfwright

After years of “JS all the things!” there has been some backlash and now people are starting to realize that the dev resources required to create and maintain complex SPA type software may not always be worth it. So many people are returning to standard server rendered HTML and injecting JS only where they need it for truly dynamic features. live_render makes it easy to do that, but to use LV instead of JS for those features. So as @cmo says there’s no general rule for which is “better,” rather you first have to describe what kind of app you want to build. If you are building a SPA you probably won’t need it because every view will already by a LV.

travisf

travisf

Based on the original question, with Phoenix, if you are following their patterns, you are already building with models and views. As @cmo mentioned, the C part of MVC is controllers, if you are using LiveViews you will have a live folder rather than a controllers folder. I’m not sure it’s harmful to think of them as being drastically different, the live folder will act as a sort of controller for data from the model and pass it to the view.

This is of course an over simplification but I think in theory it’s a good way to think of things.

As @cmo mentioned using controllers vs LiveView absolutely depends but you are not wedded to either one, you can create a controller for some pages that will have traditional HTTP request-responses and frontend JavaScript and LiveView for dynamic pages where you want to push data to and from the client without a page refresh. Personally, I find working with traditional HTTP request-responses tends to get pretty limited if I’m trying to build an interactive user experience so I tend to stick with LiveView as a default but it’s conditional on what the page is.

derek-zhou

derek-zhou

My only advice is don’t blend static view and LiveView until you are very comfortable with both of them. Limit your choice first; if the problem space is too vast you can easily get lost exploring.

jan-swiatek

jan-swiatek OP

Thank you guys for all replies.
I’ll try both ways in that case.

tfnielson-se

tfnielson-se

This is very helpful, I’ve been battling with how to make the connection between liveview and controllers, makes sense that the “live” folder is the “controllers” folder. If this concept is true, this just unstuck me for a while.

codeanpeace

codeanpeace

Yeah, it’s a useful analogy for sure, but it’s good to know it’s not a perfect one.

For example, a key difference is that stateless HTTP requests pass through plugs before reaching Controller actions whereas LiveView events sent within stateful connections do not pass through plugs before reaching LiveView callbacks. And this distinction introduces some important security considerations for the LiveView model around authentication and authorization.

— All posts loaded —

Where Next? Top

Trending in Questions Top

axelson
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
yasoob
Hi all! I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
Liam_or
I don’t suppose you can lazy load a library depending on runtime data? For example if it’s a certain user they can lazy load ‘library A’ ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
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
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
PJUllrich
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews