How saveliy12/microservices2 works
Purpose and topology
This Go workspace implements an order-processing microservice system: inventory, order, and payment services. Each service is independently buildable/containerized, while shared owns inter-service API contracts and generated bindings. Deployment is organized as service-specific Docker Compose stacks.
Service entry points
Each service starts from its own Go command and Docker image:
• Inventory: inventory/cmd/main.go, inventory/Dockerfile
• Order: order/cmd/main.go, order/Dockerfile
• Payment: payment/cmd/main.go, payment/Dockerfile
The root go.work ties the service and shared modules into one local workspace. Compose definitions reside in deploy/compose/core/docker-compose.yml and per-service directories.
Contract boundary and transport
shared is the API-contract module. Inventory and payment expose protobuf/gRPC contracts defined under shared/proto/inventory/v1/inventory.proto and shared/proto/payment/v1/payment.proto, with checked-in generated clients/server bindings in shared/pkg/proto/....
Order exposes an OpenAPI-described HTTP API: shared/api/order/v1/order.openapi.yaml, with generated server/client/router code in shared/pkg/openapi/order/v1/. Its API handlers are implemented in order/internal/api/order/v1/.
Inventory service
Inventory follows a layered request path: gRPC/API adapter → service → repository → Mongo-oriented database adapter. API operations are implemented in inventory/internal/api/inventory/v1/get.go and inventory/internal/api/inventory/v1/list.go; business operations live in inventory/internal/service/part/; persistence is in inventory/internal/repository/part/.
The database boundary is abstracted by collection interfaces in inventory/internal/client/db/collection.go, with Mongo implementation under inventory/internal/client/db/mongo/. Repository seeding is part of the inventory persistence component (inventory/internal/repository/part/seed.go).
Order orchestration and persistence
Order is the workflow-owning service. Its actions cover create, retrieve, pay, and cancel through order/internal/api/order/v1/, with orchestration and state transitions in order/internal/service/order/.
Order persists orders through repository abstractions and a PostgreSQL client: order/internal/repository/order/, order/internal/client/db/pg/client.go. Schema initialization is managed through order/internal/migrator/migrator.go and order/migrations/20260805000001_init_orders.sql.
Cross-service order flow
Order creation/payment logic calls inventory and payment through explicit outbound client adapters: order/internal/clients/inventory/inventory.go and order/internal/clients/payment/payment.go. These adapters isolate generated RPC/client protocol details from the order service layer.
The expected primary flow is: HTTP order request → API action handler → order service → PostgreSQL repository; payment-related actions additionally invoke inventory/payment clients before updating order state. Cancellation, payment, and creation are separate service commands, enabling their own validation and external-call sequencing.
Payment service
Payment is a focused gRPC service with API-to-service layering: payment/internal/api/payment/v1/pay.go delegates to payment/internal/service/payment/pay.go. It has no repository or database implementation in this tree, so payment processing is currently modeled as service-layer behavior rather than durable local persistence.
Runtime and infrastructure
Services run as Go binaries in Docker. Inventory’s persistence integration is MongoDB-oriented; Order’s is PostgreSQL-oriented. The order service is the only service with explicit synchronous dependencies on the other two. Service topology and backing dependencies are provisioned through deploy/compose/inventory/docker-compose.yml, deploy/compose/order/docker-compose.yml, and deploy/compose/payment/docker-compose.yml.
Main entry points: get.go Inventory gRPC API · pay.go Payment gRPC API · docker-compose.yml Service Compose stacks · main.go Inventory binary
Components 20
Shared contracts
Versioned API definitions and generated bindings.
- Inventory protobuf · Generated bindings are owned by shared.
shared/proto/inventory/v1/inventory.proto - Payment protobuf · Generated bindings are owned by shared.
shared/proto/payment/v1/payment.proto - Order OpenAPI · Generated server, client, and router bindings are owned by shared.
shared/api/order/v1/order.openapi.yaml
Inventory service
- Inventory binary
inventory/cmd/main.go - Inventory gRPC API
inventory/internal/api/inventory/v1/get.go - Part service
- Part repository · Includes inventory seed data.
- Mongo DB adapter · Collection interfaces isolate the Mongo implementation.
inventory/internal/client/db/collection.go
Order service
Owns order workflow and state transitions.
- Order binary
order/cmd/main.go - Order HTTP API
- Order service · Handles create, retrieve, pay, and cancel commands.
- Order repository
- PostgreSQL client
order/internal/client/db/pg/client.go - Order schema migrator
order/internal/migrator/migrator.go - Inventory client
order/internal/clients/inventory/inventory.go - Payment client
order/internal/clients/payment/payment.go
Payment service
- Payment binary
payment/cmd/main.go - Payment gRPC API
payment/internal/api/payment/v1/pay.go - Payment service · Payment processing has no local durable persistence.
payment/internal/service/payment/pay.go
Deployment
- Service Compose stacks · Provisions services and backing dependencies.
deploy/compose/core/docker-compose.yml
Connections 21
- Inventory binary → Inventory gRPC API: serves
- Inventory gRPC API → Part service: delegates
- Part service → Part repository: uses
- Part repository → Mongo DB adapter: persists via
- Inventory gRPC API → Inventory protobuf: implements
- Order binary → Order HTTP API: serves
- Order HTTP API → Order service: delegates
- Order HTTP API → Order OpenAPI: implements
- Order service → Order repository: persists orders
- Order repository → PostgreSQL client: uses
- Order schema migrator → PostgreSQL client: initializes schema
- Order service → Inventory client: reserves/checks inventory
- Inventory client → Inventory gRPC API: gRPC
- Order service → Payment client: processes payment
- Payment client → Payment gRPC API: gRPC
- Payment binary → Payment gRPC API: serves
- Payment gRPC API → Payment service: delegates
- Payment gRPC API → Payment protobuf: implements
- Service Compose stacks → Inventory binary: runs
- Service Compose stacks → Order binary: runs
- Service Compose stacks → Payment binary: runs