Files
goplt/docs/content/stories/epic3/3.3-module-loader.md
0x1d 38a251968c docs: Align documentation with true microservices architecture
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
2025-11-06 08:54:19 +01:00

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

  1. Create Service Initialization Helpers

    • Create internal/service/init.go
    • Implement service bootstrap pattern
    • Integrate with Consul service registry
  2. Implement Dependency Resolution

    • Create internal/service/deps.go
    • Check service dependencies via Consul
    • Wait for services to be healthy
  3. Create Service Bootstrap

    • Create internal/service/bootstrap.go
    • Common bootstrap pattern
    • FX lifecycle integration
  4. Create Service Template

    • Service template generator
    • Example service entry point
  5. 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

Files to Create/Modify

  • internal/service/init.go - Service initialization helpers
  • internal/service/deps.go - Service dependency resolution
  • internal/service/bootstrap.go - Service bootstrap pattern
  • internal/service/template.go - Service template generator
  • Example: cmd/blog-service/main.go - Example service entry point