Home › Elixir / Phoenix › Elixir Phoenix CLAUDE.md

Elixir Phoenix CLAUDE.md

CLAUDE.md for Phoenix 1.8 + LiveView 1.x apps in Elixir: contexts, Ecto changesets, and ExUnit tests.

Claude Code (CLAUDE.md)Elixir / Phoenix

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

CLAUDE.mdDownload  
# CLAUDE.md: Phoenix + LiveView

## Commands
- `mix setup` · `iex -S mix phx.server` · `mix test` · `mix format` · `mix credo --strict` (if present)
- Before finishing run `mix precommit` if the project defines it, otherwise `mix compile --warnings-as-errors && mix format --check-formatted && mix test`.

## Architecture
- Business logic lives in contexts (`lib/my_app/accounts.ex`). LiveViews and controllers call context functions; they never call `Repo` directly.
- Data changes go through Ecto changesets with validations; return `{:ok, struct} | {:error, changeset}` and pattern match on it.
- Use `Ecto.Multi` or `Repo.transact` for multi-step writes.
- Generators are a starting point: `mix phx.gen.live` / `mix phx.gen.context`, then trim.

## LiveView
- Use streams (`stream/3`) for lists, not big assigns.
- Forms: `to_form(changeset)` with `<.form for={@form}>` and `<.input field={@form[:email]}>`.
- Load data in `mount` only when `connected?/1` is needed for expensive work; use `assign_async` for slow loads.
- Use `push_patch` / `<.link patch>` within a LiveView, `navigate` across LiveViews.
- Authorization in `on_mount` hooks and again in context functions taking the scope/current user.

## Style
- Pattern matching and `with` over nested `case`. No `try/rescue` for control flow.
- Tests: `DataCase` for contexts, `ConnCase` + `Phoenix.LiveViewTest` for UI.

More: all Elixir / Phoenix rules · all Claude Code (CLAUDE.md) rules

Related rules

Bun runtime CLAUDE.md

CLAUDE.md for TypeScript projects on Bun 1.2+: bun test, Bun.serve, built-in SQLite/Postgres, and bundling.

Claude Code (CLAUDE.md)Bun

Django CLAUDE.md

CLAUDE.md for Django 5 projects with DRF, pytest-django and PostgreSQL.

Claude Code (CLAUDE.md)Django

Django models & migrations .claude/rules file

A path-scoped Claude Code rules file for Django models, migrations, and ORM queries, loaded only for those files.

Claude Code (CLAUDE.md)Django

Go backend CLAUDE.md

CLAUDE.md for idiomatic Go HTTP services using the standard library, sqlc and table-driven tests.

Claude Code (CLAUDE.md)Go

Go CLI (Cobra) CLAUDE.md

CLAUDE.md for command-line tools in Go 1.27 with Cobra: commands, flags, output formats, exit codes, and tests.

Claude Code (CLAUDE.md)Go

NestJS CLAUDE.md

CLAUDE.md for NestJS 11 APIs in TypeScript: modules, DTO validation, providers, and e2e tests.

Claude Code (CLAUDE.md)NestJS

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.