A mini wallet service project with Clean Architecture
Flow of HTTP request in clean architecture at wallet.
HTTP > usecase
usecase > repository (Postgres)
usecase < repository (Postgres)
HTTP < usecase
Controller and Database don't know anything about each other. These two layers use usecase to communicate.
For local usage, run your terminal:
docker compose up
Then ready to GO.
This endpoint crate an user.
Request model;
{
"name": "John Dee",
"email": "john.dee@gmail.com"
}
This endpoint crate a wallet.
Request model;
{
"user_id": 7,
"currency": "USD"
}
This endpoint get wallet by user id.
This endpoint crate a deposit/withdraw transaction.
Request model;
{
"wallet_id": 1,
"transactionType": "deposit",
"currency": "USD",
"amount": 100.25
}
This endpoint get all transaction history.
Configuration and logger initialization. Then the main function "continues" in internal/app/app.go
with app.Run(cfg)
function.
The config folder has config structure and config.yml
. For configuration, I used viper library. This is most popular configuration library for config management.
Run function in the app.go
file, which "continues" the main function. This is where all the main objects are created.
The Controller layer has handler, router. The structure of the business logic is injected into the router structure, which will be called by the handlers.
Interfaces and Entities of business logic (models) can be used in any layer.
The Mocks are generated to interface. I used mockery.
A repository is an abstract storage (database) that business logic works with.
Business logic and usecase tests.
The pkg folder has external package. Which is database(postgres), logger (zerolog), httpserver(gin).
The pkg folder has database.go for db configuration and migration folder. I manage to migration with goose tool.