Mantra getting started guide

To start with Mantra, you just need a few steps to build your first application.

First check you have Node.js installed (currently, all major versions +12 are tested and supported by Mantra).

Install current Mantra release in a few steps.

Have a look to basic commands:

$ mantrad
new-project (mantra) : Creates a new Mantra project
version (mantra) : Show Mantra version
More info at site
No detected Mantra config file (mantraconfig.json)

A Mantra application should contain a json configuration file named as mantraconfig.json.

As explained in documentation, this file defines a number of properties to indicate:

  • Components in the project and their locations.
  • Applications configurations (like ports, etc.).
  • Mantra core and components configurations.
  • Global vars.
  • etc.

Here is a basic example from a demo project named "QR Code Generator":

   "CurrentVersion": "1",
   "ComponentsLocations": ["components"],
   "Apps": {
      "mainapp": { "Port": 8080 }
   "ComponentsConfig": {
      "core": {
         "croncleanupevent": "* */5 * * * *",
         "cronbackupevent": "0 */5 * * * *"
      "static": { "cached": false }
   "Entities": {
      "default": {"provider":"sqlite","databasepath":"./qrdemo.db"}
   "DefaultComponents": ["qrmain", "qrcodegenerator"],
   "ActiveServices": ["middleware","view","post","get"],
   "NotFoundRedirect": "/404.html",
   "LandingView": "qrmain.mainview",
   "GlobalTemplateVars": {
      "global-sitename": "This is a Mantra application!"

Many of these properties are optional and many others can be overwritten for each application.

As an explanation of that sample file:

  • It defines an application identified by "mainapp". It is an application which web services will be listening at port 8080.
  • The project has two components located at "/components" folder: "qrmain" and "qrcodegenerator".
  • The configuration file says that the landing page (what should be rendered when pointing to http://localhost:8080/), will be the view "qrmain.mainview" (view "mainview" defined by component "qrmain").
  • Also, it indicates that the data repository ("Entities" entry), will be a simple Sqlite database, which file will be qrdemo.db. This file will be generated when the application is installed with command "mantrad install" inside the folder of the project.

This is a very simple introduction to the anatomy of a Mantra project.

Try to create your first project with:

$ mantrad new-project

Current version of Mantra comes with some templates for new projects and for adding new components to an existing one.

Have a look to what it creates when you run that command. Also, we publish lots of demo projects introducing each Mantra concept.


One of the main paradigm principles of Mantra applications, consists of a thin but fast and efficient layer to persist data transparently for the components that need to persist any kind of data. Mantra does this with RedEntities (a subproject of Mantra).

The purpose of this layer, basically, is:

  • Isolate how components data are persisted.
  • Avoid big databases with complex models difficult to migrate and maintain.
  • Implement independent simple table models.
  • Have in the same application or system, differents data repositories engines according to data consumption needs.
  • The components can perform CRUD operations (create, read, update and delete) easily with a semantic chain calls fast to write and understand, like this:
getUserById: async (Mantra, userId) => {
   // Get database model instance of component "users"
   const usersDb = Mantra.models.users;

   // Select the entity of "usersinfo" table by entity ID
   return usersDb.usersinfo.S().W("ID=?",userId).Single();

Where to go from here?

After having a very simple idea of how to work with Mantra, you can go deeper with these resources:

  • Go to demo projects and download some sample projects and run them.
  • Read the official documentation
  • Download some components and read them.
  • Read about Mantra data persistance layer: RedEntities
  • Build your own projects:
    • Learn (is easy to understand Mantra principles and develop Mantra projects 🤓).
    • Read and play with other projects 😮.
    • And finally, master Mantra as a professional 💪.