Shared Data Models
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Shared Data Models in the BT Speaker project reside within the bt_speaker_core package. This package acts as the backbone of the monorepo, providing common Dart classes that define the structure of data exchanged between the phone_app (client) and the pi_app (server). These models ensure consistency in how audio metadata, visualizer data, equalizer settings, and LED commands are serialized and deserialized across the WebSocket protocol.
Sources: CLAUDE.md:14-17, README.md:21-25
Core Data Structures
The project defines four primary data models within bt_speaker_core. Each model is equipped with toJson() and fromJson() methods to facilitate communication over WebSockets using JSON payloads.
Primary Models
| Model | Purpose | Key Attributes |
|---|---|---|
| BeatData | Live audio analysis data for the visualizer. | FFT bars, BPM, intensity. |
| NowPlaying | Metadata for the currently active track. | Title, Artist, Album Art, Progress. |
| EqSettings | Audio equalization parameters. | Bass, Mid, Treble levels. |
| LedCommand | Control signals for the WS2812B LED ring. | Mode, Color. |
Sources: CLAUDE.md:38-41, README.md:24-25, README.md:37-41
Data Flow Architecture
Data flow is primarily unidirectional in the current phase, moving from the Phone application to the Raspberry Pi application. The Pi app parses these models into a sealed class hierarchy of events.
The diagram shows how the shared models in bt_speaker_core define the contract for communication between the phone client and the Pi server.
Sources: CLAUDE.md:38-42, README.md:27-32
Implementation Details
Serialization and Protocol
The communication layer relies on a 'type' field within the JSON objects to identify which shared model is being transmitted. The Pi app uses these types to route data to the appropriate BLoC (Business Logic Component).
| Message Type Key | Corresponding Core Model | Pi App Handler |
|---|---|---|
beat | BeatData | VisualizerBloc |
eq | EqSettings | EqBloc |
led | LedCommand | LedBloc |
now_playing | NowPlaying | NowPlayingBloc |
Sources: CLAUDE.md:38-41, README.md:37-41
Dependency Management
The shared models are integrated into the applications using Flutter's workspace resolution. Both the phone_app and pi_app reference the core package via relative path dependencies in their respective pubspec.yaml files.
# Found in apps/phone_app/pubspec.yaml and apps/pi_app/pubspec.yaml
dependencies:
bt_speaker_core:
path: ../../packages/bt_speaker_core
Sources: apps/phone_app/pubspec.yaml:47-49, apps/pi_app/pubspec.yaml:40-42, pubspec.yaml:8-11
Conclusion
The Shared Data Models are critical for maintaining a synchronized state between the remote control (phone) and the display/audio output (Pi). By centralizing BeatData, NowPlaying, EqSettings, and LedCommand in a dedicated core package, the system ensures type safety and reduces redundancy across the monorepo architecture.
Sources: CLAUDE.md:14-17, README.md:21-25