A comprehensive Spring Boot microservice for managing customer wallet balances and daily reconciliation with external providers. This system enables customers to maintain credit balances for consuming third-party services like CRB, credit scoring, and KYC document verification.
- Features
- Architecture
- Prerequisites
- Quick Start with Docker
- API Documentation
- Configuration
- Development Setup
- Testing
- Balance Management: Track customer wallet balances with full transaction history
- Top-up Operations: Secure balance increase functionality
- Consumption Control: Balance deduction with insufficient funds protection
- Transaction Ledger: Complete audit trail of all wallet operations
- Idempotency: Protection against double deductions on retries
- Daily Reconciliation: Automated comparison between internal and external transactions
- Mismatch Detection: Identifies missing transactions and amount discrepancies
- Report Generation: CSV export capabilities for reconciliation reports
- External Provider Integration: Support for CSV/JSON transaction reports
- Message Queuing: RabbitMQ integration for asynchronous transaction processing
- Database: PostgreSQL with JPA/Hibernate for data persistence
- API Documentation: Swagger/OpenAPI integration
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Spring Boot β β PostgreSQL β β RabbitMQ β
β Application βββββΊβ Database β β Message β
β (Port 8065) β β (Port 5432) β β Broker β
βββββββββββββββββββ βββββββββββββββββββ β (Port 5672) β
βββββββββββββββββββ
Key Components:
- Wallet Module: Balance management and transaction processing
- Reconciliation Module: Daily settlement and mismatch detection
- Ledger System: Complete transaction audit trail
- Queue Processing: Asynchronous transaction handling
- Docker & Docker Compose
- Git
- Java 17+ (for local development)
- Gradle 7+ (for local development)
git clone git@github.com:Zackius/Wallet-MicroService.git
cd wallet-app
chmod +x setup.sh && ./setup.shdocker-compose up --build- Wallet API: http://localhost:8065
- Swagger UI: http://localhost:8065/swagger-ui.html
- RabbitMQ Management: http://localhost:15672 (guest/guest)
All API documentation is available through Swagger UI: http://localhost:8065/swagger-ui.html
Swagger provides:
- Complete API Reference: All endpoints with detailed descriptions
- Interactive Testing: Test APIs directly from the browser interface
- Request/Response Schemas: Full data models with validation rules
- Real-time Examples: Live request/response examples
- Authentication Details: Security requirements for each endpoint
- Wallet Top-up:
POST /wallets/{customerId}/topup - Balance Consumption:
POST /wallets/{customerId}/consume - Balance Inquiry:
GET /wallets/{customerId}/balance - Reconciliation Report:
GET /api/v1/reconciliation/report - Export Report:
GET /api/v1/reconciliation/export
π‘ Primary Documentation: Use Swagger UI for complete API documentation, testing, and examples. All endpoint details, schemas, and validation rules are documented there.
- local: For local development
- docker: For containerized deployment
- test: For unit testing
-
Start Dependencies:
# PostgreSQL docker run -d --name postgres -e POSTGRES_DB=wallet -e POSTGRES_USER=zackius -e POSTGRES_PASSWORD=zackius -p 5432:5432 postgres:15-alpine # RabbitMQ docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management-alpine
-
Run Application:
./gradlew bootRun
# Build JAR
./gradlew clean build
# Run tests
./gradlew test
# Build Docker image
docker build -t wallet-app ../gradlew test./gradlew integrationTestFor quick testing without Swagger UI, you can use these curl commands:
Test Top-up:
curl -X POST http://localhost:8065/wallets/CUST001/topup \
-H "Content-Type: application/json" \
-d '{"amount": 100.00, "description": "Initial top-up"}'Test Consumption:
curl -X POST http://localhost:8065/wallets/CUST001/consume \
-H "Content-Type: application/json" \
-d '{"amount": 25.00, "serviceType": "KYC_VERIFICATION", "description": "KYC document verification"}'Check Balance:
curl http://localhost:8065/wallets/CUST001/balance- customers: Customer information
- collections: Top-up transactions
- spending: Consumption transactions
- reconciliation_reports: Daily reconciliation results
- ACID Transactions: Ensures data consistency
- Audit Trail: Complete transaction history
- Optimistic Locking: Prevents concurrent modification issues
- Collection Queue:
collection.ledger.request.v1 - Spending Queue:
spending.ledger.request.v1
- API receives transaction request
- Transaction validated and processed
- Message queued for asynchronous processing
- Ledger entries created
- Balance updated atomically
- Input Validation: Comprehensive request validation
- Transaction Integrity: ACID compliance for all operations
- Idempotency Keys: Prevention of duplicate transactions
- Balance Protection: Insufficient funds validation
wallet-app/
βββ src/main/java/com/example/wallet_app/
β βββ config/
β β βββ auth/WebSecurityConfiguration.java
β β βββ rabbitmq/RabbitMQConfig.java
β β βββ swagger/SwaggerConfig.java
β βββ controllers/
β β βββ CustomerController.java
β β βββ CollectionController.java
β βββ domain/
β β βββ customer/
β β βββ wallet/
β βββ persistence/
β β βββ customer/
β β βββ collection/
β β βββ spending/
β βββ exceptions/
βββ src/main/resources/
β βββ application.properties
βββ docker-compose.yml
βββ Dockerfile
βββ README.md
- Update environment variables for production
- Configure external database and message broker
- Deploy using Docker Compose or Kubernetes
- Database: Configure connection pooling for high load
- Message Processing: Scale worker instances for queue processing
- Load Balancing: Use multiple application instances behind a load balancer
Queue Declaration Failures:
# Restart with fresh volumes
docker-compose down -v
docker-compose up --buildDatabase Connection Issues:
- Verify PostgreSQL is running and accessible
- Check database credentials in environment variables
RabbitMQ Connection Issues:
- Ensure RabbitMQ management plugin is enabled
- Verify queue configuration in definitions.json
# View application logs
docker-compose logs wallet-app
# View all services logs
docker-compose logs
# Follow logs in real-time
docker-compose logs -f- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with Spring Boot, PostgreSQL, RabbitMQ, Docker, and documented with Swagger π