mantraconfig.json file

Every Mantra project consists of a mantraconfig.json and a set of components.

In file mantraconfig.json, some properties are indicated, such us:

  • Locations where to find components
  • Location of frontend templates
  • Components properties if necesary
  • Properties of core components
  • Apps properties
  • Data persistance properties (based on RedEntities object-mapping project)

Some of root properties con be overwritten in an specific app configuration, like frontend location or port to listen, allowing multiple frontends in same project for different but related apps (final user application, admin application and so on).

Given all main properties of the project in a simple file, you can have a mantraconfig.json file for development and a different file for production.

This json file has these properties described below:

{
   "CurrentVersion": "<current version of the project>",
   "ComponentsLocations": [
      "basecomponents"
   ],
   "Apps": {
      "appsample1": {
         "Port": 8081
      },
      "appsample2": {
         "Port": 8083,
         "FrontendLocation": "frontendadmin",
         "LandingView": "admin.dashboard"
      },
      "appsample3": {
         "ActiveServicesByComponent": [
            "admin/cron,extend",
            "books/cron,extend",
            "hdlanalytics/cron,extend",
            "hdltasks/cron,extend",
            "master/cron,extend",
            "tasks/cron,extend"
         ],
         "ActiveServices": [
            "cron"
         ]
      }
   },
   "Port": 8081,
   "LandingView": "landing.landing",
   "ComponentsConfig": {
      "core": {
         "croncleanupevent": "*/5 * * * * *",
         "cronbackupevent": "0 */5 * * * *",
         "minifyhtml": false,
         "compressresponses": false,
         "translatejsapi": "resourceminifier.translatejsfiles",
         "translatecssapi": "resourceminifier.translatecssfiles",
         "baseurl": "http://core.localhost:8081/"
      },
      "logs": {
         "logToConsole": "true",
         "daystoremoveoldlogs": 1
      },
   },
   "Entities": {
      "default": {
         "provider": "mysql",
         "host": "localhost",
         "database": "mysampleapp",
         "user": "mysamplemysqluser",
         "password": "12345"
      }
   },
   "DefaultComponents": [
       "mymantracomponent"
   ],
   "ActiveServices": [
      "middleware",
      "view",
      "post",
      "get"
   ],
   "NotFoundRedirect": "/404.html",
   "GlobalTemplateVars": {
      "global-sitename": "My project name",
      "global-sitecompany": "Mantra Microkernel Project"
   }
}

Description of mantraconfig.json file properties

"CurrentVersion" (optional)

Indicates the current version of the mantra project, usually in the form of x.y.z numbers.

This property can be overwritten by specific app configuration.

"ComponentsLocations" Array of strings indicating the local paths where Mantra will find project components.

When installing a new component or running an application, Mantra will find those folders.

"Port" (optional)

In the case when Mantra application runs an user interface or REST API, this number indicates the port to listen to.

This property can be overwritten by specific app configuration.

*"LandingView" (optional)

In the case when Mantra application runs an user interface, this property indicated the landing view to render for landing page of the ui (http://<yoursite>/).

This property can be overwritten by specific app configuration.

"ComponentsConfig"

JSON object with the configuration if needed for each component.

Each component of the project can set a number of properties to configure it according to specific needs inside the project.

This properties are available with MantraAPI.GetComponentConfig("<component name>") or MantraAPI.config.<component name>.

"Entities"

JSON object with data repositories accesing properties.

"Default" indicates the default properties.

With Mantra, some specific components can have their own data repositories, allowing multiple database within the same running application.

In this case, indicating the name of the component as property in "Entities" will be managed by the framework to instantiate the connection when calling the component, like this:

"Entities": {
   "default": {
      "provider": "mysql",
      "host": "localhost",
      "database": "mysampleapp",
      "user": "mysamplemysqluser",
      "password": "12345"
   },
   "mycomponent": "mysql",
      "host": "localhost",
      "database": "mycomponentdatabase",
      "user": "mysamplemysqluser",
      "password": "12345"
}

This is one of the nice feature of Mantra Microkernel Framework :-)

"DefaultComponents"

Array with the names of the components to install by default when installing the project in a new machine.

"ActiveServices"

This property is an array of strings indicating the services to run when running the application:

  • "middleware": indicates to run components middlewares.
  • "view": indicates to run and activate views.
  • "post": indicates to run and activate HTTP POST calls.
  • "get": indicates to run and activate HTTP GET calls.
  • "cron": indicates to run and activate components cron definition jobs.

