Skip to content
/ phoenix-boilerplate Public template

Base to start a new Phoenix Framework project

License

Notifications You must be signed in to change notification settings

Plus17/phoenix-boilerplate

Repository files navigation

Content

This boilerplate comes with batteries included, you’ll find:

Configurations

  • warnings_as_errors: true

Useful libraries

Here is an opinionated list of other useful libraries to consider:

Category Libraries
Authentication ueberauth
Token based auth Guardian
Emails bamboo, swoosh
HTTP client Tesla
Job processing Oban
Pagination Scrivener (limit/offset), Quarto (cursor based)
Mocks Mox, Mimic
Cache Cachex, Nebulex (distributed cache)
Date/Time Timex
CSV NimbleCSV, CSV
Feature Flags/Toggles FunWithFlags
Clustering libcluster

Rename your porject

  1. Open the script rename.sh
  2. Change NEW_NAME & NEW_OTP variables with your app name
  3. Execute the script sh rename.sh
  4. Remove the file rename.sh

Development with Docker

Dependencies

  1. Install Docker
  2. Install Make: sudo apt install make or brew install make

First run

  1. Clone the project repository: git clone [email protected]:Plus17/phoenix-boilerplate.git
  2. Go to project dir: cd phoenix-boilerplate
  3. Execute: make setup to install dependencies, setup the database, execute migrations, etc.
  4. Get a .env file executing cp env.template .env and set the SECRET_KEY_BASE value. Get a new value executing make gen.secret
  5. Execute: make run to run the server at https://localhost:4000

New environment variables

If you want to add new environment variables you need to put the new env var in some places:

  1. In the .env.dist template file to include in new installations
  2. In your .env file

NOTE: When you add a new env var you must restart the container, so the container can read the new variable.

Makefile

For convenience, you can use the commands included in the Makefile:

Command Description
make bootstrap Bootstrap the phoenix project (dependencies & databse)
make deps.get Gets & compile dependencies
make deps.clean Clean unused dependencies & remove from mix.lock
make seeds Run seeds
make reset Resets the project removing deps & builds
make ecto.setup Setup the database for dev
make ecto.reset Resets the database for dev
make ecto.reset.test Resets the database for test
make test Runs tests
make check.all Run all CI verifications (formatter, credo, coverage)
make run Start Phoenix server
make gettext Search & merge new translations
make format Format all phoenix files

Development without Docker

Dependencies

  1. Install asdf
  2. Add the asdf erlang plugin asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
  3. Add the asdf elixir plugin asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
  4. Install fnm curl -fsSL https://fnm.vercel.app/install | bash

First run

  1. Clone the project repository: git clone [email protected]:Plus17/phoenix-boilerplate.git my_app
  2. Go to project dir: cd my_app
  3. Install Erlang, Elixir & NodeJS using the .tools-versions file with: asdf install
  4. Install NodeJs usign the .node-version file with fnm install
  5. Copy the env.dist file to .env and set the SECRET_KEY_BASE value. Get a new value executing mix phx.gen.secret.
  6. Run export $(cat .env | xargs) on project root folder
  7. Run mix local.hex && mix local.rebar
  8. Run mix setup to download dependencies & setup database
  9. Run mix phx.server

New environment variables

If you want to add new environment variables you need to put the new env var in some places:

  1. In the .env.dist template file to include in new installations
  2. In your .env file.

AppName

To start your Phoenix server:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.setup
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server

Now you can visit localhost:4000 from your browser.

Ready to run in production? Please check our deployment guides.

Learn more