Gamification System (Badges, Levels, Scores) - Technical Documentation
Generated on 9/18/2025 | AI Workflow Portal
๐ Executive Summary
The Xikolo Gamification System (cluster 15_LEARN_Gamification) is a pivotal component designed to significantly boost user engagement and motivation across the platform. Operating on an event-driven architecture, it meticulously rewards user activities through a sophisticated points-based scoring system, achievement badges, and a progressive user leveling structure. Key components include a dedicated consumer for real-time event processing, rule-based logic for dynamic score generation, and specialized view components for the intuitive display of user achievements. The systemโs primary purpose is to recognize user contributions, foster continuous platform interaction, and provide visual feedback on individual progression, ensuring a rewarding and interactive user experience by integrating seamlessly with core platform services.
๐๏ธ Architecture Overview
The Gamification Systemโs architecture is rooted in an event-driven paradigm, ensuring responsive processing of user actions. At its core, the system consumes various events from a message queue, applying a set of predefined rules to calculate and store user scores, which in turn drive badge and level progression. The userโs achievements are then presented through a dedicated display layer, which integrates with the core platform UI.
Key Components:
-
GamificationConsumer: This
Msgrconsumer serves as the primary entry point for all gamification-related events. It actively listens to RabbitMQ for diverse event types, such asxikolo.course.result.createorxikolo.pinboard.vote.create. Before processing, it checks the globalXikolo.config.gamification['enabled']flag. If active, it dispatches event payloads to specificGamification::Rulesclasses. -
Gamification::Rules::*: These are a family of service classes (e.g.,
Gamification::Rules::Course::TakeExam) instantiated by theGamificationConsumer. Each class encapsulates specific logic to calculate points for an event and subsequently persists aGamification::Scorerecord. They implement thecreate_score!method, applying gamification logic based on the event payload. -
Gamification::Score: This model represents an individual score earned by a user for a specific action. It records
user_id,course_id, theruleapplied,pointsawarded, and event-specificdata. Achecksummechanism is integral to prevent the creation of duplicate scores for identical events. These scores are foundational for calculating user levels and badge progression. -
Gamification::Badge: This model or entity represents an awarded digital badge, storing its
nameandlevel. It is passed as an object to theDashboard::GamificationBadgeViewComponent for rendering, where its attributes (name, level, persisted?) determine the display logic. -
Dashboard::GamificationBadge: A
ViewComponentresponsible for rendering individualGamification::Badgeobjects within the user interface. It dynamically generates image paths (e.g.,communicator_1.pngorcommunicator_not_gained.png) based on the badgeโs status and name. It also interacts withI18nfor localized badge level titles. -
Gamification Configuration (YAML) & Xikolo.config.gamification: These encompass several YAML files like
app/models/gamification/badge_types.yml(defining badge progression and rules) andapp/models/gamification/user_levels.yml(defining user level thresholds and metadata).Xikolo.config.gamificationis a global feature flag that controls the overall enablement of the gamification system, checked byGamificationConsumerprior to event processing.
Architecture Diagrams
Main Gamification Architecture
graph TD eventQueue["RabbitMQ Event Queue"] gamificationConsumer["GamificationConsumer"] gamificationConfig["Xikolo.config.gamification & YAML"] gamificationRules["Gamification::Rules::*"] gamificationScore["Gamification::Score"] achievementDisplay["Achievement Display (UI)"] eventQueue -->|"publishes events"| gamificationConsumer gamificationConsumer -->|"checks enabled status"| gamificationConfig gamificationConsumer -->|"dispatches payload"| gamificationRules gamificationRules -->|"creates score"| gamificationScore gamificationScore -->|"updates progression"| achievementDisplay gamificationConfig -->|"defines rules/levels"| achievementDisplay
๐ Component Interactions
Key interactions between components in this cluster:
- GamificationConsumer: Consumes messages from RabbitMQ via the
Msgrgem. - GamificationConsumer: Checks
Xikolo.config.gamification['enabled']to determine if gamification processing should occur. - Gamification::Rules::*: Instantiated by
GamificationConsumerwith an eventpayload. - Gamification::Rules::*: Executes the
create_score!method to apply gamification logic and persist scores. - Gamification::Score: Created by
Gamification::Rules::*classes [Inferred from app/consumers/gamification_consumer.rb] - Gamification::Score: Used in calculations for user levels and badge progression [Inferred from RAG: app/models/gamification/badge_types.yml, RAG: app/models/gamification/user_levels.yml]
- Gamification::Badge: Passed as a parameter to
Dashboard::GamificationBadgefor rendering. - Gamification::Badge: Its attributes (
name,level,persisted?) are accessed by the ViewComponent to determine display logic. - Dashboard::GamificationBadge: Receives a
Gamification::Badgeobject during initialization. - Dashboard::GamificationBadge: Uses
helpers.image_tagto render the badge image, constructing the path based on badge name and level/gained status. - Gamification Configuration (YAML): Defines the rules for
Gamification::Badgeprogression [Source: RAG: app/models/gamification/badge_types.yml] - Gamification Configuration (YAML): Defines the thresholds and metadata for user levels [Source: RAG: app/models/gamification/user_levels.yml]
- Xikolo.config.gamification: Checked by
GamificationConsumerto determine if event processing should occur [Source: app/consumers/gamification_consumer.rb] - Xikolo.config.gamification: Configured in test environments to enable/disable gamification for specific tests [Source: spec/events/xikolo.course.result.create_spec.rb]
- Open Badges Configuration: Enables/disables Open Badges functionality [Source: RAG: spec/fixtures/files/badge_config.yml]
- Open Badges Configuration: Provides cryptographic keys for badge signing [Source: RAG: spec/fixtures/files/badge_config.yml, RAG: spec/support/files/certificate/badge_config.yml]
- Gamification::Badge (Implied Model): Provided as an input to
Dashboard::GamificationBadge. - Gamification::Badge (Implied Model): Its attributes (
name,level,persisted?) are accessed byDashboard::GamificationBadge. - Gamification::Configuration: Checked by
GamificationConsumerbefore processing events. - Gamification::Configuration: Manipulated by integration tests to enable/disable the feature.
- Gamification::BadgeTypes (YAML): Defines the structure and requirements for
Gamification::Badgeinstances. - Gamification::UserLevels (YAML): Defines the progression and display properties for user levels based on accumulated XP.
- Gamification Badge Configuration: Informs the gamification system about the criteria for awarding and leveling up badges.
- Gamification Badge Configuration: Implicitly guides the implementation of
Gamification::Rulesby listing contributing events. - Gamification User Level Configuration: Used by the gamification system to determine a userโs current level based on their accumulated XP.
- Gamification User Level Configuration: Establishes naming conventions for user level image assets.
- Gamification (Presenter/Decorator): Provides collections of
badgesandscoresto theachievements.html.slimview. - Gamification (Presenter/Decorator): Encapsulates logic for retrieving and structuring gamification data relevant to a user.
- State::Empty: Rendered conditionally in
achievements.html.slimwhen@gamification.scoresis empty.
โ๏ธ Technical Workflows
1. Event Processing and Score Generation Workflow
graph TD userAction["User Action (e.g., Take Exam)"] eventQueue["RabbitMQ Event Queue"] gamificationConsumer["GamificationConsumer"] ruleDispatcher["Dispatch to Gamification::Rules"] scoreCreation["Create Gamification::Score"] scorePersisted["Score Record Persisted"] userAction -->|"generates event"| eventQueue eventQueue -->|"consumes message"| gamificationConsumer gamificationConsumer -->|"checks Xikolo.config.gamification"| ruleDispatcher ruleDispatcher -->|"invokes create_score!"| scoreCreation scoreCreation -->|"saves record with checksum"| scorePersisted
This workflow is the backbone of the gamification system, translating user actions into tangible scores. It begins when a user performs a tracked action, which publishes an event to a centralized message queue (RabbitMQ). The GamificationConsumer continuously monitors this queue. Upon receiving an event, the consumer first performs a critical check on Xikolo.config.gamification['enabled'] to ensure the gamification system is active. If the feature is enabled, the consumer then intelligently dispatches the event payload to a specialized Gamification::Rules class. For example, a xikolo.course.result.create event with an โexamโ exercise type would be handled by Gamification::Rules::Course::TakeExam. This rule class processes the payload, applies its specific gamification logic, and then creates and persists a new Gamification::Score record. A checksum embedded within the score record prevents duplicate entries for the same event, ensuring data integrity. This score then becomes a basis for badge and user level calculations, triggering subsequent updates within the system.
2. Badge and User Level Display Workflow
graph TD userRequest["User Request Achievements Page"] gamificationPresenter["Gamification (Presenter)"] scoresAndBadges["Gamification::Score & Gamification::Badge"] dashboardBadge["Dashboard::GamificationBadge ViewComponent"] i18nService["I18n Service"] userUI["User Interface Render"] userRequest -->|"requests data"| gamificationPresenter gamificationPresenter -->|"fetches data from"| scoresAndBadges gamificationPresenter -->|"prepares badge object for"| dashboardBadge dashboardBadge -->|"looks up titles"| i18nService dashboardBadge -->|"renders badge and level UI"| userUI
This workflow focuses on presenting accumulated achievements to the user. When a user navigates to their dashboard or an achievements page, a Gamification (Presenter/Decorator) component is invoked. This presenter is responsible for aggregating relevant gamification data, including the userโs Gamification::Score records and Gamification::Badge instances. It structures this information for optimal display within the achievements.html.slim view. For each badge, the Dashboard::GamificationBadge ViewComponent is initialized with a Gamification::Badge object. This component then renders the badgeโs visual representation. It dynamically determines the correct image source based on the badgeโs name and level, distinguishing between earned (communicator_1.png) and unearned (communicator_not_gained.png) states, drawing from paths like app/assets/images/gamification/badges/. Localization for badge level titles is handled through I18n. Concurrently, the userโs overall progression, represented by user levels, is calculated based on their total experience points (XP) against thresholds defined in app/models/gamification/user_levels.yml, with corresponding images displayed in the UI. If a user has no scores, a State::Empty component is conditionally rendered.
3. Open Badges Integration Workflow
This workflow outlines the foundational capability for integrating with the Open Badges standard, allowing for external verification and recognition of user achievements. The systemโs ability to support Open Badges is primarily driven by specific configuration files, namely spec/fixtures/files/badge_config.yml and spec/support/files/certificate/badge_config.yml. These YAML configurations are critical, as they not only contain feature flags to enable or disable Open Badges functionality but also store essential cryptographic assets, such as public and private RSA keys. The presence of these keys indicates the systemโs preparedness to digitally sign verifiable digital badges, making them compliant with the Open Badges standard. While the explicit steps for triggering the issuance of an Open Badge are not fully detailed in the provided cluster data, the existence of these cryptographic elements and their configuration demonstrates a robust capability for generating secure, externally verifiable achievement credentials. This allows for a potential future expansion where users could export their achievements to external Open Badge platforms.
๐ง Implementation Details
The Gamification System leverages an event-driven architecture with several key implementation details and dependencies. The core event processing is handled by the Msgr gem, which facilitates communication with RabbitMQ, serving as the message broker for various gamification-related events. Each specific gamification rule is encapsulated within a Gamification::Rules::* class, designed to be independently invoked by the GamificationConsumer based on the event type. A checksum field on the Gamification::Score model is a critical technical consideration, implemented to ensure that only unique scores are persisted for any given event, thereby preventing data duplication and maintaining score accuracy.
Dependencies and Integrations:
- Message Queue: The system depends on RabbitMQ (via the
Msgrgem) for asynchronous event consumption. Events such asxikolo.course.result.createandxikolo.pinboard.vote.createare ingested from this queue. - Configuration Management:
Xikolo.config.gamification(anActiveSupport::Configurableobject) is a primary dependency for enabling/disabling the entire system.YAMLis heavily used for static configurations, includingapp/models/gamification/badge_types.ymlandapp/models/gamification/user_levels.yml. - Internationalization: The
Dashboard::GamificationBadgecomponent explicitly usesI18nfor localizing badge level titles, though aTODOexists to move more title logic to locale files. - View Components:
Dashboard::GamificationBadgeandState::EmptyareApplicationComponentsubclasses, integrating with the Rails view layer to render dynamic UI elements.
Configuration Requirements:
- Feature Toggle: The systemโs operation is contingent on
Xikolo.config.gamification['enabled']being set totrue. This flag is checked by theGamificationConsumerbefore any event processing occurs and can be manipulated in test environments. - Badge Definitions:
app/models/gamification/badge_types.ymlis mandatory for defining all badges, their contributing rules, and the score thresholds for various levels (e.g., bronze, silver, gold). This file also implies image paths for badges inapp/assets/images/gamification/badges/. - User Level Definitions:
app/models/gamification/user_levels.ymldefines the progression of user levels, specifyingmin_xprequirements,titles, andimagepaths (e.g.,kyu02yellow.png). These images are expected inapp/assets/images/gamification/userstates/. - Open Badges: Configuration for Open Badges, including
open_badgessettings and cryptographic keys (public and private RSA keys), is located inspec/fixtures/files/badge_config.ymlandspec/support/files/certificate/badge_config.yml. This configuration dictates the systemโs ability to issue verifiable digital badges. - Rule Deactivation: Individual gamification rules can be deactivated by setting their awarded points to zero in configuration. However, removing or commenting out rules in the config requires careful consideration due to potential side effects on dependent rules or badge calculations, as explicitly noted in
app/consumers/gamification_consumer.rb. This suggests a need for robust dependency management, which is not specified in cluster data beyond the warning.
Missing Information: Specific database schema details for Gamification::Score and Gamification::Badge beyond the mentioned attributes (e.g., exact column types, indices, on_delete constraints) are not specified in cluster data.
๐ Technical Sources & References
Components
- ๐ Gamification::Badge (Implied Model)
app/components/dashboard/gamification_badge.rb - ๐ Gamification::Badge (Implied Model)
RAG: app/models/gamification/badge_types.yml - ๐ Gamification (Presenter/Decorator)
app/views/dashboard/achievements.html.slim
Configuration
- ๐ GamificationConsumer
app/consumers/gamification_consumer.rb - ๐ Gamification::Rules::*
app/consumers/gamification_consumer.rb - ๐ Gamification::Score
spec/factories/gamification.rb - ๐ Gamification::Score
spec/events/xikolo.course.result.create_spec.rb - ๐ Gamification::Badge
app/components/dashboard/gamification_badge.rb - ๐ Gamification::Badge
RAG: app/models/gamification/badge_types.yml - ๐ Dashboard::GamificationBadge
app/components/dashboard/gamification_badge.rb - ๐ Dashboard::GamificationBadge
RAG: app/models/gamification/badge_types.yml - ๐ Gamification Configuration (YAML)
RAG: app/models/gamification/badge_types.yml - ๐ Gamification Configuration (YAML)
RAG: app/models/gamification/user_levels.yml - ๐ Xikolo.config.gamification
app/consumers/gamification_consumer.rb - ๐ Xikolo.config.gamification
spec/events/xikolo.course.result.create_spec.rb - ๐ Open Badges Configuration
RAG: spec/fixtures/files/badge_config.yml - ๐ Open Badges Configuration
RAG: spec/support/files/certificate/badge_config.yml - ๐ Gamification::Configuration
app/consumers/gamification_consumer.rb - ๐ Gamification::Configuration
integration/features/steps/gamification/user_score.rb - ๐ Gamification::BadgeTypes (YAML)
RAG: app/models/gamification/badge_types.yml - ๐ Gamification::UserLevels (YAML)
RAG: app/models/gamification/user_levels.yml - ๐ Gamification Badge Configuration
RAG: app/models/gamification/badge_types.yml - ๐ Gamification User Level Configuration
RAG: app/models/gamification/user_levels.yml - ๐ Configuration
config/application.rb, Gemfile, config/database.yml - ๐ Process Management
Procfile, Procfile.web - ๐ Build & Deploy
Rakefile, package.json
Other
- ๐ State::Empty
app/views/dashboard/achievements.html.slim
This documentation is automatically generated from cluster analysis and should be validated against the actual codebase.