anantbhandarkar/make-it-right/mir-backend-beam-phoenix
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (Phoenix module). Phoenix + LiveView + Ecto + Plug + PostgreSQL specific reliability augmentation. Chains: mir-backend (generic gates) -> mir-backend-beam (BEAM runtime) -> this (Phoenix/LiveView/Ecto/Plug library mechanics). Adds the mechanical footguns the framework-agnostic tiers omit: LiveView per-connection process memory, with streams vs temporary_assigns for large collections; the async-assign APIs (assign_async/4, start_async/4 + handle_async/3, cancel_async/3) and why a bare Task.async in a LiveView kills the LiveView on crash; handle_event as a public websocket endpoint that must re-authorize on every event; Phoenix 1.8 scopes threading %Scope{} through context functions; Ecto N+1 on unloaded associations; changeset cast/4 as the mass-assignment allow-list; and migration safety on populated tables (concurrently, disable_ddl_transaction, expand/contract, NOT VALID + VALIDATE). TRIGGER only when the BEAM backend stack is Phoenix - building, reviewing, or debugging a Phoenix controller, LiveView, channel, Ecto query, changeset, or migration. SKIP for plain Erlang/OTP applications, Nerves, and Broadway-only pipelines with no web layer (those stop at mir-backend-beam), and for every non-BEAM runtime.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-beam-phoenixSKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-beam-phoenix.
/mir-backend-beam-phoenix · Make It Right (Phoenix)
Bottom tier of the chain: mir-backend (generic gates) → mir-backend-beam (BEAM/Erlang VM process model) → this (Phoenix/LiveView/Ecto/Plug library mechanics). Run the gates first; load the BEAM runtime tier for supervision, mailbox, ETS and atom-exhaustion concerns; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (supervision trees, unbounded mailboxes, GenServer bottlenecks, `:persistent_term`, distributed Erlang, `binary_to_term`, Hex supply chain) live in `mir-backend-beam` — not here.
Stack assumed: Phoenix · LiveView · Ecto · Plug · Bandit · PostgreSQL · PubSub. Verified 13 Aug 2026 on hex.pm: Phoenix 1.8.11 (12 Aug 2026, 1.9 is unreleased and in development), phoenix_live_view 1.2.9 (10 Aug 2026, with 1.1.33 as a maintained line), ecto 3.14.1 (9 Jul 2026), ecto_sql 3.14.0, plug 1.20.3 (9 Jul 2026), bandit 1.12.4 (27 Jul 2026), postgrex 0.22.4 (7 Aug 2026), phoenix_pubsub 2.2.0. Bandit is the default adapter in generated Phoenix apps. Phoenix 1.8 requires OTP 25+. If the project uses an Ecto adapter other than Postgres, note the divergence before applying the migration-safety items — the CONCURRENTLY and NOT VALID patterns below are PostgreSQL-specific.
The Phoenix footguns AI walks into most
1. LiveView state is per-connection — memory scales with concurrent users
Each connected LiveView client is a stateful process holding all socket assigns in its heap. A list of thousands of records in assigns is multiplied by the number of connected users.
- Use LiveView streams (
stream/4,stream_insert/4,stream_delete/3) for large or dynamically updating collections. The server keeps only the diff bookkeeping; the list itself is not retained in assigns. - The template half is mandatory and is where streams silently break. The immediate parent of the items needs a unique DOM
idandphx-update="stream", and every item element needs the stream-generateddom_id. Miss either and inserts and deletes stop patching correctly — the assigns are fine, the DOM is not:
- `temporary_assigns` is not deprecated and is still a documented
mount/3option in 1.2.9 — "a keyword list of assigns that are temporary and must be reset to their value after every render." It solves a different problem from streams: it resets a value after render rather than managing a client-side collection. Use it for one-shot render data, not as a substitute for streams. - Streams fix socket memory, not query size.
stream(socket, :items, Repo.all(Item))still loads every row into the LiveView process for the duration of that call. Paginate or use a cursor in the query itself. - LiveView 1.1 added `stream_async/4` to insert stream items from an async task, and an
:update_onlyoption onstream_insert/4for updating an existing item without inserting when it is absent. - LiveView 1.1 tracks changes per item inside `:for` comprehensions, and adds
:keyso reordering produces a minimal diff instead of a full re-send:
Two LiveView 1.1 upgrade breaks that bite immediately: :phoenix_live_view must be prepended to the `:compilers` list in `mix.exs`, and Phoenix.LiveViewTest moved from Floki to LazyHTML, so the fl-contains / fl-icontains selectors no longer work — use the text_filter argument, element("main a", "Sign up").
2. Don't block the LiveView process in handle_event
A LiveView process serializes all events for that client — one handle_event/3 at a time. Heavy work inside it freezes that client's UI; if the client times out the socket drops and the LiveView remounts.
The current async APIs, verified against LiveView 1.2.9:
| API | Returns to | Use when | |
|---|---|---|---|
assign_async(socket, key_or_keys, func, opts \\ []) | Assigns an AsyncResult under each key; the function must return {:ok, assigns} or {:error, reason} | The result is the assign and you want :loading / :ok / :failed tracked for you | |
start_async(socket, name, func, opts \\ []) | Invokes your handle_async/3 with {:ok, result} or {:exit, reason} | You need to do something with the result other than assign it directly | |
cancel_async(socket, async_or_keys, reason \\ {:shutdown, :cancel}) | Kills the underlying process | Superseded searches, navigation away, an explicit cancel button |
Do not use a bare `Task.async/1` in a LiveView. Task.async links the task to the caller and leaves the exit unhandled, so a crash inside the task takes the LiveView process down with it and the user's page resets. start_async/4 also links, but it wraps errors and exits and hands them to handle_async/3 as {:exit, reason} — that wrapping, not supervision, is what keeps the LiveView alive. It is not supervised by default; pass supervisor: MyApp.TaskSup if the work must run under a Task.Supervisor. Rolling your own means Task.Supervisor.async_nolink/3.
For work the user can supersede — a search box firing on every keystroke, a filter change — reuse the same async name: LiveView already discards the earlier result when a later start_async under that name is in flight, so a slow first query cannot overwrite a fresh one. cancel_async/3 is for stopping the superseded task's actual work (the DB query, the HTTP call) rather than for ordering. Use a different name per operation and you lose the built-in ordering guarantee.
3. Ecto N+1 — unloaded associations raise, they do not silently query
Accessing an unloaded association returns %Ecto.Association.NotLoaded{}; it does not transparently issue a query the way ActiveRecord does. AI writes loops over returned structs and ships code that either fails at render or issues N roundtrips when something preloads lazily inside the loop.
- Preload what you will access, either in the query (
from u in User, preload: [:posts]) or explicitly (Repo.preload(users, :posts)). - `join` + `preload` in one query when you also filter on the association — otherwise preload issues a second query.
- In LiveView, preload in `mount/3` or in the context function that fills the assign. Never touch an association during render.
Two Ecto API notes that change what new code should look like: Repo.transaction/2 was soft-deprecated in Ecto 3.13 in favour of `Repo.transact/2`, which takes a function returning {:ok, value} or {:error, reason} and rolls back on {:error, _} without Repo.rollback/1. Repo.all_by/3 (3.13) replaces the Repo.all(from x in X, where: ...) boilerplate for simple filters. Ecto 3.14 also requires Decimal v3 — that is a transitive-dependency break, not an opt-in.
4. Ecto migration safety on populated tables
AI writes migrations as if the table is empty. In production, ALTER TABLE takes an ACCESS EXCLUSIVE lock and blocks reads and writes.
- Adding an index:
create index(:table, [:col], concurrently: true)plus@disable_ddl_transaction trueand@disable_migration_lock true—CONCURRENTLYcannot run inside a transaction. If a concurrent index build fails it leaves an INVALID index behind, which costs write time and is never used by the planner. Checkpg_index.indisvalidafter a failed deploy, thendrop index(:table, [:col])and retry, orREINDEX INDEX CONCURRENTLY. Do not reach for `create_if_not_exists` as the recovery —IF NOT EXISTSmatches on name only, so it silently skips and leaves the invalid index in place forever. - Adding a NOT NULL column: Postgres 11 and later store a non-volatile default in the catalog with no rewrite — and that includes
now(), which isSTABLE, not volatile. The rewrite comes from a genuinely volatile default:gen_random_uuid(),clock_timestamp(),random(). The safe sequence: (1) add the column nullable, (2) backfill in batches, (3)ADD CONSTRAINT ... CHECK (col IS NOT NULL) NOT VALID, (4)VALIDATE CONSTRAINTin a later step — that takes only SHARE UPDATE EXCLUSIVE, (5)SET NOT NULL. Postgres 12 and later use the validated constraint to skip theSET NOT NULLscan; confirm your server version before relying on that. - Renaming a column or table: never rename while old code is still running. Expand/contract — add the new column, dual-write, migrate reads, drop the old column in a later deploy.
- Backfilling: never one unbounded
UPDATE. It locks every row and fills WAL. Batch withRepo.update_allover a bounded id range, and put the backfill in its own migration with@disable_ddl_transaction trueso each batch commits.
5. PubSub fan-out — don't broadcast large payloads to many subscribers
Phoenix.PubSub.broadcast/3 delivers to every subscriber of a topic, and each subscriber is a separate process. Broadcasting a full Ecto struct with nested preloads copies that data into every subscriber's heap at once — see the per-process heap rules in mir-backend-beam.
- Broadcast an event name and an ID, not the struct. Each LiveView refetches exactly what it renders, scoped to its own user.
- High fan-out (thousands of subscribers on one topic) wants partitioned topics, or
:persistent_termfor data every subscriber reads identically. - Don't broadcast from inside `handle_event` in a way that cascades re-renders across every connected client per keystroke. Debounce or batch.
6. Channels — bounded joins, bounded state, bounded pushes
Channels are stateful processes, one per joined topic per client. The LiveView rules apply: don't store large collections in socket assigns, don't block handle_in/3.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-beam-phoenix/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-beam-phoenix)