# Add modules to your dapp · A simple Chromia app with Rell and React · Learn Chromia

> Now apply this by splitting the code into smaller modules. Start by creating a news_feed folder and adding a module.rell file to it:

Source: https://chromia.com/learn/my-news-feed/module-one/project-structure/incorporate-modules/

A simple Chromia app with Rell and ReactLesson 18 of 27

1. [01Building a simple Chromia app with Rell, React and FT4](https://chromia.com/learn/my-news-feed/introduction/)
2. [02Project setup complete](https://chromia.com/learn/my-news-feed/setup/)

Module 1: A Rell backend with FT accounts

1. [03Overview](https://chromia.com/learn/my-news-feed/module-one/)
2. [04Part 1: Designing the database schema](https://chromia.com/learn/my-news-feed/module-one/data-modeling/)
3. [05The data model](https://chromia.com/learn/my-news-feed/module-one/data-modeling/tables/)
4. [06Code the model in Rell](https://chromia.com/learn/my-news-feed/module-one/data-modeling/model/)
5. [07Part 2: Set up accounts](https://chromia.com/learn/my-news-feed/module-one/create-accounts/)
6. [08FT4 accounts configuration](https://chromia.com/learn/my-news-feed/module-one/create-accounts/install-configure-ft4/)
7. [09Authentication with FT4 accounts](https://chromia.com/learn/my-news-feed/module-one/create-accounts/authentication/)
8. [10Part 3: A closer look at operations and queries](https://chromia.com/learn/my-news-feed/module-one/operations-queries/)
9. [11Basic operations](https://chromia.com/learn/my-news-feed/module-one/operations-queries/basic-operations/)
10. [12Basic queries](https://chromia.com/learn/my-news-feed/module-one/operations-queries/write-queries/)
11. [13Part 4: Validating and verifying input](https://chromia.com/learn/my-news-feed/module-one/input-verification/)
12. [14Verify inputs](https://chromia.com/learn/my-news-feed/module-one/input-verification/input-verification/)
13. [15Run unit tests](https://chromia.com/learn/my-news-feed/module-one/input-verification/tests/)
14. [16Part 5: How the dapp project is organized](https://chromia.com/learn/my-news-feed/module-one/project-structure/)
15. [17Work with Rell modules](https://chromia.com/learn/my-news-feed/module-one/project-structure/modules/)
16. [18Add modules to your dapp](https://chromia.com/learn/my-news-feed/module-one/project-structure/incorporate-modules/)
17. [19Part 6: Sign up users with an EVM wallet](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/)
18. [20Sign up accounts with EVM wallets](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/register-evm-accounts/)
19. [21Test the registration](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/test-registration/)

Module 2: The React project

1. [22Overview](https://chromia.com/learn/my-news-feed/module-two/)
2. [23Set up the project](https://chromia.com/learn/my-news-feed/module-two/setup/)
3. [24Project scaffold](https://chromia.com/learn/my-news-feed/module-two/scaffold/)
4. [25Connect the client](https://chromia.com/learn/my-news-feed/module-two/connecting-the-client/)
5. [26Summary and manual testing](https://chromia.com/learn/my-news-feed/module-two/summary-and-tests/)

1. [27What is next?](https://chromia.com/learn/my-news-feed/what-next/)

[Learn](https://chromia.com/learn/)[A simple Chromia app with Rell and React](https://chromia.com/learn/my-news-feed/)

18 / 27Module 1: A Rell backend with FT accountsBeginner

# Add modules to your dapp

Now apply this by splitting the code into smaller modules. Start by creating a `news_feed` folder and adding a `module.rell` file to it:

src/news\_feed/module.rell

```nolines
module;
```

In `main.rell`, add this line to import everything from the new module:

src/main.rell

```nolines
import news_feed.*;
```

Create a `model.rell` file in `src/news_feed` and move the entity definitions out of the main file into it:

src/news\_feed/model.rell

```
entity user {
  mutable name;
  key id: byte_array;
  key account;
}

entity follower {
  index user;
  index follower: user;
  key user, follower;
}

entity post {
  timestamp = op_context.last_block_time;
  index user;
  content: text;
}
```

Move the import of the `account` entity from `ft-library` into `module.rell`. Placing it there makes it available to every file in the module:

src/news\_feed/module.rell

```
module;

import lib.ft4.accounts.{ account };
import lib.ft4.auth;
```

Relocate the remaining code as follows:

* `auth_handler` goes to `src/news_feed/auth.rell`.
* `post_dto` goes to `src/news_feed/dto.rell`.
* The queries go to `src/news_feed/queries.rell`.
* The operations go to `src/news_feed/operations.rell`.

You can also put the `require_user` and `format_user` utility functions directly in `module.rell` if you prefer.

Once you have made these changes, `module.rell` in the `news_feed` module looks like this:

src/news\_feed/module.rell

```
module;

import lib.ft4.accounts.{ account };
import lib.ft4.auth;

function require_user(id: byte_array) = require(user @? { id }, "User with id %s does not exist".format(id));
function format_user(user) = "%s#%s".format(user.name, user.id.to_hex().sub(0, 5));
```

With the imports set up correctly, `main.rell` only needs to contain the `create_user` operation, which helps when testing.

Next, add a `test_operations` module to the `test` folder: create a file there and declare it as a module:

src/test/test\_operations.rell

```
module;

import lib.ft4.core.accounts. { create_account_with_auth };
import lib.ft4.accounts.{ single_sig_auth_descriptor };
import ^^.news_feed.{ user };

operation create_user(name, pubkey) {
    val account = create_account_with_auth(single_sig_auth_descriptor(pubkey, set(["A", "T", "S"])));
    create user ( name, pubkey, account );
}
```

Import the module explicitly in the test file. You can use a relative import here:

src/test/news\_feed\_test.rell

```nolines
import ^.test_operations.{ create_user };
```

Your project is now organized into Rell modules. The file structure should look similar to this:

text

```
rell/src
├─ main.rell
├─ news_feed
│  ├─ auth.rell
│  ├─ dto.rell
│  ├─ model.rell
│  ├─ module.rell
│  ├─ operations.rell
│  └─ queries.rell
├─ registration
│  └─ module.rell
└─ test
   ├─ news_feed_test.rell
   ├─ registration_test.rell
   └─ test_operations.rell
```

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Work with Rell modules**](https://chromia.com/learn/my-news-feed/module-one/project-structure/modules/)[Next →**Part 6: Sign up users with an EVM wallet**](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/)
