The project consists of the following main components:
- Account Service
- Catalog Service
- Order Service
- GraphQL API Gateway
Each service has its own database:
- Account and Order services use PostgreSQL
- Catalog service uses Elasticsearch
-
Clone the repository:
git clone <repository-url> cd <project-directory> -
Start the services using Docker Compose:
docker compose up -
Access the GraphQL playground at
http://localhost:8000/playground
Go – Core backend language for all microservicesgRPC – Fast and type-safe service-to-service communication
GraphQL – Centralized API gateway
Docker – Containerization of services
Docker Compose – Local orchestration
PostgreSQL – Relational data storage
To generate Go code from your .proto files, run:
protoc --go_out=./pb --go-grpc_out=./pb account.proto
To install protoc:
brew install protoc
You need these plugins installed:
protoc-gen-goprotoc-gen-go-grpc
Run these commands:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Make sure your Go binaries path is in your PATH environment variable. Add this line to your shell profile (~/.bashrc or ~/.zshrc):
export PATH="$PATH:$(go env GOPATH)/bin"
Reload your shell or run source ~/.bashrc (or your profile) after adding the line.
Now protoc can find the plugins and generate Go and gRPC code correctly.
The GraphQL API provides a unified interface to interact with all the microservices.
query {
accounts {
id
name
}
}mutation {
createAccount(account: {name: "New Account"}) {
id
name
}
}query {
products {
id
name
price
}
}mutation {
createProduct(product: {name: "New Product", description: "A new product", price: 19.99}) {
id
name
price
}
}mutation {
createOrder(order: {accountId: "account_id", products: [{id: "product_id", quantity: 2}]}) {
id
totalPrice
products {
name
quantity
}
}
}query {
accounts(id: "account_id") {
name
orders {
id
createdAt
totalPrice
products {
name
quantity
price
}
}
}
}query {
products(pagination: {skip: 0, take: 5}, query: "search_term") {
id
name
description
price
}
}query {
accounts(id: "account_id") {
name
orders {
totalPrice
}
}
}After the app is up and running, ElasticSearch DB can be accessed at:
http://localhost:9200
To check all indices visit:
http://localhost:9200/_cat/indices?v
To check all documents in the catalog index:
http://localhost:9200/catalog/_search?pretty
PostgreSQL can be accessed and used via CLI (Command Line Interface) After the app is up and running, in the terminal follow the below commands:
docker exec -it <container_id_for_accountDB> psql -U <db_username> -d <db_name>
Once you are in the PostgreSQL CLI, use the following commands:
To view tables:
\dt
To view accounts information:
SELECT * FROM accounts;
PostgreSQL can be accessed and used via CLI (Command Line Interface) After the app is up and running, in the terminal follow the below commands:
docker exec -it <container_id_for_orderDB> psql -U <db_username> -d <db_name>
Once you are in the PostgreSQL CLI, use the following commands:
To view tables:
\dt
To view orders information:
SELECT * FROM order;
To view ordered products information:
SELECT * FROM order_products;