5 Elixir Libraries I Install on Every New Project

5 Elixir Libraries I Install on Every New Project
Photo by Matt Briney / Unsplash

My list of indispensable tools & libraries for building with Elixir/Phoenix

The Elixir language — even better with a couple of small additions.

I’m a huge fan of the Elixir language and the Phoenix web framework in particular. As a functional language with a well-designed actor model for concurrency, Elixir helps avoid entire categories of bugs & other complications that you might encounter in another programming environment. But there are a couple of extra tools I like to use on every project to get the most out of the language and to build high best quality software.

Here are five tools I consider indispensible when starting a new project. With the exception of one library for building admin interfaces, all of these tools are appropriate for any Elixir project, not just for web apps built on Phoenix.

Credo — code linter for Elixir

Credo is a linter & static analysis linter tool which helps developers improve Elixir code quality. It points out opportunities for refactoring & style improvements based on a set of configurable options. It can be configured to find code quality issues like not following proper naming conventions, improper or inconsistent use of language constructs, and much more. I like to integrate Credo into a pre-commit hook to make sure that my team and I are addressing an errors or warnings before pushing code.

Dialyzer — type checking

As much I love writing code in Elixir, the one thing I find missing from the Elixir developer experience is static type checking. Don’t get me wrong — I love the development & iteration speed enabled by Elixir’s dynamic typing, but once it’s time to harden code for production usage, static typing helps find bugs and ensure quality.

Though Elixir does not have static typing, it does have a tool which catches most of the errors a static typing system would find — Dialyzer. Dialyzer is an entirely different beast than a full static typing system, and is most certainly worth its own post, so I won’t get into it too much here. But the takeaway is, when it comes time to harden your code and discover hidden bugs or other issues, Dialyzer is a must-have tool. Like credo, I also like to integrate Dialyzer into a pre-commit hook to ensure that errors are addressed before pushing code.

TypedEctoSchema — automatic typespecs for Ecto models

Elixir supports optional type specifications (typespecs) which are used both for documentation and for code analysis tools like Dialyzer (described above). TypedEctoSchema is a module to automatically generate typespecs for the Ecto database schema defined in your app. This means better results with Dialyzer and better documentation, automatically.

Kaffy — ready-made admin tools for Phoenix apps

Kaffy is an excellent tool to generate an admin interface automatically from the Ecto schema in your app. If you’re familiar with phpMyAdmin for PHP or Active Admin for Rails, Kaffy is pretty similar. As your application grows, you may outgrow Kaffy, especially if you want to build an interface open to your application’s end users. But to get an admin interface up & running quickly for internal usage, Kaffy is unbeatable.

Libcluster — unlock the power of the Erlang OTP

One of the most amazing aspects of working with Elixir is the Erlang OTP (Open Telecom Platform). Among other things, it enables powerful distributed computing features right out of the box. The OTP makes it dead simple to distribute computing or storage among a set of different servers and is one of the reasons for Elixir’s amazing scalability attributes.

Even if you don’t write code to use the OTP & clustering explicitly, you’re probably taking advantage of their benefits when using Phoenix or other popular Elixir libraries & frameworks. Phoenix’s channels functionality, for example, which is used to easily implement real-time features like chat, takes advantage of the OTP and will automatically work across a cluster if configured to do so.

To fully unlock the amazing power of the OTP in a multi-server environment, however, you need to enable Erlang clustering. Though it’s possible to configure a cluster manually, it can be highly impractical in a deployed environment: application servers can come up & down and may have unknown IP addresses.

Libcluster makes cluster configuration simple and automatic by providing a variety of different clustering strategies for different environments & configurations. For example, it supports a Kubernetes strategy which enables automatically building a cluster from Kubernetes metadata. Though you’ll need to pick & configure the right strategy for your particular environment, libcluster makes it easy.

Conclusion

Elixir is a fantastic language right out of the box, but there are a few add-ons that can help take it to the next level. The tools described here help unlock the full power of Elixir and the OTP, and for me, must haves on any new project.