This project implements a modern microservices architecture using Go, with GraphQL as the API gateway and gRPC for inter-service communication.
The system follows a microservices architecture with the following components:
- GraphQL API Gateway: Provides a unified entry point for clients
- Account Service: Manages user accounts and authentication
- Catalog Service: Handles product information and search functionality
- Order Service: Processes orders and manages the purchase lifecycle
- Go: Primary programming language
- GraphQL: API gateway interface
- gRPC: Inter-service communication
- PostgreSQL: Database for Account and Order services
- Elasticsearch: Database for Catalog service
- Docker: Containerization and deployment
- Go 1.21 or higher
- Docker and Docker Compose
- PostgreSQL
- Elasticsearch
-
Clone the repository
-
Start the services using Docker Compose:
docker-compose up -d --build -
Access the GraphQL playground at
http://localhost:8000/playground
For generating gRPC files, follow these steps:
-
Install Protocol Buffers compiler:
wget https://github.com/protocolbuffers/protobuf/releases/download/v23.0/protoc-23.0-linux-x86_64.zip unzip protoc-23.0-linux-x86_64.zip -d protoc sudo mv protoc/bin/protoc /usr/local/bin/ -
Install Go plugins for Protocol Buffers:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest -
Update PATH:
export PATH="$PATH:$(go env GOPATH)/bin" source ~/.bashrc -
Generate gRPC code:
mkdir -p pb # Add this to your proto files: option go_package = "./pb"; protoc --go_out=./pb --go-grpc_out=./pb account.proto
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
}
}Manages user accounts, authentication, and authorization.
Provides product catalog functionality with advanced search capabilities using Elasticsearch.
Handles order creation, processing, and management with a complete history of purchases.
Unifies all services under a single GraphQL API, providing a seamless experience for client applications.