Skip to main content

Work with Rell modules

In this section, we'll explore project structuring and modularization of your dapp to make your code more organized and maintainable.

In Chromia, you can organize your code into modules to improve its structure and maintainability. A module is defined by adding the module; keyword at the top of a file. By default, the module name derives from the file name, unless the file is named module.rell. In that case, the entire folder becomes a module, named after the folder itself. You can create sub-modules by adding folders within modules or by declaring another module; in a file within the same folder.

For example:

src/main.rell
module;

This defines a module called main.

src/main/module.rell
module;

This also defines a module called main.

If you add a second file, src/main/foo.rell, without a module declaration, it becomes a part of the main module. However, if we declare the file as a module:

src/main/bar.rell
module;

It then becomes a sub-module called main.bar.

By following this pattern, you can create a modular structure for your code.