Phoenix Framework — Productive Web Framework for Elixir
Phoenix is a web framework for Elixir that provides peace of mind from prototype to production. Channels for real-time communication, LiveView for server-rendered reactive UI, and the fault-tolerance of the BEAM VM. Built for apps that need to scale.
What it is
Phoenix is a web framework for the Elixir programming language built on top of the BEAM virtual machine. It provides a productive development experience from prototype to production, with first-class support for real-time communication via Channels and server-rendered reactive UI via LiveView.
Phoenix targets developers who want the reliability and concurrency guarantees of Erlang/OTP combined with a modern, Ruby-on-Rails-like developer experience. If you build apps that handle many simultaneous connections (chat, dashboards, IoT), Phoenix is a strong fit.
How it saves time or tokens
Phoenix's LiveView eliminates the need for a separate JavaScript frontend framework in many cases. Instead of building a React or Vue app plus a REST API, you write server-side Elixir that renders HTML diffs over WebSockets. This reduces the total codebase, avoids client-server state synchronization bugs, and cuts development time for interactive UIs.
The BEAM VM's lightweight process model means you can handle millions of WebSocket connections on a single node without reaching for external message brokers. Channels and PubSub are built in.
How to use
- Install the Phoenix project generator:
mix archive.install hex phx_new
- Create a new project and start the server:
mix phx.new my_app
cd my_app
mix ecto.create
mix phx.server
- Open
http://localhost:4000in your browser. Edit files inlib/my_app_web/and see changes hot-reloaded.
Example
A minimal LiveView counter:
defmodule MyAppWeb.CounterLive do
use MyAppWeb, :live_view
def mount(_params, _session, socket) do
{:ok, assign(socket, count: 0)}
end
def handle_event('increment', _params, socket) do
{:noreply, update(socket, :count, &(&1 + 1))}
end
def render(assigns) do
~H"""
<h1>Count: <%= @count %></h1>
<button phx-click='increment'>+1</button>
"""
end
end
No JavaScript required. The button click is handled server-side, and the HTML diff is pushed over WebSocket.
Related on TokRepo
- Automation tools -- Explore scripts and workflows for automating development tasks
- AI tools for coding -- Developer tools that pair well with Phoenix projects
Common pitfalls
- Assuming LiveView replaces all client-side JS. Complex animations, offline-first features, and heavy canvas work still need JavaScript hooks.
- Skipping Ecto (the database layer). Phoenix ships with Ecto for good reason. Fighting it or replacing it with raw SQL leads to migration headaches.
- Ignoring PubSub topology in multi-node deployments. The default PubSub adapter works on a single node; for clusters you need the Phoenix.PubSub.PG2 adapter or a Redis-backed adapter.
Frequently Asked Questions
LiveView is a Phoenix feature that renders interactive, real-time UIs entirely from the server using WebSockets. You write Elixir instead of JavaScript. Use it for dashboards, forms, search-as-you-type, and admin panels. Avoid it for offline-first apps or heavy client-side animations where JavaScript is unavoidable.
Phoenix draws direct inspiration from Rails in project structure and developer productivity. The key difference is concurrency: Phoenix runs on the BEAM VM, which handles millions of lightweight processes. Rails uses OS threads. For real-time features (chat, live updates), Phoenix has a structural advantage. For rapid CRUD prototyping, both are strong.
Yes. The BEAM VM spawns lightweight processes (not OS threads) for each connection. Phoenix Channels have been benchmarked at 2 million simultaneous WebSocket connections on a single server. This is possible because each Erlang process uses only a few kilobytes of memory.
No. Phoenix is written in Elixir, which compiles to BEAM bytecode but has its own syntax (closer to Ruby). You rarely interact with Erlang directly. Understanding OTP concepts (supervisors, GenServers) helps for advanced patterns, but the Phoenix docs teach these progressively.
Phoenix uses Mix releases for production builds. Run 'mix release' to compile a self-contained binary, then deploy via Docker, Fly.io, Gigalixir, or bare metal. For LiveView apps, ensure your load balancer supports WebSocket connections and sticky sessions if running multiple nodes.
Citations (3)
- Phoenix Framework GitHub— Phoenix is a web framework for the Elixir programming language
- Phoenix LiveView Docs— LiveView provides rich real-time UX over server-rendered HTML
- Erlang BEAM Documentation— BEAM VM handles millions of lightweight processes for concurrency
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.