Chapter 5. Elixir application structure

 

This chapter covers

  • Organizing Elixir code in a project
  • Using the Mix utility to manage your Elixir projects
  • Using hex.pm to make use of third-party tools and libraries

So far, you’ve been writing and using Elixir code in an IEx session or, in chapter 4, in a single file. The majority of your Elixir and Phoenix projects won’t be organized like this, however. As your application grows in complexity, it’s important to impose some sort of organizational structure to keep things manageable.

In this chapter, we’ll cover the structure of a typical Elixir application. Along the way, you’ll use the Mix utility to automate a lot of tasks that would take some effort if done manually. Finally, you’ll use the Hex package manager to bring third-party tools and libraries into your application. All of this will help you get your application set up properly before you tackle using a real database in chapter 6.

5.1. Moving from a single file to an application

Your auction application in chapter 4 consisted of a fake repo, a public interface layer to access the data in the repo, and an Item struct that defined the data structure of your auction items. All that code—three modules—existed in a single file. Once you start adding more functionality, that kind of project structure will become unmaintainable.

5.2. Organizing, compiling, and running your new application

5.3. Using Hex to get external dependencies

Summary