Skip to main content

Overview

MentraOS Cloud uses a Manager pattern to organize functionality within UserSessions. Each manager is responsible for a specific domain of functionality, encapsulating related state, logic, and operations. This pattern promotes separation of concerns, maintainability, and testability.

Architecture

Manager Characteristics

Common Patterns

All managers follow these patterns:
  1. Constructor Pattern
  2. Disposal Pattern
  3. Session Reference
    • Each manager holds a reference to its parent UserSession
    • Allows access to other managers when needed
    • Provides context for operations

Manager Categories

1. Hardware Managers

Managers that interface with smart glasses hardware:

2. Processing Managers

Managers that process data streams:

3. Control Managers

Managers that coordinate system behavior:

Manager Interactions

Direct Communication

Managers can interact through the UserSession:

Event-Based Communication

Some managers use events for loose coupling:

Shared State

Managers access shared state through UserSession:

Lifecycle Management

Initialization

Managers are created when UserSession is instantiated:

Active Operation

During session lifetime:
  • Managers respond to incoming messages
  • Process data streams
  • Maintain internal state
  • Coordinate with other managers

Cleanup

When session ends, all managers are disposed:

Best Practices

1. Single Responsibility

Each manager should focus on one domain:
  • ✅ AudioManager handles only audio
  • ❌ AudioManager shouldn’t manage display

2. Proper Resource Management

3. Error Isolation

Errors in one manager shouldn’t crash others:

4. Logging Context

Always use contextual logging:

Common Manager Methods

State Queries

Configuration

Data Processing

Cleanup

Threading Considerations

  • All managers run in the Bun runtime event loop
  • Long operations should be async or use workers
  • Avoid blocking operations
  • Use timers for periodic tasks

Testing Managers

Managers should be testable in isolation:

Performance Guidelines

  1. Buffer Management: Clear old data regularly
  2. Event Throttling: Limit high-frequency events
  3. Resource Pooling: Reuse expensive resources
  4. Lazy Initialization: Create resources only when needed

Manager Documentation

Each manager has detailed documentation: