12
12

More than 5 years have passed since last update.

Phoenix Framework(v0.13) 概要

Last updated at Posted at 2015-05-19

niku様の翻訳
http://qiita.com/niku/items/b54fdc9ca3c027f95fc7
を元に,
http://www.phoenixframework.org/v0.13.1/docs/overviewを翻訳しました.
翻訳の誤りなどあればご指摘お待ちしております.


Phoenix is a web development framework written in Elixir which implements the server-side MVC pattern. If you've ever used a similar framework, say Ruby on Rails or Python's Django, many of the concepts will be familiar to you. Phoenix gives you the best of both worlds, high developer productivity and high application performance. It also has some interesting new twists, channels for managing realtime events, pre-compiled templates and the potential for alternative architectures which may make services more manageable from the very beginning of your project.

Phoenix は Elixir で書かれた,サーバーサイド MVC パターンで実装した Web 開発フレームワークです.
もし Ruby on Rails や Python の Django といった,これと似ているフレームワークを使ったことがあれば,多くのコンセプトはあなたに馴染みのあるものでしょう.
Phoenix は,高い生産性と高いアプリケーションパフォーマンス,両方の長所をもたらします.そしてまた,いくつか面白い特徴を持っています.リアルタイムイベントを管理するための channnel,プリコンパイルされたテンプレート,プロジェクト当初からサービスを作りやすく,管理しやすくなる,既存のアーキテクチャの代替となる可能性を秘めています.

If you are already familiar with Elixir, great! If not, there are a number of places you can go to learn. You might want to read through the Elixir guides first. You might also want to look through any of the books, blogs or videos listed in the Resources Guide.

もし既に Elixir に慣れているなら,すばらしいことです!
もしそうではないなら,学べる場所がいくつかあります.
最初に Elixir guides を通して読むことをおすすめします.
また,Resources Guide に記載されている書籍,ブログ,ビデオのいずれかに目を通すとよいでしょう.

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.

この入門ガイドでは,Phoenix の大まかな概要と,それを構成するための部品,階層を簡潔に示します.

Phoenix

Phoenix is actually the top layer of a multi-layer system designed to be modular and flexible. The other layers are the Elixir middleware project, Plug, and the Erlang web server, Cowboy. Plug and Cowboy are covered in the next sections of this guide.

実際のところ Phoenix はモジュール化と柔軟性の向上を目的にデザインされた複数の階層の上になりたっています.
Phoenix と別の階層とは Elixir のミドルウェアプロジェクトである Plug,Erlang のウェブサーバーである Cowboy です.
Plug と Cowboy についてはこのガイドの次のセクションで説明します.

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.

Phoenix は,個々の目的を持った独立した部品で構成されており,それぞれが web アプリケーションの構築の中で役割をはたすことで組みあげられています.
それぞれについては後ほどこのガイドで掘り下げますが,ここでは簡単に分類してみましょう.

The Endpoint

  • handles all aspects of requests up until the beginning of our applications
  • provides a core set of middleware to apply to all requests
  • dispatches requests into designated routers

The Endpoint

  • アプリケーションを開始するまでに,全てのリクエストにおいて興味のある部分を扱います
  • リクエストに応答するためのミドルウェアの中心的なセットを提供します
  • 指定されたルータに要求をディスパッチします

The Router

  • parses incoming requests and dispatches to the correct controller/action, passing parameters as needed
  • provides helpers to generate route paths or urls to resources

The Router

  • 来るリクエストをパースして,正しいコントローラー/アクションへと送ります.必要なパラメーターも渡します
  • パスや url をリソースへとルーティングするためのヘルパーを提供します

Pipelines

  • Allow easy segregation of middleware across different routes

Pipelines

  • 異なるルートを横断する,ミドルウェアの容易な分離を可能にします

Controllers

  • provide functions, called actions, to handle requests
  • Actions
    • prepare data and pass it into views
    • invoke rendering via views
    • perform redirects

Controllers

  • リクエストを扱うためにアクションから呼ばれる関数を提供します
  • Actions
    • データを用意して View に渡します
    • view を通してレンダリングします
    • リダイレクトを実行します

Views

  • render templates
  • act as a presentation layer
  • define helper functions, available in templates, to decorate raw data

Views

  • テンプレートをレンダリングします
  • プレゼンテーション層として作用します
  • 生のデータを見やすくするため,テンプレート内で使えるヘルパー関数を定義します

