Categories
Implementation Specs (157)
- specs/AnomalyDetection/TASK1.1.md
- specs/AnomalyDetection/TASK1.2.md
- specs/AnomalyDetection/TASK1.3.md
- specs/AnomalyDetection/TASK1.4.md
- specs/AnomalyDetection/TASK2.1.md
- specs/AnomalyDetection/TASK2.2.md
- specs/AnomalyDetection/TASK3.1.md
- specs/AnomalyDetection/TASK3.2.md
- specs/AnomalyDetection/TASK3.3.md
- specs/AnomalyDetection/TASK4.1.md
- specs/AnomalyDetection/TASK4.2.md
- specs/AnomalyDetection/TASK4.3.md
- specs/AnomalyDetection/TASK4.4.md
- specs/AnomalyDetection/TASK5.1.md
- specs/AnomalyDetection/TASK5.2.md
- specs/AnomalyDetection/TASK5.3.md
- specs/AnomalyDetection/TASK6.1.md
- specs/AnomalyDetection/TASK6.2.md
- specs/AnomalyDetection/TASK6.3.md
- specs/AnomalyDetection/TASKS.md
- specs/ApiServicePostgresTestStability/TASK.md
- specs/BackendDatabaseConsolidation/TASK.md
- specs/BackendDatabaseConsolidation/TASK1.1.md
- specs/BackendDatabaseConsolidation/TASK1.2.md
- specs/BackendDatabaseConsolidation/TASK1.3.md
- specs/BackendDatabaseConsolidation/TASK2.1.md
- specs/BackendDatabaseConsolidation/TASK2.2.md
- specs/BackendDatabaseConsolidation/TASK2.3.md
- specs/BackendDatabaseConsolidation/TASK3.1.md
- specs/BackendDatabaseConsolidation/TASK3.2.md
- specs/BackendDatabaseConsolidation/TASK4.1.md
- specs/BackendDatabaseConsolidation/TASK4.2.md
- specs/BackendDatabaseConsolidation/TASK4.3.md
- specs/BackendDatabaseConsolidation/TASK5.1.md
- specs/BackendDatabaseConsolidation/TASK5.2.md
- specs/BrinkLaborGetShiftsStaging/TASK.md
- specs/BrinkPosOrdersFirstEtlJob/TASK.md
- specs/BrinkPosOrdersFirstEtlJob/TASK0.md
- specs/BrinkPosOrdersFirstEtlJob/TASK1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.md
- specs/BrinkPosOrdersFirstEtlJob/TASK7.md
- specs/BrinkPosOrdersFirstEtlJob/TASK8.md
- specs/BrinkPosOrdersFirstEtlJob/TASK9.md
- specs/BrinkSettings2ToStaging/TASK.MD
- specs/CuratedToS3Stage/TASK.md
- specs/CuratedToS3Stage/TASK0.md
- specs/CuratedToS3Stage/TASK1.md
- specs/CuratedToS3Stage/TASK2.md
- specs/CuratedToS3Stage/TASK3.md
- specs/CuratedToS3Stage/TASK4.md
- specs/CustomerCredentialCustomHeaders/TASK.md
- specs/CustomerCredentialCustomHeaders/TASK1.1.md
- specs/CustomerCredentialCustomHeaders/TASK1.2.md
- specs/CustomerCredentialCustomHeaders/TASK2.1.md
- specs/CustomerCredentialCustomHeaders/TASK2.2.md
- specs/CustomerCredentialCustomHeaders/TASK3.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK.md
- specs/CustomerCredentialTriggeredProvisioning/TASK1.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK1.2.md
- specs/CustomerCredentialTriggeredProvisioning/TASK2.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK2.2.md
- specs/CustomerCredentialTriggeredProvisioning/TASK3.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK3.2.md
- specs/CustomerCredentialTriggeredProvisioning/TASK4.1.md
- specs/EtlSourceAdapterFramework/TASK.md
- specs/EtlSourceAdapterFramework/TASK0.md
- specs/EtlSourceAdapterFramework/TASK1.md
- specs/EtlSourceAdapterFramework/TASK2.md
- specs/EtlSourceAdapterFramework/TASK3.md
- specs/EtlSourceAdapterFramework/TASK4.md
- specs/EtlSourceAdapterFramework/TASK5.md
- specs/EtlSourceAdapterFramework/TASK6.md
- specs/KdsCdcDebeziumIntegration/TASK.md
- specs/KdsCdcDebeziumIntegration/TASK1.md
- specs/KdsCdcDebeziumIntegration/TASK2.md
- specs/KdsCdcDebeziumIntegration/TASK3.md
- specs/KdsCdcDebeziumIntegration/TASK4.md
- specs/KdsCdcDebeziumIntegration/TASK5.md
- specs/KdsCdcDurableRelationRouting/TASK.md
- specs/KdsCdcDurableRelationRouting/TASK1.md
- specs/KdsCdcDurableRelationRouting/TASK2.md
- specs/KdsCdcDurableRelationRouting/TASK3.md
- specs/KdsCdcDurableRelationRouting/TASK4.md
- specs/KdsCdcDurableRelationRouting/TASK5.md
- specs/KdsCdcIngestion/TASK.md
- specs/KdsCdcIngestion/TASK1.md
- specs/KdsCdcIngestion/TASK2.md
- specs/KdsCdcIngestion/TASK3.md
- specs/KdsCdcIngestion/TASK4.md
- specs/KdsCdcIngestion/TASK5.md
- specs/KdsCdcIngestion/TASK6.md
- specs/KdsCdcIngestion/TASK7.md
- specs/KdsCdcIngestion/TASK8.md
- specs/KdsCdcIngestion/TASK9.md
- specs/KdsCdcReplayExecution/TASK.md
- specs/KdsCdcReplayExecution/TASK1.md
- specs/KdsCdcReplayExecution/TASK2.md
- specs/KdsCdcReplayExecution/TASK3.md
- specs/KdsCdcReplayExecution/TASK4.md
- specs/KdsMonitorServingContractMigration/TASK.md
- specs/KdsMonitorServingContractMigration/TASK1.1.md
- specs/KdsMonitorServingContractMigration/TASK1.2.md
- specs/KdsMonitorServingContractMigration/TASK2.1.md
- specs/KdsMonitorServingContractMigration/TASK2.2.md
- specs/KdsMonitorServingContractMigration/TASK3.1.md
- specs/KdsMonitorServingContractMigration/TASK3.2.md
- specs/RedshiftFoundation/TASK.md
- specs/RedshiftFoundation/TASK1.1.md
- specs/RedshiftFoundation/TASK1.2.md
- specs/RedshiftFoundation/TASK1.3.md
- specs/RedshiftFoundation/TASK1.4.md
- specs/RedshiftFoundation/TASK2.1.md
- specs/RedshiftFoundation/TASK2.2.md
- specs/RedshiftFoundation/TASK3.1.md
- specs/RedshiftFoundation/TASK3.2.md
- specs/RedshiftFoundation/TASK3.3.md
- specs/RedshiftSyntheticDataFeed/TASK.md
- specs/RedshiftSyntheticDataFeed/TASK1.1.md
- specs/RedshiftSyntheticDataFeed/TASK1.2.md
- specs/RedshiftSyntheticDataFeed/TASK1.3.md
- specs/RedshiftSyntheticDataFeed/TASK2.1.md
- specs/RedshiftSyntheticDataFeed/TASK2.2.md
- specs/RedshiftSyntheticDataFeed/TASK3.1.md
- specs/RedshiftSyntheticDataFeed/TASK3.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK1.1.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK1.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK2.1.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK2.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK2.3.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK3.1.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK3.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK4.1.md
Backend Database Consolidation - Implementation Tasks
Overview
Implementation of the backend database consolidation delivery slice.
This task plan is derived from analysis of the current repository state across:
backend/Kds.Ai.Databackend/Kds.Ai.ApiServicebackend/Kds.Ai.WarehouseDataModelFront/appFront/configFront/routesFront/database/migrations
This slice consolidates all application-owned persistence into the backend and converts the Laravel app into a stateless BFF with no database connection.
The slice outcome is:
- backend becomes the system of record for application data,
- Keycloak becomes the system of record for user identity and login,
- Laravel no longer owns users, customers, API keys, uploaded file metadata, or activity logs,
- Laravel no longer uses database-backed auth, sessions, cache, or queue configuration,
- backend document storage absorbs the current Laravel
uploaded_filesresponsibilities, - tenant resolution and authorization no longer depend on a front-end database lookup or a spoofable tenant header.
Source Documents
- repository analysis of
backend/andFront/performed during this planning session backend/Kds.Ai.Data/KdsAiDbContext.csbackend/Kds.Ai.Data/Entities/Document.csbackend/Kds.Ai.ApiService/Program.csbackend/Kds.Ai.ApiService/Tenancy/TenantMiddleware.csbackend/Kds.Ai.ApiService/Endpoints/DocumentEndpoints.csFront/app/Models/User.phpFront/app/Models/Customer.phpFront/app/Models/CustomerApiKey.phpFront/app/Models/UploadedFile.phpFront/app/Models/ActivityLog.phpFront/app/Http/Controllers/LoginController.phpFront/app/Http/Controllers/Admin/AdminAuthController.phpFront/app/Http/Controllers/Admin/AdminApiController.phpFront/app/Http/Controllers/Admin/UsersController.phpFront/app/Http/Controllers/FilesController.phpFront/app/Http/Controllers/DashboardController.phpFront/app/Services/AiApiService.phpFront/config/auth.phpFront/config/session.phpFront/config/cache.phpFront/config/queue.php
Spec Name
The canonical implementation spec should be referred to as Backend Database Consolidation.
Fixed Decisions
- Laravel must become a stateless BFF with no database connection.
- Laravel must not use database-backed sessions.
- Authentication and user identity move to Keycloak.
- Backend becomes the system of record for application-owned data.
- Existing local Laravel data does not need to be preserved because the system is not yet deployed to production.
- Laravel
uploaded_filesresponsibilities should be merged into backendDocumentownership instead of creating a separate long-term file metadata system. - The warehouse database used through
Kds.Ai.WarehouseDataModelremains separate and out of scope. - The current backend pattern of trusting
X-Tenant-Idwithout authentication is not acceptable after this migration.
Scope
This task includes:
- adding Keycloak-based authentication and authorization integration,
- replacing backend tenant resolution based on raw request headers with identity-backed tenant resolution,
- introducing backend entities and APIs for customer/tenant management,
- introducing backend entities and APIs for customer API key management,
- extending backend
Documentownership to cover current file metadata and dashboard use cases, - introducing backend audit logging if the current admin activity history remains required,
- refactoring Laravel controllers, middleware, views, and services to use backend APIs and Keycloak-backed identity only,
- removing Laravel reliance on local Eloquent models and local persistence,
- switching Laravel session, cache, and queue configuration away from database-backed providers,
- deleting obsolete Laravel persistence code after cutover.
In short, this slice ends when Laravel can run as a DB-free BFF in front of Keycloak and backend APIs, while backend owns all application persistence.
Out of Scope
The following items are explicitly excluded from this task:
- migrating or redesigning the warehouse read model in
backend/Kds.Ai.WarehouseDataModel, - preserving pre-production Laravel data,
- production infrastructure rollout for Keycloak,
- multi-region identity architecture,
- end-user self-service registration flows unless separately requested,
- redesign of anomaly detection, monitor runtime, or warehouse ETL behavior unrelated to tenant/auth consolidation.
Task Checklist
Phase 1: Identity and Tenant Resolution
- [x] TASK 1.1 - Define Keycloak integration and identity contract
- [x] TASK 1.2 - Add backend authentication, authorization, and tenant resolution
- [x] TASK 1.3 - Wire Aspire host for Keycloak-backed local app configuration
Phase 2: Backend Application Data Ownership
- [ ] TASK 2.1 - Add backend customer and tenant membership persistence
- [ ] TASK 2.2 - Add backend customer API key and audit log persistence
- [ ] TASK 2.3 - Merge Laravel uploaded file ownership into backend
Document
Phase 3: Backend API Surface
- [ ] TASK 3.1 - Add backend customer, API key, and document management endpoints
- [ ] TASK 3.2 - Add backend authenticated user context and admin user-management integration
Phase 4: Laravel BFF Refactor
- [ ] TASK 4.1 - Replace Laravel auth with Keycloak-backed BFF auth flow
- [ ] TASK 4.2 - Refactor Laravel pages, admin flows, and file flows to backend APIs only
- [ ] TASK 4.3 - Remove Laravel database-backed infrastructure and local persistence code
Phase 5: Validation and Cleanup
- [ ] TASK 5.1 - Validate end-to-end BFF, auth, and tenant enforcement behavior
- [ ] TASK 5.2 - Remove obsolete code paths and document final architecture
Dependency Graph
Phase 1 (Identity and Tenant Resolution)
|-- 1.1 Keycloak integration and identity contract
|-- 1.2 Backend authentication, authorization, and tenant resolution <-- (depends on 1.1)
+-- 1.3 Aspire host wiring for Keycloak-backed local configuration <-- (depends on 1.1)
Phase 2 (Backend Application Data Ownership) <-- depends on 1.2
|-- 2.1 Customer and tenant membership persistence
|-- 2.2 Customer API key and audit log persistence <-- (depends on 2.1)
+-- 2.3 Merge uploaded file ownership into backend Document <-- (depends on 2.1)
Phase 3 (Backend API Surface) <-- depends on Phase 2
|-- 3.1 Customer, API key, and document management endpoints
+-- 3.2 Authenticated user context and admin user-management integration <-- (depends on 1.1, 1.2, 2.1)
Phase 4 (Laravel BFF Refactor) <-- depends on Phase 3
|-- 4.1 Replace Laravel auth with Keycloak-backed BFF auth flow
|-- 4.2 Refactor pages, admin flows, and file flows to backend APIs only <-- (depends on 4.1, 3.1, 3.2)
+-- 4.3 Remove Laravel DB-backed infrastructure and local persistence code <-- (depends on 4.2)
Phase 5 (Validation and Cleanup) <-- depends on all
|-- 5.1 End-to-end validation
+-- 5.2 Cleanup and architecture documentationRecommended Session Order
| Session | Tasks | Description |
|---|---|---|
| 1 | 1.1, 1.2, 1.3 | Define Keycloak contract, secure backend identity/tenant enforcement, and wire local Aspire resources |
| 2 | 2.1, 2.2 | Add backend ownership for customers, membership, API keys, and audit logs |
| 3 | 2.3, 3.1 | Merge file metadata into Document and expose management APIs |
| 4 | 3.2, 4.1 | Add user context/admin integration and switch Laravel auth to Keycloak |
| 5 | 4.2, 4.3 | Refactor Laravel UI/BFF flows and remove all DB dependencies |
| 6 | 5.1, 5.2 | Validate full flow and remove obsolete code |
Key Design Decisions
Keycloak Owns Identity
The old Laravel users table should not be recreated as the long-term source of truth in backend.
Identity concerns belong in Keycloak:
- login,
- logout,
- credentials,
- user lifecycle,
- roles/claims.
Backend may still need app-owned user linkage data keyed by Keycloak subject when tenant membership or app-specific authorization cannot live entirely in token claims.
Backend Owns Application Data
The backend must own all application-level data previously stored in Laravel:
- customers,
- customer API keys,
- file/document metadata,
- activity/audit logs if retained,
- tenant membership or user-to-customer mapping if needed for authorization.
Tenant Resolution Must Be Identity-Backed
The current backend middleware trusts X-Tenant-Id from the caller. That is acceptable only for pre-auth local development and must not remain the production authorization mechanism.
After this migration, tenant scope must come from verified identity, either:
- directly from trusted Keycloak claims, or
- from backend-owned membership lookup keyed by the authenticated Keycloak subject.
Laravel Must Be DB-Free
Laravel should not keep a hidden residual database dependency through:
authprovider,- session storage,
- cache storage,
- queue storage,
- local admin CRUD,
- local file metadata.
This slice is complete only when Laravel can run without a configured database connection.
Merge UploadedFile Into Document
Backend Document already covers part of the current file metadata model. Extend it to serve the dashboard and document management UX instead of creating a parallel long-term file entity surface.
No Legacy Data Migration Required
Because the system is not yet deployed to production, the implementation can prefer clean replacement over compatibility layers, historical data migration, or temporary synchronization between Laravel and backend data stores.