Coding Week 7&8: GSoC’ 22 with SCoRe Lab

Pranjal Walia
Leopards Lab
Published in
4 min readSep 4, 2022

In this post, I’ll be talking about how the consequent weeks of coding went. You can read my previous post about weeks 5&6 here as well.

This time we’re gonna be talking a bit about monorepos and workspace management. Let’s get started!

What are monorepos?

A monorepo is a version-controlled code repository that holds many projects. While these projects may be related, they are often logically independent and run by different teams.

monorepo structure for the JavaScript stack

Monorepos are sometimes called monolithic repositories, but they should not be confused with the monolithic architecture, which is a software development practice for writing self-contained applications.

Benifits of monorepos

The most prominient benifits of the monorepo architecture are namely the following:

  • Easy visibility: If you are invoking a service that calls other services, you can look at the code, understand how it works, and determine if bugs are happening in your own code or in another team’s microservice.
  • Code sharing: Duplicating code for various services causes additional engineering overhead. If common models, shared libraries, and helper code are all stored in a single repository, teams can share them among many services.

How is all this employed in NodeCloud?

NodeCloud uses all the benifits of monorepos to a large extent and is almost a textbook example of the same.

The NodeCloud workspace config

The above package.json indicates that there are two workspaces housed inside the monorepo of NodeCloud, namely the generator and packages.

The generator workspace is what houses the codegeneration module. It takes care of generating the classes that build the plugins for NodeCloud. The packages workspaces houses the individual plugins as individual namespaces that contain a plugin for every provider for NodeCloud.

Packages within NodeCloud

As mentioned earlier, monorepos promote code reusability, the same is at work in the above picture. The common workspace in packages houses the reusable components that are responsible for the functionality of NodeCloud as individual plugins. The remaining projects are individual plugin classes generated by the code-generation module i.e. the generator workspace.

Workspace Management and Lerna

For large projects that have common functionality which can be broken down into smaller ones, Lerna is a one-stop shop. When downloaded and set up, the npm module Lerna can assist you in separating your projects and managing their dependencies separately (In form of monorepos)

The two most important commands in Lerna are lerna publishand lerna bootstrap.Bootstrap will connect repository dependencies. Updated packages can be published with the aid of publish. Let’s start by adding lerna as a dev dependency in your project root.

$ npx lerna init

This creates a project root config file named as lerna.jsonas well as a packages folder. Here is a great tutorial to help you explore and integrate lerna further into your JavaScript projects.

Packaging the AliCloud Plugin

As we’re done with the code generation component for AliCloud which was generating classes for the package, now its time to use those classes and build a plugin out of it, that can be used when someone add nodecloud to there project.

The NodeCloud Aliyun Plugin

What remains in completing the plugin functionality is to expose instances of all the classes via a factory class and for this purpose we create the ali.js provider class which acts as a top level for the plugin. We essentially import all the submodules and environment variables into the top level and export all functions from here.

All of the above is managed independently via lerna. These plugins are standalone monorepos, and the shared core module is the nodecloud installation’s default. On top of it, the plugins are additionally installed.

Epilogue 🔚

Over the course of this week, I worked on getting the plugin working for all the required services. I’ll be working on improving the documentation of my work over the course of the next few weeks.

Well, this is the end of the line for now, till next time! Follow me on my socials in case of any questions, tips, and guidance pertaining to GSoC or anything in general.

Connect with me: Linkedin, Github, Twitter 😀

--

--