This repo contains an implementation for a REST API to transfer money between two accounts. It is meant to be simple while taking into consideration the implicit requirements in this domain.
Design and implement a RESTful API (including data model and the backing implementation) for money transfers between accounts.
- You can use Java or Kotlin.
- Keep it simple and to the point (e.g. no need to implement any authentication).
- Assume the API is invoked by multiple systems and services on behalf of end users.
- You can use frameworks/libraries if you like (except Spring), but don't forget about requirement #2 and keep it simple and avoid heavy frameworks.
- The datastore should run in-memory for the sake of this test.
- The final result should be executable as a standalone program (should not require a pre-installed container/server).
- Demonstrate with tests that the API works as expected.
- The code produced by you is expected to be of high quality.
- There are no detailed requirements, use common sense.
The implementation in this repo is:
- follows DDD principles
- Developed using TDD
- REST Api exposes 2 controllers, 1 for accounts and another for transfers
- End 2 End tests written in cucumber & junit
- Uses In-Memory repositories without any backing DB
- gradle as a build tool
I used the below dependencies when developing the project:
-
micronaut: to expose the controller and dependency injection This can be easily replaced with Google guice and any other framework to expose REST api
-
Lombok: to avoid boilerplate code
-
guava: primarily used for the AccountLockingService
-
junit: for unit tests (already imported by micronaut)
-
mockito: for unit test mocking
Gradle is used as the build tool. You can run the below gradle task to have a server running on localhost:8080
gradlew run
Once launched, the server running on localhost:8080 exposes 2 controllers to manage accounts and transfers swagger yaml definition
End 2 End tests are written in cucumber. you can run them by executing:
gradlew :e2e:clean :e2e:cucumber
The results will be logged to the console
2 scenarios are written to test a money transfer between 2 accounts; one of them is successful while the other results in INSUFFICIENT_FUNDS error. One Additional scenario is added to test concurrency behavior.