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.8 KiB
3.8 KiB
Story 1.5: HTTP Server Foundation with Middleware Stack
Metadata
- Story ID: 1.5
- Title: HTTP Server Foundation with Middleware Stack
- Epic: 1 - Core Kernel & Infrastructure
- Status: Completed
- Priority: High
- Estimated Time: 6-8 hours
- Dependencies: 1.1, 1.3, 1.4
Goal
Create HTTP and gRPC server foundation that services can use. Each service will have its own server instance.
Description
This story implements HTTP and gRPC server foundations that services will use to create their own server instances. It includes common middleware, server lifecycle management, and integration with the DI container. Services (Auth, Identity, etc.) will use these foundations in Epic 2.
Deliverables
1. HTTP Server Foundation (internal/server/http.go)
- HTTP server helper functions
- Gin router initialization helper
- Server configuration (port, host, timeouts)
- Graceful shutdown handling
- Reusable by services
2. gRPC Server Foundation (internal/server/grpc.go)
- gRPC server initialization helper
- Interceptor support (logging, tracing, metrics)
- Server lifecycle management
- Reusable by services
3. Common Middleware Stack
- Request ID Generator: Unique ID per request
- Structured Logging: Log all requests with context
- Panic Recovery: Recover panics → error bus
- Prometheus Metrics: Collect request metrics
- CORS Support: Configurable CORS headers (for HTTP)
- Request Timeout: Handle request timeouts
- Response Compression: Gzip compression for responses (HTTP)
4. FX Lifecycle Integration
- Server lifecycle management helpers
- Graceful shutdown support
- Port configuration from config system
- Reusable by services
Note: Services will use these foundations to create their own server instances in Epic 2.
Implementation Steps
-
Install Dependencies
go get github.com/gin-gonic/gin -
Create HTTP Server
- Create
internal/server/server.go - Initialize Gin router
- Configure server settings
- Create
-
Implement Middleware
- Request ID middleware
- Logging middleware
- Panic recovery middleware
- Metrics middleware
- CORS middleware
- Timeout middleware
- Compression middleware
-
Register Core Routes
- Health endpoints
- Metrics endpoint
-
Integrate with FX
- Add lifecycle hooks
- Handle graceful shutdown
-
Test Server
- Verify server starts
- Test all endpoints
- Test graceful shutdown
Acceptance Criteria
- HTTP server foundation is reusable by services
- gRPC server foundation is reusable by services
- All middleware executes in correct order
- Request IDs are generated and logged
- Metrics are collected for all requests
- Panics are recovered and handled
- Graceful shutdown works correctly
- Servers are configurable via config system
- Services can create their own server instances using these foundations
Related ADRs
Implementation Notes
- Use Gin for HTTP routing
- Middleware order is important
- Support graceful shutdown with connection draining
- CORS should be configurable per environment
- Consider adding rate limiting in future (Epic 6)
Testing
# Test server startup
go run cmd/platform/main.go
# Test endpoints
curl http://localhost:8080/healthz
curl http://localhost:8080/ready
curl http://localhost:8080/metrics
# Test graceful shutdown
# Send SIGTERM and verify graceful shutdown
Files to Create/Modify
internal/server/http.go- HTTP server foundationinternal/server/grpc.go- gRPC server foundationinternal/server/middleware.go- Common middleware functionsconfig/default.yaml- Add server configuration
Note: Services will create their own server instances using these foundations in Epic 2.