A modern e-commerce platform built using microservices architecture with Go, gRPC, and GraphQL. This project demonstrates the implementation of a distributed system with separate services for account management, product catalog, and order processing.
The project consists of the following microservices:
- Account Service: Handles user account management
- Catalog Service: Manages product inventory and details
- Order Service: Processes customer orders
- GraphQL API Gateway: Provides a unified API interface for clients
- Backend: Go (Golang)
- API Gateway: GraphQL with gqlgen
- Inter-Service Communication: gRPC
- Database: PostgreSQL (for accounts and orders)
- Search: Elasticsearch (for product catalog)
- Configuration: Environment variables with envconfig
- Dependencies: Managed with Go modules
┌─────────────┐
│ Client │
└──────┬──────┘
│
┌────────┴────────┐
│ GraphQL │
│ Gateway │
└───┬────┬────┬───┘
│ │ │
┌───────┘ │ └───────┐
│ │ │
┌──────┴───┐ ┌─────┴────┐ ┌────┴────┐
│ Acc Svc │ │ Cat Svc │ │ Ord Svc │
└──────────┘ └──────────┘ └─────────┘
- User account management
- CRUD operations for user accounts
- gRPC endpoints for account operations
- Product management
- Product search and filtering
- Elasticsearch integration for efficient product search
- Order processing
- Order history tracking
- Handles order status updates
- Unified API layer
- Query resolution
- Data aggregation from multiple services
accounts
: Fetch user accounts with paginationproducts
: Search and retrieve products with filtering
createAccount
: Create new user accountscreateProduct
: Add new products to the catalogcreateOrder
: Process new orders
-
Clone the repository:
git clone https://github.com/sid995/ecommerce-microservice.git cd ecommerce-microservice
-
Install dependencies:
go mod download
-
Set up environment variables:
export ACCOUNT_SERVICE_URL=localhost:50051 export CATALOG_SERVICE_URL=localhost:50052 export ORDER_SERVICE_URL=localhost:50053
-
Start the services:
# Start Account Service cd account/cmd/account go run main.go # Start Catalog Service cd ../../catalog/cmd/catalog go run main.go # Start Order Service cd ../../order/cmd/order go run main.go # Start GraphQL Gateway cd ../../graphql go run .
-
Access the GraphQL Playground:
- Open
http://localhost:8080/playground
in your browser - The GraphQL endpoint is available at
http://localhost:8080/graphql
- Open
query {
accounts(pagination: { skip: 0, take: 10 }) {
id
name
orders {
id
createdAt
totalPrice
}
}
}
mutation {
createProduct(product: {
name: "Example Product"
description: "Product description"
price: 99.99
}) {
id
name
price
}
}
mutation {
createOrder(order: {
accountId: "account123"
products: [
{ id: "product123", quantity: 2 }
]
}) {
id
totalPrice
createdAt
}
}
.
├── account/ # Account service
│ ├── cmd/ # Service entry point
│ ├── pb/ # Generated protobuf files
│ └── ... # Service implementation
├── catalog/ # Catalog service
│ ├── cmd/ # Service entry point
│ ├── pb/ # Generated protobuf files
│ └── ... # Service implementation
├── order/ # Order service
│ ├── cmd/ # Service entry point
│ ├── pb/ # Generated protobuf files
│ └── ... # Service implementation
├── graphql/ # GraphQL gateway
│ ├── schema.graphql # GraphQL schema
│ └── ... # Resolver implementations
├── go.mod # Go module file
└── go.sum # Go module checksum
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.