| name | adversarial-elixir |
| description | Use this skill when reviewing or refactoring existing Elixir/OTP/Ecto/Phoenix code that carries an alien mental model — OO/enterprise ceremony, imperative for-loops, or defensive nil-checking ported onto the BEAM. It is the adversarial, architecture-level counterpart to greenfield idiom advice — it names the paradigm the code betrays and prescribes the deep, wide refactor that collapses it, up to deleting whole layers (repository/DAO wrappers over Ecto, service-object tiers, GenServer-per-entity "objects", DI behaviours for a single implementation, anemic maps and boolean-flag state, macro DSLs). Applies whenever the work is "make this Elixir actually Elixir", "flatten this architecture", "why is this non-idiomatic", or a pedantic review of code that fights the runtime. |
Adversarial Elixir
An adversarial, architecture-level review-and-refactor pass for Elixir on the BEAM. Where a greenfield idiom skill answers "which tool should I reach for now?", this skill takes code that already exists and imported the wrong mental model — objects, service layers, defensive control flow, imperative loops — names the paradigm it betrays, and prescribes the refactor that collapses it back to idiomatic Elixir. The refactors are deep and wide by design: they cross module boundaries and often delete an entire layer (a repository over Ecto, a service tier, a per-entity process).
Each rule names one alien pattern and the Elixir it flattens to. There is no rule for things a capable model already gets right (syntax, standard idioms, the stdlib).
When to Apply
- Reviewing or refactoring existing Elixir for architecture, not just style — "make this actually idiomatic", "why does this feel like Java/Ruby in Elixir"
- Flattening ported layers — repository/DAO wrappers, service/manager objects, DI behaviours for a single implementation, DTO/mapper tiers
- Untangling process misuse — a GenServer per entity, an Agent used as a variable, a global singleton "Manager", scattered
GenServer.call
- Fixing anemic data — free-form maps as domain objects, boolean-flag or stringly-typed state, god-structs, hand-rolled type dispatch
- Removing defensive scaffolding —
try/rescue as control flow, nil-guard pyramids, non-assertive access that leaks nil
- Replacing imperative iteration and needless metaprogramming —
reduce/recursion reimplementing Enum, macro DSLs, use-instead-of-import, compile-time coupling
For greenfield "which tool, which convention" judgment calls while writing new code, use staff-level-elixir instead — this skill is its diagnostic, layer-deleting counterpart.
Rule Categories
| # | Category | Prefix | The alien model it rips out |
|---|
| 1 | Enterprise Ceremony & Layering | arch- | Repository/DAO, service objects, DI behaviours → contexts + Ecto + pure functions |
| 2 | Processes as Objects | proc- | GenServer-per-entity, process-as-variable, singleton manager → DB/ETS + functions |
| 3 | Anemic Data Modeling | type- | Bare maps, boolean/stringly-typed state, god-structs → structs, tagged unions, protocols |
| 4 | Defensive Control Flow | flow- | rescue-as-control, nil-guards, non-assertive access → assertive matching + tagged tuples |
| 5 | Imperative Iteration | iter- | reduce/recursion reimplementing Enum → declarative pipelines |
| 6 | Needless Metaprogramming & Coupling | meta- | Macro DSLs, use-not-import, compile-time deps → functions, protocols, runtime config |
Quick Reference
1. Enterprise Ceremony & Layering
2. Processes as Objects
3. Anemic Data Modeling
4. Defensive Control Flow
5. Imperative Iteration
6. Needless Metaprogramming & Coupling
How to Use
Read a reference file when its smell shows up in the code under review. Each rule names the alien pattern, explains why the paradigm rejects it, and shows the refactor (with an Incorrect/Correct contrast where the wrong way is a real, common trap). Prefer the deepest refactor the change budget allows — flattening a layer beats patching a symptom inside it.
Related Skills
staff-level-elixir — the greenfield counterpart: which process/convention/idiom to reach for while writing new code. Use it for authoring decisions; use this skill for adversarial review and layer-flattening refactors.
Reference Files