mybank-tx

module
v0.0.0-...-a6a5f53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2021 License: MIT

README ΒΆ

Mybank transactions 🏦 πŸ’°

GitHub Workflow Status Go Report Card

Over engineered bank transactions microservice. It was designed following DDD and clean arch principles protecting its domain logic from everything else. Don't get to much attached to the choice of frameworks and drivers because that's now really the point. They could be easily replaced by any other without having to change a single domain line of code.

This microservice handles transaction requests through a REST API. It process incoming requests by communicationg with another microservice using gRPC and storing transactional data on database.



Make yourself at home

For some of the following steps Golang or Docker are gonna be necessary.

Run application 100% on Docker (no need for Golang in this case)

$ make docker-run

Run application dependencies on background using Docker

$ make setup-dev

Run it locally

$ go run cmd/api/*

Buid it

$ make compile (generates binary output at ./build)

Run tests

$ make test

Run linter

$ make metalint


API doc

Once application is running API docs can be found at Swagger UI.

curl -i -X POST http://localhost:3000/api/v1/transactions -d '{ "account_id": "8dd68a39-4aed-4f30-b88a-f589266fc1be", "amount": 1000, "operation_type_id": 4}'

Project tree
$ tree
β”œβ”€β”€ cmd # everything starts here: main files are located here
β”œβ”€β”€ docs # autogenerated documentation
β”œβ”€β”€ pkg
β”‚   β”œβ”€β”€ config # centralized configuration of the project
β”‚   β”œβ”€β”€ domain
β”‚   β”‚   β”œβ”€β”€ entities # domain entities and aggregates
β”‚   β”‚   β”œβ”€β”€ error.go # some domain errors
β”‚   β”‚   β”œβ”€β”€ usecases # domain use cases
β”‚   β”‚   └── vos      # value objects package
β”‚   β”œβ”€β”€ gateway
β”‚   β”‚   β”œβ”€β”€ api  # REST API infrastructure layer
β”‚   β”‚   β”œβ”€β”€ db   # database infrastructure layer
β”‚   β”‚   └── grpc # gRPC client infrastructure layer
β”‚   └── tests # integration tests and test helpers to be used within the project
β”‚       └── servers # fake servers for integration testing porpuses
Database schema
             Table "public.operation_types"
   Column    |  Type   | Nullable | Default 
-------------+---------+----------+---------
 id          | integer | not null | 
 description | text    |          | 
Indexes:
    "operation_types_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE "transactions" CONSTRAINT "fk_operation" FOREIGN KEY (operation_type) REFERENCES operation_types(id)

--------------------------------------------------------------------------------------------------------------

                              Table "public.transactions"
     Column     |           Type           | Nullable |      Default       
----------------+--------------------------+----------+--------------------
 id             | uuid                     | not null | uuid_generate_v4()
 account_id     | uuid                     | not null | 
 operation_type | integer                  | not null | 
 amount         | integer                  | not null | 
 created_at     | timestamp with time zone | not null | CURRENT_TIMESTAMP
 updated_at     | timestamp with time zone | not null | CURRENT_TIMESTAMP
Indexes:
    "transactions_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "fk_operation" FOREIGN KEY (operation_type) REFERENCES operation_types(id)
Triggers:
    set_timestamp_transactions BEFORE UPDATE ON transactions FOR EACH ROW EXECUTE FUNCTION trigger_set_timestamp()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL