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
3.7 KiB
Story 3.3: Service Loader and Initialization
Metadata
- Story ID: 3.3
- Title: Service Loader and Initialization
- Epic: 3 - Module Framework (Feature Services)
- Status: Pending
- Priority: High
- Estimated Time: 6-8 hours
- Dependencies: 3.1, 1.2, 1.7
Goal
Implement service initialization helpers for feature services with dependency resolution, Consul registration, and automatic migration execution. Each service initializes itself in its own entry point.
Description
This story implements service initialization helpers that feature services use in their entry points (cmd/{service}/main.go). Services initialize themselves, resolve dependencies (other services), register with Consul, run migrations, and start their gRPC servers. The loader provides helpers for common service initialization patterns.
Deliverables
1. Service Initialization Helpers (internal/service/init.go)
InitializeService(cfg, module IModule)function- Bootstrap core kernel services
- Initialize service-specific components
- Register with Consul service registry
- Run database migrations (per-service schema)
- Start gRPC server
- Handle graceful shutdown
2. Service Dependency Resolution (internal/service/deps.go)
- Resolve service dependencies (check other services are available via Consul)
- Wait for dependent services to be healthy
- Service discovery integration
- Dependency validation
3. Service Bootstrap Pattern (internal/service/bootstrap.go)
- Common bootstrap pattern for feature services
- FX lifecycle integration
- Service registration helpers
- Health check setup
- Migration runner (per-service)
4. Service Template/Scaffolding
- Service template generator
- Standard service structure
- Example service entry point
Note: Each feature service has its own cmd/{service}/main.go that uses these helpers to initialize itself.
Implementation Steps
-
Create Service Initialization Helpers
- Create
internal/service/init.go - Implement service bootstrap pattern
- Integrate with Consul service registry
- Create
-
Implement Dependency Resolution
- Create
internal/service/deps.go - Check service dependencies via Consul
- Wait for services to be healthy
- Create
-
Create Service Bootstrap
- Create
internal/service/bootstrap.go - Common bootstrap pattern
- FX lifecycle integration
- Create
-
Create Service Template
- Service template generator
- Example service entry point
-
Test Service Initialization
- Test service startup
- Test Consul registration
- Test dependency resolution
Acceptance Criteria
- Service initialization helpers work correctly
- Services register with Consul automatically
- Service migrations run on startup (per-service schema)
- Service dependency resolution works via Consul
- Services wait for dependencies to be healthy
- FX lifecycle integration works
- Service bootstrap pattern is reusable
- Service template generator creates standard structure
Related ADRs
- ADR-0021: Module Loading Strategy
- ADR-0029: Microservices Architecture
- ADR-0030: Service Communication Strategy
- ADR-0033: Service Discovery Implementation
Files to Create/Modify
internal/service/init.go- Service initialization helpersinternal/service/deps.go- Service dependency resolutioninternal/service/bootstrap.go- Service bootstrap patterninternal/service/template.go- Service template generator- Example:
cmd/blog-service/main.go- Example service entry point