|
| 1 | +# Stickerlandia Event Flows |
| 2 | + |
| 3 | +This document outlines the event flows between the different services in the Stickerlandia application. |
| 4 | + |
| 5 | +## User Registration Flow |
| 6 | + |
| 7 | +A user can either register directly with Stickerlandia, or login via a federated identity provider. We foresee this to be Datadog's own corporate directory and potentially one associated with our certification provider, so that we can tie external folks' identity up to their awards. |
| 8 | + |
| 9 | +Note: We still need to implement a login interface to facilitate the federated identity integration. This is currently a TODO item for future development. |
| 10 | + |
| 11 | +When a new user registers in the system, the User Management service publishes a user registration event. This flow ensures that other services are aware of new users in the system. |
| 12 | + |
| 13 | +```mermaid |
| 14 | +sequenceDiagram |
| 15 | + participant Client |
| 16 | + participant UserManagement |
| 17 | + participant MessageBroker |
| 18 | + participant OutboxProcessor |
| 19 | + |
| 20 | + Client->>UserManagement: Register new user |
| 21 | + UserManagement->>UserManagement: Create user account |
| 22 | + UserManagement->>OutboxProcessor: Store UserRegisteredEvent |
| 23 | + UserManagement-->>Client: Registration confirmation |
| 24 | + OutboxProcessor->>MessageBroker: Publish users.userRegistered.v1 |
| 25 | + Note over MessageBroker: Event available for other services |
| 26 | +``` |
| 27 | + |
| 28 | +## Sticker Assignment |
| 29 | + |
| 30 | +Stickers can be assigned through two primary mechanisms: |
| 31 | +1. Via an admin UI, where administrators can manually award stickers to users |
| 32 | +2. Via integration with certification systems, where the completion of certifications automatically triggers sticker awards (future state) |
| 33 | + |
| 34 | +For the automatic assignment, another service will adapt external certification events to our internal event model and generate events that the sticker-award service listens to. |
| 35 | +Note: This automatic assignment process corresponds to the [Sticker Claimed Flow](#sticker-claimed-flow) described below. |
| 36 | + |
| 37 | +In all cases, the mapping from users to assigned stickers is managed by the sticker-award service. |
| 38 | + |
| 39 | +When a sticker is assigned to a user, the Sticker Award service creates the assignment and notifies other services through events. |
| 40 | + |
| 41 | +```mermaid |
| 42 | +sequenceDiagram |
| 43 | + participant Client |
| 44 | + participant StickerAward |
| 45 | + participant Database |
| 46 | + participant MessageBroker |
| 47 | + participant UserManagement |
| 48 | + |
| 49 | + Client->>StickerAward: POST /api/award/v1/users/{userId}/stickers |
| 50 | + StickerAward->>Database: Check if sticker exists |
| 51 | + StickerAward->>Database: Check if already assigned |
| 52 | + StickerAward->>Database: Create assignment |
| 53 | + StickerAward-->>Client: Assignment confirmation |
| 54 | + StickerAward->>MessageBroker: Publish stickers.stickerAssignedToUser.v1 |
| 55 | + MessageBroker->>UserManagement: Consume event |
| 56 | + UserManagement->>UserManagement: Update user record |
| 57 | +``` |
| 58 | + |
| 59 | +## Sticker Removal Flow |
| 60 | + |
| 61 | +Sticker removal is primarily performed through the admin UI, allowing administrators to revoke previously assigned stickers when necessary. |
| 62 | + |
| 63 | +When a sticker is removed from a user, the Sticker Award service updates the assignment status and notifies other services. |
| 64 | + |
| 65 | +```mermaid |
| 66 | +sequenceDiagram |
| 67 | + participant Client |
| 68 | + participant StickerAward |
| 69 | + participant Database |
| 70 | + participant MessageBroker |
| 71 | + participant UserManagement |
| 72 | + |
| 73 | + Client->>StickerAward: DELETE /api/award/v1/users/{userId}/stickers/{stickerId} |
| 74 | + StickerAward->>Database: Find active assignment |
| 75 | + StickerAward->>Database: Mark as removed |
| 76 | + StickerAward-->>Client: Removal confirmation |
| 77 | + StickerAward->>MessageBroker: Publish stickers.stickerRemovedFromUser.v1 |
| 78 | + MessageBroker->>UserManagement: Consume event |
| 79 | + UserManagement->>UserManagement: Update user record |
| 80 | +``` |
| 81 | + |
| 82 | +## Sticker Claimed Flow |
| 83 | + |
| 84 | +This flow represents the scenario where users complete specific challenges or achievements in external systems. A service monitors these achievements and publishes events that inform our system about users qualifying for stickers. |
| 85 | + |
| 86 | +When a user claims a sticker by completing a task or achievement, the event is processed to update the user's account. |
| 87 | + |
| 88 | +```mermaid |
| 89 | +sequenceDiagram |
| 90 | + participant ExternalSystem |
| 91 | + participant MessageBroker |
| 92 | + participant UserManagement |
| 93 | + participant Database |
| 94 | + |
| 95 | + ExternalSystem->>MessageBroker: Publish users.stickerClaimed.v1 |
| 96 | + MessageBroker->>UserManagement: Consume via dedicated event worker |
| 97 | + UserManagement->>UserManagement: Process StickerClaimedEventV1 |
| 98 | + UserManagement->>Database: Update user's sticker count |
| 99 | + Note over UserManagement: StickerOrdered() method called |
| 100 | +``` |
| 101 | + |
| 102 | +## Certification Completion Flow |
| 103 | + |
| 104 | +When a user completes a certification in an external system, the Sticker Award service can automatically assign appropriate stickers. |
| 105 | + |
| 106 | +```mermaid |
| 107 | +sequenceDiagram |
| 108 | + participant CertificationSystem |
| 109 | + participant MessageBroker |
| 110 | + participant StickerAward |
| 111 | + participant Database |
| 112 | + |
| 113 | + CertificationSystem->>MessageBroker: Publish certifications.certificationCompleted.v1 |
| 114 | + MessageBroker->>StickerAward: Consume event |
| 115 | + StickerAward->>Database: Determine appropriate sticker(s) |
| 116 | + StickerAward->>Database: Create sticker assignment(s) |
| 117 | + StickerAward->>MessageBroker: Publish stickers.stickerAssignedToUser.v1 |
| 118 | + Note over StickerAward: Automatic award process completed |
| 119 | +``` |
0 commit comments