✓ Recommended
Elixir + Phoenix LiveView
Elixir with Phoenix LiveView, Ecto, OTP patterns, and real-time features.
CLAUDE.md
# Elixir + Phoenix LiveView You are an expert in Elixir 1.16, Phoenix 1.7, Phoenix LiveView, Ecto, and OTP patterns. Architecture: - Organize by bounded contexts using Phoenix contexts (lib/my_app/accounts.ex) - Contexts are the public API for each domain; never call Repo from controllers - Use LiveView for interactive UIs; minimize JavaScript - Use PubSub for real-time broadcasting between processes - Design with the "Let it crash" philosophy: supervisors handle failures Phoenix LiveView: - Use handle_event for user interactions; handle_info for server-pushed updates - Use assigns_new to avoid redundant data loading on reconnect - Use streams for large collections (replace temporary_assigns) - Keep LiveView modules focused; extract logic into separate modules - Use live components for reusable interactive elements - Use JS hooks only when LiveView cannot handle it natively Ecto: - Use Ecto.Multi for transactional multi-step operations - Define changesets on the schema module; validate at the boundary - Use Ecto.Query composable queries with named bindings - Preload associations explicitly; never lazy-load in templates - Use database constraints (unique_constraint, foreign_key_constraint) - Write migrations that are safe for zero-downtime deploys OTP Patterns: - Use GenServer for stateful processes (caches, counters, rate limiters) - Use Task.Supervisor for fire-and-forget async work - Use Agent only for simple state wrappers; prefer GenServer for complex state - Use Registry for process discovery instead of global names - Design supervision trees that isolate failure domains Testing: - Use ExUnit with async: true for concurrent test execution - Use Ecto sandbox for isolated database tests - Test LiveView with live/2 and render_click/render_submit helpers - Use Mox for behavior-based mocking of external services - Test context functions directly (not through controllers) Performance: - Use ETS tables for read-heavy shared state across processes - Use connection pooling with DBConnection (Ecto default) - Cache expensive computations in GenServer or ETS - Use telemetry for metrics and observability
Add to your project root CLAUDE.md file, or append to an existing one.