Templates

  • are what they sound like :)
  • Precompiled & fast

Templates

  • 名は体を表します :)
  • 事前コンパイル&高速

Channels

  • manage sockets for easy realtime communication
  • analogous to controllers except that they allow bi-directional communication with persistent connections

Channels

  • 容易なリアルタイム通信のための socket を管理します
  • 双方向通信ができて,ずっと繋っている.ということを除けばコントローラーと似ています

PubSub

  • Underlies the channel layer and allows topics to be subscribed to
  • Abstracts the underlying pubsub adapter for third-party pubsub integration

PubSub

  • チャネル層の下にあり,トピックが購読されることを可能にします
  • サードパーティ pubsub 統合のために基礎となる pubsub アダプタを抽象化します

Plug

Plug is Elixir's web middleware layer. Conceptually, it shares a lot with other middleware layers like Rack for Ruby or WSGI for Python. Plugs are reusable modules that share the same very small, very regular public api. They provide discrete behaviors - like request header parsing or logging. Because the Plug api is so consistent, they can be stacked and executed in a set order, like a pipeline. They can also be re-used within a project or across projects.

Plug は Elixir のミドルウェア層です.概念としては,Ruby の Rack,Python の WSGI のようなミドルウェアと共通しています.
Plugs はとても小さく,とても一般的な公開APIをもった再利用可能なモジュールです.
それらは控えめな振舞いを提供します - 例えばリクエストヘッダーをパースしたり,ログを取るといったことです.
ですから,Plug の API はとても安定しています.それらはスタックに積み上げられ,パイプラインのように順番に実行されます.
それらはプロジェクト内やプロジェクトにまたがって再利用できます.

Plugs can be written to handle almost anything, from authentication to parameter pre-processing, and even rendering.

Plugs は認証,パラメーターの前処理,レンダリングでさえも,ほとんど全てのことを扱えるように書かれています.

Phoenix takes great advantage of Plug in general - the router and controllers especially so.

Phoenix は Plug に備わっているそのすばらしい利点を得ています - router と controllers では特にそうです.

One of the most important things about Plug, is that it provides adapters to HTTP servers which will ultimately deliver application content to your users. Currently, Plug only provides an adapter to Cowboy, which we will talk about next, but there are plans to provide adapters for other servers in the future.

Plug で最も大事なことの一つに,アプリケーションの内容を最終的にユーザーへと届けるための HTTP サーバーのアダプターを提供していることがあります.
現在,Plug は Cowboy へのアダプターのみを提供しています.今後への話をすると,他のサーバーへのアダプターを提供する予定があります.

Links to more in-depth information on Plug can be found in the Resources Guide.

Plug のもっと詳しい情報へのリンクは Resources Guide にあります.

Cowboy

Cowboy is an HTTP server written in Erlang by Loïc Hoguin of 99s. Cowboy is built in a modular way on top of Ranch, Bullet, and Sheriff. This is how 99s describes them.

Cowboy は 99s の Loïc Hoguin によって Erlang で書かれて HTTP サーバーです.
Cowboy は 組立式で Ranch, Bullet, Sheriff といったものの上に構築されています.
以下は 99s が書いたそれぞれの特徴です.

  • Cowboy is a small, fast, modular HTTP server supporting Websockets, SPDY and more.
  • Ranch is a socket acceptor pool for TCP protocols. It is also a standalone library for building networked applications.
  • Bullet is a simple, reliable, efficient streaming library.
  • Sheriff uses parse transforms for type based validation. Sheriff also validates data dynamically using Erlang's type system with no extra code required.
  • Cowboy は小さく,速く,組立式の HTTP サーバーで Websockets や SPDY などをサポートしています.
  • Ranch は TCP プロトコルのためのソケット受け入れプールです.これはネットワークを使うアプリケーションを構築するための独立したライブラリにもなっています.
  • Bullet は簡潔で,信頼性の高い,効果的なストリーミングライブラリです
  • Sheriff は型ベースのバリデーションのために parse transform を使います.Sheriff は外部の追加コードを必要とせずに Erlang の型システムを使って動的にデータをバリデーションします.

Cowboy has fantastic documentation. The Guides are especially helpful. Learning more about Cowboy will surely help you to understand Phoenix more fully.

Cowboy には素晴しいドキュメントがあります.特に Guides がためになります.
Cowboy について学ぶことはきっと Phoenix をもっと知るための助けになるでしょう.

