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:-
Constructor Pattern
-
Disposal Pattern
-
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:- MicrophoneManager: Controls microphone state and audio streaming
- DisplayManager: Manages display updates with throttling
- PhotoManager: Handles photo capture requests
- VideoManager: Manages video streaming
2. Processing Managers
Managers that process data streams:- AudioManager: Buffers and routes audio data
- TranscriptionManager: Converts speech to text
- TranslationManager: Translates text between languages
- DashboardManager: Generates dashboard displays
3. Control Managers
Managers that coordinate system behavior:- AppManager: Manages app lifecycle and connections
- ManagedStreamingExtension: Handles RTMP streaming
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
- Buffer Management: Clear old data regularly
- Event Throttling: Limit high-frequency events
- Resource Pooling: Reuse expensive resources
- Lazy Initialization: Create resources only when needed
Manager Documentation
Each manager has detailed documentation:- AppManager - App lifecycle and connections
- AudioManager - Audio buffering and routing
- DisplayManager - Display updates and throttling
- TranscriptionManager - Speech-to-text processing
- MicrophoneManager - Microphone state control
- PhotoManager - Photo capture handling
- VideoManager - Video streaming
- DashboardManager - Dashboard generation
- TranslationManager - Language translation
- ManagedStreamingExtension - RTMP streaming
Related Documentation
- UserSession Class - Parent container
- Session Lifecycle - Manager lifecycle context
- Data Flow - How data flows through managers