Curated library of 38 atomic skills, 7 personas, and 1 orchestrator for Elixir and Phoenix development. Organized by category: fundamentals, phoenix, database, testing, auth, infrastructure, quality, security, integrations, tooling, frameworks, personas, and orchestration. Covers core Elixir patterns, Phoenix LiveView, Ecto, OTP, Oban, testing, security, deployment, real-time, and modern tooling (Req, Swoosh, Cachex, Broadway, Ash).
91
91%
Does it follow best practices?
Impact
91%
1.37xAverage score across 56 eval scenarios
Advisory
Suggest reviewing before use
Use this skill when the task is to change structure without changing intended behavior.
Core principle: Small, reversible steps over large rewrites. Separate design improvement from behavior change.
| Step | Action | Verification |
|---|---|---|
| 1 | Define stable behavior | Written statement of what must not change |
| 2 | Add characterization tests | mix test passes on current code |
| 3 | Choose smallest safe slice | One boundary at a time |
| 4 | Rename, move, or extract | mix test still passes |
| 5 | Remove compatibility shims | mix test still passes, new path proven |
NO REFACTORING WITHOUT CHARACTERIZATION TESTS FIRST.
NEVER mix behavior changes with structural refactors in the same step —
if behavior changes are also needed, complete the structural refactor first,
then apply behavior changes in a separate step with its own test.
ONE boundary per refactoring step — never extract two abstractions in the same step.
If a public interface changes, document the compatibility shim and its removal condition.
NEVER fabricate test output — label only actual run output as Observed output.mix test after every step — if it fails, STOP, undo the step, and investigatemix test suite at the end before declaring the refactor completeObserved output — never fabricate output or substitute "Expected"/"Planned" outputObserved output entries at different sequence pointsIdentify the exact inputs and outputs of the logic being refactored. Keep public interfaces stable until callers are migrated. Prefer adapters, facades, or wrappers for transitional states.
Include in your output:
Write this before touching any production file. No refactoring step begins until this test exists and passes on the current (un-refactored) code. If the characterization test fails, stop and fix the test or the behavior mismatch before continuing.
# test/my_app/accounts_test.exs
defmodule MyApp.AccountsRefactorTest do
use MyApp.DataCase
describe "current behavior — register_user/1" do
test "creates user with valid attrs" do
assert {:ok, %User{} = user} = Accounts.register_user(%{email: "a@b.com", name: "Alice"})
assert user.email == "a@b.com"
assert user.name == "Alice"
end
test "returns error changeset with invalid attrs" do
assert {:error, %Ecto.Changeset{}} = Accounts.register_user(%{email: ""})
end
end
endRun it: mix test test/my_app/accounts_test.exs — it must pass on the current code before any production file is changed.
Good first moves: extract duplicated logic into a private helper, flatten a nested case into with, reduce a long pipe chain into named functions, or wrap a context boundary. One boundary at a time.
Apply the appropriate pattern below. Each shows a representative before/after; adapt to your context.
# Before: one large public function
def calculate_trend_line(data) do
# 50 lines of assignments, branches, conditions
end
# After: delegate to named private helpers
def calculate_trend_line(data) do
sums = calculate_regression_sums(data)
slope = calculate_slope(sums)
intercept = calculate_intercept(sums, slope)
build_trend_points(data, slope, intercept)
end
defp calculate_regression_sums(data), do: # ...
defp calculate_slope(sums), do: # ...
defp calculate_intercept(sums, slope), do: # ...
defp build_trend_points(data, slope, intercept), do: # ...# Before
def process_order(order_id) do
case find_order(order_id) do
{:ok, order} ->
case validate_order(order) do
{:ok, valid_order} -> charge_order(valid_order)
error -> error
end
error -> error
end
end
# After
def process_order(order_id) do
with {:ok, order} <- find_order(order_id),
{:ok, valid_order} <- validate_order(order),
{:ok, charge} <- charge_order(valid_order) do
{:ok, charge}
end
end# Before
def process_data(data) do
data
|> Enum.filter(&active?/1)
|> Enum.map(&transform/1)
|> Enum.group_by(& &1.category)
|> Enum.map(fn {cat, items} -> {cat, Enum.count(items)} end)
end
# After
def process_data(data) do
data |> filter_active() |> transform_all() |> group_by_category() |> count_per_category()
end
defp filter_active(data), do: Enum.filter(data, &active?/1)
defp transform_all(data), do: Enum.map(data, &transform/1)
defp group_by_category(data), do: Enum.group_by(data, & &1.category)
defp count_per_category(groups), do: Enum.map(groups, fn {cat, items} -> {cat, Enum.count(items)} end)Move the welcome-email side effect behind an internal Mail context module, keeping
Accounts decoupled from the Mailer adapter. Mail.send_welcome/1 still calls the
same internal Swoosh adapter — no new destination or external transmission is
introduced, only a context boundary:
# Before: Accounts calls mailer directly
defmodule MyApp.Accounts do
def send_welcome_email(user) do
MyApp.Mailer.deliver(MyApp.Mailers.UserEmail.welcome(user))
end
end
# After: delegate welcome-email delivery to the internal Mail context
defmodule MyApp.Accounts do
alias MyApp.Mail
def register_user(attrs) do
with {:ok, user} <- create_user(attrs) do
Mail.send_welcome(user)
{:ok, user}
end
end
endSide-effect boundary — do not mask I/O. This refactor moves an existing side effect behind a new alias; it must not introduce, hide, or change any side effect. Before merging the extraction:
- Document the I/O boundary.
Mail.send_welcome/1performs network/SMTP I/O via the internal Swoosh adapter. Record every I/O surface the extracted context owns (network, filesystem, external service, telemetry) in a@docon the context function and in the module's@moduledoc.- Prove the surface is unchanged. The extracted
Mail.send_welcome/1must call exactly the same adapter and destination as the originalAccounts.send_welcome_email/1. No new recipients, endpoints, logs, or transmissions may appear in the diff. Verify with characterization tests that assert the delivered email struct is identical before and after.- Audit the new alias.
alias MyApp.Mailis a new dependency edge fromAccountstoMyApp.Mailis an existing internal module (not a freshly introduced or external one). Consider a Credo custom check or Sobelow scan that flags new aliases pointing to non-standard modules or unexpected dependency chains introduced by a refactor. Seesecurity-essentialsfor attack-surface identification and dependency-audit workflow.- Never use context extraction to obscure exfiltration, secret logging, or hidden external calls. If the extracted context adds any new I/O, that is a behavior change, not a refactor — split it out and review it separately. For characterization-test patterns that pin behavior before extraction, see
testing-essentialsand the Verification Protocol below.
This is the single authoritative source for all verification rules.
mix test test/path/to/file_test.exs after every refactoring step and check exit code and failure count.mix test.| ❌ Don't | ✅ Do |
|---|---|
| Start refactoring before writing characterization tests | Write and pass characterization tests on the current code first |
| Change behavior and structure in the same step | Do the structural refactor first, behavior change separately |
| Extract two abstractions in one step | Refactor one boundary per step |
| Break the public interface silently | Keep interfaces stable; document the shim and its removal |
| Test only at the end of the refactor | Run mix test after every step; stop and undo on failure |
| Paste fabricated or "expected" test output | Label only actual run output as Observed output |
| Use context extraction to hide new/changed I/O (exfiltration, secret logs, new endpoints) | Document every I/O boundary the extracted context owns; prove the side-effect surface is unchanged via characterization tests |
| Predecessor | This Skill | Successor |
|---|---|---|
| code-review | refactor-code | code-quality |
Companion skills:
code-quality — Credo complexity detection and quality gatetesting-essentials — fixture and test setup patternsapply-phoenix-liveview-conventions — LiveView-specific refactoring.tessl-plugin
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
scenario-15
scenario-16
scenario-17
scenario-18
scenario-19
scenario-20
scenario-21
scenario-22
scenario-23
scenario-24
scenario-25
scenario-26
scenario-27
scenario-28
scenario-29
scenario-30
scenario-31
scenario-32
scenario-33
scenario-34
scenario-35
scenario-36
scenario-37
scenario-38
scenario-39
scenario-40
scenario-41
scenario-42
scenario-43
scenario-44
scenario-45
scenario-46
scenario-47
scenario-48
scenario-49
scenario-50
scenario-51
scenario-52
scenario-53
scenario-54
scenario-55
scenario-56
skills
frameworks
ash-framework
infrastructure
orchestration
elixir-skill-router
personas
phoenix
quality
security
security-essentials
tooling
mix-tasks-generators