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 code structure and maintainability. A module is defined by adding the module; keyword at the top of a file. By default, the module name is derived from the file name unless the file is named module.rell, in which case the entire folder becomes a module and is 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;

Defines a module called main.

src/main/module.rell
module;

It also defines a module called main.

Adding a second file src/main/foo.rell without module declaration becomes a part of the main module, but if we instead declare the file as a module

src/main/bar.rell
module;

it becomes a sub-module called main.bar.

You can create sub-modules by following this pattern, allowing you to create a modular structure for your code.