libflitter is the core package that runs Flitter. Flitter's initialization structure is broken into individual bits called units, and these units are chained one after the other to create the initialization chain (usually referred to as the stack or the chain).
Each unit contains a function that, when called, initializes that particular unit. When forming the stack, Flitter passes each unit's function to the one before it. When it finishes initializing itself, the unit should call that function from within whatever scope it initializes. In Flitter, these are called contexts. The concept of contexts is important to understanding how Flitter works. Each unit of the initialization chain creates a context and the rest of the chain continues from within that context, and therefore has access to the resources that context exposes.
For example, the first unit to start is the
GlobalUnit. This unit creates the global
_flit object with various resources, then it calls the function of the next unit in the series. From that point on, all other units have access to the
Another example is the
DatabaseUnit. The database unit reads the configured model schemata and creates Mongoose models from them. Then, it uses Mongoose to connect to the configured MongoDB connection. It calls the function of the next unit in the series from within the callback of the Mongoose connect function -- this is its context. That means that all other units loaded after that are guaranteed access to the database -- they run from within (a.k.a. under) the database context.
libflitter contains the units that comprise the core functionality of Flitter, as well as the base classes for things like the
Unit files. In order, libflitter provides the following units:
In this chapter, we'll go through the different units provided in libflitter, as well as the API they provide.