Write idiomatic Elixir and Phoenix code with pattern matching, small composable functions, OTP-friendly boundaries, and BEAM-aware error handling. Use when creating or reviewing Elixir code, APIs, GenServers, Phoenix apps, Ecto code, or tests.
Use this skill to keep Elixir code assertive, readable, and aligned with core language and OTP conventions.
Prefer:
Write code that feels natural to experienced Elixir developers, not translated from Ruby, JavaScript, or OO languages.
Prefer assertive code:
Prefer:
case for branching on a valuewith for linear happy-path flows that short-circuit on failureAvoid:
cond or case blocks where private helper functions would clarify intentwith ... else blocks that normalize many unrelated error shapes in one placeIf with needs a complicated else, push normalization closer to the source via small private helpers.
If with needs a lot of different error handlers, use private helpers to handle the error handling, keeping the with tidy.
{:ok, value} / {:error, reason} for expected operational failures.For maps and structs:
map.key when the key must exist.map[:key] only when the key is optional or dynamic.String.to_atom/1.When working with processes:
Avoid turning GenServers into generic service objects or dumping all business logic into callbacks.
In Phoenix code:
In Ecto code:
! only for the raising variant of an existing safe operation.?.@moduledoc and @doc for public modules and public functions when it helps users of the API.When writing or reviewing Elixir code, check: