What is Elixir Phoenix?

Review of Elixir's Phoenix framework with overvies of it's structure and main features
24 July 2017   846
Elixir

Elixir is a dynamic, functional language designed for building scalable and maintainable applications

A framework is a logical ordering of code that implements a certain idea, as well as a set of tools for easy development of software products. But the main role for the framework, including what it can allow for the developer, is the programming language on which it is written.

The Phoenix Framework is written in elixir. In essence, its language is a "syntactic sugar" for another well-known programming language - erlang. But the most important thing about it is that it's written in the rubyst (Jose Valim) and it is very similar to Ruby on Rails. But some similarities can be found only in the syntax. Everything else - data structures, control blocks is different. The main thing to remember about Elixir is a functional programming language.

Framework structure

Phoenix is ​​an MVC framework. Structuring is very Rails look-alike:

  • Web/controllers - here are the controllers;
  • Web/models - here are the models;
  • Web/views - here are the views.

But if you go to the Web/views, you will not find a single template there. Here begins an interesting feature of phoenix.

Elixir syntax
Elixir syntax

Templates are located in another place - Web/templates. It turns out that views are not what we are used to seeing in the Rails. The Phoenix Framework views perform the following functions (at least what I was able to figure out at the moment):

  • Rendering templates.
  • Additional functions that can be used in templates.

Access to data

There are several options for where to store the data:

  • DB mnesia, which is written in erlang and is native to elixir as well;
  • Ecto, analogue of Active Record. At the moment, there are adapters for postgresql and mysql. ActiveRecord this library, of course, a little like, but it immediately goes out of the box and is, by itself, a standard solution.

Ecto supports almost all the necessary functionality to work with this data, which we are accustomed to using in the rails:

  • Creating a database using a special mix of the task;
  • Creating models;
  • Generation of migrations;
  • Associations;
  • Validation;
  • CRUD operations, etc.

Assets

By default, the compilation of the asserts is done using the node.js from brunch package. So, you will have to install node.js

Development

Another bunch of similar Rails-style features:

  • Batch manager;
  • A large number of libraries, plug-ins;
  • There is an analogue of the rake of the tusks - mix;
  • Generate an application using a mix;
  • Different scaffold generators;
  • There is an analog Gemfile'a - mix.exs.

In general, everything is quite similar to Rails. Commands are only named differently, but semantically they perform the same actions.

Conclusion

Given all the factors, and also that product is still active development, Phoenix Framework will be an excellent alternative to Ruby on Rails. We will be happy to observe the development! 

ElixirLangMoscow Meetup #7

Meetup will be held on February 15th, Thursday, in Moscow, Pyatnitsky Lane 2
22 January 2018   247

Club ElixirLangMoscow invites all lovers of Elixir, Erlang and functional programming languages to the next meeting of our club. This time the event was decided to be held in the "Dear, I will call back" bar. Because, what could be better than listening to interesting reports for a glass of beer. And even in the company of friends!

Speakers

We are waiting for two cool reports and a free microphone for those who have something to say.

Dmitry Rubinstein

Topic: “Introduction to Agala

Dmitry Rubinstein
Dmitry Rubinstein

The report will highlight the Agala framework - a platform for real-time interaction with third-party services. Currently, this platform has implemented bots for Telegram and Vk, which are used in the combat environment in our company. Let's analyze the main differences from the known solutions for creating bots on Elixir, consider the internal structure of the platform and learn how to support any necessary third-party service.
 

Dmitry Rubinstein
CTI

Alexandr Shorin 

Topic: “Apache CouchDB: more than a database with HTTP API

Alexandr Shorin
Alexandr Shorin

This will be an introductory report with Apache CouchDB and its ecosystem. Main features and capabilities. Details of the implementation of the replication protocol and why this is important. Forks: Couchbase, Cloudant - what are the differences and why should not they be confused with the original project. The history of clustering, what happened in the end in 2.0 and how it works. What is interesting about the new release and where the project is heading.
 

Alexandr Shorin 
Rambler

As a pleasant chip, the bar will prepare an "Elixir" cocktail especially for us. Admission is free, everyone pays their bill.

The event has an age limit of 18+. Register for free.