Skip to content

Event Sourcing and Player Action Audit Log #206

@Mkalbani

Description

@Mkalbani

Description

Introduce an event sourcing pattern for player actions so every significant game event is stored as an immutable log entry. This powers replay, debugging, anti-cheat investigation (extends #18), and verifiable on-chain reputation when integrated with mesh-contract.

Acceptance Criteria

  • PlayerEvent entity: id, userId, sessionId, eventType, payload (JSONB), timestamp
  • Events emitted for: puzzle.started, puzzle.solved, puzzle.abandoned, hint.used, answer.submitted, achievement.unlocked
  • Events published to an internal NestJS EventEmitter2 bus and persisted to DB asynchronously
  • GET /players/:id/events — paginated event history (admin only)
  • GET /sessions/:id/events — full event replay for a session (admin/owner only)
  • Events are append-only — no update or delete on PlayerEvent table
  • Aggregates (e.g., total hints used, solve time) computable from event log
  • Tests for: event emission on each trigger, append-only enforcement, aggregate calculation

Technical Notes

  • Use @nestjs/event-emitter for internal bus
  • Persist asynchronously via a queue to avoid blocking the request cycle
  • Index on (userId, eventType, timestamp) for efficient querying
  • JSONB payload schema validated per eventType at write time

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions