*20 Nov 2019*
All [Ruby](https://www.ruby-lang.org)/[Rails](https://rubyonrails.org) developers know that for features neither provides, there is probably a [Ruby Gem](https://rubygems.org) contributed by someone in the community that solves that problem.
[Elixir](https://elixir-lang.org/getting-started/introduction.html)’s equivalent to Ruby Gems are [**Hex packages**](https://hex.pm). Hex is a package manager that provides reusable libraries for both Elixir and the [Erlang](https://www.erlang.org/) ecosystem.
When you first start developing in Elixir it’s hard to track down the best libraries, so here’s my pick after 6 months of Elixir’ing at [Drover](https://joindrover.com):
[**Ecto**](https://hexdocs.pm/ecto/getting-started.html) is the equivalent to Rails’ ActiveRecord. It handles connections to a database, as well as migrations and all that jazz.
[**Phoenix**](https://hexdocs.pm/phoenix/up_and_running.html) is Elixir’s more direct equivalent to Rails. It implements the server-side Model View Controller (MVC) pattern and should feel familiar to all Rails devs.
If you hate writing javascript for mundane tasks like form validation and other simple use cases, or if you just want something realtime on the browser without having to worry about the Javascript part of it, then Phoenix [**LiveView**](https://dockyard.com/blog/2018/12/12/phoenix-liveview-interactive-real-time-apps-no-need-to-write-javascript) is for you. It’s the new kid on the block and allows for rich user interactions writing only server side code. Check it out.
[**Broadway**](https://github.com/plataformatec/broadway) is a library that allows you to easily build data processing pipelines in Elixir. It’s data production agnostic and the most common case is to use it with [**broadway_sqs**](https://github.com/plataformatec/broadway_sqs) to consume and process messages from SQS queues (it also supports [RabbitMQ](https://www.rabbitmq.com/) and is easily extended).
[**HTTPoison**](https://github.com/edgurgel/httpoison) allows you to perform http requests (similar to [HTTParty](https://github.com/jnunemaker/httparty)) and uses Erlang’s hackney under the hood.
If you need a token based authentication mechanism then [**Guardian**](https://github.com/ueberauth/guardian) is for you. By default JSON Web Tokens are supported out of the box but any token that implements *Guardian.Token* behaviour can be used.
Speaking of authentication, if you need to provide multiple ways to auth your app — including social login and signup — you probably want something like [**Ueberauth**](https://github.com/ueberauth/ueberauth). Heavily inspired by [Omniauth](https://github.com/intridea/omniauth), it allows for many [authentication strategies](https://github.com/ueberauth/ueberauth/wiki/List-of-Strategies) to be used.
[**Telemetry**](https://github.com/beam-telemetry/telemetry) is a metrics and instrumentation dispatching library. It’s a joint effort by the Erlang community to provide metrics for Erlang and Elixir projects.
Being a dynamic language, types can become tricky in Elixir. The good news is that projects like [**Norm**](https://github.com/keathley/norm) can help you specify and structure your data to make it conform to any values you expect. Using \`conform!\` is a great way to assert data structure inside your functions.
<figure>
<img src="https://cdn-images-1.medium.com/max/580/1*DnRsTAR5M2SIeShVcTjMIw.png" />
<figcaption>Cats are nice, here's a picture of a kitten.</figcaption>
</figure>
Thwarting abusive web requests is a must nowadays. And you can use [**PlugAttack**](https://github.com/michalmuskala/plug_attack) for that. It’s inspired by the Rack::Attack middleware for Ruby.
Date and time handling in Elixir/Erlang is not the most usable thing in the world. Thankfully there are libraries like [**Timex**](https://hexdocs.pm/timex/Timex.html) that can help. If you need to manipulate dates, times, datetimes, timestamps, etc., (timezone support included) then Timex is for you.
[**CORSPlug**](https://github.com/mschae/cors_plug) is a library to provide CORS support as a plug (that can be used in Phoenix), so that different systems can easily interact with your API, even from another domain.
### Bonus track: documentation, development and test tools
Here’s a few more libraries, this time dedicated to development time, documentation and testing:
[**PhoenixSwagger**](https://github.com/xerions/phoenix_swagger) gives you a way to generate Swagger documentation for Phoenix apps. It can also serve a web interface to browse and interact with API documentation that you generate. A must, if you are developing a web API.
If you love to have your code well documented, [**EXDoc**](https://github.com/elixir-lang/ex_doc) allows you to generate HTML and EPUB docs for it.
[**Mix Test Watch**](https://github.com/lpil/mix-test.watch) runs your project tests whenever you change a file. You never need to run tests manually ever again. It’s that awesome.
The perfect complement to that is [**ExUnitNotifier**](https://hexdocs.pm/ex_unit_notifier/readme.html), which shows you desktop notifications when the tests run with information about pass or fail. You don’t even need to leave your IDE to know if you broke something or not.
You will want to check out [**Credo**](https://github.com/rrrene/credo) as well. It’s a tool similar to [Rubocop](https://github.com/rubocop-hq/rubocop), that performs static code analysis for best practices. A must have for all projects.
Speaking of static analysis, [Dialyzer](http://erlang.org/doc/apps/dialyzer/dialyzer_chapter.html) is a static analysis tool for Erlang and other languages that compile to BEAM byte code for the Erlang VM. It can analyse the BEAM files and provide warnings about problems in your code including type mismatches and other issues that are commonly detected by static language compilers. You can use [**Dialyxir**](https://github.com/jeremyjh/dialyxir) to simplify using the Dialyzer in Elixir projects.
If you write unit tests in Ruby you probably [mocked](https://www.rubydoc.info/github/rspec/rspec-mocks/RSpec%2FMocks%2FExampleMethods:expect_any_instance_of) some classes or method calls at some point. In Elixir you can mock any function call with [**Mox**](https://github.com/plataformatec/mox) by using behaviours and explicit contracts.
You probably heard of Brakeman, a security focused gem that analyses your code for vulnerabilities. For Elixir you have [**Sobelow**](https://github.com/nccgroup/sobelow).
And last, but not least, if you need test coverage reports you can use [**ExCoveralls**](https://github.com/parroty/excoveralls) for that. It also (optionally) integrates with the [coveralls.io](https://coveralls.io/) service if you track your coverage on the cloud.
If you have any suggestions about other interesting libraries, feel free to share in the comments below.
Happy coding!
------------------------------------------------------------------------
[Cool Elixir libraries](https://medium.com/drover-engineering/cool-elixir-libraries-6faed3cea474) was originally published in [Drover Engineering](https://medium.com/drover-engineering) on Medium, where people are continuing the conversation by highlighting and responding to this story.
[[tags/elixir|elixir]] [[tags/erlang|erlang]] [[tags/libraries|libraries]] [[tags/phoenix|phoenix]] [[tags/phoenix-framework|phoenix-framework]]