Examples of Plugin Architecture in Elixir?

Background

I am studying the concept of Plugin Architecture and part of this task involves finding examples of this within the Elixir community.

My first attempt at searching for this resulted in finding this post by @mudasobwa

While the article differentiates between different types of plugins, it does not offer examples and sample projects in Elixir for analysis and contemplation (still great job by him, go and read his blog !).

Research

So in my search for clear implementations of the Plugin Architecture in Elixir, I though about Plug.

The problem here, is that I find no sources whatsoever specifying if Plug (despite the similar name) indeed follows the Plugin architecture or not. To my knowledge, Plug follows the tenets of the Middleware architecture instead:

Objective

So I was hoping someone could help me find clear examples of Plugin architecture projects using Elixir.

For some context, some clear examples of this are Vim, Eclipse and Minecraft (Clean Coder Blog)

2 Likes

This doesn’t 100% answer your question but I believe it’s common for the Protocols feature in Elixir to support a sort of plugin architecture.

For example:

  • Jason lets you implement the Jason.Encoder protocol to decide how structs in your own app serialize to JSON
  • In Livebook there is the Kino.Render protocol which allows you to decide how custom data types render inside of Livebook.

The key here is that these libraries do not decide in advance all of the different implementations. By exposing the protocol, they allow others to extend in a “plugin style” with other implementations.

1 Like

Does the middleware approach of Tesla fit your question?
https://hexdocs.pm/tesla/Tesla.Middleware.html

1 Like

There might be different examples of what we call plugin. In my humble opinion, we might simply call anything that is allowed by the library author to extend the library functionality the plugin.

Backends

Supporting different backends via custom implementations might be treated as “Plugins architecture example”

  • broadway allows plugins to handle different sources
  • rambla which is kinda supplemental to Broadway (it publishes to different destinations in the same sense as Broadway reads from) shows the example of configuration-managed plugin architecture where different publish targets might be configured based on the “channel name” so that publishing to the “channel” would result in publishing to all the configured destinations
  • telemetria allows transparent switching between actual backends (telemetry, open_telemetry, Logger, etc.)

Middlewares

Yep, Plug is the best example.

Also: Req.

Plugins per se

The very example of a plugin per se might be hard to find in Elixir sources because “plugin” is something adding the functionality not only unknown to the library/framework author, but also unexpected by them; plugins are usually made for standalone applications, specifically for editors/IDEs and such. Elixir code, even despite being a framework, is usually narrowed to some domain and therefore the pure plugin support is kinda “unpure.”

3 Likes

Alright, this explanation is just what I needed. Thanks !

One more thing that I also wanted to mention. Since elixir doesn’t provide sandboxing, using something like luerl goes a long way in ensuring relative safety of the code that is being run.

Obiviously this goes beyond elixir only, as you will write those scripts in lua, but this is more how a pure plugin would look like if you don’t trust the source.

i’m not sure if a “plugin architecture” is something that you’d apply to a library/package, at least by reading the article it seems to apply to a full application that can have it’s behavior extended through configuration. No enduser would deploy an app and change the plug pipeline, or a broadway config, or a tesla client setup.

but the two apps that come to my mind that might fit a “plugin architecture” is bonfire and astarte…

https://docs.astarte-platform.org/

2 Likes