How rajapremsai/microservices_using_go works
Project Type and Purpose
• This is a Go-based microservices system with an API gateway.
• It implements three domain services (Account, Catalog, Order) communicating via gRPC, with a GraphQL gateway providing a unified HTTP API.
• It uses Docker Compose for deployment and separate databases per service (PostgreSQL and Elasticsearch).
File Structure
• Top-level directories:
• account/ – Account service code, protobuf definitions, Dockerfiles, SQL migrations
• catalog/ – Catalog service with protobuf, ES integration, Dockerfiles
• order/ – Order service depending on account/catalog services and PostgreSQL
• graphql/ – GraphQL gateway using gqlgen, resolvers, schema, Dockerfile
• Shared files: docker-compose.yaml orchestrates all containers; Makefile or scripts for building/testing.
• Each service has:
• cmd/<service>/main.go as entrypoint
• server.go, service.go, repository.go for service logic
• pb/ contains generated gRPC code from .proto
• client.go for calling other services (Order service depends on account/catalog)
• app.dockerfile and db.dockerfile for container images
README for Additional Insights
• Lists ports and technologies for each service.
• Emphasizes microservices pattern, GraphQL gateway, data stores, gRPC endpoints.
• Provides sample GraphQL queries/mutations, environment variables, and database schemas.
a. Main Components
• GraphQL Gateway (gqlgen)
• Account Service (Go + gRPC + PostgreSQL)
• Catalog Service (Go + gRPC + Elasticsearch)
• Order Service (Go + gRPC + PostgreSQL)
• Databases: Account DB, Order DB (both PostgreSQL), Catalog ES Cluster
• External Interfaces: GraphQL Playground, gRPC clients
b. Relationships & Data Flows
• Clients → HTTP → GraphQL Gateway
• Gateway → gRPC → Account, Catalog, Order services
• Order service → gRPC → Account, Catalog (to validate account and fetch product details)
• Each service → its own database
c. Architectural Patterns & Principles
• Microservices per bounded context (accounts, products, orders)
• API Gateway pattern implemented with GraphQL
• Database per service (encapsulation)
• gRPC for inter-service RPC and protobuf for contracts
• Separation of concerns: server, service logic, repository layers
d. Key Technologies/Frameworks
• Go modules (go.mod)
• gRPC/protobuf (account.proto, catalog.proto, order.proto)
• gqlgen for GraphQL gateway
• PostgreSQL, Elasticsearch
• Docker & Docker Compose
Elements
• Microservices (e.g., blue rectangles)
• API Gateway (e.g., orange rectangle)
• Annotations for ports, protocols (HTTP, gRPC), and major endpoints