valinor-domain
Core domain types and data structures for the MudWorld virtual world platform.
Purpose
This crate defines the foundational data models shared across the MudWorld system. It provides pure, serializable types with no business logic dependencies, making it suitable as a dependency for any layer of the application.
The domain model represents a MUD-inspired virtual world where:
- Principals authenticate via public keys
- Agents are user profiles that interact in the world
- Places are locations agents can visit
- Friendships form between agents who meet
- Events track everything that happens
When to Use
Use valinor-domain when you need to:
- Define API request/response types
- Persist or retrieve entities from storage
- Pass domain objects between crates
- Serialize data for wire transmission (JSON, protobuf)
- Validate entity ID formats
Do not use this crate for business logic, validation rules, or database operations. Those belong in higher-level crates like valinor-acl, valinor-validate, and valinor-db.
Installation
Add to your Cargo.toml:
[]
= { = "../valinor-domain" }
Or if published:
[]
= "0.1"
API Overview
ID Prefixes
Entity IDs follow a prefix convention for type safety and debugging:
| Entity | Prefix | Example |
|---|---|---|
| Principal | p_ |
p_abc123 |
| Session | s_ |
s_xyz789 |
| Agent | ag_ |
ag_player1 |
| Place | pl_ |
pl_tavern |
| Post | post_ |
post_notice1 |
m_ |
m_letter42 |
|
| Friendship | fr_ |
fr_bond99 |
| MeetOffer | mo_ |
mo_invite7 |
use ;
let agent_id = "ag_abc123";
assert!;
Core Types
Principal
Authentication identity tied to a public key.
use Principal;
let principal = Principal ;
Agent
User profile that exists in the world.
use Agent;
let agent = new;
Place
A location with ownership and access control.
use ;
let place = Place ;
Friendship
Bidirectional relationship between two agents.
use Friendship;
let friendship = new;
// Agent IDs are stored in sorted order for consistent lookups
assert_eq!;
assert_eq!;
// Find the other party in a friendship
let other = friendship.other_agent;
assert_eq!;
MeetOffer
Time-limited invitation to form a friendship.
use MeetOffer;
let offer = new;
// Offers expire after 5 minutes (300 seconds)
assert!;
assert!;
Access Control
Fine-grained permissions for places and boards.
use ;
// Default: public discover/read/write, self-only admin
let acl = default;
// Custom access: friends can read, allowlist can write
let custom_acl = AccessControl ;
Access Modes:
Public- Anyone can accessFriends- Only friends of the ownerAllowlist- Only agents inallow_agent_idsSelf_- Only the ownerUnspecified- No explicit policy
Events
Typed events for real-time updates.
use ;
use json;
let event = Event ;
Event Types:
presence.joined/presence.left- Agent enters/leaves a placeplace.updated- Place metadata changedchat.say/chat.emote- Chat messagesmeet.offered/meet.accepted- Friendship workflowboard.posted- New board postmail.received- Direct message receivedsystem.maintenance/system.broadcast- System announcements
Utilities
use ;
let unix_seconds = now_seconds; // For timestamps
let unix_millis = now_millis; // For event ordering
Related Crates
| Crate | Purpose |
|---|---|
valinor-acl |
Access control evaluation logic |
valinor-validate |
Input validation rules |
valinor-db |
Database persistence layer |
valinor-auth |
Authentication and session management |
valinor-events |
Event streaming and subscriptions |
valinor-wire |
Wire protocol encoding/decoding |
valinor-proto |
Protobuf message definitions |
valinor-place |
Place management operations |
valinor-session |
Session lifecycle handling |
valinor-router |
Request routing |
valinor-worker |
Cloudflare Worker runtime |
valinor-cli |
Command-line interface |
License
MIT