# Data model

The Data model is the foundation of a solution. It contains a definition of how your data is structured and how it is connected. The data model is shared across all apps and services in a solution. A data model is made up of *object classes* and *enumerated types (enums)*.&#x20;

{% hint style="info" %}
If you are new to the concepts of data modeling we recommend reading [Data modeling 101](https://docs.appfarm.io/appcademy/background/databases/data-modeling-101).
{% endhint %}

An [object class](https://docs.appfarm.io/reference/data-model/object-classes) is a structured definition of a single business object. Often, this data is reflected in the real world somehow. If you have worked with a spreadsheet in Microsoft Excel this will be familiar. For example you might have a sheet for registering employees called `Employees`. In the sheet there are columns with the headers `Employee Number`, `Firstname`, `Lastname`, `Department`, `Employed Date`, `Email Address`. For each cell you can format what type of data it should contain, for example text (string), a date, or a number (integer).

To represent this structure in the data model you would create an object class `Employee`. You would then add [object class properties](https://docs.appfarm.io/reference/object-classes#object-class-properties) for each column (`Employee Number`, `Firstname`, etc). Within an app you can create and modify `Employee` objects based on this definition and store them in the database. Objects represent the rows in your spreadsheet.

{% content-ref url="data-model/object-classes" %}
[object-classes](https://docs.appfarm.io/reference/data-model/object-classes)
{% endcontent-ref %}

An [enum](https://docs.appfarm.io/reference/data-model/enumerated-types) is a set of key-value pairs used to define constant values in a solution. Continuing the example above, you might create an enum called `Departments` to store the names of the different departments in the company. You can add this enum as an object class property and  restrict the possible departments an `Employee` object can have to those you have defined.

{% content-ref url="data-model/enumerated-types" %}
[enumerated-types](https://docs.appfarm.io/reference/data-model/enumerated-types)
{% endcontent-ref %}

To expose an object class or enum to an app or service, it must be added as a [data source](https://docs.appfarm.io/reference/apps/data/data-sources). This approach allows you to create different views into your data by creating apps tailored to different roles and use cases. You can also read and manipulate data using [GraphQL](#graphql).

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FYcLP179OwDKLrCJu3h9a%2FGlobal%20Data%20Model.png?alt=media&#x26;token=718a540b-c824-418d-9821-4196ce8d555a" alt="Screenshot of the Global data model in Appfarm Create"><figcaption><p>The Data model in Appfarm Create</p></figcaption></figure>

## **Data model designer**

The data model designer is a visual tool to define and view your [object classes](https://docs.appfarm.io/reference/data-model/object-classes). You can choose between a list view of your object classes or an entity-relationship diagram that visualizes how your object classes are related. To see the [enums](https://docs.appfarm.io/reference/data-model/enumerated-types) in your solution, you need to use the table view.

In the table view you can expand and collapse the object classes to view and add properties.

In the diagram view, you can drag and drop the object classes around the canvas. You can expand and collapse each object class to show or hide the properties. When expanded, [tags](#tags) are represented by a colored line at the bottom. The lines between the object classes indicate that they are connected with reference properties.&#x20;

## **Tags**

You can label object classes with tags and quickly filter by those tags to see a subset of your data model. This can be helpful as your solution grows and you have data which are only used by some or one of your apps. You can tag both [object classes](https://docs.appfarm.io/reference/object-classes#general-properties) and [enums](https://docs.appfarm.io/reference/enumerated-types#properties).

To add a new tag to your data model:

* Click the tags icon at the top of the data model designer.
* Click **Create new tag**.
* Enter a **Tag name** and select a color to represent the tag.
* Click **Add tag**.

## Filtering the Global Data Model

In the top section of the Global Data Model, you may filter the Object Classes - both from the diagram view and list view. You may filter by Tags, or choose to se the Data Model just for a single App or Service by selecting an App or Service in the **App Scoped Data Model** or **Service Scoped Data Model**, as seen below.

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FVOu7V0OEGJ0UpTaC0Ed7%2FGlobal%20Data%20Model%20-%20Scoped.png?alt=media&#x26;token=89c3e76c-e75a-4826-8df1-7c6f402ab83f" alt=""><figcaption><p>See the Data Model for a single App</p></figcaption></figure>

Note that downloading Apps from the [Farmers Market](https://docs.appfarm.io/reference/appfarm-create/farmers-market), some of these Apps comes with a Scoped Data Model. A Scoped Data Model contains Object Classes that only exists in that App. Once the App is deleted, so are the Scoped Object Classes. A Scoped Object Class may be turned into a Global Object Class in order for other Apps to use these Object Classes as well.

## GraphQL

The Appfarm platform has built-in support for querying your data through GraphQL. GraphQL can be used as a developer tool to view and modify data in your solution, as well as a method for exposing your data model to external parties for integration.

To access the GraphiQL IDE for your environments:

* Click **Explore GraphQL** in the toolbar.
* Click the relevant button for the environment you wish to access and the GraphiQL will open in a new tab.

{% content-ref url="data-model/graphql" %}
[graphql](https://docs.appfarm.io/reference/data-model/graphql)
{% endcontent-ref %}
