Skip to content

mybank is a Bank API implemented with Golang's Gin, PostgreSQL, and Redis that allows for the creation of users, accounts related to users, deposits, withdrawals, and transfers.

License

Notifications You must be signed in to change notification settings

marco-almeida/mybank

Repository files navigation

mybank

test workflow codecov Go Version

Bank API implemented with Golang's Gin, PostgreSQL, and Redis.

It is a REST API that allows for the creation of users, accounts related to users, deposits, withdrawals, and transfers.

This project can be considered as a refactor and extension of techschool's course Backend Master Class [Golang, Postgres, Redis, Gin, gRPC, Docker, Kubernetes, AWS, CI/CD] .

Features

  • User creation
  • Account creation
  • Transfers
  • Deposits
  • Withdrawals

Technical features:

  • Project layout
  • Layered Architecture
  • Dependency Injection
  • Rest API
  • Versioning
  • Pagination
  • Global Error Handling (via middleware)
  • Authentication and Authorization (via middleware)
  • Rate Limiting per IP (via middleware)
  • Role-based access control
  • Persistent storage (with PostgreSQL)
  • Background tasks (with Redis)
  • Secure configuration
  • OpenAPI documentation
  • Database migrations
  • Graceful shutdown
  • Containerization (using docker multi-stage builds)
  • Container Orchestration (using docker compose)
  • Testing (with coverage analysis) triggered by CI/CD

Project Layout

This is an opinionated folder structure for Go projects where scalability and maintainability are the main concerns.

The Standard Go Project Layout was taken into account as well as opinions from the golang community.

  • cmd: Entrypoint for this project, where the whole application is configured and executed.
  • build: Packaging and Continuous Integration.
    • ci should contain configurations and scripts for CI. In this case, github actions is used for continuous integration, so this folder is not used.
    • package should contain cloud, container (Docker) and OS configurations as well as scripts for packaging.
  • internal: Domain specific errors and models. Private application and library code. This is the code you don't want others importing in their applications or libraries. Note that this layout pattern is enforced by the Go compiler itself.
    • handler: API code containing the handlers.
    • config: Configuration code.
    • pkg: Code shared by the internal packages.
    • middleware: Middlewares used by the handlers/router.
    • <datastoreName>: Data store(postgresql, redis) interaction code.
    • service: Business logic code called by the handlers.
  • api: OpenAPI/Swagger specs, JSON schema files, protocol definition files.

Before server creation, the layers are instantiated and configured using dependency injection.

Service interfaces are defined in the handler package and implemented in the service package. Repository interfaces are defined in the service package and implemented in the postgresql package. This way, the layers are decoupled from each other.

Getting Started

Prerequisites

Run locally

If you want to run the API locally, you will need the following:

Steps

  1. Clone the repository.
git clone https://github.com/marco-almeida/mybank.git
  1. Create a development.env file in the project's root directory according to the template in example.env.

If the environment value MYBANK_ENV is set, the file with name ${MYBANK_ENV}.env will be used instead of development.env.

  1. Run the containers.
docker compose --env-file ./development.env up # --build if needed for a new image, -d for detached mode

If running the API locally, execute the following command:

make run

Access the API at http://localhost:3000.

Documentation

OpenAPI documentation is available at https://github.com/marco-almeida/mybank/blob/main/api/openapi.yaml.

About

mybank is a Bank API implemented with Golang's Gin, PostgreSQL, and Redis that allows for the creation of users, accounts related to users, deposits, withdrawals, and transfers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages