Why I selected Elixir and Phoenix as my main stack

Camilo - Jan 21 '23 - - Dev Community

This is just a personal journey documentation on how I decided to use my current tech stack.

Over the years I have tried different frameworks, mostly in PHP, like Code Igniter (2010), ProcessWire (2014) and Laravel (2015).

They helped me complete different projects with diverse complexity. They are wonderful tools. But sadly most of the jobs I managed to land were using legacy versions of PHP and the codebase and developer experience was spartan to say the least. As an example in one project (2020) I had to connect to a remote Windows machine, edit the code in Notepad++ and then upload it using FTP. Odd workflows aside, I wanted to land more modern projects. So I embarked in a quest to find a new tech stack.

First I wanted to update my tools, maybe I just needed a small patch instead of changing them. So I made a project for a client using Laravel, Inertia.js Svelte, and then other project using Laravel, Inertia and React. I liked Svelte over React, so if future frontend projects appear, my main tool would be Svelte.

Both projects resulted in a superb improved developer experience and were finished in record time. A single monolith with backend and frontend did wonders because I did not need to create REST apis or GraphQL endpoints to make a fullstack system. Now I can have all the power of an SPA with all the good parts of a Backend, like direct access to a database.

I explored using Inertia.js as my main tool and made some adapters for ProcessWire, to understand better how it worked.

Vapor (Swift)

My first option other than PHP was using Swift and Vapor. I have made some projects with iOS and Objective-C, maybe I could also learn Swift and create both native iOS apps and backends with the same language.

But I discovered that it lacked the Inertia.js adapter, so I found this project

GitHub logo Lloople / vapor-inertia-adapter

The Vapor framework adapter for Inertia.js

Vapor Inertia Adapter

Vapor Logo Swift 5.2 Logo Build Status MIT License

This package is meant to help you using Inertia JS in your Vapor 4 project.

Features

Installation

Add the adapter in your dependencies array in Package.swift:

dependencies: [
    // ...,
    .package(name: "vapor-inertia-adapter",
            url: "https://github.com/lloople/vapor-inertia-adapter.git", 
            from: "0.3.0")
],
Enter fullscreen mode Exit fullscreen mode

Also ensure you add it as a dependency to your target:

targets: [
    .target(name: "App", dependencies: [
        .product(name: "Vapor", package: "vapor")
        // ..., 
        .product(name:"VaporInertiaAdapter", package:"vapor-inertia-adapter")
        ]),
    
Enter fullscreen mode Exit fullscreen mode

and created an example

Pros

  • Using Xcode to program a backend application was super nice, It was awesome to have an IDE with all the bells and whistles for the Swift language.

  • Coming from Objective-C was helpful to understand the Apple ecosystem and workflows.

Cons

  • I often have to resort to other editors such as VSCode to edit non well supported files such as JS, CSS or HTML files.

  • If you want to use XCode you need to use an updated operating system, if you have an older not supported Mac computer you will need to use Docker and use the Linux version of the Vapor framework, with poorer perfomance and developer experience due to using containers instead of Xcode.

Masonite (Python)

Masonite is a wonderful Python framework, much similar to Laravel I found in 2018. I even chatted with Joseph about it in the old Slack channels, before the community moved to Discord.

And there were some Masonite Inertia adapter too

GitHub logo girardinsamuel / masonite-inertia

Server-side Masonite adapter for Inertia.js

Masonite Package GitHub Workflow Status (branch) Python Version PyPI License Code style: black

Introduction

Inertia is a new approach to building classic server-driven web apps. From their own web page:

Inertia allows you to create fully client-side rendered, single-page apps, without much of the complexity that comes with modern SPAs. It does this by leveraging existing server-side frameworks.

Inertia requires an adapter for each backend framework. This repo contains the Masonite server-side adapter for Inertia.js You can find the legacy Inertia PingCRM demo with Masonite here demo (WIP).

Documentation 📚 Quick Start ⚡️

Features

Almost all features of the official server-side adapters are present 😃

  • Shared data
  • Partial reloads
  • Lazy loaded props
  • Set root view in a provider
  • Set root view per view
  • Enable sharing Masonite routes (prefer using masonite-js-routes)
  • Enable sharing Masonite flash messages

Official Masonite Documentation

New to Masonite ? Please first read the Official Documentation Masonite strives to have extremely comprehensive documentation 😃. It would…

Pros

  • I liked the way is well organized and the maintainer is super friendly.

  • You can leverage all the wonderful tools that Python has like PyCharm.

Cons

  • I did not like the way Python manage it dependencies, having so many options like Poetry or Pipenv, it feels non standarized as other languages.

  • Many of the available jobs for Python that I could find were either for Django based projects or Machine Learning stuff I didn't like too much. So using Masonite would only be for green field type projects.

Springboot (Java)

In university I learned a bit of Java, so maybe I could use it professionally I guess?. There were many options to choose from. DropWizard, Spark, Play Framework. But the more documented one in the internet I found was Springboot, besides there were some courses in spanish and some friends that knew something about Springboot, so I give it a chance.

I created some experiments like a simple Discord bot

GitHub logo NinjasCL / wrenbot

A simple discord bot that executes Wren code

Wren Bot 🪶

Seagull icons created by Freepik - Flaticon

Example Run Image

Ninjas.cl MPL v2 Tests

🚀 Environment setup

Requirements

application.properties

Configure your discord token and wren-cli executable path inside application.properties

Run

Execute

./mvnw spring-boot:run
Enter fullscreen mode Exit fullscreen mode

You can now send messages and it will return the output of the code.

☣️ Warning

Highly experimental, use at your own risk.

👩‍💻 Project explanation

Wrenbot is a small Discord bot created for testing out Wren scripts inside Discord.

📘 License

Unless explicitily stated, all source code is under the permissive MPL v2.0 (Mozilla Public License Version 2.0) license.

Is a copyleft license that is easy to comply with. You can combine the MPL version 2.0 software with a proprietary or differently licensed code.

  • If you don’t modify…

But I could not find an adapter to Inertia, just some POC, and I did not want to invest too much time in creating an adapter for it.

GitHub logo jrodalo / inertia

Spring Boot + InertiaJS Demo project

Spring Boot + InertiaJS

Demo project using Spring Boot and Inertia, because why not? :)

