Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 38 ยท Getting Started

What Is Phoenix?

Learn what the Phoenix web framework is, why it runs on Elixir and the BEAM, and how a request travels through endpoint, router, controller and view.

Phoenix is a web framework for the Elixir language. It gives you a router, controllers, HTML templates, a database layer (through Ecto), real-time channels and LiveView, all in one coherent package. Phoenix apps are known for low latency, small memory use per connection and code that stays readable as the project grows.

This lesson explains what Phoenix is made of and how one request moves through it. You do not need to know every part yet; the next lessons build each piece. It helps to have read the Elixir basics, especially functions and modules and maps and structs.

Phoenix needs a full Elixir and Erlang installation, which this site does not run. Phoenix and Elixir code is therefore shown read-only. The JavaScript TryIts are small stand-ins that model the ideas (a connection value flowing through functions), so you can experiment with the concepts in your browser.

Why choose Phoenix

Phoenix inherits its strengths from the platform underneath it.

  • The BEAM virtual machine. Elixir runs on the Erlang VM, designed for telephone switches that never go down. Every request runs in its own lightweight process, and a crash in one process does not take down the others.
  • Concurrency without callbacks. You write plain, sequential-looking code. The VM schedules thousands of processes across all CPU cores.
  • Real-time built in. WebSocket channels, presence tracking and LiveView are part of the framework, not add-ons.
  • Explicit code. Phoenix generates plain modules that you own. There is little hidden magic: routes are listed in one file, plugs are ordinary functions.

Phoenix is not a good fit if your team needs a huge ready-made plugin ecosystem for every possible feature (the Elixir ecosystem is smaller than Ruby's or JavaScript's), or if you only need a static site.

The pieces of a Phoenix app

The main parts of Phoenix

Endpoint The front door that every request enters.
Router Maps a method and path to code.
Controller Handles one action and picks a response.
HEEx templates Turn data into safe HTML.

Plugs connect the steps together.

1 / 2

The request lifecycle

Every HTTP request follows the same path. The web server (Bandit by default in new projects) parses the bytes and hands a %Plug.Conn{} struct, called the conn, to your endpoint. The endpoint runs a list of plugs (static files, logging, session parsing) and passes the conn to the router. The router runs a pipeline of more plugs, then calls a controller action. The action calls your business code, then renders a template or JSON and returns the conn with the response filled in.

flowchart LR
  A["Browser"] --> B["Endpoint<br/>plugs"]
  B --> C["Router<br/>pipeline"]
  C --> D["Controller<br/>action"]
  D --> E["Template<br/>or JSON"]
  E --> A

Each box takes a conn and returns a conn. Nothing is mutated; every step builds a new value.

Because Elixir data is immutable, the conn is never changed in place. Each plug returns a new version with a header added, a user assigned or a response set. This makes the flow easy to test: call a function with a conn, check the returned conn.

A tiny Phoenix example

Here is what a minimal route, controller and template look like. You will build each part properly later.

ELIXIR
# lib/my_app_web/router.ex
scope "/", MyAppWeb do
  pipe_through :browser
  get "/hello/:name", HelloController, :show
end

# lib/my_app_web/controllers/hello_controller.ex
defmodule MyAppWeb.HelloController do
  use MyAppWeb, :controller

  def show(conn, %{"name" => name}) do
    render(conn, :show, name: name)
  end
end
HEEX
<%!-- lib/my_app_web/controllers/hello_html/show.html.heex --%>
<h1>Hello, {@name}!</h1>

The route says: a GET to /hello/ada calls HelloController.show/2 with the params %{"name" => "ada"}. The controller renders the show template with an assign called name. The template prints it, and Phoenix escapes it so a name like <script> cannot inject code.

Model it yourself

You can see the lifecycle idea with plain JavaScript. A "conn" is an object, each plug returns a new object, and the router picks which function runs last.

JS A conn flowing through plugs

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The loop is the whole idea of a Phoenix pipeline: start with a request value, run a list of functions, end with a response value.

JS Immutability: the old conn is untouched

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In Elixir you get this behavior for free: assign(conn, :user, "grace") returns a new conn and the original stays as it was.

Phoenix versus other frameworks

If you know another framework, this mapping helps:

Idea Phoenix Rails Express Laravel
Routing router.ex routes.rb app.get() routes/web.php
Middleware Plugs Rack middleware app.use() Middleware
Database Ecto ActiveRecord any ORM Eloquent
Templates HEEx ERB EJS and others Blade
Real-time Channels, LiveView Action Cable Socket.io Echo

The biggest difference is that Ecto is not an ORM that hides SQL. Schemas describe data, queries are composable expressions, and changesets validate input. You will meet all three in Ecto schemas and migrations.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a plug receive and return?

    A plug takes a %Plug.Conn{} and returns an updated one. A pipeline is a list of plugs run in order.
  2. 2. Why can a crash in one Phoenix request leave other requests unaffected?

    BEAM processes share nothing, so a failure in one is contained and the others keep running.
  3. 3. Where does a request go right after the endpoint's plugs?

    The endpoint runs its plugs and hands the conn to the router, which runs a pipeline and calls a controller action.
  4. 4. Which statement about Ecto is true?

    Ecto is a data-mapping and query library built around schemas, queries and changesets, not an object-relational mapper.

Summary

  • Phoenix is Elixir's full-stack web framework, running on the BEAM with one lightweight process per request.
  • A request enters the endpoint, passes the router's pipeline and reaches a controller action that renders a response.
  • All steps work on an immutable %Plug.Conn{}; each plug returns a new conn.
  • Ecto handles data, contexts hold business logic, LiveView and channels add real-time features.

Next: Installing Phoenix and creating a project