apply-phoenix-liveview-conventions
Apply Phoenix LiveView Conventions
Use this skill when writing new LiveView modules or modifying existing LiveView code to ensure consistent, idiomatic Phoenix patterns.
Precondition: Invoke phoenix-liveview-essentials before this skill for the full callback lifecycle reference.
Canonical FP bar: docs/fcis-engineering-rules.md — Functional Core, Imperative Shell: pure domain modules; side effects at edges. Keep LiveView/controller callbacks thin; delegate business rules to contexts/pure modules.
RULES — Follow these with no exceptions
1. Always add @impl true before every callback (mount/3, handle_event/3, handle_info/2, handle_params/3, render/1)
2. Initialize every assign to a safe default in mount/3 — the disconnected render must never raise KeyError
3. Guard side effects with if connected?(socket) — PubSub subscriptions, timers, and async work run only when the WebSocket is connected
4. Return {:noreply, socket} from handle_event/3 and handle_info/2 — never {:reply, ...} unless replying to a client push
5. Assign errors to the socket via put_flash or changeset assigns — never raise inside a callback
6. Export reusable function components with def, not defp — private components cannot be used across templates
7. Use with for 2+ sequential fallible operations instead of nested case
8. Never query Repo directly from a LiveView — delegate to context functions