Running the App

To build and run the app, just type the following command:

./gradlew bootRun
Enter fullscreen mode Exit fullscreen mode

Then go to http://localhost:8080 and be amazed by the beauty of this PoC ;)




Pros

  • Highly robust framework, lots of documentation, courses and examples.

  • Super mature libraries and dependencies.

Cons

  • Most of the jobs I could find were for Banks and other "older" institutions. That have requirements such as going to the office (before C19) and even dress codes. I prefer to work remotely.

JavaScript

I already use some Javascript at the frontend, why not use it at the backend?. I tried Adonis.js because it was similar to Laravel, but felt odd to me. Also a client once required some bridge and I used Fastify.

GitHub logo NinjasCL / airnotifier-moodle-bridge

A replacement API for AirNotifier Moodle Plugin that connects directly to Firebase and other Push Notification Providers

AirNotifier Moodle Plugin Bridge

A replacement API for AirNotifier server for the AirNotifier Moodle Plugin that connects directly to Firebase, or others Push Notification Providers. This was made since newer versions of AirNotifier seems to be not working with the Moodle Plugin due to usage of old apis. This server implements all needed endpoints and acts as a middleware between Moodle AirNotifier Plugin and Push Notification Providers.

Installation

This server uses NodeJS instead of Python (Used by AirNotifier). Be sure to have NodeJS version >= 10 installed.

Also install Firebase SDK to your platform in order to obtain FCM Token or the other Client SDKs needed.

Configure

You would need to get the configuration from your firebase console or other adapters Check the index.js file for each…

Pros

  • I already knew Javascript and made some small apis and scripts.

Cons

  • There are lot of different frameworks out there. If you learn one, there is no guarantee that the next job you find will use the same. For example if you learn Express and the next one used Koa or Nest.

  • Already felt like a there were something wrong in Javascript, because there is always some breaking change that needs to rewrite the codebase or update the dependencies. I did not like that npm throws a lot warnings in the bootstrap of the project or installing deps.

Elixir and Phoenix

Ok so I previously toyed around with Elixir in Exercism and liked a lot the language. I found Phoenix framework but I did not understand it quite well.

A functional language took time for me to understand the conventions and workflows. It was like a whole new world.

Nevertheless I just waited some time before going fulltime as an Elixir dev. Accepting small freelance jobs in PHP and other small projects. But I decided to write in my CV:

"Would love to participate in Elixir based projects"

I really loved the idea of LiveView and how it wasn't needed a separate frontend framework to achieve a SPA like experience. So Inertia.js wasn't needed in the first place.

Although an adapter is available, before LiveView was created.

GitHub logo devato / inertia_phoenix

Inertiajs Adapter for Elixir Phoenix

Inertia Phoenix

Maintained by Devato

Tests Coverage Codacy Badge Hex.pm

Inertiajs Adapter for Elixir Phoenix 1.4 and 1.5

Usage

Getting started with Inertia.js in a few steps.

Installation

Add to mix.exs:

{:inertia_phoenix, "~> 0.3.0"}
Enter fullscreen mode Exit fullscreen mode

Add Plug to WEB_PATH/router.ex

  pipeline :browser do
    ...
    plug InertiaPhoenix.Plug
  end
Enter fullscreen mode Exit fullscreen mode

Import render_inertia lib/active_web.ex

  def controller do
    quote do
      ...
      import InertiaPhoenix.Controller
    end
  end
Enter fullscreen mode Exit fullscreen mode

Configuration

Add to config/config.exs

config :inertia_phoenix,
  assets_version: 1,          # default 1
  inertia_layout: "app.html"  # default app.html
Enter fullscreen mode Exit fullscreen mode

Render from Controller

NOTE: Flash data is automatically passed through to the page props.

def index(conn, _params) do
  render_inertia(conn, "Home", props: %{hello: "world"})

  # OR

  render_inertia(conn, "Home")
end
Enter fullscreen mode Exit fullscreen mode

Layout/Templates

In February 2022 I received my first offer as a fulltime Elixir developer, just because I said I liked to work with Elixir, no previous experience with it required!.

There I learned more deeply about LiveView and Surface UI.

Even took a course with Grox.io's awesome teacher Bruce Tate, It was an awesome experience. Highly recommended.

Pros

  • Elixir is a fun language. functional and fun to work with.

  • Is easier to find good jobs and be selected, comparing it to other markets such as Javascript were there are more job opportunities, but also more people to compete with.

  • The Erlang (1986) ecosystem is older than Java (1995). So is filled with lots of robust solutions to real world problems, like concurrency.

Cons

  • In my country there are few companies that uses Elixir (I hope that changes soon), but if you know english you can easily access international remote positions.

Conclusions

Why I selected Elixir?. Because I found it fun, functional and robust. And I landed a dream like job just because I liked the language, compared to other technologies that I have to create a "doctoral thesis" just to be interviewed. Elixir's job seeking experience was smooth.

That first Elixir job finished in October 2022 and after some small vacations I landed another dream like job soon after.

Elixir is a powerhouse both in the Technology side of things and the Job market side of things.

For me is the technology of the 2020's decade and much more!.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player