Skip to content

matoanbach/simple-bank

Repository files navigation

Simple Back-end for Simple Bank

If you're reading this README.md, it's likely that you're reading what Ive learned from a project.

I've been learning Kubernetes and Docker in theory, this project is to make my hands dirty with Cloud computing and DevOps.

Despite that, along the way, I also picked up and used CI/CD with Github Actions, gRPC vs HTTP, Go with Gin, AWS, PostgreSQL, JWT vs PASETO, etc. Overall, this project was a good learning experience.

Shout out to Tech School for making the guide.

Architecture

API documentation using Swagger UI

Database

Alright, I'm not going to write an interface for PostgreSQL from scratch in Go (it's fun, but painful). So sqlc is here to help us, minimizing mistakes along the way.


So, I need a yaml for that ... like below:

version: "2"
sql:
  - schema: "./db/migration" # Path to the schema directory
    queries: "./db/query" # Path to the queries directory
    engine: "postgresql" # Database engine
    gen:
      go:
        package: "db"
        out: "./db/sqlc" # Directory for generated Go code
        emit_json_tags: true
        emit_empty_slices: true
        emit_interface: true
    rules:
      - sqlc/db-prepare

Run this to generate go code, so that we can talk with PostgresSQL
sqlc generate
# or
make sqlc # it's the Makefile, which is basically the same

RESTful with Gin

Gin is a popular web frameworks for Go. JWT and/or PASETO are used to enhance security by creating and verifying tokens. Later on, we can use this to make token-based sessions.


func runGinServer(config util.Config, store db.Store) {
	server, err := api.NewServer(config, store)
	if err != nil {
		log.Fatal().Msg("cannot create server")
	}
	err = server.Start(config.HTTPServerAddress)
	if err != nil {
		log.Fatal().Msg("cannot start the server")
	}
}
// routers down below
func (server *Server) setupServer() {
	router := gin.Default()

	router.POST("/users", server.createUser)
	router.POST("/users/login", server.loginUser)
	router.POST("/tokens/renew_access", server.renewAccessToken)

	authRoutes := router.Group("/").Use(authMiddleWare(server.tokenMaker))
	authRoutes.POST("/accounts", server.createAccount)
	authRoutes.GET("/accounts/:id", server.getAccount)
	authRoutes.GET("/accounts", server.listAccount)
	authRoutes.POST("/transfers", server.createTransfer)
	server.router = router
}

Containerize it with k8s and docker

Here we go, this phase is what I've been waiting for. This is where we set Github Actions for CI/CD, Docker and Kubernetes for containerization and orchestration.

For cloud provider, we work with

  • ECR (Elastic Container Registy) to store docker images
  • Secret Managers to retrieve env variables
  • EC2 instances to run worker nodes
  • EKS (Elastic Kubernetes Service) to run kubernetes
  • RDS (Managed relational database service) to run PostgreSQL virtually, but most of the time, we use local PostgreSQL
  • Of course, IAM to manage authentication and authorization in AWS

gRPC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published