{"category":"5777c9635b2b430e00b982a6","parentDoc":null,"project":"54348ec95b10711400c6c445","user":"5435b410495d5d0800f3a603","version":"5777c9635b2b430e00b982a5","updates":["5481fc83c7026c210099d121","55838150afccfd0d00fcb034"],"_id":"5777c9635b2b430e00b982ab","createdAt":"2014-10-09T04:19:06.947Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":0,"body":"Phoenix is a web development framework written in Elixir which implements the server-side MVC pattern. Many of its components and concepts will seem familiar to those of us with experience in other web frameworks like Ruby on Rails or Python's Django.\n\nPhoenix provides the best of both worlds - high developer productivity _and_ high application performance. It also has some interesting new twists like channels for implementing realtime features and pre-compiled templates for blazing speed.\n\nIf you are already familiar with Elixir, great! If not, there are a number of places to learn. The [Elixir guides](http://elixir-lang.org/getting-started/introduction.html) are a great place to start. We also have a list of helpful resources in the [Learning Elixir and Erlang Guide](http://www.phoenixframework.org/docs/learning-elixir-and-erlang).\n\nThe aim of this introductory guide is to present a brief, high-level overview of Phoenix, the parts that make it up, and the layers underneath that support it.\n\n[block:embed]\n{\n  \"html\": \"<iframe class=\\\"embedly-embed\\\" src=\\\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F131633172&url=https%3A%2F%2Fvimeo.com%2F131633172&image=http%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F523962190_1280.jpg&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=vimeo\\\" width=\\\"1280\\\" height=\\\"720\\\" scrolling=\\\"no\\\" frameborder=\\\"0\\\" allowfullscreen></iframe>\",\n  \"url\": \"https://vimeo.com/131633172\",\n  \"title\": \"Phoenix - a framework for the modern web - Chris Mccord\",\n  \"favicon\": \"https://f.vimeocdn.com/images_v6/favicon.ico\",\n  \"image\": \"http://i.vimeocdn.com/video/523962190_1280.jpg\"\n}\n[/block]\n### Phoenix\n\nPhoenix is actually the top layer of a multi-layer system designed to be modular and flexible. The other layers include Plug, and Ecto, which we will cover right after Phoenix in this overview. The Erlang HTTP server, Cowboy, acts as the foundation for Plug and Phoenix, but we won't be covering Cowboy directly in these guides.\n\nPhoenix is made up of a number of distinct parts, each with its own purpose and role to play in building a web application. We will cover them all in depth throughout these guides, but here's a quick breakdown.\n\n- The Endpoint\n  - handles all aspects of requests up until the point where the router takes over\n  - provides a core set of plugs to apply to all requests\n  - dispatches requests into a designated router\n- The Router\n  - parses incoming requests and dispatches them to the correct controller/action, passing parameters as needed\n  - provides helpers to generate route paths or urls to resources\n  - defines named pipelines through which we may pass our requests\n  - Pipelines\n    - allow easy application of groups of plugs to a set of routes\n- Controllers\n  - provide functions, called *actions*, to handle requests\n  - Actions\n    - prepare data and pass it into views\n    - invoke rendering via views\n    - perform redirects\n- Views\n  - render templates\n  - act as a presentation layer\n  - define helper functions, available in templates, to decorate data for presentation\n- Templates\n  - are what they sound like :)\n  - are precompiled and fast\n- Channels\n  - manage sockets for easy realtime communication\n  - are analogous to controllers except that they allow bi-directional communication with persistent connections\n- PubSub\n  - underlies the channel layer and allows clients to subscribe to *topics*\n  - abstracts the underlying pubsub adapter for third-party pubsub integration\n\n### Plug\n\n[Plug](http://hexdocs.pm/plug/) is a specification for constructing composable modules to build web applications. Plugs are reusable modules or functions built to that specification. They provide discrete behaviors - like request header parsing or logging. Because the Plug API is small and consistent, plugs can be defined and executed in a set order, like a pipeline. They can also be re-used within a project or across projects.\n\nPlugs can be written to handle almost anything, from authentication to parameter pre-processing, and even rendering.\n\nPhoenix takes great advantage of Plug in general - the router and controllers especially so.\n\nOne of the most important things about Plug is that it provides adapters to HTTP servers which will ultimately deliver application content to our users. Currently Plug only provides an adapter for [Cowboy](https://github.com/ninenines/cowboy), a web server written in Erlang by Loïc Hoguin of [99s](http://ninenines.eu/).\n\nHave a look at the [Plug Guide](http://www.phoenixframework.org/docs/understanding-plug) for more details.\n\n### Ecto\n\n[Ecto](http://hexdocs.pm/ecto) is a language integrated query composition tool and database wrapper for Elixir. With Ecto, we can read and write to different databases, model our domain data, write complex queries in a type-safe way, protect against attack vectors - including SQL injection, and much more.\n\nEcto is built around four main abstractions:\n\n* Repo - A repository represents a connection to an individual database. Every database operation is done via the repository.\n\n* Model - Models are our data definitions. They define table names and fields as well as each field's type. Models also define associations - the relationships between models.\n\n* Query - Queries tie both models and repositories together, allowing us to elegantly retrieve data from the repository and cast it into the models themselves.\n\n* Changeset - Changesets declare transformations we need to perform on our model data before our application can use it. These include type casting, validations, and more.\n\nA new Phoenix application will use Ecto with PostgreSQL storage by default.\n\n\n## A Note about these guides\nIf you find an issue with the guides or would like to help improve these guides please checkout the [Phoenix Guides](https://github.com/phoenixframework/phoenix_guides/) github. Issues and Pull Requests are happily accepted!","excerpt":"","slug":"overview","type":"basic","title":"Overview","__v":0,"childrenPages":[]}
Phoenix is a web development framework written in Elixir which implements the server-side MVC pattern. Many of its components and concepts will seem familiar to those of us with experience in other web frameworks like Ruby on Rails or Python's Django. Phoenix provides the best of both worlds - high developer productivity _and_ high application performance. It also has some interesting new twists like channels for implementing realtime features and pre-compiled templates for blazing speed. If you are already familiar with Elixir, great! If not, there are a number of places to learn. The [Elixir guides](http://elixir-lang.org/getting-started/introduction.html) are a great place to start. We also have a list of helpful resources in the [Learning Elixir and Erlang Guide](http://www.phoenixframework.org/docs/learning-elixir-and-erlang). The aim of this introductory guide is to present a brief, high-level overview of Phoenix, the parts that make it up, and the layers underneath that support it. [block:embed] { "html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F131633172&url=https%3A%2F%2Fvimeo.com%2F131633172&image=http%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F523962190_1280.jpg&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=vimeo\" width=\"1280\" height=\"720\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "url": "https://vimeo.com/131633172", "title": "Phoenix - a framework for the modern web - Chris Mccord", "favicon": "https://f.vimeocdn.com/images_v6/favicon.ico", "image": "http://i.vimeocdn.com/video/523962190_1280.jpg" } [/block] ### Phoenix Phoenix is actually the top layer of a multi-layer system designed to be modular and flexible. The other layers include Plug, and Ecto, which we will cover right after Phoenix in this overview. The Erlang HTTP server, Cowboy, acts as the foundation for Plug and Phoenix, but we won't be covering Cowboy directly in these guides. Phoenix is made up of a number of distinct parts, each with its own purpose and role to play in building a web application. We will cover them all in depth throughout these guides, but here's a quick breakdown. - The Endpoint - handles all aspects of requests up until the point where the router takes over - provides a core set of plugs to apply to all requests - dispatches requests into a designated router - The Router - parses incoming requests and dispatches them to the correct controller/action, passing parameters as needed - provides helpers to generate route paths or urls to resources - defines named pipelines through which we may pass our requests - Pipelines - allow easy application of groups of plugs to a set of routes - Controllers - provide functions, called *actions*, to handle requests - Actions - prepare data and pass it into views - invoke rendering via views - perform redirects - Views - render templates - act as a presentation layer - define helper functions, available in templates, to decorate data for presentation - Templates - are what they sound like :) - are precompiled and fast - Channels - manage sockets for easy realtime communication - are analogous to controllers except that they allow bi-directional communication with persistent connections - PubSub - underlies the channel layer and allows clients to subscribe to *topics* - abstracts the underlying pubsub adapter for third-party pubsub integration ### Plug [Plug](http://hexdocs.pm/plug/) is a specification for constructing composable modules to build web applications. Plugs are reusable modules or functions built to that specification. They provide discrete behaviors - like request header parsing or logging. Because the Plug API is small and consistent, plugs can be defined and executed in a set order, like a pipeline. They can also be re-used within a project or across projects. Plugs can be written to handle almost anything, from authentication to parameter pre-processing, and even rendering. Phoenix takes great advantage of Plug in general - the router and controllers especially so. One of the most important things about Plug is that it provides adapters to HTTP servers which will ultimately deliver application content to our users. Currently Plug only provides an adapter for [Cowboy](https://github.com/ninenines/cowboy), a web server written in Erlang by Loïc Hoguin of [99s](http://ninenines.eu/). Have a look at the [Plug Guide](http://www.phoenixframework.org/docs/understanding-plug) for more details. ### Ecto [Ecto](http://hexdocs.pm/ecto) is a language integrated query composition tool and database wrapper for Elixir. With Ecto, we can read and write to different databases, model our domain data, write complex queries in a type-safe way, protect against attack vectors - including SQL injection, and much more. Ecto is built around four main abstractions: * Repo - A repository represents a connection to an individual database. Every database operation is done via the repository. * Model - Models are our data definitions. They define table names and fields as well as each field's type. Models also define associations - the relationships between models. * Query - Queries tie both models and repositories together, allowing us to elegantly retrieve data from the repository and cast it into the models themselves. * Changeset - Changesets declare transformations we need to perform on our model data before our application can use it. These include type casting, validations, and more. A new Phoenix application will use Ecto with PostgreSQL storage by default. ## A Note about these guides If you find an issue with the guides or would like to help improve these guides please checkout the [Phoenix Guides](https://github.com/phoenixframework/phoenix_guides/) github. Issues and Pull Requests are happily accepted!