# 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](/appcademy/background/databases/data-modeling-101.md).
{% endhint %}

An [object class](/reference/data-model/object-classes.md) 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](/reference/data-model/object-classes.md#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="/pages/-MiQSN96uYmd\_VhrbATZ" %}
[Object classes](/reference/data-model/object-classes.md)
{% endcontent-ref %}

An [enum](/reference/data-model/enumerated-types.md) 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="/pages/-MiQSen9MaSvJvdou-1h" %}
[Enumerated types](/reference/data-model/enumerated-types.md)
{% endcontent-ref %}

To expose an object class or enum to an app or service, it must be added as a [data source](/reference/apps/data/data-sources.md). 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="/files/dC2NIgDFeqXWqN2KWsNb" alt=""><figcaption><p>The data model designer in Appfarm Create</p></figcaption></figure>

## **Data model designer**

The data model designer is the main workspace for defining and browsing object classes, time series object classes, and enumerated types in your solution.

The designer is organized into three tabs:

* **Object Classes** — lists the standard and file object classes in your solution. You can view them as an expandable list or as an entity-relationship diagram. The count next to the tab name shows how many object classes exist.
* **Time Series** — lists time series object classes separately from standard object classes.
* **Enums** — lists all enumerated types in your solution, with a count next to the tab name.

Selecting an object class or enum updates the URL so that you can reference items with direct links.

#### List view and diagram view

The **Object Classes** tab can be displayed in two layouts, toggled using the icons in the toolbar:

In **list view**, object classes are shown as an expandable list. Expand an object class to view and add properties. Tags are shown as colored badges on the right side of each row.

In **diagram view**, object classes are displayed as an entity-relationship diagram. Lines between boxes indicate reference properties connecting the object classes. Each box can be expanded or collapsed to show or hide its properties, and tags are represented by colored indicators on each box.

The diagram uses **auto-layout** to arrange the object class boxes automatically. You can zoom in and out using the controls in the bottom-left corner of the canvas or with `Ctrl` /`Cmd` + scroll, and pan by clicking and dragging the canvas background. Right-click on the canvas and select **Refresh auto-layout** to rearrange the object class boxes. A **minimap** in the bottom-right corner shows a thumbnail of the full diagram with your current viewport highlighted, making it easier to navigate large data models.

#### Search

Click the search icon in the toolbar to search for object classes by name. The search filters the current view — in both list view and diagram view, only matching object classes are shown.

### Tags

You can label object classes and enums with tags and quickly filter by those tags to see a subset of your data model. Tags are commonly used to separate different parts of a solution — for example, grouping all object classes and enums associated with a specific concept or user flow. This is especially helpful as your solution grows. You can tag both object classes and enums.

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

In the toolbar, click the filter icon to open the filter panel. The following filters are available:

* **Tag is any of** — show only object classes that have one or more of the selected tags.
* **GDPR Classification is any of** — show only object classes that have a specific GDPR classification.
* **Hide the User Object Class** — hide the built-in User object class from the diagram. This can reduce visual clutter in the diagram view when you do not need to see User and its connections.

<figure><img src="/files/H90pLLEZrd5VCf3wb8cK" alt=""><figcaption></figcaption></figure>

You can also scope the data model to a single app or service using the dropdown in the breadcrumb at the top of the page. Selecting an app or service shows only the object classes used by that app or service.

{% hint style="info" %}
**Good to know**

Some apps downloaded from the Farmers Market include a scoped data model. A scoped data model contains object classes that only exist within that app. If the app is deleted, its scoped object classes are also deleted. A scoped object class can be converted to a global object class so that other apps can use it.
{% endhint %}

## 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 to expose 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="/pages/8EK7u2JpSjG3cHh2cuv5" %}
[GraphQL](/reference/data-model/graphql.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appfarm.io/reference/data-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
