> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Data Collections Extension Files and Code

## Article: Data Collections Extension Files and Code

## Article Link: https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/backend/data-collections/data-collections-extension-files-and-code.md

## Article Content:

# Data Collections Extension Files and Code

When you generate a [data collections extension](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/data-collections/about-data-collections-extensions.md), the CLI adds the following files to your project:

```bash
src/
  └── extensions/
      └── backend/
          └── data-collections/
              ├── data-collections.extension.ts   # Shared extension file
              └── <your-collection-name>.ts       # Collection definition file
```

- `data-collections.extension.ts`: Builds the [data collections extension](#data-collections-builder-file).
- `<your-collection-name>.ts`: Defines the [collection's schema, permissions, indexes, and initial data](#data-collection-definition-file). Each file represents a collection.

The CLI also adds an import and a `.use()` call to your project's [`extensions.ts`](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/wix-cli/supported-extensions/about-the-extensions-ts-file.md) file so the extension is registered with your project.

> **Note**: You can move these files to any location in the `src/` folder and update the references in your `extensions.ts` file. Learn more about the [flexible file system](https://dev.wix.com/docs/wix-cli/cli-for-apps/project-structure/folders-and-files/src-extensions.md).

## Data collections builder file

The `data-collections.extension.ts` file contains the data collections extension's builder configuration. The builder is defined using the following schema:

```ts
import { extensions } from '@wix/custom-extensions';

export default extensions.dataCollections({
  id: string,
  name: string,
  collections: Collection[],
});
```

Here's an example builder definition with 2 registered collections:

```ts
import { extensions } from "@wix/custom-extensions";

import customerFeedbackCollection from "./customer-feedback";
import productReviewsCollection from "./product-reviews";

export default extensions.dataCollections({
  id: "c7bdcb61-9c98-45d5-8a1e-76ce89b407eb",
  name: "Data Collections",
  collections: [customerFeedbackCollection, productReviewsCollection],
});
```

### Data collection builder fields

The following fields can be used in the builder's configuration object:

| Field         | Type   | Description                                                                                                                                                                                                                              |
| ------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`          | string | Required. The data collections extension ID as a [GUID](https://en.wikipedia.org/wiki/Universally_unique_identifier). Wix automatically generates it when you add the extension. It must be unique across all extensions in the project. |
| `name`        | string | Required. A human-readable name for the extension. Defaults to `'Data Collections'`. You can edit it directly in the file, and view it in the app dashboard under **Extensions**.                                                        |
| `collections` | array  | Required. The default exports from each `<your-collection-name>.ts` collection definition file you want this extension to register. Each time you generate a new collection, the CLI adds it to this array.                              |

## Data collection definition file

Each `<your-collection-name>.ts` file defines a single collection. The default export is an object that follows the schema documented in the [data collections extension JSON reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md).

Each collection definition file comes with default fields, default permissions, and other configuration that you can customize. The starting file looks like this:

```ts
import type { DataCollection } from "@wix/custom-extensions";

export const collectionIdSuffix = "<your-collection-name>";

export default {
  idSuffix: collectionIdSuffix,
  displayName: "<your-collection-name>",
  fields: [
    { type: "TEXT", displayName: "Title", key: "title" },
    { type: "IMAGE", displayName: "Image", key: "image" },
  ],
  displayField: "title",
  dataPermissions: {
    itemInsert: "CMS_EDITOR",
    itemRead: "CMS_EDITOR",
    itemRemove: "CMS_EDITOR",
    itemUpdate: "CMS_EDITOR",
  },
  indexes: [],
  initialData: [],
} satisfies DataCollection;
```

The `satisfies DataCollection` check makes TypeScript validate the object against the collection schema, so your IDE flags a missing or invalid field before you build.

The file also exports a named constant, `collectionIdSuffix`, which has the same string used as `idSuffix`. To reference this collection elsewhere in your project, import this constant from your backend code.

### Collection fields

The default export object accepts the following top-level fields. For the full schema, including supported field types, permission roles, index options, and the initial-data format, see the [data collections extension JSON reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md).

| Field             | Type   | Description                                                                                                                                                                                                                                   |
| ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `idSuffix`        | string | Required. The suffix appended to the full collection ID. The full ID in the CMS becomes `@<company>/<app-name>/<idSuffix>`. It must be 1-36 characters and can only contain letters, numbers, underscores, and hyphens.                       |
| `displayName`     | string | Required. The collection's display name in the CMS.                                                                                                                                                                                           |
| `displayField`    | string | Required. The `key` of the field used to identify items in this collection when they're referenced from other collections.                                                                                                                    |
| `fields`          | array  | Required. The collection's schema. See the [supported field types](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md).                                              |
| `dataPermissions` | object | Required. The role required for each [item action](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-permissions/introduction.md#item-actions): `itemInsert`, `itemRead`, `itemRemove`, and `itemUpdate`. |
| `indexes`         | array  | Indexes to improve query performance.                                                                                                                                                                                                         |
| `initialData`     | array  | Items to seed the collection with when it's first created on a site. Each item must conform to the schema declared in `fields`.                                                                                                               |

## See also

- [Add a Data Collections Extension with the Wix CLI](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/backend/data-collections/add-a-data-collections-extension-with-the-wix-cli.md)
- [About Data Collections Extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/data-collections/about-data-collections-extensions.md)
- [Data Collections Extension JSON Reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md)
- [About the Wix Data Collections API](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/introduction.md)