Document the decision to store raw API JSON in the daemon and parse it in the tauri-app instead of mapping events to typed Rust structs.
10 KiB
Plan: Store Raw Data Only in record-daemon
Problem
The record-daemon currently parses League Client API events into typed Rust structs (GameEvent enum with variants like LpChangeInfo, KillEvent, etc.) before storing them. This causes:
- Field name mismatches — e.g., the LP_CHANGE event: the API returns
lpChange/lpAfterbut the daemon remaps toleaguePointsDelta/leaguePoints, creating confusion - Data loss — any API field not captured in the Rust struct is silently dropped
- Maintenance burden — every API change requires daemon updates
- Redundant parsing — the
raw_datafield already exists onTimestampedEventbut the parsedGameEventis the primary data carrier
Solution
The record-daemon should only store raw JSON data. The tauri-app will parse the values it needs from the raw data.
The daemon still needs minimal event classification for state machine transitions (start/stop recording), but this can be derived from the URI alone — no typed structs needed.
Current vs Proposed Data Flow
---
title: Current Data Flow
---
flowchart LR
A[WebSocket raw JSON] --> B[websocket.rs: parse into GameEvent enum]
B --> C[ParsedEvent with event + raw_data]
C --> D[main.rs: handle_game_event]
D --> E[TimestampedEvent with event: GameEvent + raw_data]
E --> F[Stored to disk as JSON]
F --> G[tauri-app reads timeline]
G --> H[Uses raw_data from metadata + event from TimestampedEvent]
---
title: Proposed Data Flow
---
flowchart LR
A[WebSocket raw JSON] --> B[websocket.rs: classify event type from URI only]
B --> C[ParsedEvent with event_type + raw_data + uri]
C --> D[main.rs: handle_game_event]
D --> E[TimestampedEvent with raw_data + uri + event_type]
E --> F[Stored to disk as JSON]
F --> G[tauri-app reads timeline]
G --> H[Parses everything from raw_data]
Detailed Changes
1. record-daemon/src/lqp/events.rs — Remove typed event structs
Remove:
- The entire
GameEventenum and all variant structs:LpChangeInfo,MatchInfo,ChampSelectStartInfo,ChampionPickInfo,GameStartInfo,KillEvent,DeathEvent,ObjectiveEvent,InGameStats,GameEndInfo,PlayerStats,PhaseChangeInfo,ObjectiveType,Position RawEventandEventDataenumsGameEvent::from_json(),GameEvent::description(),GameEvent::event_type_name(),GameEvent::is_relevant()
Keep:
GameflowSession,QueueInfo,TeamMember,PlayerChampionSelection— these are used byclient.rsfor REST API response parsing, not for event storagePlayerGameMetadata,RunePage,SummonerSpells,ItemBuild,ItemInfo,PlayerIdentity,RuneSlot— used for metadata, not event storage
Add:
- Event type constants:
pub const EVENT_TYPE_GAME_START: &str = "game_start"; pub const EVENT_TYPE_GAME_END: &str = "game_end"; pub const EVENT_TYPE_PHASE_CHANGE: &str = "phase_change"; pub const EVENT_TYPE_LP_CHANGE: &str = "lp_change"; pub const EVENT_TYPE_KILL: &str = "kill"; pub const EVENT_TYPE_DEATH: &str = "death"; pub const EVENT_TYPE_OBJECTIVE: &str = "objective"; pub const EVENT_TYPE_MATCH_FOUND: &str = "match_found"; pub const EVENT_TYPE_CHAMP_SELECT_START: &str = "champ_select_start"; pub const EVENT_TYPE_CHAMPION_PICK: &str = "champion_pick"; pub const EVENT_TYPE_STATS_UPDATE: &str = "stats_update"; pub const EVENT_TYPE_UNKNOWN: &str = "unknown";
2. record-daemon/src/lqp/websocket.rs — Simplify to classification only
Change ParsedEvent:
pub struct ParsedEvent {
/// Event type string derived from URI.
pub event_type: String,
/// The raw JSON data from the API — stored as-is.
pub raw_data: serde_json::Value,
/// The URI of the endpoint that triggered this event.
pub uri: String,
}
Replace all parse_* functions with a single classify_event(uri, event_type, data) -> ParsedEvent that:
- Maps the URI to an event type string
- Generates a brief description from the raw data for logging
- Returns the raw data unchanged
The massive functions like parse_lp_change_notification, parse_end_of_game_stats, parse_game_event, parse_game_start_event, etc. are all replaced by simple URI-based classification. No field extraction, no JSON reconstruction.
3. record-daemon/src/lqp/client.rs — Use raw JSON for state updates
Change update_state_from_event:
- Instead of matching on
GameEvent::GameStart(info), match onevent_type == EVENT_TYPE_GAME_STARTand extractgame_idfromraw_data.get("gameId") - Same for
GameEvent::GameEnd→ check event_type string
Change duplicate GameStart detection:
- Extract
game_idfromraw_datainstead ofparsed.event.game_id
Change live client event poller:
- Use new
ParsedEventformat
4. record-daemon/src/state/machine.rs — Use event type strings
Change process_event:
pub fn process_event(&self, event_type: &str, raw_data: &serde_json::Value) -> Option<StateTransition> {
match event_type {
EVENT_TYPE_GAME_START => Some(StateTransition::GameStarted),
EVENT_TYPE_GAME_END => Some(StateTransition::GameEnded),
EVENT_TYPE_PHASE_CHANGE => {
if raw_data.as_str() == Some("EndOfGame") && self.is_recording() {
Some(StateTransition::GameEnded)
} else {
None
}
}
_ => None,
}
}
5. record-daemon/src/timeline/store.rs — Update TimestampedEvent
New TimestampedEvent:
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimestampedEvent {
pub video_timestamp: Duration,
pub game_timestamp: Option<Duration>,
pub timestamp: DateTime<Utc>,
/// Event type derived from URI — e.g. game_start, lp_change, kill.
pub event_type: String,
/// Brief human-readable description for logging.
#[serde(default)]
pub description: String,
/// The raw JSON data from the API — the single source of truth.
pub raw_data: serde_json::Value,
/// URI of the endpoint that triggered this event.
pub uri: String,
}
Key changes:
- Remove
event: GameEventfield raw_datais nowserde_json::Value— required, notOptionuriis nowString— required, notOptiondescriptiongets#[serde(default)]for backward compat
Backward compatibility: serde ignores unknown fields by default, so old JSON files with "event": {...} will still load — the event key is simply ignored. New fields raw_data and uri get #[serde(default)] so old files without them get empty defaults.
6. record-daemon/src/timeline/mod.rs — Update Timeline methods
- Remove
add_event()— no longer needed since we always have raw data - Rename
add_event_with_raw()toadd_event()or simplify - Update
event_type_name()to just return the event_type string directly
7. record-daemon/src/main.rs — Update handle_game_event
- Use
parsed.event_typeinstead of matching onGameEventvariants - Extract
game_idfromparsed.raw_datafor recording metadata - Pass
event_typestring to state machine - Create
TimestampedEventwith raw data only
8. record-daemon/src/lqp/mod.rs — Update exports
- Remove
GameEventand all variant struct exports - Add event type constant exports
- Update
ParsedEventexport
9. tauri-app/src/types/timeline.ts — Update TypeScript types
Update TimestampedEvent:
export interface TimestampedEvent {
video_timestamp: [number, number];
game_timestamp: [number, number] | null;
timestamp: string;
event_type: string;
description: string;
/** Raw JSON data from the League Client API — parse as needed based on event_type and uri */
raw_data: Record<string, unknown>;
/** URI of the API endpoint that produced this event */
uri: string;
}
Add LP change parsing from raw data:
export interface LpChangeData {
queueType: string;
leaguePointsDelta: number; // from API field lpChange
leaguePoints: number; // from API field lpAfter
tier: string;
division?: string;
// ... all other fields from the raw API response
}
export function getLpChangeData(event: TimestampedEvent): LpChangeData | null {
if (event.event_type !== 'lp_change') return null;
const raw = event.raw_data;
return {
queueType: raw.queueType as string ?? 'UNKNOWN',
leaguePointsDelta: raw.lpChange as number ?? 0,
leaguePoints: raw.lpAfter as number ?? 0,
tier: raw.tier as string ?? 'UNRANKED',
division: raw.division as string | undefined,
};
}
Update event categorization — getEventCategory() and getEventLabel() already use event_type string, so they should work with minimal changes.
10. tauri-app/src/components/GameReview.vue — Update event rendering
- Any code accessing
event.event(typed event data) should useevent.raw_datainstead - Kill/death/objective details should be parsed from
raw_databased onevent_type
Migration Strategy
- Old timeline JSON files on disk will continue to load because serde ignores unknown fields
- Old files will have
raw_data: {}anduri: ""defaults — the oldeventfield data is lost for display purposes, but the metadata fields (raw_session,raw_end_game_stats, etc.) are unaffected - New recordings will have complete raw data in every event
Files Modified
| File | Change |
|---|---|
record-daemon/src/lqp/events.rs |
Remove GameEvent enum and variants; add event type constants |
record-daemon/src/lqp/websocket.rs |
Replace parse functions with URI-based classification; update ParsedEvent |
record-daemon/src/lqp/client.rs |
Use raw JSON for state updates and dedup |
record-daemon/src/lqp/mod.rs |
Update exports |
record-daemon/src/state/machine.rs |
Use event_type string instead of GameEvent |
record-daemon/src/timeline/store.rs |
Update TimestampedEvent struct |
record-daemon/src/timeline/mod.rs |
Update Timeline methods |
record-daemon/src/main.rs |
Update handle_game_event to use raw data |
tauri-app/src/types/timeline.ts |
Update TimestampedEvent; add raw data parsing helpers |
tauri-app/src/components/GameReview.vue |
Use raw_data for event details |