> For the complete documentation index, see [llms.txt](https://gnosza.gitbook.io/substrate-blockchain-starter-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gnosza.gitbook.io/substrate-blockchain-starter-kit/architecture/database.md).

# Database

<figure><img src="https://657856132-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOTJDcluFmQraO1qYj7vv%2Fuploads%2FndMtwRFUAaFE4nYjabUr%2FScreenshot%202023-09-21%20at%2001.12.31.png?alt=media&amp;token=ccf6d004-ad0b-4da9-bab3-188f9e35b267" alt=""><figcaption><p>Database Diagram</p></figcaption></figure>

## Software used

We are using [PostgreSQL](https://www.postgresql.org) as our Database for persisting data and [Sequalize ORM](https://sequelize.org) to simplify the interaction with the database in our Typescript project.

### Sequalize Migrations & Seeders

These utility files are named and sorted by date when they were created to ensure consistent and deterministic deployment between multiple different computers or installations.

#### Migrations

Sequalize allows us to easily create migrations located in `/database/migrations` folder, which allow us to easily recreate the db on new machines, as well to alter the db in the future consistently between multiple machines or team members.

#### Seeders

The seeders allow us to pre-fill the data of our tables such as User profiles, Admin profiles, Pallets etc.

Sequalize being in typescript, we can re-use our business logic configuration files and generate table entries dynamically during the setup without repeating our code.

## Tables

### Sequalize

These are the tables that sequalizes internally uses for it's own metadata:

* **sequalize\_meta**
* **sequalize\_seed**

### Session

Tables we use for management of our session cookie

* **session**

### Users

Tables for managing users and ther permissions

* **users**

### Pallets

Tables that hold all of the Pallet related data, normalised to [2NF](https://www.geeksforgeeks.org/second-normal-form-2nf/) ensure zero data redudancy

* **pallets**: Holds all the pallet metadata
* **pallet-dependency**: Tracks relationships between module dependency of the pallets
* **pallet-category**: Simple table to track which categories a pallet belongs to
* **pallet-author:** Simple table to track Authors of a pallet (There can be multiple)

### Templates

Tables that hold of the Template related data, normalised to 1NF

* **templates:** Holds all the template metadata
* **template-dependency:** Tracks which pallets a template uses
