Architecture
Understand how Hyperbasis organizes and persists spatial data.
Overview
┌─────────────────────────────────────────────────────────────┐
│ Your AR App │
├─────────────────────────────────────────────────────────────┤
│ Hyperbasis SDK │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ HBSpace │ │ HBAnchor │ │ HBStorage │ │
│ │ (Model) │ │ (Model) │ │ (Persistence API) │ │
│ └─────────────┘ └─────────────┘ └──────────┬──────────┘ │
│ │ │
│ ┌─────────────┐ ┌─────────────┐ │ │
│ │ HBTimeline │ │ HBDiff │─────────────┤ │
│ │ (History) │ │ (Changes) │ │ │
│ └─────────────┘ └─────────────┘ │ │
│ ┌──────────────────────────┼───────────┐ │
│ │ │ │ │
│ ┌─────▼─────┐ ┌───────▼───────┐ │ │
│ │HBLocalStore│ │ HBCloudStore │ │ │
│ │(FileManager)│ │ (Supabase) │ │ │
│ └─────┬─────┘ └───────┬───────┘ │ │
│ │ │ │ │
│ ┌─────▼──────────────────────────▼─────┐ │ │
│ │ HBCompression (zlib) │ │ │
│ └──────────────────────────────────────┘ │ │
└─────────────────────────────────────────────────────────────┘Core Components
Models
| Component | Purpose |
|---|---|
| HBSpace | Container for ARWorldMap + metadata |
| HBAnchor | 3D transform + custom metadata for placed objects |
| AnyCodableValue | Type-erased value for flexible metadata |
| HBAnchorEvent | Immutable record of anchor changes |
| HBTimeline | History navigation and state reconstruction |
| HBDiff | Comparison between two points in time |
Storage
| Component | Purpose |
|---|---|
| HBStorage | Main persistence API |
| HBLocalStore | FileManager-based local persistence |
| HBCloudStore | Supabase cloud sync (optional) |
| HBCompression | Zlib compression utilities |
Data Flow
Save Flow
ARWorldMap → HBSpace.serialize() → HBCompression.compress()
→ HBLocalStore.saveSpace() → [optional] HBCloudStore.uploadSpace()- •ARWorldMap is serialized using
NSKeyedArchiver - •Data is compressed with zlib (~40% size reduction)
- •Saved to local file system
- •Optionally synced to cloud
Load Flow
HBLocalStore.loadSpace() → HBCompression.decompress()
→ HBSpace.deserialize() → ARWorldMap → ARSession.run(initialWorldMap:)- •Load compressed data from local storage
- •Decompress
- •Deserialize to ARWorldMap
- •Use for relocalization
Anchor Flow
simd_float4x4 → HBAnchor.flatten() → JSON encode
→ HBLocalStore.saveAnchor() → [optional] HBCloudStore.uploadAnchor()Anchors store transforms as flat arrays of 16 floats (column-major order).
Event Flow
Every anchor modification is recorded:
save(anchor) → detect change type → append HBAnchorEvent → save anchor state
│ │
├─ new anchor → created event
├─ transform changed → moved event
├─ metadata changed → updated event
├─ deleted → deleted event
└─ restored → restored eventEvents are stored in append-only JSONL files (one per space).
File Structure
Local storage location:
~/Documents/Hyperbasis/
├── spaces/
│ ├── {uuid}.json # Space metadata + compressed worldMapData
│ └── ...
├── anchors/
│ ├── {uuid}.json # Anchor data
│ └── ...
├── events/ # Event logs for versioning
│ └── {spaceId}/
│ └── events.jsonl # Append-only event log
├── pending_operations.json # Queue for failed cloud operations
└── sync_metadata.json # Last sync timestampKey Design Decisions
Why Flat Transform Arrays?
The 4x4 transformation matrix is stored as 16 floats rather than nested arrays because:
- •Direct mapping to
simd_float4x4memory layout - •Efficient JSON serialization
- •Column-major order matches GPU conventions
Why Soft Delete for Anchors?
Anchors use soft delete (deletedAt timestamp) rather than hard delete to:
- •Enable undo functionality
- •Support sync conflict resolution
- •Allow historical queries
Why Compress World Maps?
ARWorldMap data is typically 5-50MB. Compression provides:
- •~40% size reduction
- •Faster cloud upload/download
- •Reduced storage costs
Why Event Sourcing for Versioning?
Events provide:
- •Immutable history - Events are append-only, never modified
- •Small storage - Events are 200-500 bytes vs 5-50MB snapshots
- •Flexible queries - Reconstruct state at any point in time
- •Audit trail - Know exactly what changed and when
Next Steps
- •HBSpace - Detailed space API
- •HBAnchor - Detailed anchor API
- •HBStorage - Storage operations
- •Versioning - Timeline and rollback