How to create a custom project structure?

Hi,

Despite the different discussion related to that same subject:
(Concept of "area" in Phoenix project structure - #4 by thiagomajesk)
(Domain-oriented web folder structure - #2 by tme_317)
I would like to ask again but in a tad different way.

My goal is to have a under lib/mini_spa a module MiniSPA that encapsulate mostly everything a view under a single root have.

MiniSPA is basically a live view that have hooks and components and live components on top of small logic bits.

My end game would be:

  • if one need to reproduce the view from a project to another they can just copy paste the module folder and only make the minimum modification in MyAppWeb/router to get it working.

This means, indeed, that the interaction between MiniSPA and the rest of the project is small and obvious.

When I naively did move it out, the view was not working properly (surprise).

My understanding the that the module MyAppWeb.ex is essential for a view to work (the use ThePortalWeb, :live_view in the live modules)
As well as where the file is actually located the location of the module for that what parent module the view belongs to.
(just moving back Mini.SPA from mini_SPA/ back under MyAppWeb/live fixed many things)

I understand why Phoenix default to the current organization of modules (if you cannot assume anything of the app intra coupling then you default to the most agnostic one) but in my case there is clear separation between views.

So far I banged my head against the wall (and my AI’ s head too) with little result.

Without going into details can one of you tell me what module/part of the project make assumption about the repo structure? So I know at least where actually look into and where not to look into to understand and change stuff.

You are welcome to tell how much of a bad idea it is too, if you feel like to.

thanks

Worth noting that all invocations of use PhoenixAutogeneratedWeb, :thing are simply doing common aliases/imports/uses for :thing. If you want source code files that stand alone and are movable without dependencies on the PhoenixAutogeneratedWeb macro, you can simply do the aliasing/importing/using at the top of the file as normal.

thanks, that was more or less my intuition.
I tried to import directly but I may have miss something since it seems that some macros use themselves other macros …
Probably need to give it a go again with a fresh and ready mind.

Probably need to give it a go again with a fresh and ready mind.

I, too, usually deviate from the Phoenix conventions on small projects. I recommend using the phx generators to create a reference project, then doing a clean phoenix installation by hand in an existing mix project—starting with adding it to mix.exs yourself. It’s very educational, quickly shows you what all the moving parts the generator spits out are doing.

2 Likes