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.
For some of the following steps Golang or Docker are gonna be necessary.
$ make docker-run
$ make setup-dev
$ go run cmd/api/*
$ make compile (generates binary output at ./build)
$ make test
$ make metalint
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}'
$ 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 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()