Application Structure & Tech Stack
Service decomposition, technology choices, repository & folder structure, frontend/admin apps, environments and CI/CD.
Service Decomposition
Engagement & Loyalty Platform is composed of independently deployable services aligned to the container architecture. Each owns its data and exposes versioned APIs.
| Service | Responsibility | Owns (data) |
|---|---|---|
| ingestion-svc | Receive/validate/dedupe transactions; publish events. | transaction_raw, ingestion_batch, outbox |
| accrual-svc | Eligibility + rule evaluation + point calc. | accrual_rule, rule_version (read txn) |
| campaign-svc | Campaigns, milestones, segments, enrolment. | campaign, milestone, segment, enrolment |
| ledger-svc | Immutable ledger & balance projection. | ledger_entry, point_balance, point_lot |
| redemption-svc | Burn, OTP, fulfilment orchestration, vouchers. | redemption, voucher, fulfilment_request |
| catalogue-svc | Reward catalogue & partner inventory. | reward_catalogue, partner |
| merchant-svc | Merchant onboarding, funded offers, settlement. | merchant, merchant_offer, settlement |
| notification-svc | Templates, triggers, channel dispatch, status. | notification_template, notification_log, consent |
| admin-svc | RBAC, maker-checker, budgets, config. | app_user, role, approval_request, budget, config_param |
| reporting-svc | MIS, reconciliation, audit query. | report_run, reconciliation, audit_log (read) |
| engagement-svc | Bank-event ingestion (POST /api/v1/events), trigger-rule evaluation, scratch-card issue/reveal, milestone progress. | bank_event, trigger_rule, scratch_card, milestone_def, milestone_progress |
| gateway | Edge routing, authN, rate-limit, request-id. | — |
Frontend / Client Applications
| App | Users | Stack | Notes |
|---|---|---|---|
| Admin Web Portal | Bank teams | React + TypeScript, Vite, Tailwind | Campaign builder, catalogue, approvals, MIS dashboards. |
| Customer Rewards UI | Cardholders | Embedded web / SDK in the Bank app & net-banking | the Bank-branded; consumes Customer API. |
| Support Console | Support agents | Module within Admin Web | Customer 360, history, adjustments (maker-checker). |
| the Bank App (sample) axis-bank-app :4005 | Demo / cardholders | Node + Express, phone-frame web UI | the Bank's mobile app-style journey: UPI / bills / card activation / FD actions fire bank events; scratch-card reveal & milestone progress; deep-links to the Bank Rewards portal (:4002). |
Technology Stack
| Layer | Choice (recommended) | Rationale / alternatives |
|---|---|---|
| Service runtime | Node.js (LTS) + TypeScript + NestJS Decided | Team expertise → faster delivery & maintainability; one language across services & UI. NestJS gives DI, RBAC guards, idempotency/audit interceptors & OpenAPI generation. |
| Language & runtime detail | TypeScript (strict), Node.js LTS | Strict types + generated API types; integer/BigInt money & points (never floats). |
| Async / batch workers | BullMQ / worker_threads | Accrual ingestion, expiry & settlement run as workers/streams — keep the API event loop free. |
| API style | REST + OpenAPI 3.1 | Broad compatibility; gRPC optional intra-service. |
| Primary datastore | PostgreSQL (HA) | ACID ledger, JSONB for flexible config. |
| Cache | Redis | Balances, catalogue, sessions, rate-limit. |
| Messaging | Apache Kafka or RabbitMQ | Event-driven, at-least-once + idempotency. |
| Analytics store | Columnar warehouse | MIS & reporting at scale. |
| Search (optional) | OpenSearch | Catalogue / log search. |
| Frontend | React + TypeScript + Tailwind | Reusable component system. |
| Containerisation | Docker + Kubernetes | On the Bank private cloud / DC. |
| IaC | Terraform + Helm | Reproducible environments. |
| CI/CD | GitLab CI / Jenkins | Per bank tooling. |
| Observability | Prometheus + Grafana + ELK + OpenTelemetry | Metrics, logs, traces. |
| Secrets | Vault / KMS | Key & secret management. |
BigInt — never JS floats for financial math; use a decimal library only for ratios/FX. (2) Run accrual ingestion, expiry & settlement as workers/streams (BullMQ / worker_threads) so the API event loop is never blocked. (3) Enable strict TypeScript, generate types from the OpenAPI contract, and enforce the idempotency + transactional-outbox patterns. PostgreSQL remains the ACID system of record.Repository & Folder Structure
Polyrepo or monorepo per the Bank preference. Reference monorepo layout:
chegrewards/ ├─ services/ │ ├─ gateway/ │ ├─ ingestion-svc/ │ ├─ accrual-svc/ │ │ ├─ src/ │ │ │ ├─ api/ # controllers, DTOs │ │ │ ├─ domain/ # rules, entities, value objects │ │ │ ├─ application/ # use-cases / services │ │ │ ├─ infra/ # db, queue, clients │ │ │ └─ config/ │ │ ├─ test/ # unit + integration │ │ └─ Dockerfile │ ├─ campaign-svc/ ledger-svc/ redemption-svc/ │ ├─ catalogue-svc/ merchant-svc/ notification-svc/ │ ├─ admin-svc/ reporting-svc/ ├─ apps/ │ ├─ admin-web/ # React admin portal (+ Event Triggers & Scratch Cards pages) │ ├─ customer-rewards-ui/ # embeddable rewards UI/SDK │ └─ axis-bank-app/ # the Bank's mobile app sample app (:4005) — events, scratch cards, milestones ├─ libs/ │ ├─ shared-domain/ # common types, money, points │ ├─ auth/ # OIDC/OAuth helpers, RBAC │ ├─ messaging/ # bus client, outbox │ └─ observability/ ├─ db/ │ ├─ migrations/ # versioned schema (Flyway/Liquibase) │ └─ seeds/ ├─ deploy/ │ ├─ helm/ # charts per service │ ├─ terraform/ # infra │ └─ k8s/ ├─ contracts/ │ └─ openapi.yaml # API contract ├─ docs/ # this documentation suite └─ .ci/ # pipelines
Internal Service Layering
Each service follows a clean/hexagonal layering: api (transport) → application (use-cases) → domain (business rules, framework-free) → infra (DB, queue, external clients). This keeps the rule engine and ledger logic testable and independent of frameworks.
Deployment Topology & Right-Sizing
The platform is architected as a modular monolith ("modulith") plus a small set of independently-scalable deployables — not fine-grained microservices on day one. The ~12 modules above are logical boundaries (NestJS modules with clean api→application→domain→infra layering); they are deployed as a few physical services and split further only when a real throughput, SLA or independent-deploy need emerges.
| Deployable | Contains (logical modules) | Scaling driver |
|---|---|---|
| core-api | accrual ingest endpoint, ledger, campaign, redemption, admin, customer, engagement (bank events, trigger rules, scratch cards, milestones) (synchronous APIs) | Request rate (HPA on CPU/RPS) |
| worker tier | batch statement ingestion, accrual processing, expiry, settlement, notification dispatch (async, queue-driven) | Queue depth / batch windows |
| customer-api optional | customer-facing reads & stubbed/real redemption | Public exposure isolation |
| gateway | edge routing, authN, rate-limit, signature pre-checks | Ingress |
| demo / companion apps | transaction simulator (:4001), rewards portal (:4002), comms viewer (:4003), sample feeder (:4004), axis-bank-app (:4005, NEW) — the Bank's mobile app sample app | Companion scope (separate) |
| bank-side simulators | axis-txn-provider (:3101) and axis-comms-gateway (:3102) — renamed from iob-txn-provider / iob-comms-gateway | Companion scope (separate) |
POST /api/v1/events (idempotent by eventRef), GET /api/v1/events, GET /api/v1/triggers, GET/POST /api/v1/scratch-cards (+ /:id/scratch) and GET /api/v1/milestones. It evaluates trigger rules against bank events (USER_REGISTERED, CARD_ACTIVATED, KYC_COMPLETED, UPI_TRANSACTION, BILL_PAYMENT, SALARY_CREDIT, FD_BOOKED) and internal CARD_SPEND milestones, issuing scratch cards or direct points through the same immutable ledger. CORS is enabled for http://localhost:4002, :4005 and :5173.Extraction path: if accrual throughput, an independent release cadence, or a hard latency SLA demands it, accrual-svc (or ledger-svc, notification-svc) is lifted out of core-api into its own deployable — cheap, because the module boundary and the event/outbox contract already exist. The Architecture (CR-ARC-004) container view shows these as logical services; this section governs how they map to running processes.
Scale & Batch Card-Statement Processing
Target load: ~2M transactions/day (~60M/month), bursty around statement batches. This is comfortable for Node.js + PostgreSQL when the batch path is built deliberately and kept separate from the realtime accrual path.
| Concern | Design |
|---|---|
| Bulk ingestion | Statement files streamed & loaded via COPY / batched multi-row inserts (never row-by-row API calls); chunked into work units. |
| Async accrual | Ingested rows enqueued (Kafka/Bull) and processed by a horizontally-scaled worker pool; autoscale on queue lag. |
| Exactly-once | Idempotency key = external_txn_ref; safe to retry/replay a batch with no double-credit. |
| Checkpoint / resume | Batches track per-chunk offsets; a failed/long run resumes mid-file rather than restarting. |
| Backpressure | Bounded queues & consumer concurrency protect the DB; producers slow when consumers lag. |
| Partitioning | Monthly range partitions on transaction/ledger_entry/audit_log keep inserts & queries fast; old partitions archived. |
| Scheduling & isolation | Heavy statement runs scheduled off-peak in the worker tier; the realtime/near-real-time accrual path (API/stream) is unaffected. |
| Workload fit | Bulk accrual is I/O-bound (DB writes) — Node's strength; CPU-light rule evaluation. No need for Go/Python at this scale. |
Environments
| Environment | Purpose | Data |
|---|---|---|
| DEV | Development & unit/integration tests. | Synthetic. |
| SIT | System integration with bank stubs/sandboxes. | Masked / synthetic. |
| UAT | Business acceptance & pilot. | Masked production-like. |
| PRE-PROD | Performance, DR & security validation. | Masked. |
| PROD | Live, inside the Bank environment. | Real (tokenised). |
CI/CD & Quality Gates
- Pipeline: build → unit tests → static analysis & SAST → container build & image scan → integration tests → deploy (Helm) → smoke tests.
- Quality gates: coverage threshold, no critical SAST/secret findings, contract tests pass, DB migrations validated.
- Promotion via approvals; blue-green / rolling deploys; automated rollback on health-check failure.
- Schema changes via versioned migrations only (Flyway/Liquibase); no manual DDL in higher environments.
Configuration & Feature Management
Runtime behaviour is config-driven (see CR-CFG-008): accrual rules, campaigns, catalogue, templates and system parameters are data, changeable without redeploy. Feature flags gate progressive rollout of new capabilities.