Indicating which services to activate in each application, you can tune the needs for specific applications.

This property can be overwritten by specific app configuration.

"NotFoundRedirect" (optional)

Indicates the html file to render when a route is not found. Only needed if the application defines an user interface.

"GlobalTemplateVars" (optional)

This json object indicates a number of properties available for all views within the application, useful for global variables like name of the site and so one.

As an example:

  • "global-sitename": "your project name"
  • "global-sitecompany": "company of the project"

With this, in any html view or template, property "Mantra Framework" and "Mantra" will be available.

Overwritting properties y "Apps" section

A Mantra project can define a number of diffents applications; each application configuration goes inside "Apps" section; most of the properties of an app, overwrites roots properties.

The general schema for "Apps" property is as following:

"Apps": {
   "app-one": {
      ... properties ...
   },
   "app-two": {
      ... properties ...
   },
   ...
}

The name of the application is the name of the properties under "Apps" (in the case, "app-one", "app-two" and the like).

By doing so, you can start an specific Mantra application with:

$ mantrad startapp app-one

The properties than can be used to overwrite root ones, are the following:

  • "ActiveServices"
  • "FrontendLocation"
  • "LandingView"
  • "Port"

Two properties are "Apps" specific: "ActiveServicesByComponent"

By default, all services (cron, views, middlewares, etc.) defined and registered by all components are active (loaded by bootstrap process when running the application).

However, for specific applications which only need some services from some specific components, can indicated exactly which ones should be loaded when starting the application.

"ActiveServicesByComponents" is an array indicating with string which components and its services to be loaded in the format "<componentname>/<services to activate separated by comman>", like this sample:

"Apps": {
   "hdltasks": {
      "ActiveServicesByComponent": [
         "admin/cron,componentextend",
         "hdlanalytics/cron,componentextend",
         "master/cron,componentextend",
      ],
      "ActiveServices": [
         "cron"
      ]
   }
}

In this sample,for "hdltasks" application, only will be loaded services "cron" and "componentextend" for components "admin", "hdlanalytics" and "master", and only "cron" service will be loaded when starting the application.

"InactiveComponents"

This property is an array of strings indicating a number of components than shouldn't be loaded when starting the application:

"Apps": {
   "adminapp": {
      "InactiveComponents": ["books", "authors", "pdfgenerator"]
   }
}

In this case, when running "adminapp", "books", "authors" and "pdfgenerator" will not be loaded.

Using "ActiveServicesByComponent" and "InactiveComponents" you can control exactly which services and components should be loaded for any specific application, if this feature is needed.

Some mantraconfig.json file samples

Here you can check a basic mantraconfig.json files example:

{
  "CurrentVersion": "3",
  "ComponentsLocations": [
    "components"
  ]
   "Apps": {
    "mainapp": {
      "LandingView": "landing.landingpageview"
    },
  },
  "Port": 8081,
  "ComponentsConfig": {
    "core": {
      "croncleanupevent": "0 */5 * * * *",
      "cronbackupevent": "0 */5 * * * *",
      "minifyhtml": true,
      "compressresponses": true,
      "enablesecurity": true,
      "baseurl": "http://192.168.1.187:8081/"
    },
    "Entities": {
      "default": {
        "provider": "mysql",
        "host": "localhost",
        "database": "pay_core",
        "user": "mysqluser",
        "password": "**************"
      },
    },
    "DefaultComponents": [
      "admin",
      "date",
      "dbremoveolder",
      "deltatohtml",
      "eventasync"
    ]
   "ActiveServices": [
      "middleware",
      "view",
      "post",
      "get"
    ],
    "NotFoundRedirect": "/404.html",
    "GlobalTemplateVars": {
      "global-sitename": "Your site name",
      "global-sitecompany": "Your company name",
      "global-privacyandtermslink": "/content/privacidad-y-terminos",
      "global-contactsupportlink": "/contact/support",
      "global-usersitelink": "http://localhost:8081"
    }
  }
}

In mantra-demos GitHub project, you can find several working Mantra applications.

Multiple mantraconfig.json file

Usually, mantraconfig.json file is environment specific (development, production, etc.).

Mantra always looksup "mantraconfig.json" file, so, to have multiple versions of this file according to the environment, is recommendable to have that file as a link to real configuration files using command ls.

By doing so, you can have "dev.mantraconfig.json" and "prod.mantraconfig.json" files with differents configurations an "mantraconfig.json" file as a link to one of them according to the environment.