How I set up an Elixir project
How I set up an Elixir project#
A short checklist for every new Elixir project: the libraries I use and the rules I apply.
Libraries#
- Ecto: database (PostgreSQL).
- Phoenix: web layer and APIs.
- LiveView: the UI, when possible.
- daisyUI: UI components on top of Tailwind, when I build the frontend.
- Req + Finch: HTTP requests. Easy to test:
Req.Testmocks the responses. - Swoosh: emails, with HTML templates rendered by Phoenix. Easy to test with its test adapter.
- Guardian: authentication.
- OpenApiSpex: OpenAPI spec of the APIs, request validation, Swagger UI.
- Oban: background jobs.
- PromEx: Prometheus metrics.
Rules#
- Folders by feature: Organize code by feature, not by type.
- Errors: one
Errorstruct, caught only where you can handle them: Errors: model them once, catch them once. - Docker: always containerized.
- A Mix release in a multi-stage image (
mix phx.gen.release --docker). - A health route (e.g.
GET /health) for the container health check. - Built and labeled in CI following Docker containers management.
- A Mix release in a multi-stage image (