> For the complete documentation index, see [llms.txt](https://docs.internetobject.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.internetobject.org/schema-definition-language/advanced-schema-concepts/composition.md).

# Composition & Reuse

Composing and reusing schemas through references.

Large schemas are built by **composing** smaller, named pieces. Define a shape once in the header as a `$` reference and reuse it wherever it's needed — across fields, arrays, and other schemas.

## Reuse a shape across fields

```ruby
~ $address: { street, city }
~ $schema: { name: string, home: $address, office?: $address }
---
~ John, { Main St, NYC }, { 5th Ave, NYC }
~ Jane, { Oak Ave, LA }
```

## Compose schemas from other schemas

A reference can be used inside another reference, building larger shapes from smaller ones:

```ruby
~ $address: { street, city }
~ $person: { name: string, address: $address }
~ $schema: { lead: $person, members: [$person] }
---
~ { Ann, { Main St, NYC } }, [{ Bob, { Oak Ave, LA } }, { Cy, { 5th Ave, NYC } }]
```

Here `members` is an array whose element type is the `$person` schema.

## Set the default schema by reference

`$schema` may itself be a reference:

```ruby
~ $address: { street, city }
~ $person: { name: string, home: $address }
~ $schema: $person
---
~ John, { Main St, NYC }
```

## Guidance

* For readability, define a shape **before** you reference it. Order within the header is not significant — references resolve after the whole header is read (see [Schema References](/definitions/schema-references.md)).
* Reuse keeps documents consistent and small; change a shape once, everywhere updates.

## See Also

* [Schema References](/definitions/schema-references.md)
* [Object (SchemaDef)](/schema-definition-language/data-types/object.md) · [Array](/schema-definition-language/data-types/array.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.internetobject.org/schema-definition-language/advanced-schema-concepts/composition.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
