MegaYours Docs
  • 🚀MegaYours
    • Extending your on chain data
  • 💾Megadata
    • Solana Integration
  • 🌎Yours Protocol
    • 🤔Getting Started
      • Setting up Your Project
      • Creating Your First Module
      • Creating & Minting Tokens
      • Composable Tokens
      • Making Your Tokens Interoperable
    • 💱Tokens
      • Types
      • Functions
      • Unique Identifier
    • 🧩Modules
      • 🔌Attaching Modules
      • 🌈Relationships
      • 🎭ERC1155
      • 📚Declaration
      • 👾External
    • 📄Metadata
    • 🔗Interoperability
    • 🔄Migration from Originals
      • FT3
      • Interfaces
      • Prototype
  • 👾Import Existing Tokens from any Chain
    • 🛰️Gamma Chain
  • 🔗Links
    • Github: Yours Protocol
Powered by GitBook
On this page
  • Direct Relationships
  • Indirect Relationships
  • Best Practices

Was this helpful?

  1. Yours Protocol
  2. Modules

Relationships

When building modules in Yours Protocol, there are different ways to create relationships between them. Let's explore these patterns using a game example where characters can equip items.

Direct Relationships

A direct relationship is when one module directly references another module's entities:

// modules/items/model.rell
entity item {
  key yours.token;
  mutable power: integer;
}

// modules/characters/model.rell
import items;

entity character {
  key yours.token;
  mutable experience_points: integer;
}

entity equipped_item {
  key character;
  key item: items.item; // Reference the token through the items module
  mutable slot: text;
}

Avoid doing this! While this approach works, it creates tight coupling between modules. The character module cannot exist without the items module, making it less reusable.

Indirect Relationships

A better approach is to have modules reference tokens independently:

// modules/items/model.rell
entity item {
  key yours.token;
  mutable experience_points: integer;
}

// modules/characters/model.rell
entity character {
  key yours.token;
  key name;
  mutable level: integer;
}

entity equipped_item {
  key character;
  key item: yours.token; // Reference the underlying token and therefore create an indirect relationship
  mutable slot: text;
}

Here both modules are loosely coupled through the token. The benefits are:

  1. Loose Coupling: The character module doesn't need to know about equippable entities

  2. Modularity: Each module can be used independently

  3. Reusability: The modules can be shared and used in different contexts

For example, the same item token could be:

  • Equipped by a character

  • Displayed in a marketplace

  • Used in crafting

  • Stored in a vault

Each of these features can be implemented as separate modules without direct dependencies.

Best Practices

We highly recommend using the Indirect Relationship approach. The key features of Yours Protocol are flexibility, modularity, and reusability. It's important for modules to be shareable, which is much easier if each module is self-contained and doesn't directly depend on other modules.

A Direct Relationship may simplify querying slightly in certain scenarios, but we only recommend using it in modules that are specific to your dApp and ones that you do not intend to share or promote as reusable.

PreviousAttaching ModulesNextERC1155

Last updated 3 months ago

Was this helpful?

🌎
🧩
🌈