cosmos-sdk/docs/building-modules/modules-manager.md
2019-08-26 09:09:18 -04:00

2.5 KiB

Module Manager and AppModule Interface

Pre-requisite Reading

Synopsis

Cosmos SDK modules need to implement the AppModule interfaces, in order to be managed by the application's module manager. The module manager plays an important role in message and query routing, and allows the application developer to set the order of execution of a variety of functions like BeginBlocker and EndBlocker.

Application Module Interfaces

Application module interfaces exist to facilitate the composition of modules together to form a functional SDK application. There are 3 main application module interfaces:

  • AppModuleBasic for independent module functionalities.
  • AppModule for inter-dependent module functionalities (except genesis-related functionalities).
  • AppModuleGenesis for inter-dependent genesis-related module functionalities.

The AppModuleBasic interface exists to define independent methods of the module, i.e. those that do not depend on other modules in the application. This allows for the construction of the basic application structure early in the application definition, generally in the init() function of the main application file.

The AppModule interface exists to define inter-dependent module methods. Many modules need to interact with other modules, typically through keepers, which means there is a need for an interface where modules list their keepers and other methods that require a reference to another module's object. AppModule interface also enables the module manager to set the order of execution between module's methods like BeginBlock and EndBlock, which is important in cases where the order of execution between modules matters in the context of the application.

Lastly the interface for genesis functionality AppModuleGenesis is separated out from full module functionality AppModule so that modules which are only used for genesis can take advantage of the Module patterns without having to define many placeholder functions.

AppModuleBasic

AppModule

AppModuleGenesis

Implementing the Application Module Interfaces

Module Manager