Data Model: Objects & Fields
Relevant source files
The following files were used as context for generating this wiki page:
- packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts
- packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.service.ts
- packages/twenty-front/src/pages/settings/data-model/SettingsObjects.tsx
- packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx
- packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/metadata-builder-agent.ts
- packages/twenty-server/src/engine/metadata-modules/ai/ai-agent/constants/agent-system-prompts.const.ts
- packages/twenty-front/src/modules/spreadsheet-import/utils/tests/normalizeTableData.test.ts
The Data Model is a core feature of Twenty that provides a flexible and customizable structure for CRM data. It allows users to define their own data schemas by creating, updating, and managing "Objects" and their associated "Fields". This system is what enables Twenty to be adapted to a wide variety of business needs, moving beyond a rigid, predefined CRM structure.
This customizability is exposed to users through both a graphical interface in the workspace settings and an AI-powered agent, the "Metadata Builder". The distinction between modifying the data model (schema) and manipulating data (records) is critical. For instance, "Create an object called Project" is a schema modification handled by the Metadata Builder, whereas "Create a company called Acme" is a data manipulation task.
Sources: README.md, packages/twenty-server/src/engine/metadata-modules/ai/ai-agent/constants/agent-system-prompts.const.ts:31-40
Core Concepts
The data model is built on two fundamental concepts: Objects and Fields.
Objects
Objects represent the entities in the data model, analogous to tables in a database. Examples include standard CRM objects like Company, Person, and Opportunity, but users can also define custom objects like Project or Invoice. Each object has properties such as a display label, an internal name, an icon, and a description.
Fields
Fields are the properties of an object, analogous to columns in a database table. Each field has a specific type (e.g., TEXT, NUMBER, RELATION) that determines the kind of data it can store. Fields also have properties like labels, descriptions, and constraints (e.g., required, unique).
The following diagram illustrates the relationship between Objects, Fields, and the actual data records.
This diagram shows that an Object has many Fields, and contains many Records. The set of Fields on an Object defines the data structure for its Records.
Backend Architecture
The backend logic for managing the data model is primarily handled by two NestJS services: ObjectMetadataService and FieldMetadataService. These services are part of the metadata-modules and provide the API for all schema modifications.
Key Services
| Service | Description | Key Methods |
|---|---|---|
ObjectMetadataService | Manages the lifecycle of custom objects. It handles creation, updates, and deletion of object schemas. | createOne, updateOne, deleteOne |
FieldMetadataService | Manages the lifecycle of fields within objects. It handles adding, updating, and deleting fields. | createOne, updateOne, deleteOne |
Sources: packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts, packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.service.ts
The diagram below shows the interaction between these services.
This flow shows that API requests to modify the data model are routed to the appropriate metadata service, which then interacts with the database to persist schema changes.
Frontend Implementation
The user interface for managing the data model is located in the Settings section of the twenty-front application.
Sources: packages/twenty-front/src/pages/settings/data-model/SettingsObjects.tsx, packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx
Object Management (SettingsObjects.tsx)
This component displays a list of all available objects, both standard and custom. It allows users to:
- View existing objects.
- Initiate the creation of a new custom object.
- Navigate to the field editing view for a specific object.
Field Management (SettingsObjectFieldEdit.tsx)
This component is used to manage the fields of a specific object. It provides an interface to:
- View all fields associated with an object.
- Add new fields by selecting a field type and defining its properties.
- Edit the properties of existing fields.
- Delete custom fields.
The following sequence diagram shows the flow of creating a new field from the user interface.
This diagram illustrates the end-to-end process for a user adding a new field to an object, from the UI interaction to the backend service call and back.
*Sources: packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx, packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.service.ts *
AI-Powered Schema Modification
Twenty includes a "Metadata Builder" AI agent specialized in modifying the workspace schema. This agent interprets natural language requests to perform data modeling tasks.
Agent Name: metadata-builder
Description: AI agent specialized in modifying the workspace SCHEMA/DATA MODEL - creating new object types, adding fields to objects, and managing object structure. It is explicitly distinguished from agents that manipulate data records.
Sources: packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/metadata-builder-agent.ts:9-12, packages/twenty-server/src/engine/metadata-modules/ai/ai-agent/constants/agent-system-prompts.const.ts:31-40
Capabilities
- Create new custom objects.
- Add fields of various types to existing objects.
- Update object and field properties (labels, descriptions, icons).
- Create relations between objects.
Available Field Types
The metadata-builder agent, and by extension the entire data model, supports a wide range of field types.
| Field Type | FieldMetadataType Enum | Description |
|---|---|---|
| Text | TEXT | Simple text fields. |
| Number | NUMBER | Numeric values (integers or decimals). |
| Boolean | BOOLEAN | True/false values. |
| Date Time | DATE_TIME | Date and time values. |
| Date | DATE | Date only values. |
| Select | SELECT | Single choice from a list of options. |
| Multi-Select | MULTI_SELECT | Multiple choices from a list of options. |
| Link | LINK | URL fields. |
| Links | LINKS | Multiple URL fields. |
EMAIL | Email address fields. | |
| Emails | EMAILS | Multiple email fields. |
| Phone | PHONE | Phone number fields. |
| Phones | PHONES | Multiple phone fields. |
| Currency | CURRENCY | Monetary values. |
| Rating | RATING | Star ratings. |
| Relation | RELATION | Links to other objects (one-to-many, many-to-one). |
| Rich Text | RICH_TEXT | Formatted text content. |
Sources: packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/metadata-builder-agent.ts:24-41, packages/twenty-front/src/modules/spreadsheet-import/utils/tests/normalizeTableData.test.ts:10-12, 33-39, 90-99
Summary
The Data Model is a cornerstone of Twenty's architecture, providing the essential flexibility for users to tailor the CRM to their specific needs. It is supported by a robust backend with dedicated services for objects and fields, a clean frontend interface for manual configuration, and an advanced AI agent for intuitive, natural-language-based schema management. The clear separation between schema modification (metadata-builder) and data manipulation is a key design principle that ensures system integrity and predictability.