Skip to content

hoangtk0100/simple-bank

Repository files navigation

GO - Simple bank

GO - Simple Bank Service

This service implements these main features:

  1. Create and manage users and its bank accounts.
  2. Record all balance changes to each of the accounts.
  3. Perform money transactions between the accounts.

Infrastructure:

  • Database migrations: golang-migrate
  • Generate CRUD code from SQL: sqlc
  • Database: postgreSQL
  • Mock database for testing: gomock
  • Database documentation: dbdocs
  • Generate SQL schema: dbml2sql
  • Queue: Redis
  • Web framework: Gin
  • RPC framework: gRPC
  • API gateway supports both HTTP and gRPC request: grpc-gateway
  • API documentation: Swagger
  • CI/CD: github-action
  • Containerize: docker, docker-compose
  • Deployment: Kubernetes
  • AWS services: IAM - ECR - RDS - Secrets Manager - EKS - Route53
  • TLS: Let's Encrypt

Setup local development

Install tools

  • Migrate

    brew install golang-migrate
  • DB Docs

    npm install -g dbdocs
    dbdocs login
    
  • DBML CLI

    npm install -g @dbml/cli
    dbml2sql --version
  • Sqlc

    brew install sqlc
  • Gomock

    go install github.com/golang/mock/mockgen@v1.6.0

Setup infrastructure

  • Create the bank-network

    make network
  • Start postgres container:

    make postgres
  • Create database:

    make createdb
  • Run db migration up all versions:

    make migrateup
  • Run db migration up 1 version:

    make migrateup1
  • Run db migration down all versions:

    make migratedown
  • Run db migration down 1 version:

    make migratedown1

Documentation

  • Generate DB documentation:

    make db_docs
  • Access the DB documentation at this address. Password: hoangtk

How to generate code

  • Generate schema SQL file with DBML:

    make db_schema
  • Generate SQL CRUD with sqlc:

    make sqlc
  • Generate DB mock with gomock:

    make mock
  • Create a new db migration:

    make new_migration name=<migration_name>

How to run

  • Run server:

    make server
  • Run test:

    make test
  • Access database:

    make db
  • Run containers:

    make up
  • Remove containers:

    make down

Deploy to kubernetes cluster

  • Install nginx ingress controller:

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml
  • Install cert-manager:

    kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.yaml