Transform all documentation from modular monolith to true microservices
architecture where core services are independently deployable.
Key Changes:
- Core Kernel: Infrastructure only (no business logic)
- Core Services: Auth, Identity, Authz, Audit as separate microservices
- Each service has own entry point (cmd/{service}/)
- Each service has own gRPC server and database schema
- Services register with Consul for service discovery
- API Gateway: Moved from Epic 8 to Epic 1 as core infrastructure
- Single entry point for all external traffic
- Handles routing, JWT validation, rate limiting, CORS
- Service Discovery: Consul as primary mechanism (ADR-0033)
- Database Pattern: Per-service connections with schema isolation
Documentation Updates:
- Updated all 9 architecture documents
- Updated 4 ADRs and created 2 new ADRs (API Gateway, Service Discovery)
- Rewrote Epic 1: Core Kernel & Infrastructure (infrastructure only)
- Rewrote Epic 2: Core Services (Auth, Identity, Authz, Audit as services)
- Updated Epic 3-8 stories for service architecture
- Updated plan.md, playbook.md, requirements.md, index.md
- Updated all epic READMEs and story files
New ADRs:
- ADR-0032: API Gateway Strategy
- ADR-0033: Service Discovery Implementation (Consul)
New Stories:
- Epic 1.7: Service Client Interfaces
- Epic 1.8: API Gateway Implementation
5.2 KiB
Story 1.7: Service Client Interfaces
Metadata
- Story ID: 1.7
- Title: Service Client Interfaces
- Epic: 1 - Core Kernel & Infrastructure
- Status: In Progress
- Priority: High
- Estimated Time: 4-6 hours
- Dependencies: 1.1
Goal
Create service client interfaces for all core services to enable microservices communication. All inter-service communication will go through these interfaces.
Description
This story defines service client interfaces for all core services (Auth, Identity, Authz, Audit) and creates a service client factory that can create gRPC (primary) or HTTP (fallback) clients. Service clients use Consul for service discovery.
Deliverables
1. Service Client Interfaces (pkg/services/)
Define interfaces for all core services:
-
AuthServiceClientinpkg/services/auth.go:Login(ctx, email, password) (*TokenResponse, error)RefreshToken(ctx, refreshToken) (*TokenResponse, error)ValidateToken(ctx, token) (*TokenClaims, error)
-
IdentityServiceClientinpkg/services/identity.go:GetUser(ctx, id) (*User, error)GetUserByEmail(ctx, email) (*User, error)CreateUser(ctx, user) (*User, error)UpdateUser(ctx, id, user) (*User, error)DeleteUser(ctx, id) errorVerifyEmail(ctx, token) errorRequestPasswordReset(ctx, email) errorResetPassword(ctx, token, newPassword) error
-
AuthzServiceClientinpkg/services/authz.go:Authorize(ctx, userID, permission) errorHasPermission(ctx, userID, permission) (bool, error)GetUserPermissions(ctx, userID) ([]Permission, error)
-
AuditServiceClientinpkg/services/audit.go:Record(ctx, action) errorQuery(ctx, filters) ([]AuditLog, error)
2. Service Client Factory (internal/services/factory.go)
NewServiceClient(serviceName string, registry ServiceRegistry) (ServiceClient, error)- Support for gRPC clients (primary)
- Support for HTTP clients (fallback)
- Service discovery integration via Consul
- Connection pooling and lifecycle management
3. gRPC Client Implementation (internal/services/grpc/client/)
- gRPC client implementations for each service
- Service discovery integration
- Connection management
- Retry and circuit breaker support
4. HTTP Client Implementation (internal/services/http/client/)
- HTTP client implementations for each service (fallback)
- Service discovery integration
- Request/response handling
- Retry support
5. Configuration
- Service client configuration in
config/default.yaml:- Protocol selection (gRPC/HTTP)
- Service discovery settings
- Connection pool settings
- Retry and timeout configuration
Implementation Steps
-
Define Service Client Interfaces
- Create
pkg/services/auth.go - Create
pkg/services/identity.go - Create
pkg/services/authz.go - Create
pkg/services/audit.go
- Create
-
Create Service Client Factory
- Create
internal/services/factory.go - Implement client creation logic
- Integrate with service registry (Consul)
- Create
-
Implement gRPC Clients
- Create
internal/services/grpc/client/ - Implement clients for each service
- Add service discovery integration
- Create
-
Implement HTTP Clients (Fallback)
- Create
internal/services/http/client/ - Implement clients for each service
- Add service discovery integration
- Create
-
Add Configuration
- Update
config/default.yaml - Add service client configuration
- Update
-
Test Service Clients
- Test client creation
- Test service discovery
- Test gRPC and HTTP clients
Acceptance Criteria
- Service client interfaces are defined for all core services
- Service factory creates gRPC clients
- Service factory creates HTTP clients (fallback)
- Service clients use Consul for service discovery
- Service clients are injectable via DI
- Configuration supports protocol selection
- All inter-service communication goes through service clients
- Service clients handle connection pooling and lifecycle
Related ADRs
Implementation Notes
- gRPC is the primary protocol, HTTP is fallback
- All clients use Consul for service discovery
- Service clients should handle retries and circuit breakers
- Connection pooling is important for performance
- Service clients should be stateless and thread-safe
Testing
# Test service client interfaces
go test ./pkg/services/...
# Test service client factory
go test ./internal/services/...
# Test with Consul
docker-compose up consul
go test ./internal/services/... -tags=integration
Files to Create/Modify
pkg/services/auth.go- AuthServiceClient interfacepkg/services/identity.go- IdentityServiceClient interfacepkg/services/authz.go- AuthzServiceClient interfacepkg/services/audit.go- AuditServiceClient interfaceinternal/services/factory.go- Service client factoryinternal/services/grpc/client/- gRPC client implementationsinternal/services/http/client/- HTTP client implementationsconfig/default.yaml- Add service client configuration