Git Product home page Git Product logo

wallet's Introduction

wallet-service

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.

Wallet Service DB Diagram

Content

Usage

For local usage, run your terminal:

 docker compose up

Then ready to GO.

Endpoints

POST http://localhost:8080/v1/user

This endpoint crate an user.

Request model;

{
      "name": "John Dee",
      "email": "[email protected]"       
}

POST http://localhost:8080/v1/wallet

This endpoint crate a wallet.

Request model;

{
     "user_id": 7,
     "currency": "USD"
}

GET http://localhost:8080/v1/user/:id/wallet

This endpoint get wallet by user id.

POST http://localhost:8080/v1/transaction

This endpoint crate a deposit/withdraw transaction.

Request model;

{
     "wallet_id": 1,
     "transactionType": "deposit",
     "currency": "USD",
     "amount": 100.25
}

GET http://localhost:8080/v1/transaction/history

This endpoint get all transaction history.

Project structure

cmd/wallet/main.go

Configuration and logger initialization. Then the main function "continues" in internal/app/app.go with app.Run(cfg) function.

config

The config folder has config structure and config.yml. For configuration, I used viper library. This is most popular configuration library for config management.

internal/app

Run function in the app.go file, which "continues" the main function. This is where all the main objects are created.

internal/controller

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.

internal/entity

Interfaces and Entities of business logic (models) can be used in any layer.

internal/entity/mocks

The Mocks are generated to interface. I used mockery.

internal/core/repository

A repository is an abstract storage (database) that business logic works with.

internal/core/usecase

Business logic and usecase tests.

pkg

The pkg folder has external package. Which is database(postgres), logger (zerolog), httpserver(gin).

pkg/db

The pkg folder has database.go for db configuration and migration folder. I manage to migration with goose tool.

wallet's People

Contributors

svbnbyrk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.