How wlayray/order-demo works
Main Components of the System
• API Layer: Represented by the “api” directory which includes OpenAPI and protobuf (gRPC) definitions. This layer acts as the external contract for clients and serves as a point of integration.
• Microservices: Each business domain is implemented as its own service:
• Order Service (internal/order): Manages order-related operations, with clear domain, application, adapters, and repository layers. Uses both HTTP and gRPC channels.
• Payment Service (internal/payment): Takes care of payment processing, uses adapters (e.g., ordering via gRPC), application logic, and integrates with external processors like Stripe.
• Stock Service (internal/stock): Manages stock/inventory information. It implements similar architectural patterns (domain, application, adapters) and integrates with external systems (stripe for integrations) and uses PostgreSQL through the ent ORM.
• Goods Service (internal/goods): Likely responsible for handling product catalogs and possibly integrating orders; it includes its own infrastructure and adapters.
• Shared/Common Components: Under internal/common, you have:
• Broker (RabbitMQ): For event-based messaging.
• Client (gRPC and OpenAPI clients): For inter-service communication.
• Database connectivity and discovery (PostgreSQL adapters, etcd integration).
• Logging (using zap), metrics (Prometheus), and tracing (Jaeger).
• External Dependencies and Infrastructure:
• Docker Compose: Presence of docker-compose.yml indicates container orchestration for local development or deployment.
• Prometheus: For monitoring (configuration exists in the “prometheus” directory).
• External payment processors (like Stripe) integrated in both payment and stock modules.
Relationships and Interactions
• Microservices communicate with each other via both direct gRPC calls and indirectly through messaging (RabbitMQ, as seen in consumer adapters).
• The API layer exposes endpoints (documented in the OpenAPI spec) which front for one or more microservices.
• Discovery and configuration are central – etcd is used for both storage connectivity and service discovery among the microservices.
• Common cross-cutting concerns (logging, metrics, and tracing) are integrated into all services.
Architectural Patterns and Design Principles
• Microservices and Separation of Concerns: Each service (order, payment, stock, goods) is self-contained, featuring domain, application, and infrastructure layers.
• Domain-Driven Design (DDD): Evident from the “domain” directories and the explicit separation into application and adapter layers.
• Adapter/Decorator Patterns: The “adapters” and “decorator” directories show that the project uses patterns to abstract implementation details (e.g., logging, metrics) from business logic.
• Event-Driven Architecture: Use of RabbitMQ for asynchronous communication and handling events between services.
Relevant Technologies, Frameworks, and Libraries
• Language: Go
• Communication protocols: gRPC and HTTP
• API Documentation: OpenAPI
• Messaging: RabbitMQ
• Service Discovery: etcd
• ORM: ent (for database interactions, likely with PostgreSQL)
• Monitoring and Tracing: Prometheus (metrics), Jaeger (tracing)
• External APIs: Stripe (payment and stock integrations)
Elements
• Clear labels for each major component and sub-module.
• Visual segregation of different types of components (frontend/API vs. backend services vs. shared infrastructure).
• Annotations highlighting the key technologies used (grpc, openAPI, RabbitMQ, PostgreSQL, etcd, Prometheus, Jaeger, Stripe).