# Application Data

## 📘 Application Schema

This section describes the structure, relationships, and event mappings of the `Application` entities within the subgraph.

### 🟨 Application

```graphql
type Application @entity {
  id: ID!
  name: String!
  owner: Bytes!
  records: [ApplicationRecord!]! @derivedFrom(field: "application")
  createdAt: BigInt!
  transactionHash: Bytes!
}
```

Represents a deployed game, app, or service set via the `ApplicationSet` event.\
Each application is uniquely identified by its name (lowercased).

**Created by:**

```solidity
event ApplicationSet(string name, address indexed owner);
```

***

### 🟦 ApplicationRecord

```graphql
type ApplicationRecord @entity {
  id: ID!
  application: Application!
  recordId: BigInt!
  applicationVersion: String!
  companyName: String!
  addressHistory: [ApplicationAddressSet!]! @derivedFrom(field: "record")
  metadata: [ApplicationMetadata!]! @derivedFrom(field: "record")
  createdAt: BigInt!
  transactionHash: Bytes!
}
```

Tracks a specific version or configuration of an application.\
Each new `ApplicationRecord` begins a fresh versioned state.

**Created by:**

```solidity
event ApplicationRecordCreated(
  uint256 recordId,
  string applicationVersion,
  string companyName,
  address[] contractAddresses
);
```

***

### 🟧 ApplicationAddressSet

```graphql
type ApplicationAddressSet @entity {
  id: ID!
  record: ApplicationRecord!
  contractAddresses: [Bytes!]!
  updatedAt: BigInt!
  transactionHash: Bytes!
  isInitial: Boolean!
}
```

Stores the versioned list of smart contract addresses tied to the `ApplicationRecord`.\
The first address set comes from `ApplicationRecordCreated` (`isInitial = true`), while updates come later.

**Created by:**

```solidity
event ApplicationRecordAddressesUpdated(
  uint256 recordId,
  address[] contractAddresses
);
```

***

### 🟪 ApplicationMetadata

```graphql
type ApplicationMetadata @entity {
  id: ID!
  record: ApplicationRecord!
  key: String!
  value: String!
  addedAt: BigInt!
  transactionHash: Bytes!
}
```

Tracks optional metadata added to an application record, such as descriptions, tags, or config.

**Created by:**

```solidity
event ApplicationRecordMetadataAdded(
  uint256 recordId,
  string key,
  string value
);
```

***

### 📌 Relationships Summary

| Entity                | Relation    | Description                             |
| --------------------- | ----------- | --------------------------------------- |
| Application → Records | One-to-Many | Each application can have many versions |
| Record → AddressSet   | One-to-Many | Contract address history (versioned)    |
| Record → Metadata     | One-to-Many | Arbitrary key-value metadata            |

***

## 📚 Application Entity Structure

This page outlines the structural hierarchy of entities related to `Application` in the subgraph.

### 📦 Entity Relationship Tree

```
Application
│
├── 1:N ── ApplicationRecord (via application)
│           │
│           ├── 1:N ── ApplicationAddressSet (via record)
│           │           └── isInitial: true/false
│           │
│           └── 1:N ── ApplicationMetadata (via record)
```

### 🔗 Relationship Overview

* **Application**
  * Set via `ApplicationSet` event
  * Uniquely identified by `name.toLowerCase()`
  * Has many `ApplicationRecord`
* **ApplicationRecord**
  * Created via `ApplicationRecordCreated`
  * References an `Application`
  * Stores version, company, and address history
  * Has many `ApplicationAddressSet` and `ApplicationMetadata`
* **ApplicationAddressSet**
  * First one created with the record (`isInitial = true`)
  * Subsequent ones created via `ApplicationRecordAddressesUpdated`
  * Versioned list of associated smart contracts
* **ApplicationMetadata**
  * Optional key-value pairs for extra metadata
  * Only created via `ApplicationRecordMetadataAdded`

### 🧠 Notes

* Entities use `@derivedFrom` to establish GraphQL relationships
* Events are the primary mechanism for updating subgraph state


---

# 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.gamerslab.gg/indexed-data/application-data.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.
