Schemas and Data Modeling
Schemas in Dubhe Engine define the structure of your game entities and their components, providing a type-safe way to model your application’s data layer.What are Schemas?
Schemas are the blueprint for your application’s data structure. They define:- Components: Data containers that hold specific attributes
- Systems: Logic that operates on components
- Entities: Game objects that combine multiple components
Defining Components
Components are the building blocks of your entities. Here’s how to define them:Schema Configuration
Define your schemas in thedubhe.config.js file:
Common Data Types
Dubhe Engine supports all Move primitive types and collections:| Type | Description | Example |
|---|---|---|
u8 | 8-bit unsigned integer | 255 |
u64 | 64-bit unsigned integer | 18446744073709551615 |
bool | Boolean value | true or false |
address | Sui address | 0x123... |
vector<T> | Dynamic array | vector<u64> |
String | UTF-8 string | "Hello World" |
Relationships Between Components
You can model relationships between entities using references:Schema Generation
The Dubhe CLI automatically generates Move code from your schema definitions:Best Practices
Component Design Principles
- Single Responsibility: Each component should represent one logical aspect
- Composition over Inheritance: Combine components to create complex entities
- Data Normalization: Avoid duplicating data across components
- Performance Considerations: Keep frequently accessed data in separate components
Example: Game Character
Migration and Updates
When you need to update schemas:- Add new fields (backwards compatible)
- Create migration functions for breaking changes
- Version your schemas for complex applications
Next Steps
ECS Architecture
Learn about Entity Component Systems
Contract Development
Build your first Move contract