Mybank transactions π¦ π°
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()