Phoenix
Overview
Phoenix is a web framework written in Elixir that aims for "peace of mind from prototype to production." Running on the Erlang VM (BEAM), it provides an MVC structure, realtime communication via Channels, and server-rendered interactive UIs via LiveView. Read this when building Phoenix web apps, APIs, or realtime features.
Official sources
Install / setup
# Install the Phoenix application generator
mix archive.install hex phx_new
# Create a new application (replace "hello" with your app name)
mix phx.new hello
Core concepts
- Endpoint & Router: the Endpoint is the entry point handling all requests; the Router maps paths to controllers and pipelines.
- Plugs & pipelines: composable request-processing functions; pipelines group plugs (e.g.
:browser, :api) applied to route scopes.
- Controllers, views, templates: controllers handle requests and render templates via view modules, following an MVC structure.
- Contexts: modules that group related domain logic and data access, keeping the web layer thin.
- Channels: bidirectional realtime messaging over WebSockets for features like chat and live updates.
- LiveView: server-rendered, stateful interactive UIs without writing custom client-side JavaScript.
- Ecto: the data-mapping/query library typically used with Phoenix for schemas and migrations.
Best practices
- Organize domain logic into Contexts so the web layer (controllers/LiveViews) stays thin (https://hexdocs.pm/phoenix/contexts.html).
- Use router pipelines (
:browser, :api) to apply the right plugs per route group.
- Use Channels/LiveView for realtime rather than polling, leveraging the BEAM's concurrency.
- Use Ecto migrations and changesets for schema changes and validation.
Common pitfalls
- Putting business logic in controllers or LiveViews → move it into Contexts for testability and reuse.
- Applying the wrong pipeline to a route (e.g. CSRF-protected
:browser plugs on an API) → scope routes under the matching pipeline.
- Confusing the package on Hex (
phx_new generator) with the runtime dependency (phoenix) → install the generator archive first, then generate the app.
Examples
# lib/hello_web/router.ex
scope "/", HelloWeb do
pipe_through :browser
get "/", PageController, :home
end
Further reading
Related skills
- ../rails — another MVC, convention-driven web framework
- ../laravel — full-stack framework with realtime broadcasting
1---2name: phoenix3description: Elixir web framework with realtime channels, LiveView, and an MVC structure on the BEAM; consult when building Phoenix apps or realtime features.4domain: stack5category: backend6tags: [elixir, phoenix, liveview, realtime, web-framework]7official_sources:8 - https://hexdocs.pm/phoenix/9 - https://github.com/phoenixframework/phoenix10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/phoenix13---1415# Phoenix1617## Overview18Phoenix is a web framework written in Elixir that aims for "peace of mind from prototype to production." Running on the Erlang VM (BEAM), it provides an MVC structure, realtime communication via Channels, and server-rendered interactive UIs via LiveView. Read this when building Phoenix web apps, APIs, or realtime features.1920## Official sources21- Docs: https://hexdocs.pm/phoenix/ (canonical: https://phoenix.hexdocs.pm/)22- Repo: https://github.com/phoenixframework/phoenix23- Install / download: https://hexdocs.pm/phoenix/installation.html2425## Install / setup26```bash27# Install the Phoenix application generator28mix archive.install hex phx_new2930# Create a new application (replace "hello" with your app name)31mix phx.new hello32```3334## Core concepts35- Endpoint & Router: the Endpoint is the entry point handling all requests; the Router maps paths to controllers and pipelines.36- Plugs & pipelines: composable request-processing functions; pipelines group plugs (e.g. `:browser`, `:api`) applied to route scopes.37- Controllers, views, templates: controllers handle requests and render templates via view modules, following an MVC structure.38- Contexts: modules that group related domain logic and data access, keeping the web layer thin.39- Channels: bidirectional realtime messaging over WebSockets for features like chat and live updates.40- LiveView: server-rendered, stateful interactive UIs without writing custom client-side JavaScript.41- Ecto: the data-mapping/query library typically used with Phoenix for schemas and migrations.4243## Best practices44- Organize domain logic into Contexts so the web layer (controllers/LiveViews) stays thin (https://hexdocs.pm/phoenix/contexts.html).45- Use router pipelines (`:browser`, `:api`) to apply the right plugs per route group.46- Use Channels/LiveView for realtime rather than polling, leveraging the BEAM's concurrency.47- Use Ecto migrations and changesets for schema changes and validation.4849## Common pitfalls50- Putting business logic in controllers or LiveViews → move it into Contexts for testability and reuse.51- Applying the wrong pipeline to a route (e.g. CSRF-protected `:browser` plugs on an API) → scope routes under the matching pipeline.52- Confusing the package on Hex (`phx_new` generator) with the runtime dependency (`phoenix`) → install the generator archive first, then generate the app.5354## Examples55```elixir56# lib/hello_web/router.ex57scope "/", HelloWeb do58 pipe_through :browser59 get "/", PageController, :home60end61```6263## Further reading64- https://hexdocs.pm/phoenix/up_and_running.html — Up and running65- https://hexdocs.pm/phoenix/contexts.html — Contexts66- https://hexdocs.pm/phoenix/channels.html — Channels (realtime)6768## Related skills69- ../rails — another MVC, convention-driven web framework70- ../laravel — full-stack framework with realtime broadcasting