How goel-aadhaar/payment-wallet-microservices works
Purpose and entry points
Payment Wallet is a microservice platform for user identity, wallet balances, transfers, notifications, and rewards. Clients use the Next.js UI or REST APIs through the gateway. Backend service entry points are Spring Boot applications, e.g. api-gateway/src/main/java/com/payment_wallet/api_gateway/ApiGatewayApplication.java; frontend routes begin at frontend/src/app/page.tsx and authenticated dashboard pages under frontend/src/app/(authenticated)/.
Edge gateway and client boundary
The API gateway is the public backend boundary: it proxies requests to internal services, validates JWTs, configures CORS/security, and applies Bucket4j rate limits. Core paths: api-gateway/src/main/java/com/payment_wallet/api_gateway/controller/ProxyController.java, api-gateway/src/main/java/com/payment_wallet/api_gateway/config/SecurityConfig.java, and api-gateway/src/main/java/com/payment_wallet/api_gateway/config/RateLimitConfig.java. The frontend maintains auth state and calls this API boundary via frontend/src/context/AuthContext.tsx and frontend/src/lib/api.ts.
Identity and authentication
User service owns registration, login/JWT issuance, profile, and password changes, persisted in userdb. Its HTTP boundary and business logic are user-service/src/main/java/com/payment_wallet/user_service/controller/AuthController.java, user-service/src/main/java/com/payment_wallet/user_service/controller/UserController.java, and user-service/src/main/java/com/payment_wallet/user_service/service/UserServiceImpl.java. It synchronously calls wallet service to create a user wallet through user-service/src/main/java/com/payment_wallet/user_service/client/WalletClient.java.
Wallet ledger and hold lifecycle
Wallet service owns balances, ledger transactions, and temporary holds in walletdb. It exposes credit/debit and hold/capture/release operations through wallet-service/src/main/java/com/payment_wallet/wallet_service/controller/WalletController.java, with state represented by wallet-service/src/main/java/com/payment_wallet/wallet_service/entity/Wallet.java and wallet-service/src/main/java/com/payment_wallet/wallet_service/entity/WalletHold.java. Expired holds are released by wallet-service/src/main/java/com/payment_wallet/wallet_service/scheduler/HoldExpiryScheduler.java; this service is the authoritative funds boundary.
Transfer orchestration and event publication
Transaction service owns transfer records and search/history in transactiondb. It coordinates the transfer sequence—hold sender funds, verify receiver, capture sender, credit receiver—using resilient synchronous Feign calls to wallet service. Key paths: transaction-service/src/main/java/com/payment_wallet/transaction_service/service/TransactionServiceImpl.java, transaction-service/src/main/java/com/payment_wallet/transaction_service/client/WalletClient.java, and transaction-service/src/main/java/com/payment_wallet/transaction_service/kafka/KafkaEventProducer.java. After a successful transaction it publishes txn-initiated to Kafka; its fallback factory defines the inter-service failure boundary.
Asynchronous notification and rewards projections
Kafka decouples post-transfer side effects. Notification service consumes transaction events, idempotently stores user notifications/read state in notificationdb, and exposes query/read APIs: notification-service/src/main/java/com/payment_wallet/notification_service/kafka/NotificationConsumer.java, notification-service/src/main/java/com/payment_wallet/notification_service/service/NotificationServiceImpl.java, notification-service/src/main/java/com/payment_wallet/notification_service/controller/NotificationController.java. Reward service independently consumes the same events to persist cashback/loyalty outcomes and summaries in rewarddb: reward-service/src/main/java/com/payment_wallet/reward_service/kafka/RewardConsumer.java, reward-service/src/main/java/com/payment_wallet/reward_service/service/RewardServiceImpl.java, reward-service/src/main/java/com/payment_wallet/reward_service/controller/RewardController.java.
Shared platform conventions
common is auto-configured into services and centralizes JWT utilities, RFC-7807 exception responses, pagination, and correlation IDs: common/src/main/java/com/payment_wallet/common/CommonAutoConfiguration.java, common/src/main/java/com/payment_wallet/common/error/GlobalExceptionHandler.java, common/src/main/java/com/payment_wallet/common/web/CorrelationIdFilter.java. Services run on Java 25/Spring Boot 4 with PostgreSQL, JPA, Flyway-owned schemas, Kafka (including dead-letter handling), Actuator/Micrometer/Prometheus, and Resilience4j. Local/container infrastructure is defined by docker-compose.yml, database bootstrap in docker/postgres/init-db.sql, and service migrations under each */src/main/resources/db/migration/.
Main entry points: ProxyController.java API gateway · TransactionServiceImpl.java Transfer orchestration · WalletController.java Wallet API · CommonAutoConfiguration.java Common auto-configuration
Components 20
Client
- Next.js UI · Authentication state and dashboard routes.
frontend/src/app/page.tsx
Edge
- API gateway · Public REST boundary and service proxy.
api-gateway/src/main/java/com/payment_wallet/api_gateway/controller/ProxyController.java - JWT, CORS & rate limits · Validates tokens and applies Bucket4j limits.
api-gateway/src/main/java/com/payment_wallet/api_gateway/config/SecurityConfig.java
Core services
- User API · Registration, login, profile, and password boundary.
user-service/src/main/java/com/payment_wallet/user_service/controller/AuthController.java - User service logic · Issues JWTs and provisions wallets for new users.
user-service/src/main/java/com/payment_wallet/user_service/service/UserServiceImpl.java - userdb
- Wallet API · Authoritative credit, debit, hold, capture, and release boundary.
wallet-service/src/main/java/com/payment_wallet/wallet_service/controller/WalletController.java - Hold expiry scheduler · Releases expired temporary holds.
wallet-service/src/main/java/com/payment_wallet/wallet_service/scheduler/HoldExpiryScheduler.java - walletdb · Balances, ledger transactions, and holds.
- Transfer orchestration · Coordinates sender hold/capture and receiver credit.
transaction-service/src/main/java/com/payment_wallet/transaction_service/service/TransactionServiceImpl.java - transactiondb · Transfer records and history search.
- Transaction event producer · Publishes successful transfers to txn-initiated.
transaction-service/src/main/java/com/payment_wallet/transaction_service/kafka/KafkaEventProducer.java
Event projections
- Kafka · Decouples post-transfer projections and dead-letter handling.
- Notification projection · Idempotently records notification and read state.
notification-service/src/main/java/com/payment_wallet/notification_service/kafka/NotificationConsumer.java - notificationdb
- Reward projection · Persists cashback, loyalty outcomes, and summaries.
reward-service/src/main/java/com/payment_wallet/reward_service/kafka/RewardConsumer.java - rewarddb
Shared platform
- Common auto-configuration · JWT, problem responses, pagination, and correlation IDs.
common/src/main/java/com/payment_wallet/common/CommonAutoConfiguration.java - Postgres bootstrap · Initializes local service databases; schemas are Flyway-owned.
docker/postgres/init-db.sql - Container stack · Local platform infrastructure definition.
docker-compose.yml
Connections 25
- Next.js UI → API gateway: REST API
- API gateway → JWT, CORS & rate limits: enforces
- API gateway → User API: proxies
- API gateway → Wallet API: proxies
- API gateway → Transfer orchestration: proxies
- API gateway → Notification projection: query APIs
- API gateway → Reward projection: query APIs
- User API → User service logic: delegates
- User service logic → userdb: persists users
- User service logic → Wallet API: creates wallet
- Wallet API → walletdb: updates funds and holds
- Hold expiry scheduler → walletdb: releases expired holds
- Transfer orchestration → Wallet API: Feign hold / capture / credit · Resilient synchronous funds calls.
- Transfer orchestration → transactiondb: persists transfers
- Transfer orchestration → Transaction event producer: on success
- Transaction event producer → Kafka: txn-initiated
- Kafka → Notification projection: consumes
- Notification projection → notificationdb: stores state
- Kafka → Reward projection: consumes
- Reward projection → rewarddb: stores outcomes
- Common auto-configuration → API gateway: auto-configures
- Common auto-configuration → User API: auto-configures
- Common auto-configuration → Wallet API: auto-configures
- Common auto-configuration → Transfer orchestration: auto-configures
- Container stack → Postgres bootstrap: runs