Cowboy has its own section of links in the Resources Guide.

Resources Guide の中に Cowboy へのリンクがあります.

System Dependencies

There are a number of dependencies external to Phoenix which we will encounter as we work our way through these guides. Elixir and Erlang are hard dependencies, meaning that we won't be able to work with Phoenix at all unless we have them installed. The rest may not prevent us from getting started if we don't have them, but their absence may lead to errors that prevent us from moving forward. Simply installing these dependencies may save us from confusion and frustration later on.

このガイドを通して,いくつかの Phoenix 外部への依存関係が出てきます. Elixir と Erlang には強く依存します,すなわちこれらをインストールしないかぎり Phoenix で作業することはできません.残りのものは,無くても始めることはできますが,エラーを引き起こし前に進めなくなるかもしれません.これらをインストールしておけば,のちの混乱と不満から解放されます.

Let's take a look at each of them now.

  • Elixir
    Phoenix is written in Elixir, and our application code will also be written in Elixir. In order to do any work with Phoenix, we need Elixir installed on our system. The Elixir site itself has great installation instructions.

  • Erlang
    Elixir source code compiles to Erlang byte code which runs on the Erlang Virtual Machine. That means we must have Erlang installed on our system - in addition to Elixir - in order to work with Phoenix. The Elixir site also has Erlang installation instructions.

  • node.js (>= 0.12.0)
    Node is an optional dependency. Phoenix will use brunch.io to compile static assets (javascript, css, etc), by default. Brunch.io uses the node package manager (npm) to install its dependencies, and npm requires node.js.
    If we don't have any static assets, or we want to use another build tool, we can pass the --no-brunch flag when creating a new application and node won't be required at all.

  • PostgreSQL
    PostgreSQL is a relational database server. Phoenix configures applications to use it by default, but we can switch to MySQL by passing the --database mysql flag when creating a new application.
    When we work with Ecto models in these guides, we will use PostgreSQL and the Postgrex adapter for it. In order to follow along with the examples, we will need to install PostgreSQL on our system. The PostgreSQL wiki has installation guides for a number of different systems.

  • inotify-tools
    This is a Linux-only filesystem watcher that Phoenix uses for live code reloading. (Mac OS X or Windows users can safely ignore it.)
    Linux users need to install this dependency. Please consult the inotify-tools wiki for distribution-specific installation instructions.

それでは,それぞれを見てみましょう.

  • Elixir

Phoenix は Elixir で書かれており,私たちのアプリケーションコードも Elixir で書きます. Phoenix でのすべての作業を行うために, Elixir をシステムにインストールする必要があります. Elixir のサイト自体にすばらしいインストール手順があります.

  • Erlang

Elixir のソースコードは Erlang の仮想マシン上で動作する Erlang のバイトコードにコンパイルされます.そのため Phoenix を使用するには, Elixir に加えて, Erlang をシステムにインストールする必要があります. Elixir のサイトには,Erlangのインストール手順もあります.

  • node.js (>= 0.12.0)

Node は,オプションの依存関係です.デフォルトでは Phoenix は,静的なアセット(javascript や css など)のコンパイルに brunch.io を使用します. Brunch.io は依存関係をインストールするために node package manager (npm) を使用し, npm は node.js を必要とします.
静的アセットを持たないか,他のビルドツールを使用する場合には,新規アプリケーションの作成時に --no-brunch フラグを使用すれば, Node は全く必要なくなります.

  • PostgreSQL

PostgreSQL はリレーショナルデータベースサーバーです.デフォルトでは Phoenix は,PostgreSQL を使用するようにアプリケーションを構成しますが,新規アプリケーションの作成時に --database mysql フラグを使用すれば, MySQL に切り替えることもできます.
このガイドで Ecto モデルを使用する場合, PostgreSQL と Postgrex アダプタを使用します.ガイドの例に従うためには, Postgres をシステムにインストールする必要があります. PostgreSQL の wiki にはさまざまなシステムへのインストールガイドがあります.

  • inotify-tools

Phoenix がライブコード再ロードに使用する, Linux 専用のファイルシステムウォッチャーです.(Mac OS X と Windows ユーザーは安全にそれを無視することができます.)
Linux ユーザーはこの依存関係をインストールする必要があります.ディストリビューション固有のインストール手順についてはinotify-tools wikiを参照してください.

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12