# Design the data model · Tic Tac Toe on Chromia with Rell and Unity · Learn Chromia

> Here you design a small database model for the Tic Tac Toe game.

Source: https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/tables/

Tic Tac Toe on Chromia with Rell and UnityLesson 5 of 20

1. [01Tic Tac Toe on Chromia with Rell and Unity](https://chromia.com/learn/tic-tac-toe/introduction/)
2. [02Set up your project](https://chromia.com/learn/tic-tac-toe/setup/)

Module 1: A Rell backend with FT4 accounts

1. [03Overview](https://chromia.com/learn/tic-tac-toe/module-one/)
2. [04Part 1: Database design, operations and queries](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/)
3. [05Design the data model](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/tables/)
4. [06Perform basic operations](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/basic-operations/)
5. [07Write basic queries](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/write-queries/)
6. [08Part 2: Set up accounts](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/)
7. [09Configure FT4 accounts](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/install-configure-ft4/)
8. [10Authentication with FT4 accounts](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/authentication/)
9. [11Update tests](https://chromia.com/learn/tic-tac-toe/module-one/create-accounts/update-tests/)
10. [12Part 3: How the dapp project is organized](https://chromia.com/learn/tic-tac-toe/module-one/project-structure/)
11. [13Work with Rell modules](https://chromia.com/learn/tic-tac-toe/module-one/project-structure/modules/)
12. [14Add modules to your dapp](https://chromia.com/learn/tic-tac-toe/module-one/project-structure/incorporate-modules/)

Module 2: The Unity project

1. [15Overview](https://chromia.com/learn/tic-tac-toe/module-two/)
2. [16Set up the project](https://chromia.com/learn/tic-tac-toe/module-two/setup/)
3. [17Project scaffold](https://chromia.com/learn/tic-tac-toe/module-two/scaffold/)
4. [18Link the client to the blockchain](https://chromia.com/learn/tic-tac-toe/module-two/connecting-the-client/)
5. [19Summary and manual testing](https://chromia.com/learn/tic-tac-toe/module-two/summary-and-tests/)

1. [20What next?](https://chromia.com/learn/tic-tac-toe/what-next/)

[Learn](https://chromia.com/learn/)[Tic Tac Toe on Chromia with Rell and Unity](https://chromia.com/learn/tic-tac-toe/)

05 / 20Module 1: A Rell backend with FT4 accounts

# Design the data model

Here you design a small database model for the Tic Tac Toe game.

The model has a single entity, `game`. It maps to a table that stores the board state, tracks whose turn it is, and records the current game status.

## Code the model in Rell

A Chromia dapp's data model is written in Rell. The code below defines the model, and the breakdown after it explains each part:

src/tic\_tac\_toe/enums.rell

```
enum game_status {
    created,
    active,
    winner,
    draw
}

enum slot_states {
    free,
    zero,
    one
}
```

src/tic\_tac\_toe/entities.rell

```
entity game {
    created_by: account;
    created_at: timestamp = get_last_block_time();
    mutable player2_account_rowid: rowid = rowid(0);
    mutable last_step_by: rowid;
    mutable last_step_at: timestamp = get_last_block_time();
    mutable winner: rowid = rowid(0);
    mutable status: game_status = game_status.created;
    mutable slot_1: slot_states = slot_states.free;
    mutable slot_2: slot_states = slot_states.free;
    mutable slot_3: slot_states = slot_states.free;
    mutable slot_4: slot_states = slot_states.free;
    mutable slot_5: slot_states = slot_states.free;
    mutable slot_6: slot_states = slot_states.free;
    mutable slot_7: slot_states = slot_states.free;
    mutable slot_8: slot_states = slot_states.free;
    mutable slot_9: slot_states = slot_states.free;
}
```

The `game` entity holds the board state and controls how the game progresses. Its fields are:

* **`created_by`**: The identifier (`account`) of the account that started the game.
* **`created_at`**: The game's start time, set automatically to the block time at creation.
* **`mutable player2_account_rowid`**: Starts at zero (`rowid(0)`) and receives the second player's row ID when that player joins.
* **`mutable last_step_by`**: The row ID of the player who moved most recently. It changes after every turn.
* **`mutable last_step_at`**: A timestamp, like `created_at`, that records when the most recent move happened. It changes with each move.
* **`mutable winner`**: Starts at zero (`rowid(0)`). When the game ends, it is set to the winning player's row ID. If nobody wins, it stays zero.
* **`mutable status`**: The game's current state, beginning at `game_status.created`. You can change it to values for other states, such as "active" or "completed."
* **`mutable slot_1`** to **`mutable slot_9`**: The nine cells of the board. Each one starts as `slot_states.free` and changes as players move, showing whether a cell belongs to one of the players or is still free.

You now have a basic Rell data model for Tic Tac Toe on the Chromia blockchain. It gives you an efficient way to store and update the board state, and it is the foundation for building the rest of the game.

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

[← Previous**Part 1: Database design, operations and queries**](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/)[Next →**Perform basic operations**](https://chromia.com/learn/tic-tac-toe/module-one/data-modeling/basic-operations/)

On this page

* [Code the model in Rell](#implement-the-model-in-rell)
