MantriDependency System

Why a new system?

Medium to Large web applications require a robust system to manage their dependencies. While module loaders excel at interoperating with external libraries, they can become difficult to work with when used as dependency systems. A new system should allow the code to be easily tested, debuged and get out of the way after the build process. Meet Mantri!

Why use Mantri?

Harder, Better, Faster, Stronger. Mantri leaves no footprint on your deployed file, which means faster delivery of your app. Provides dead easy testing by exposing all your methods and properties on development, hides them on production. Simple and lean provide and require statements, and a complete workflow to build your codebase.

How Mantri works

Mantri uses Namespaces. Each file provides a namespace and can require any number of other namespaces.

goog.provide(''); // I provide this namespace.
goog.require('foo.baz'); // I require this namespace.// The result is a giant dependency tree.

When developing, all your files are loaded synchronously before DOMContentLoaded event fires, just like your code would evaluate when packaged and minified. Using modern day build flows, Mantri will build your application removing all the provide and require statements.

Here is a breakdown of what happens when you do a page load during development, just hover over the diagram.

Mantri Development Diagram
Mantri page loading sequence

Mantri wraps around the powerfull Google Closure Tools, the same tools used by most of Google's web assets. These tools were build for the purpose of easily managing and maintaining large codebases. Mantri lowers the barier of entry by abstracting all the complexity of such sophisticated systems. In other words, Mantri will be there for you from the second file up to thousands.

Writing Modular Code

Writing Modular Code has everything to do with modular programming and nothing to do with module definitions (CJS, AMD, harmony). You can write perfectly modular code by using namespaces. It is always interesting to go back where you started and discover something new...

Busting Myths

  • Modern day build flows have changed the way we work.
  • The development environment is decoupled from production.
  • Module Definition Patterns and Module Loaders are two different things.
  • Modules !== Files
  • Modular Programming is not a trademark of AMD, CJS or any Module Definition Pattern.
  • Developing using Namespaces improves visibility throughout the project, enhances maintainability and enables scalable code.

Getting Started

Mantri consists of the Web Runtime and the Command Line Tools. The Web Runtime's job is to load the files of your application during development. The Command Line Tools perform various tasks like building your application and calculating dependencies.

Read the Getting Started guide for instructions on using Mantri.


I'd love to help, find me lurking on Freenode in #grunt or just ping me on twitter @thanpolas.