samrose

samrose

Custom restructuring Phoenix Framework tradeoffs question

Looking for opinions.

I am in discussion with someone who would like to restructure phoenix project file structure so that model, view, controller, and tests will be all in one folder per named “feature” (let’s say “blog”)

I am looking for feedback on what the tradeoffs would be for doing this.

The argument for it is that “everything you need to find for the feature would be in one folder. This should be easier for everyone to find and use these files”. But are there fundamental reasons not to restructure a phoenix project in this way? I know it would lose compatibility with with code generators. However, would this also push people off track in their reasoning about he code? What are the impacts if any, for doing this?

Thanks!

Marked As Solved

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Controller / view code isn’t really this way though. I definitely agree with you that "model" code definitely doesn’t belong to a specific controller. However for controller / view stuff there’s a decent argument for favoring a “pod” structure.

While not exactly the same, LiveView definitely takes more of a “page” oriented structure since with a given live view + leex / heex template you generally have a bunch of functionality all right next to each other.

stefanchrobot

stefanchrobot

I use that approach in my app and I’m pretty happy with it! I don’t use generators though. I even have two separate “myapp_web.ex” files - one for the SSR app and one for the API:

- lib
  - foo
    - ...
  - foo_web
    - app
      - session
        - new.html.heex
        - session_controller.ex (use FooWeb.App, :controller)
        - session_view.ex
      - ...
    - mobile_api
      - message
        - message_controller.ex (use FooWeb.MobileApi, :controller)
        - message_view.ex
      - ...
    - app.ex
    - mobile_api.ex
BartOtten

BartOtten

In practice, it’s never about the extremes though. As there is a ‘data’ App and a separate ‘web’ AppWeb both styles can be used together.

If we look at how the phx generator creates the data app, we see vertical slicing as far as I can remember. Except for migrations which are all in one folder*. It’s the web app that (historically) uses horizontal slicing and although it can be beneficial, I rather use vertical slicing there too.

LiveView seems to move towards vertical slicing, with the template files next to the rest of the code for a page/view.

*Django puts migrations within the ‘feature’. Con: touch two features at once and you have two separated migration files.

Last Post!

stefanchrobot

stefanchrobot

I use that approach in my app and I’m pretty happy with it! I don’t use generators though. I even have two separate “myapp_web.ex” files - one for the SSR app and one for the API:

- lib
  - foo
    - ...
  - foo_web
    - app
      - session
        - new.html.heex
        - session_controller.ex (use FooWeb.App, :controller)
        - session_view.ex
      - ...
    - mobile_api
      - message
        - message_controller.ex (use FooWeb.MobileApi, :controller)
        - message_view.ex
      - ...
    - app.ex
    - mobile_api.ex

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement