Data Model

SonicJs has a simple yet flexible data model. We have a core data model with only a few base entities (which map to tables). 

Each entity has a JSON based "data" property that can contain any data shape (aka "schema") desired by the site administrator. This enables site administrators to change their detailed data model (the part inside the JSON based "data" property) on the fly and instantly be able to create instances of this model with zero coding. This is possible because SonicJs' form builder is capable of generating create/edit forms on the fly for any data model defined as a content type within SonicJs.

The Data Model documentation is provided for anyone doing core development on the data access layer. In practice, you will rarely need to understand the underlying data model while building custom themes/modules.

Schema Files

If you prefer reading code, here is the location of the schema files. As you can see, there are only 4 main entities used for the entire platform.

sonicjs/
|-- server/
|   |-- data/
|   |   `-- entity/
|   |     `-- ContentSchema.js
|   |     `-- SessionSchema.js
|   |     `-- TagSchema.js
|   |     `-- UserSchema.js

Content Entity

The content entity is the main entity used in SonicJs. For most projects, well over 90% of your site content with be an instance of the content entity.

Field Type Description
Id int / primary key The Id for the entity. The Id auto increments from 1.
data text This field is used to store stringified JSON data. It is highly dynamic and contain any shape of data (properties, arrays). The "schema" for this data is defined in content types which are managed with a drag and drop content type manager.
contentTypeId varchar This is the type of content or "schema" that the above data field contains. Examples: "blog", "menu", "role"
createdByUserId int The user Id that originally created the content.
lastUpdatedByUserId int The user Id that most recently updated the content.
createdOn datetime Timestamp from when the content was first created.
updatedOn datetime Timestamp from when the content was most recently updated.
url varchar / unique:true Every content has a unique url. The provides and an easy lookup when rendering site pages.
tags relationship: many-to-many Tags that are related to the content. Content can have many tags. Tags can have many content.

User Entity

The user entity contains email, password and various profile properties for authenticated site/app users. Similar to the content entities data property, the user entities profile property is a dynamic field that can hold any data (properties and arrays) as specified by the site administrator using the drag and drop content type editor. 

Field Type Description
Id int / primary key The Id for the user. The Id auto increments from 1.
username varchar / unique:true The username (or more commonly used email address) used to login/authenticate to the website/app.
salt varchar The salt part of the password.
hash varchar The hash part of the password.
profile text This field is used to store stringified JSON profile data. It is highly dynamic and contain any shape of data (properties, arrays). The "schema" for this data is defined in the user content types which is managed with a drag and drop content type manager.
createdOn datetime Timestamp from when the user was first created.
updatedOn datetime Timestamp from when the user was most recently updated or more recently logged in.
tags relationship: many-to-many Tags that are related to the user. Users can have many tags. Tags can have many users.

Session Entity

User sessions are stored in the data to enable SonicJs to be installed across multiple server nodes in production. 

Field Type Description
Id varchar / primary key The unique Id for the session. Example: CBQOjsxWrABMwgDqi63ImJsF6UIEfrCN
expiredAt bigint The session expiration key. Example: 1627677181513
json text The content of the session. Example: {"cookie":{"originalMaxAge":null,"expires":null,"secure":false,"httpOnly":true,"path":"/"}}

Tag Entity

Tags allow for content and users to be categorized. Tag are a many-to-many relationship for both users and content.

Field Type Description
Id int / primary key The unique Id for the tag.
name varchar The name or title of the tag. Examples: "NodeJs CMS", "Headless CMS"