A Java-based microservice for managing user wallets with support for deposits, withdrawals, p2p transfers, and historical balance queries.
See the Architectural Decision Record (ADR.md) for all design and trade-off decisions.
- Create users and wallets
- Deposit and withdraw funds
- Transfer funds between wallets
- Retrieve current and historical balances (
atquery param) - Full audit log of all operations
- API documentation via Swagger/OpenAPI
- Language: Java 21
- Framework: Spring Boot 3
- Persistence: Spring Data JPA
- Database: PostgreSQL (Docker) / H2 (tests)
- Migrations: Flyway
- API Docs: Springdoc OpenAPI (Swagger UI)
- Build: Maven
- Tests: JUnit 5 + Spring Boot Test
docker compose up --buildThis will start:
- PostgreSQL on port 5432
- Simple Wallet Service on port 8080
Visit the API docs at
👉 http://localhost:8080/swagger-ui/index.html
mvn clean test- Unit tests for domain logic
- Integration tests with Spring Boot
This project uses Flyway for database versioning.
- Migrations are stored in:
src/main/resources/db/migration - First migration:
V1__create_schema.sql - Automatically executed at application startup
To manually trigger a migration (if needed):
mvn flyway:migrate| Method | Endpoint | Description |
|---|---|---|
| POST | /users |
Create a new user |
| GET | /users/{id} |
Retrieve a user |
| POST | /wallets |
Create a new wallet |
| GET | /wallets/{id} |
Retrieve a wallet |
| POST | /wallets/{id}/deposit |
Deposit funds ({ "amount": ... }) |
| POST | /wallets/{id}/withdraw |
Withdraw funds ({ "amount": ... }) |
| POST | /wallets/{id}/transfer |
Transfer funds ({ "targetWalletId": "...", "amount": ... }) |
| GET | /wallets/{id}/balance |
Current balance or historical if ?at= provided |
To facilitate manual and automated testing, we provide a ready-to-use Postman collection:
- Import the file
sws.postman_collection.jsonvia File → Import in Postman. - The collection comes with the variable
{{baseUrl}}preset tohttp://localhost:8080. - Execute the full suite of requests (Create User, Create Wallet, Deposit, Withdraw, Transfer, etc.) directly in Postman.
If you prefer the command line, you can hit any endpoint directly with curl. For example:
curl -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{"name":"Alice"}'curl -X POST http://localhost:8080/wallets \
-H "Content-Type: application/json" \
-d '{"userId":"<USER_UUID>"}'curl -X POST http://localhost:8080/wallets/<WALLET_UUID>/deposit \
-H "Content-Type: application/json" \
-d '{"amount": 50.00}'curl "http://localhost:8080/wallets/<WALLET_UUID>/balance?at=2025-04-25T19:00:00Z"General folder structure:
.
├── docker/
│ └── wait-for-flyway.sh # Script to help docker compose works (container-init mode)
├── src/
│ ├── main/
│ │ ├── java/ # Main source code
│ │ └── resources/ # Main configs and helper files
│ └── test/
│ ├── java/ # Test source code
│ └── resources/ # Test configs and helper files
├── ARD.md # Architectural decision records document
├── docker-compose.yaml
├── Dockerfile
├── pom.xml
└── README.md
Main source code:
com.rissatto.sws
├── application/
│ ├── mapper/ # Conversão entre DTOs e entidades de domínio
│ └── service/ # Serviços (regras de negócio)
├── domain/ # Entidades de domínio puro
├── infrastructure/
│ ├── config/ # Configurações Spring (Auditing etc.)
│ ├── entity/ # Entidades JPA (persistência)
│ └── repository/ # Repositórios JPA
├── presentation/
│ ├── config/ # Configurações de apresentação (Swagger)
│ ├── controller/ # REST Controllers
│ ├── dto/ # DTOs de entrada e saída
│ └── exception/ # Tratamento de exceções REST
└── SwsApplication.java # Classe principal
- Refer to ADR.md for detailed design rationale.
- All timestamps and query‐params are interpreted in UTC.