How thangchung/go-coffeeshop works
Main components
• Microservices: The project is organized as multiple services, each with its own directory under cmd (e.g., barista, counter, kitchen, product, proxy, and web). Each service implements a specific business capability.
• API Gateway: There is a gRPC gateway service that sits at the front for client requests.
• Frontend: The “web” service (with assets under cmd/web/app) acts as the user interface.
• Database: There is a Postgres database used by multiple services, and migration files exist under the “db/migrations” folder. Additionally, sqlc is used for generating database access code.
• Messaging: There is integration with RabbitMQ (with publisher and consumer code under pkg/rabbitmq) to support asynchronous communication between services (enabling a choreography saga pattern).
• Infrastructure & Deployment: Deployment artifacts for Nomad, Consul, and Terraform are provided under build directories and in files like docker-compose.yaml. There are also Dockerfiles for each service.
• Shared Kernel: Components common to all services (e.g., event types, shared domain code) appear under internal/pkg/shared_kernel.
• Configuration & Utilities: Global configuration management and logging utilities exist under pkg/config and pkg/logger.
Relationships and interactions
• The API Gateway is the front door for client requests which then directs calls to services such as product and counter.
• Services communicate with each other via gRPC and through events via RabbitMQ. For example, the counter service listens for events from the barista and kitchen services, while service interdependencies are managed using DDD patterns.
• Each microservice encapsulates its own domain logic and interfaces with its persistence layer (Postgres) via their respective internal/infras package directories.
• The microservices coordinate using a choreography saga approach—each service emits events (published to RabbitMQ) that are then consumed by other services.
• Deployment artifacts define how these services are run in a production or development Nomad/Consul environment.
Architectural patterns and design principles
• Domain-Driven Design (DDD): Notice the usage of “internal” directories to segment business logic, domain models, and infrastructure code.
• Dependency Injection: Code generation with Google Wire indicates an emphasis on wired dependency management.
• Event-Driven Architecture: The use of RabbitMQ for inter-service communication and dependency on “pkg/event” makes event flow central to the design.
• Microservices: Separation of the application into multiple, independently deployable services, each with its own configuration, REST/gRPC interface, and persistence layer.
• Containerization and orchestration: Use of Docker, Nomad, Consul, and Terraform specifies how the system is packaged and deployed.
• Clear labels for each major component (each microservice, the API gateway, the database, RabbitMQ messaging, and deployment infrastructure components like Nomad, Consul, Vault).
• Representation of the DDD layered structure, if desired, by highlighting the separation between domain logic, application layers, and infrastructure within each service.
• Notes on how dependency injection (using Google Wire) aggregates internal wiring of services and how source code generation (via sqlc for DB queries) plays a role.