DevotionGeo

DevotionGeo

Reimagining a new Elixir web framework with no Rails roots or MVC/*VC

Hi everyone, I’ve been thinking about Phoenix and its evolution, and I wanted to share some thoughts.

Remember how Phoenix was heavily influenced by Rails when it first came out? The routes, models, views, controllers, and overall structure felt very familiar to anyone coming from Rails. Then they added contexts, which was a bit of a deviation, but still, many of the core concepts remained Rails-like.

Now, with LiveView, Phoenix has really carved out its own identity. It’s exciting to see how it’s evolving, but I can’t help but wonder if we’re still carrying some unnecessary concepts from the Rails world (disclaimer: I love Rails).

Don’t get me wrong—I think it’s great for beginners, especially those coming from Rails or similar MVC frameworks. They can pick up Phoenix quite quickly. But here’s the thing: Elixir is a functional language, and sometimes I feel like the current design doesn’t fully embrace that.

For example, instead of having an EventController (which would be EventsController in Rails), what if we had a more generic Controller module that we could pass our “events” table or other data to? It feels like that would be more in line with functional programming principles.

What if we had a framework that wasn’t influenced by any other framework at all? Not copying directory structures or naming conventions from other frameworks. Instead, imagine a library of modules and functions that we just pass data to. We could have a Route module where we pass in a link to create a route, a Controller module (or whatever we decide to call it) where we pass in the data and get the desired result. Functions from these modules could be piped into each other, forming a pipeline that handles everything from security to serving the request.

I think a library/framework like that could be easier to understand and reason about.

What do you all think? Is there already a library/framework out there that works like this? Would something like this be useful, or am I just overthinking it? I’m curious to hear your thoughts!

Most Liked

zachdaniel

zachdaniel

Creator of Ash

I like exercises like this. We do things pretty differently, and don’t draw any true inspiration from other frameworks with Ash. It has pros and cons, we’re free to carve out our own paradigm, which is fundamentally different than anything else out there. For instance when building APIs with Ash, for example, you don’t write a single controller. Everything is derived from data. I think there is value in this thought process.

However, I think that its also important not to write off the similarities phoenix bears to rails as something akin to “well this was how rails did it so this is how we do it” type thinking. It’s a process of refinement, taking what worked well and what didn’t. If you are looking to reimagine a web framework from first principles, you’re going to have to solve a whole host of what I think are pretty surprising problems in the process.

For example, the typical problem with “one big controller module” is searchability. i.e how do I go and find the subsection of that code that handles requests from some given route. If I have to read a big pattern match to find the function head/case statement in question then I’m having to load up way more complexity in my brain to find what I’m looking for. If controllers are in their own module, I can fuzzy find files with “<thing I’m looking for> controller” and have a pretty solid hit-rate. So we end up doing things like having a case statement that calls a function on a nicely named module in a nicely named file so we can find the logic in question.

Couple that with the fact that 9 times out of 10 you end up with a controller-per route/group of routes, and the next big idea would probably be to put in your route handling code the ability for it to specify its own destination controller module, that way its super easy to go from route to controller, and then congratulations you’ve built a Phoenix router plus roughly the current controller convention.

I don’t say this to discourage this kind of thinking/work, as someone pushing against the grain myself! My goal is only to point out that it requires, I think, concretely better alternatives to what are out there and also wholistic thinking about why things are the way they are in today’s popular tools. For example, a lot of really simple patterns work amazingly in a small codebase with a small team, and fall apart when you start having 5, 10, or 100(:nauseated_face:) developers working on a large enterprise system.

So to answer your question more specifically:

It is entirely possible that there are alternative architectures to Phoenix that would be easy to reason about. But it isn’t inherently true because Phoenix bears some resemblance to and inspiration from something like rails. We’d have to talk specifics. The ideas of having one Route module and one Controller module do not sound like better alternatives to me on the surface.

12
Post #4
LostKobrakai

LostKobrakai

While I would generally agree I wouldn’t take it as such an absolute. I think one can surely build something that’s easier to learn and understand than phoenix. However any programming effort is still a matter of tradeoffs. Just because something is simpler to start out with doesn’t mean it’s automatically simpler to grow and keep maintainable in the long term. Phoenix sits in a spot for people trying to be productive and building a system, which is going to be larger than a quickly bootstrapped one, hence coming with more upfront structure and with more pieces of “you’ll likely need this soon anyways”. Striking a balance on that scale is hard.

D4no0

D4no0

I don’t think there is anything special about Phoenix itself if we talk about it in isolation. I’m not a big fan of a few magical things that came from Rails but it’s also important to know where you draw the line between declarative programming (that inherently does magic under the hood) and the explicit approach. I think imperative frameworks like express in JS, while having the easiest concepts to grasp, don’t offer a good abstraction level to solve business problems, plaguing them with complexity down the line.

Those who don’t know the past are condemned to repeat it. Unless you take your time to understand where the value of Phoenix comes from, you will never be able to come with a better solution.

Instead of having the attitude that we need to throw everything in garbage and to reinvent everything, why not improve the existing things? I’ve followed all previous conversations related to alternative microframeworks, everyone that is against phoenix failed to formulate a valid argument against using specific features of phoenix (plug, html) nor their alternatives they implemented were even as close to what phoenix provides today.

Where Next?

Popular in Discussions Top

Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
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
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
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
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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement