Phoenix Webframework

Install phoenix

  • brew install elixir
  • mix local.hex
  • mix archive.install phx_new

Adding authentication to a Phoenix Application

  1. Added dependency to application
{:phx_gen_auth, "~> 0.6", only: [:dev], runtime: false},
  1. mix phx.gen.auth Account User users
  2. Updated and committed files as needed
  3. Fixed test suite

Notes on framework

|> endpoint()
|> plug()
|> plug()
|> router()
|> HelloWebController()

lib/app_name/application.ex has the logic for starting, stopping, and supervising each application lib/app_name_web/endpoint.ex: beginning of the web logic

“Generally speaking, a context encapsulates all business logic for a common purpose. This way, we can interact with our business logic from controllers, channels or remote APIs, without having to duplicate code. In a nutshell, a controller exists to work with context functions. It parses end user requests, calls context functions and translates those results into something the end user can understand. Each slice of code has an isolated purpose. The context doesn’t know about the controller, and the controller doesn’t know about the business rules.”

– Form Programming Phoenix1

Rendering Pathway

Router: define pipelines and routes -> Controller: functional logic before view -> View: render template -> Template: .eex extension


  • Historically, releases were served by distillery a third party utility that packaged the web app up as a tar ball. This was replaced by a native elixir solution via mix release in elixir 1.9.


Deploy a Phoenix app with Docker stack

Console equivalent

iex -S mix


McCord, C., Tate, B. & Valim, J. Programming Phoenix: Productive |$>$ Reliable |$>$ Fast. (Pragmatic Bookshelf, 2016).

Links to this note