User Flows, Data Flows & Sequence Diagrams
End-to-end journeys and Mermaid sequence/flow diagrams for every core path in the Engagement & Loyalty Platform platform.
Reading this document
This document is the single visual reference for how value moves through the Engagement & Loyalty Platform. The core diagrams describe paths that exist in the running system: a card swipe becoming points, a UPI transaction becoming a scratch card, points becoming a voucher, a refund clawing points back, a campaign budget being consumed, and a configuration or campaign activation passing through maker-checker before it goes live (campaign lifecycle approval is enforced via config-service apply-change).
EXPIRY entries / EXPIRY_NUDGE comms) and periodic tier re-evaluation. The expiry window is configured per accrual rule, but the FIFO expiry batch job and the scheduler/cron that would fire these automatically are roadmap. Treat the expiry/nudge steps as the target design.The diagrams are authored in Mermaid and render in your browser. Where a diagram needs the network (the Mermaid CDN) and it is unavailable, the raw source is shown instead so the flow is never lost.
Actors
The same cast appears across most flows. Knowing each participant once makes every later diagram readable at a glance.
| Actor | Role in the platform | Maps to |
|---|---|---|
| Cardholder | The the Bank credit card customer who earns and redeems points. | End user |
| the Bank CBS / Txn source | Core Banking / the axis-txn-provider that emits authorised transactions, reversals and refunds. | axis-txn-provider |
| Core API | Ingest → accrual → ledger → balance. The accrual brain and system of record owner. | core-api :3001 · /api/v1 |
| Campaign Engine | Evaluates campaigns, milestones and tiers; posts campaign-sourced accruals; consumes budgets. | campaign-engine :3002 |
| Ledger | The immutable cr.ledger_entry — every movement of points. System of record. | Core API (DB) |
| Redemption | Validates eligibility and balance, books the debit, triggers fulfilment. | redemption-service :3005 |
| Fulfilment Partner | Issues the actual voucher / reward against consumed points. | reward-fulfilment-mock |
| Comms | Notifies the customer across SMS / Email / Push / In-App. | comms-gateway · comms-viewer |
| Merchant Service | Merchant-funded attribution & settlement; fulfilment-partner billing. | merchant-service :3006 |
| Admin / Maker / Checker | Operators who configure rules and campaigns under maker-checker control. | config-service :3004 |
| the Bank's mobile app app | The the Bank app (sample) where bank events originate — UPI, bill pay, card activation, FD — and where scratch cards are revealed. | axis-bank-app :4005 |
| Engagement (Core API) | Ingests bank events, evaluates trigger rules & milestones, issues and reveals scratch cards. | core-api :3001 · /api/v1/events |
Legend
- Solid arrow — a synchronous request / call. Dashed arrow — a response or asynchronous event.
- Note boxes (amber) — invariants and side-effects, e.g. an idempotency check or a balance mutation.
- alt / opt blocks — conditional branches (e.g. insufficient balance, account not active).
- Ledger entries use the canonical vocabulary: entry types ACCRUAL REDEMPTION REVERSAL EXPIRY ADJUSTMENT CLAWBACK with direction C (credit) / D (debit).
- Money is in minor units (paise); points are integers. Every external write carries an idempotency key for exactly-once semantics.
End-to-end platform data flow
The diagram below is the whole platform on one page: a card swipe enters from the Bank CBS, Core API turns it into a ledger credit and an updated balance, the Campaign Engine layers campaign and milestone rewards on top, and Comms tells the customer. Two branches hang off the spine — redemption (points out) and merchant-funded settlement (money between the Bank and merchants/partners).
flowchart LR CH([Cardholder]) -->|card swipe| CBS[the Bank CBS / Txn source] CBS -->|POST transactions| CORE[Core API ingest] CORE --> ACC[Accrual engine] ACC -->|ACCRUAL credit| LED[(Ledger cr.ledger_entry)] LED --> BAL[(point_balance projection)] CORE -->|txn event| CE[Campaign Engine] CE -->|campaign ACCRUAL| LED CE -->|milestone unlock| COMMS[Comms gateway] BAL -->|balance updated| COMMS COMMS --> CH BAL -. available .-> RS[Redemption Service] RS -->|REDEMPTION debit| LED RS -->|issue voucher| FP[Fulfilment Partner] FP --> COMMS CE -->|funded split| MS[Merchant Service] MS --> MTM[(merchant_txn_map)] MTM --> SETTLE[Settlement run] SETTLE -->|invoice| INV[MID / TID report]
| Hop | What moves | Store touched | Guarantee |
|---|---|---|---|
| CBS → Core API | Authorised transaction (amount, MCC, account) | — | Idempotent ingest |
| Accrual → Ledger | ACCRUAL credit (points) | cr.ledger_entry | Exactly-once via idempotency key |
| Ledger → Balance | available += points | cr.point_balance | Reconciled projection |
| Campaign Engine → Ledger | Campaign ACCRUAL | cr.ledger_entry | source_ref cmp:<id>:<acct>:<seq> |
| Redemption → Ledger | REDEMPTION debit | cr.redemption + ledger | Idempotency-Key + balance check |
| Merchant Service → Settlement | Funded points → money | cr.merchant_txn_map | Attribution + reconciliation |
Cardholder journey (lifecycle)
From the customer's point of view, Engagement & Loyalty Platform is a single continuous loop: spend, earn, watch a milestone fill, unlock a bonus, and finally redeem something tangible. The flow below traces that arc; the prose and touchpoint table beneath it name the notification fired at each beat.
flowchart TD
A[Enrolment] --> B[First eligible transaction]
B --> C[Accrual posted: base + MCC + tier]
C --> D[Milestone progress updated]
D --> E{Threshold reached?}
E -->|no| C
E -->|yes| F[Milestone unlocked: bonus ACCRUAL]
F --> G[Available balance grows]
G --> H{Cardholder redeems?}
H -->|not yet| C
H -->|yes| I[Redemption booked]
I --> J[Fulfilment: voucher issued]
J --> K[Reward delivered to customer]
The journey in words. A new cardholder is enrolled, which creates a cr.loyalty_account in active status. Their first eligible transaction flows in from CBS and Core API posts an ACCRUAL — base earn, plus any MCC accelerator, multiplied by their tier. As more transactions land, the customer climbs toward a milestone (say, ₹50,000 of spend in a quarter). When the threshold is crossed the Campaign Engine fires a milestone unlock and posts a bonus accrual. The growing available balance eventually motivates a redemption; Redemption Service books the debit, the Fulfilment Partner issues a voucher, and Comms delivers it. The loop then repeats.
| Stage | Touchpoint | Notification | Channel |
|---|---|---|---|
| Enrolment | Welcome to Engagement & Loyalty Platform | WELCOME | SMS + Email |
| First accrual | You earned your first points | ACCRUAL_FIRST | Push + In-App |
| Ongoing accrual | Points credited for a purchase | ACCRUAL_POSTED | In-App |
| Milestone near | You are close to a reward | MILESTONE_NUDGE | Push |
| Milestone unlock | Bonus points unlocked | MILESTONE_UNLOCK | SMS + Push |
| Redemption | Redemption confirmed | REDEMPTION_OK | SMS + Email |
| Fulfilment | Your voucher is ready | VOUCHER_ISSUED | Email + In-App |
Accrual — sequence diagram
Accrual is the platform's heartbeat. A transaction posted to POST /api/v1/transactions resolves the applicable accrual rule (base earn rate × eligible amount), adds MCC accelerators, applies the tier multiplier, and writes a single ACCRUAL credit to the ledger — guarded by an idempotency key so a replayed transaction never double-credits.
sequenceDiagram
autonumber
participant CH as Cardholder
participant CBS as the Bank CBS
participant API as Core API
participant AE as Accrual Engine
participant LED as Ledger
participant BAL as point_balance
participant CO as Comms
CH->>CBS: Card purchase
CBS->>API: POST /api/v1/transactions (Idempotency-Key)
Note over API: Dedup on idempotency key
alt key already seen
API-->>CBS: 200 (cached result)
else new transaction
API->>AE: Resolve accrual rule
AE->>AE: base earn + MCC accelerator
AE->>AE: apply tier multiplier
AE->>LED: Insert ACCRUAL credit (C)
LED->>BAL: available += points
BAL-->>API: updated balance
API->>CO: Trigger ACCRUAL_POSTED
CO-->>CH: Points credited
API-->>CBS: 201 Created
end
Event trigger → scratch card → reveal → ledger credit — sequence diagram
The engagement path is event-led. A bank event (here a UPI payment from the the Bank's mobile app app) hits POST /api/v1/events, deduplicated on eventRef. The Engagement module evaluates matching trigger rules; a match draws a prize immediately (weighted random from the rule's prize table) and issues a scratch card with the prize stored hidden. The customer scratches later — the reveal is idempotent and, for a POINTS prize, posts a single ACCRUAL credit to the same immutable ledger (idempotency key scr:<scratchCardId>).
sequenceDiagram
autonumber
participant CH as Cardholder
participant APP as the Bank's mobile app app
participant API as Core API
participant ENG as Engagement module
participant SC as scratch_card
participant LED as Ledger
participant BAL as point_balance
CH->>APP: Pay via UPI (amount)
APP->>API: POST /api/v1/events (eventRef, UPI_TRANSACTION)
Note over API: Dedup on eventRef
alt eventRef already seen
API-->>APP: 201 (same response, no new reward)
else new event
API->>ENG: Evaluate trigger rules + milestones
alt trigger matches (e.g. first UPI)
ENG->>ENG: Draw prize (weighted) from prize table
ENG->>SC: Insert scratch_card (state ISSUED, prize hidden, expires +30d)
SC-->>API: scratchCardId
end
API-->>APP: 201 { evaluations, scratchCards[] }
APP-->>CH: "You've won a scratch card!"
end
CH->>APP: Scratch to reveal
APP->>API: POST /api/v1/scratch-cards/:id/scratch
alt card EXPIRED
API-->>APP: 409 Conflict (expired)
else already SCRATCHED
API-->>APP: 200 (same prize, idempotent)
else first reveal
alt prize.kind = POINTS
API->>LED: Insert ACCRUAL credit (idem scr:<id>)
LED->>BAL: available += points
else prize.kind = VOUCHER
API->>SC: Record voucher label/value (no ledger credit)
end
API->>SC: state = SCRATCHED, scratched_at = now
API-->>APP: 200 { prize, ledgerEntryId?, balance }
APP-->>CH: Reveal prize + confetti
end
Campaign & milestone unlock — sequence diagram
Beyond base earn, the Campaign Engine layers targeted rewards. When Core API emits a transaction event, the engine evaluates every live campaign whose predicate could match — checking MCC, calendar window / day-of-week, and account eligibility — then tests milestone thresholds. A match produces a campaign-sourced ACCRUAL (tagged cmp:<id>:<acct>:<seq>) and consumes from the campaign budget.
sequenceDiagram
autonumber
participant API as Core API
participant CE as Campaign Engine
participant LED as Ledger
participant BUD as Budget
participant CO as Comms
API->>CE: Transaction event (account, MCC, amount)
CE->>CE: Evaluate predicate (MCC / day / eligibility)
alt predicate fails
CE-->>API: no-op (not eligible)
else predicate matches
CE->>CE: Update milestone progress
alt threshold not yet reached
CE-->>API: progress recorded
else milestone threshold reached
CE->>BUD: Reserve + consume budget
alt budget exhausted
BUD-->>CE: rejected (no budget)
CE->>CO: Trigger MILESTONE_BUDGET_OUT (ops)
else budget available
CE->>LED: Insert campaign ACCRUAL (source_ref cmp:id:acct:seq)
LED-->>CE: credited
CE->>CO: Trigger MILESTONE_UNLOCK
end
end
end
| Check | Source | Example |
|---|---|---|
| MCC predicate | txn.mcc | Dining MCCs 5811–5814 |
| Calendar window | campaign.start/end | Festive 01–31 Oct |
| Eligibility | account.tier / segment | Signature & above |
| Milestone threshold | cumulative spend / count | ₹50,000 in quarter |
| Budget guard | campaign budget | Stop at allocation cap |
Campaign winner & partner fulfilment — sequence diagram
A campaign reward is one of two kinds, decided by reward_def.kind. Points rewards are credited by Engagement & Loyalty Platform itself — an idempotent ACCRUAL ledger entry (key cmp:<id>:<acct>:rule), balance bump, budget consume, customer notified. Non-points rewards (a voucher, gift card, merchandise — funded by the bank or a partner) cannot be paid in points, so the engine records a winner in cr.campaign_winner (status recorded, idempotent on the same key) and calls the fulfilment partner API to deliver it. On success the winner becomes fulfilled with the partner's fulfilment_ref; the partner-API delivery is logged to comms. The runner is triggered either by POST /campaigns/:id/run or automatically by the feed scanner as new transactions post (idempotent per campaign+account, so it is safe to re-run).
sequenceDiagram
autonumber
participant SC as Feed Scanner / Run
participant CE as Campaign Engine
participant DB as cr.campaign_winner
participant LED as Loyalty Ledger
participant FP as Fulfilment Partner (:3103)
participant CM as Comms Gateway (:3102)
SC->>CE: runRuleCampaign(campaignId, affectedAccounts)
loop each matched account
alt reward_def.kind = points
CE->>LED: ACCRUAL credit (idem cmp:id:acct:rule)
CE->>CM: notify "reward unlocked: N points"
else non-points (voucher / merchandise / partner)
CE->>DB: INSERT winner (status recorded, idem cmp:id:acct:rule)
CE->>FP: POST /v1/vouchers/issue {sku, points, accountRef, label} + Idempotency-Key
FP-->>CE: 200 {voucherId / orderId, voucherMasked}
CE->>DB: UPDATE winner status=fulfilled, fulfilment_ref
CE->>CM: log "PARTNER API → issued
| Reward kind | Recorded in | Who pays it | Idempotency |
|---|---|---|---|
| Points | cr.ledger_entry (ACCRUAL) | Engagement & Loyalty Platform credits the loyalty balance | cmp:<id>:<acct>:rule (unique) |
| Non-points (voucher / gift card / merchandise) | cr.campaign_winner → partner | Fulfilment partner API delivers; bank- or partner-funded | Winner row + Idempotency-Key on issue |
REWARD_FULFILMENT_URL (default the local reward-fulfilment-mock); point it at a real partner endpoint to go live. If the partner is unreachable the winner stays recorded and is retried — no points or vouchers are lost. See CR-FPI-015.Redemption — sequence diagram
Redemption is the points-out path. A request to POST :3005/redemptions with an Idempotency-Key verifies the account is active and that available covers the cost, locks the balance row for the duration of the booking, inserts cr.redemption plus a REDEMPTION debit, then asks the Fulfilment Partner to issue a voucher. The two failure branches — insufficient balance and inactive account — are shown as alt blocks.
sequenceDiagram
autonumber
participant CH as Customer
participant RP as Rewards Portal
participant RS as Redemption Service
participant BAL as point_balance
participant LED as Ledger
participant FP as Fulfilment Partner
participant CO as Comms
CH->>RP: Choose reward, confirm
RP->>RS: POST /redemptions (Idempotency-Key)
RS->>BAL: SELECT ... FOR UPDATE
alt account not active
BAL-->>RS: status != active
RS-->>RP: 409 Account not active
RP-->>CH: Cannot redeem
else insufficient available
BAL-->>RS: available < cost
RS-->>RP: 422 Insufficient balance
RP-->>CH: Not enough points
else eligible
RS->>LED: Insert REDEMPTION debit (D)
LED->>BAL: available -= ; lifetime_redeemed +=
RS->>FP: Issue voucher (consumed points)
FP-->>RS: voucher code
RS->>CO: Trigger REDEMPTION_OK + VOUCHER_ISSUED
CO-->>CH: Voucher delivered
RS-->>RP: 201 Redemption confirmed
end
Reversal & clawback — sequence diagram
When CBS reports a reversal or refund, points earned on the original transaction must come back. Core API's reverse() posts a REVERSAL debit. If the customer has already spent those points, available cannot go negative — it is clamped at zero and the unrecovered remainder is carried to clawback_pending, then recovered automatically from the next accrual.
sequenceDiagram
autonumber
participant CBS as the Bank CBS
participant API as Core API
participant LED as Ledger
participant BAL as point_balance
CBS->>API: Reversal / refund of original txn
API->>API: reverse(original_txn)
API->>LED: Insert REVERSAL debit (D)
alt available covers reversal
LED->>BAL: available -= points
Note over BAL: fully recovered
else available insufficient
LED->>BAL: available -> 0 (clamped)
BAL->>BAL: clawback_pending += remainder
Note over BAL: remainder owed
API-->>API: recover on next ACCRUAL
end
| Field | Effect on reversal |
|---|---|
| available | Decremented, floored at 0 |
| clawback_pending | Holds the unrecovered remainder |
| Next ACCRUAL | First settles clawback_pending, then credits the rest |
| Entry type | REVERSAL (txn unwound) vs CLAWBACK (recovery) |
Merchant-funded settlement & fulfilment-partner billing
Some offers are co-funded. A Myntra 10X offer might be 5X bank-funded plus 5X merchant-funded. The merchant-funded portion is attributed to cr.merchant_txn_map; a periodic settlement run aggregates funded points per merchant and produces an invoice. Separately, fulfilment-partner billing is computed as consumed_points × point_value × (100 − discount)%.
sequenceDiagram autonumber participant CE as Campaign Engine participant MS as Merchant Service participant MTM as merchant_txn_map participant SET as Settlement Run participant FP as Fulfilment Partner participant FIN as Finance / Invoice CE->>MS: Funded offer split (bank X + merchant Y) MS->>MTM: Attribute funded points (MID/TID) Note over MTM: per-merchant ledger of funded points SET->>MTM: Aggregate funded points for period MTM-->>SET: totals by merchant SET->>FIN: Generate merchant settlement (MID/TID report) FP->>MS: Consumed points for issued vouchers MS->>FIN: Bill = consumed × point_value × (100 - discount)% FIN-->>MS: Invoice issued
flowchart LR T[Funded transaction] --> A[Attribution] A --> M[(merchant_txn_map)] M --> S[Settlement run] S --> R[MID / TID report] R --> I[Merchant invoice] V[Voucher consumption] --> B[Partner billing] B --> I
| Step | Input | Output |
|---|---|---|
| Attribution | Funded offer split, MID/TID | Rows in cr.merchant_txn_map |
| Settlement run | Funded points for period | Per-merchant totals |
| Merchant invoice | Totals + MID/TID report | Amount due from merchant |
| Partner billing | consumed_points, point_value, discount | consumed × point_value × (100 − discount)% |
Maker-checker approval — sequence diagram
No configuration, campaign or budget change reaches production unreviewed. A Maker submits a change, which creates a cr.approval_request in pending. A different operator — the Checker / Approver — reviews it and either approves (the change applies and goes live) or rejects (the change is discarded). The state machine beneath the sequence shows the lifecycle.
sequenceDiagram
autonumber
participant MK as Maker
participant CFG as Config Service
participant AR as approval_request
participant CK as Checker / Approver
participant LIVE as Live Config
MK->>CFG: Submit config / campaign / budget change
CFG->>AR: Create approval_request (pending)
AR-->>MK: Submitted, awaiting review
CK->>AR: Review pending request
alt approved
CK->>AR: status = approved
AR->>LIVE: Apply change
LIVE-->>CK: Now live
else rejected
CK->>AR: status = rejected (reason)
AR-->>MK: Discarded
end
stateDiagram-v2 [*] --> pending : Maker submits pending --> approved : Checker approves pending --> rejected : Checker rejects approved --> [*] : applied to live config rejected --> [*] : discarded
Card lifecycle — state diagram
Every loyalty account carries a status in cr.loyalty_account.status that gates what the platform will do for it. The diagram shows the legal transitions; the table records what each state permits for accrual and redemption.
stateDiagram-v2 [*] --> active : enrolment active --> dormant : inactivity dormant --> active : reactivation active --> blocked : risk / hold blocked --> active : unblock active --> closed : account closure closed --> [*]
| State | Accrual | Redemption | Notes |
|---|---|---|---|
| active | Allowed | Allowed | Normal operating state |
| dormant | Allowed (re-activates) | Blocked until active | Set after prolonged inactivity |
| blocked | Held | Blocked | Risk / fraud / customer hold |
| closed | Blocked | Blocked | Terminal — no further activity |
Notification / comms data flow
Every customer-facing message follows one pipeline: a domain event triggers a template, the template engine renders it for the chosen channel(s), the message is dispatched, and the outcome is written to the notification log for audit and the comms-viewer.
flowchart LR
EV[Domain event] --> TR[Trigger / router]
TR --> TE[Template engine]
TE --> CH{Channel}
CH -->|SMS| SMS[SMS gateway]
CH -->|Email| EM[Email]
CH -->|Push| PU[Push]
CH -->|In-App| IA[In-App inbox]
SMS --> LOG[(notification_log)]
EM --> LOG
PU --> LOG
IA --> LOG
LOG --> VIEW[comms-viewer]
| Event | Template | Default channel |
|---|---|---|
| Account enrolled | WELCOME | SMS + Email |
| ACCRUAL posted | ACCRUAL_POSTED | In-App |
| Milestone unlocked | MILESTONE_UNLOCK | SMS + Push |
| Redemption confirmed | REDEMPTION_OK | SMS + Email |
| Voucher issued | VOUCHER_ISSUED | Email + In-App |
| Reversal applied | POINTS_REVERSED | SMS |
| Points expiring soon | EXPIRY_NUDGE | Push + Email |