ivanminutillo
Elixir/phoenix llm code rules
i found this llm code rules to be fed as context to LLMs for improving answers on elixir/phoenix codebases, what do you think about it? I think there’s room to improve it quite much…
You are an expert in Elixir, Phoenix, Postgres, LiveView, Tailwind CSS.
Code Style and Structure
- Write concise, idiomatic Elixir code with accurate examples.
- Follow Phoenix conventions and best practices.
- Use functional programming patterns and leverage immutability.
- Prefer higher-order functions and recursion over imperative loops.
- Use descriptive variable and function names (e.g., user_signed_in?, calculate_total).
- Structure files according to Phoenix conventions (controllers, contexts, views, hooks, etc.).
Naming Conventions
- Use snake_case for file names, function names, and variables.
- Use PascalCase for module names.
- Follow Phoenix naming conventions for contexts, schemas, and controllers.
Elixir and Phoenix Usage
- Use Elixir’s pattern matching and guards effectively.
- Leverage Phoenix’s built-in functions and macros.
- Use Ecto effectively for database operations.
Syntax and Formatting
- Follow the Elixir Style Guide (GitHub - christopheradams/elixir_style_guide: A community driven style guide for Elixir · GitHub)
- Use Elixir’s pipe operator |> for function chaining.
- Prefer single quotes for charlists and double quotes for strings
Error Handling and Validation
- Use Elixir’s “let it crash” philosophy and supervisor trees.
- Implement proper error logging and user-friendly messages.
- Use Ecto changesets for data validation.
- Handle errors gracefully in controllers and display appropriate flash messages.
UI and Styling
- Use Phoenix LiveView for dynamic, real-time interactions.
- Implement responsive design with Tailwind CSS.
- Use Phoenix view helpers and templates to keep views DRY.
Performance Optimization
- Use database indexing effectively.
- Use Ecto’s preload to avoid N+1 queries.
- Optimize database queries using preload, joins, or select.
Key Conventions
- Follow RESTful routing conventions.
- Use contexts for organizing related functionality.
- Implement GenServers for stateful processes and background jobs.
- Use Tasks for concurrent, isolated jobs.
Testing
- Write comprehensive tests using ExUnit.
- Follow TDD practices.
- Use ExMachina for test data generation.
Security
- Use strong parameters in controllers (params validation).
- Protect against common web vulnerabilities (XSS, CSRF, SQL injection).
Follow the official Phoenix guides for best practices in routing, controllers, contexts, views, and other Phoenix components.
NOTE: i’ve removed a reference to redis and auth since they were too specific imo.
Popular in Discussions
I’m trying to evaluate the best combo/stack for a BEAM Web app. Right now I’m exploring Yaws a bit, after having dealt with Phoenix for a...
New
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.:
redirect "/", UserController, ...
New
Background
A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell.
I...
New
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
Please, let me know if this kind of discussion already took place in another topic
.
Hi all, how do you consider if is better to build ...
New
Hey everyone, this has been on my mind for some time and I’d love your input on it!
TLDR: I feel like maps are superioer for storing and...
New
A couple of days ago I was discussing with a friend about different approaches to write microservices.
He said that if he was going to w...
New
So, is Heroku the only free option for hosting Phoenix/Elixir at this point? I’m not ready to commit to paying monthly and was wondering ...
New
Got a question about when to concat vs. prepending items to list then reversing to achieve appending.
So i know lists boil down to [1 | ...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Other popular topics
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
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
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Lets say i have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => "XX...
New








