How meysamhadeli/shop-golang-microservices works
Project type and purpose
• This is a distributed microservices system written in Go, demonstrating Vertical Slice Architecture, CQRS, Event-Driven Architecture, gRPC, RabbitMQ, Postgres, OpenTelemetry/Jaeger, OAuth2, and dependency injection (Uber-fx).
• It contains three independent microservices (“identity”, “product”, “inventory”), shared libraries under internal/pkg, and a Docker-Compose deployment for infrastructure.
File structure
• Top-level directories:
• internal/pkg: shared plumbing (HTTP server, gRPC client/server wrappers, RabbitMQ publisher/consumer, logging, tracing, OAuth2, utils).
• internal/services/{identity,product,inventory}_service: each microservice’s code, organized by Vertical Slice (feature folders) + CQRS (commands, queries, handlers, DTOs, endpoints).
• deployments/docker-compose: infrastructure YAML (Postgres, RabbitMQ, Jaeger).
• Each microservice has:
• cmd/main.go, config/, DI bootstrapping (uber-fx), server/server.go (Echo HTTP), gRPC server & client code, domain slices for each feature, repository implementations (GORM/Postgres), event publishers (RabbitMQ) and consumers (where relevant).
Extract architectural insights from README
• The system is microservices-based with:
• RESTful APIs (Echo + Swagger)
• Internal RPC (gRPC) for cross-service calls
• Asynchronous messaging (RabbitMQ) for eventual consistency
• CQRS + Mediator pattern (Go-MediatR) for segregation of commands/queries
• Distributed tracing (OpenTelemetry + Jaeger)
• OAuth2 for security
• Postgres per service; Outbox/Inbox patterns planned
• Docker-Compose orchestration of infra
Main components & their relationships
a. Components:
1. Client (REST UI or API consumer)
2. Identity Service
• HTTP/REST (Echo)
• gRPC server (protos)
• Postgres DB
• OAuth2 token endpoint
3. Product Service
• HTTP/REST (Echo)
• gRPC client to Identity Service for authentication/authorization
• RabbitMQ publisher (“ProductCreated”, “ProductUpdated”, etc.)
• Postgres DB
4. Inventory Service
• HTTP/REST (Echo)
• RabbitMQ consumer (listening to “ProductCreated” events; publishing “InventoryUpdated” events)
• Postgres DB
5. RabbitMQ Broker (message exchange)
6. OpenTelemetry Collector & Jaeger (distributed tracing)
7. Docker-Compose orchestrator
b. Relationships & data flows:
• Client →(HTTP/REST)→ Identity/Product/Inventory Service
• Product Service →(gRPC)→ Identity Service (to verify tokens/user info)
• Product Service →(RabbitMQ publish)→ “product.events” exchange
• Inventory Service →(RabbitMQ consume)→ “product.events” → update inventory → (optionally) publish “inventory.events”
• Each service → Postgres DB (read/write)
• Each service →(OpenTelemetry)→ Jaeger
c. Architectural patterns:
• Vertical Slice Architecture: each feature (e.g. CreateProduct) is a slice containing endpoint, DTOs, handler, repository.
• CQRS: separate command handlers (write) vs. query handlers (read).
• Mediator Pattern: endpoints dispatch commands/queries via Go-MediatR for pipeline behaviors (validation, logging, caching).
• Event-Driven: RabbitMQ for eventual consistency between services.
• gRPC: synchronous internal RPC for authentication/authorization.
• Outbox/Inbox (planned): for atomic event persistence and delivery.
d. Key technologies:
• Echo Framework (REST)
• GORM + Postgres (ORM & DB)
• grpc-go (gRPC)
• streadway/amqp (RabbitMQ client)
• open-telemetry/opentelemetry-go + Jaeger
• go-oauth2/oauth2
• Uber-fx (DI)
• Go-MediatR (Mediator)
• swaggo/echo-swagger
• Viper (config)
• Logrus (logging)