NestJS Adventure API Part 3: Adding XP, Levels, and Badge Logic via Separate Services
The third installment of the Grimoire API series introduces gamification features including experience points, leveling, and badge unlocks to a choose-your-own-adventure NestJS application. Rather than expanding the existing ProgressService with additional conditionals, the developer extracted XP and badge logic into dedicated services to keep responsibilities clearly separated. XpService calculates player levels using a pure mathematical formula, requiring no database access and making it straightforward to unit test in isolation. BadgesService, by contrast, does query the database to prevent duplicate badge awards when a player revisits the same story page. This architectural split ensures that bugs in the leveling formula cannot interfere with how player progress is saved, and each service can be tested independently.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in