Morzaram
Hey everyone,
I have a live view app that is slowly getting bigger and I’m really struggling to find a way to manage all of the logic for each page. Components, queries, page, etc.
I was hoping to get some insight on how I can best have file structure and other tips on making sure I can manage all the code for these things. Right now I feel that the contexts are getting in the way and I should be moving the queries in a file next to the page view itself.
Any insight and resources would be much appreciated!
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cmo
I put components relevant to only the one page in a folder with or under the page. If there is a lot of web domain logic, create a
AppWeb.Whateverthat houses all of that. The extra queries I leave over inApp.Whateveror create a module under that or a new one if there is a lot of logic for a subset of the context.I feel like putting your queries in the web domain is crossing a line that a lot of people (but not all) are uncomfortable with.
Morzaram
Thanks for responding! Is there a clearer example you can give me?
For example: I have a page
MyAppWeb.Admins.Locations.Events.Indexthat has a list of events that you can:I have quite a few pages like this and its starting to feel a little overwhelming.
The more that I add here the less it feels that the query is belonging on the
Webdomain side and that background job logic belong on theMyAppside.They feel too far away from each other at this point both because it’s in a 2x nested resource and it’s a lot of logic to handle.
Therefore I’m thinking
MyAppWeb.Admins.Locations.Events.Index.Queriesfeels a bit better but I’m not sure if this the way to go.kokolegorille
Instead of passing queries from web… can You pass criteria to the queries? I use the liveview to manage parameters I send to the query
I have one list_events function that do this only by passing parameters to the query. Do You have multiple queries instead?
Morzaram
Thanks for also responding!
So you’re suggesting have a large query struct and then add conditionals based on what is in the query struct? Thus basically a god query for Events?
kokolegorille
I am suggesting a technique I learned from the book Absinthe/GraphQL..
For example…
Using this, I could probably do something like…
… and this would translate to
Morzaram
Wow this is beautiful! Thank you for this. I think this is exactly what I need
cmo
Sometimes it’s nice to have something a bit more high level than passing a keyword list of ecto query options, which can be in addition to or instead of the more low level method in the post above. Maybe you specify options
filter: filter, show_already_occured: true, after: last_event_on_pagein the web context and convert that to the lower level options in your app domain.If you feel there is too much query logic in the
Eventsmodule, you can run a separateEventQuerymodule with composable queries and functions in yourEventsmodule will pipe through them. For example, you can have aEventQuery.with_filterfunction that takes your filter (that is serialisable to URL query params) and turns it into ecto query options. In doing that, you probably don’t need to splitEvents.Indexand can flatten intoEventsjmagnani
Is it possible to follow a vertical-slice architecture in Phoenix or LiveView, to organize code?
cmo
Phoenix doesn’t impose any major constraints on how you organise your files.
mikesax
I’m (much) behind you on this journey but here are a few things things I’ve found helpful:
defdelegatemuch yet, but that seems like a great way to isolate code that takes on a life of its own and only expose what you need in your main api modules.