Skip to main content

Work with Rell modules

In this section, you will explore project structuring and modularization of your dapp to enhance the organization and maintainability of your code.

In Chromia, you can organize your code into modules to improve its structure and ease of maintenance. To define a module, simply add the module; keyword at the top of your file. By default, the module name is derived from the file name, unless the file is named module.rell. In that case, the entire folder becomes a module with the name of 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 automatically becomes part of the main module. However, if you declare it as a module:

src/main/bar.rell
module;

It will create a sub-module called main.bar.

By following this pattern, you can build a modular structure for your code, promoting better organization and maintainability.