Current version : 0.26.0
Made in 🇫🇷 ◌ GitHubNPM

Basic

An example showcasing the mechanisms of libmodulor in one single executable file.

This is the perfect example to have an overview of the most important primitives of libmodulor. In one single file, we declare an App, a UseCase, a Product and a Target.

Then we play with the use case in multiple languages (en (default) and fr). You can see how validation works and how we can manipulate the input and output.

Get

git clone git@github.com:c100k/libmodulor.git
pnpm install

Build

./scripts/examples/build.sh

Run

Open your Terminal Emulator.

# with node
(cd dist-examples/products/Basic && node index.js)

# with bun
(cd examples/products/Basic && bun index.ts)

Note how it works with both Node and Bun without having to override any implementations in the container. This is due to the high modularity of libmodulor and the great work the bun team is doing to support the Node.js API.

Here if the full output you should get, showing what's going on step by step.

****************************************************************
* Declaring
****************************************************************

Declaring a specific DataType
Declaring the App
Declaring the UseCase
Declaring the Product
Declaring the Target

****************************************************************
* Initializing
****************************************************************

Initializing i18n
Initializing dependency injected managers
Initializing the UseCase

****************************************************************
* Playing with the use case in 'en'
****************************************************************

Your email address : _
Your firstname : _
Your lastname : _

Leaving input fields blank
Submitting
 Your email address must be filled

Filling all the fields correctly except the email, filled with an invalid value
Submitting
 Your email address must be a valid email address

Filling a valid email
Submitting
 Use case executed successfully

Response with translated labels and formatted values
Your ticket #                 : 1
Amount                        : €99.99
Your registration #           : 67f7a660-0e2e-42d1-8bef-c76777ecc7e3

****************************************************************
* Playing with the use case in 'fr'
****************************************************************

Votre adresse email : _
Votre prénom : _
Votre nom : _

Leaving input fields blank
Submitting
 Votre adresse email doit être renseigné

Filling all the fields correctly except the email, filled with an invalid value
Submitting
 Votre adresse email doit être une adresse email valide

Filling a valid email
Submitting
 Use case executed successfully

Response with translated labels and formatted values
Votre # de ticket               : 1
Amount                          : €99.99
Votre # d'inscription           : f5fcd9e7-1f0b-4d60-86c0-f94ce8558fd6

Records persisted in InMemoryUCDataStore
{
  aggregateId: "67f7a660-0e2e-42d1-8bef-c76777ecc7e3",
  appName: "Event",
  createdAt: 2025-11-22T12:03:46.634Z,
  data: null,
  executionMode: "user",
  id: "3ba047f3-15fe-4df5-8482-7d2bf4040cd8",
  input: {
    email: "dexter@caramail.com",
    firstname: "Dexter",
    lastname: "Morgan",
  },
  name: "Register",
  organizationId: null,
  userId: null,
}
{
  aggregateId: "f5fcd9e7-1f0b-4d60-86c0-f94ce8558fd6",
  appName: "Event",
  createdAt: 2025-11-22T12:03:46.642Z,
  data: null,
  executionMode: "user",
  id: "7026dc60-ac37-4b70-bf16-685937568540",
  input: {
    email: "dexter@caramail.com",
    firstname: "Dexter",
    lastname: "Morgan",
  },
  name: "Register",
  organizationId: null,
  userId: null,
}

Play with the example, add features, break it 🙂.