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
This commit is contained in:
2025-11-06 08:47:27 +01:00
parent cab7cadf9e
commit 38a251968c
47 changed files with 3190 additions and 1613 deletions

View File

@@ -10,40 +10,42 @@
- **Dependencies**: 1.1, 1.3, 1.4
## Goal
Create a production-ready HTTP server with comprehensive middleware for security, observability, and error handling.
Create HTTP and gRPC server foundation that services can use. Each service will have its own server instance.
## Description
This story implements a complete HTTP server using Gin with a comprehensive middleware stack including request ID generation, structured logging, panic recovery, metrics collection, CORS, and graceful shutdown.
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 (`internal/server/server.go`)
- Gin router initialization
### 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. Comprehensive Middleware Stack
### 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
- **CORS Support**: Configurable CORS headers (for HTTP)
- **Request Timeout**: Handle request timeouts
- **Response Compression**: Gzip compression for responses
### 3. Core Route Registration
- `GET /healthz` - Liveness probe
- `GET /ready` - Readiness probe
- `GET /metrics` - Prometheus metrics
- **Response Compression**: Gzip compression for responses (HTTP)
### 4. FX Lifecycle Integration
- HTTP server starts on `OnStart` hook
- Graceful shutdown on `OnStop` hook (drains connections)
- Server lifecycle management helpers
- Graceful shutdown support
- Port configuration from config system
- Reusable by services
### 5. Integration
- Integration with main application entry point
- Integration with all middleware systems
**Note:** Services will use these foundations to create their own server instances in Epic 2.
## Implementation Steps
@@ -80,15 +82,15 @@ This story implements a complete HTTP server using Gin with a comprehensive midd
- Test graceful shutdown
## Acceptance Criteria
- [x] HTTP server starts successfully
- [x] HTTP server foundation is reusable by services
- [x] gRPC server foundation is reusable by services
- [x] All middleware executes in correct order
- [x] Request IDs are generated and logged
- [x] Metrics are collected for all requests
- [x] Panics are recovered and handled
- [x] Graceful shutdown works correctly
- [x] Server is configurable via config system
- [x] CORS is configurable per environment
- [x] All core endpoints work correctly
- [x] Servers are configurable via config system
- [x] Services can create their own server instances using these foundations
## Related ADRs
- [ADR-0006: HTTP Framework](../../adr/0006-http-framework.md)
@@ -115,8 +117,10 @@ curl http://localhost:8080/metrics
```
## Files to Create/Modify
- `internal/server/server.go` - HTTP server
- `internal/server/middleware.go` - Middleware functions
- `internal/di/providers.go` - Add server provider
- `internal/server/http.go` - HTTP server foundation
- `internal/server/grpc.go` - gRPC server foundation
- `internal/server/middleware.go` - Common middleware functions
- `config/default.yaml` - Add server configuration
**Note:** Services will create their own server instances using these foundations in Epic 2.