pnezis

pnezis

:tada: We are open sourcing workspace a set of tools for working with elixir monorepos, inspired by rust workspaces and nx.dev. Twitter announcement

You can find the docs here.

There are many reasons for having a monorepo but working with them may be cumbersome. Workspace provides a set of tools for working with big monorepos efficiently.

What is a workspace?

A workspace is nothing more than a git repository hosting multiple mix projects in any arbitrary folder structure. Path dependencies are used for cross project dependencies similarly to umbrellas.

The central concept of the workspace is the workspace graph. This is a directed acyclic graph where the nodes represent projects and the edges the dependencies between projects.

Workspace uses git to get the changes between two revisions. Knowing which files have changed we can deduce which project is modified or affected:

status

Running tasks

You can run any command from the root on all or a subset of the workspace projects. You can also run time consuming tasks only on the affected projects significantly improving CI times for large codebases.

run

Checking your workspace

When your workspace grows, it can go out of hand quickly. You need a way to check that your projects are properly defined. With the workspace.check task you can among other:

  • Ensure that specific dependencies are set on all projects, e.g. ex_doc.
  • Ensure that external dependencies versions match the expected ones.
  • Verify that no forbidden dependencies are defined.
  • Ensure that all projects have common build paths

Enforcing boundaries

One of the main purposes of monorepos is to help you split your codebase into independent, cohesive and reusable packages. You can enforce a clean architecture by tagging your projects and enforcing boundaries between them.

Creating a workspace

You can create a new workspace with the workspace.new scaffolder:

mix archive.install hex workspace_new

mix workspace.new your_workspace

Helper packages

The workspace repo is itself a workspace and comes with two extra small packages.

  • cli_options - provides an opinionated way to parse CLI options based on a schema similarly to NimbleOptions
  • cascade - is a small library for generating code for templates.

Disclaimer

Despite being stable (we successfully use it internally to manage a massive elixir codebase consisting of hundreds of packages) this is still a 0.x.x project and breaking changes may happen.

Showing Posts 1 to 10

davydog187

davydog187

This is a really exciting start!

We’ve recently moved to GitHub - casey/just: 🤖 Just a command runner · GitHub after we gave up on running various tasks through Mix. We will definitely give this a try and report back

mindreframer

mindreframer

Very interesting! How do you deal with IDE integration? Something specific? It does not work with ElixirLS on a hello-world example with package_a and package_b.

[Info  - 21:16:12] Updating incremental PLT
[Warn  - 21:16:13]     error: module PackageB is not loaded and could not be found
pnezis

pnezis OP

I don’t have any specific settings. Do path dependencies work in general for you?

mindreframer

mindreframer

Yes, they do. But I have to open each package as single folder in VSC for ElixirLS to work properly. So I thought maybe you have some tips how to open the full workspace in an IDE and still have it working. But that is probably a deep rabbit hole.

Also, a separate _build folder is maintained per package folder, right?

mindreframer

mindreframer

Would be curious about a small workspace example project with CI configs, some boundary checks and suggested folder layout for a bigger project. If that is not too much effort.

Looks really solid, I like that it provides enough structure and flexibility! Thanks for open-sourcing it.

pnezis

pnezis OP

Yes, they do. But I have to open each package as single folder in VSC for ElixirLS to work properly. So I thought maybe you have some tips how to open the full workspace in an IDE and still have it working. But that is probably a deep rabbit hole.

Indeed, this is something that can be worked on.

Also, a separate _build folder is maintained per package folder, right?

This is up to you. We use common deps and _build paths, and also enforce it using workspace checks

pnezis

pnezis OP

Would be curious about a small workspace example project with CI configs, some boundary checks and suggested folder layout for a bigger project. If that is not too much effort.

Workspace is dogfooding workspace so it is a simple example. It’s github CI is a nice example. You will see that in PRs only the affected projects are tested, while on the main branch the tasks are ran across all projects.

Regarding the project structure it’s up to you and how you wish to organize your code. In our case we prefer a domain oriented shallow folder structure. I will release the workspace demo project I used for the screenshots, which also includes some boundary checks.

mindreframer

mindreframer

Awesome! I didn’t notice, that workspace itself uses workspace, that’s cool! Yep, I guess I will have some fun time study-ing the codebase.

Thanks a lot!

cmo

cmo

Very cool. I’ll definitely be giving this ago after switching to a monorepo recently.

Are you using vscode’s workspaces? In the main menu there is “add folder to workspace”. I’ve done this for each folder and have an extension installed that opens a terminal for each one.

mindreframer

mindreframer

Yeah, vscode workspaces could be a solution. I was hoping for something a bit simpler, but with monorepos there is no such thing. :slight_smile: Maybe it’s good enough though.

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ausimian
Castle is a package I put together to assist with building Elixir releases capable of being live-upgraded via the ‘official’ release hand...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

Other Trending Topics Top

GenericJam
Mob 0.9.21 has been released. Added Mob.Storage.exclude_from_backup/1 and Mob.Storage.excluded_from_backup?/1. Apple rejects apps that...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews