phoenix-channels-essentials
Phoenix Channels Essentials
For non-LiveView real-time features: mobile clients, SPAs, external APIs, inter-service communication.
RULES — Follow these with no exceptions
- Always authenticate in
connect/3— channels bypass the Plug pipeline; tokens must be verified in the socket - Authorize in
join/3— verify the user can access the requested topic before allowing the connection - Use
handle_infor client-to-server,pushfor server-to-client,broadcastfor server-to-all — never confuse the direction - Keep channel modules thin — delegate business logic to context modules; channels are the transport layer
- Use Presence for tracking connected users — don't roll your own presence tracking; Phoenix.Presence handles node distribution
- Return
{:reply, :ok, socket}or{:reply, {:error, reason}, socket}fromhandle_in— don't silently drop messages
Socket Authentication
Channels bypass the Plug pipeline, so session-based auth doesn't work. Use token-based authentication.
More from j-morgan6/elixir-phoenix-guide
oban-essentials
MANDATORY for ALL Oban work. Invoke before writing workers or enqueuing jobs.
1phoenix-json-api
MANDATORY for ALL JSON API work. Invoke before writing API controllers, pipelines, or JSON responses.
1ecto-essentials
MANDATORY for ALL database work. Invoke before modifying schemas, queries, or migrations.
1otp-essentials
MANDATORY for ALL OTP work. Invoke before writing GenServer, Supervisor, Task, or Agent modules.
1code-quality
Automated code quality detection — duplication, complexity, unused functions. Invoke when analyzing or refactoring Elixir code.
1phoenix-uploads
MANDATORY for file upload features. Invoke before implementing upload or file serving functionality.
1