2.3 KiB
2.3 KiB
Phase 2: Remove Multi-Tenant Architecture
Agent Assignment
Primary Agent: backend-agent Duration: 20 minutes
Prerequisites
- Phase 4 (Config Cleanup) must be complete
- Backend container accessible
Objectives
- Delete all tenant-related code files
- Remove tenant middleware from application
- Remove tenant context from features
- Simplify JWT claims to user-only
Step-by-Step Instructions
Step 1: Delete Tenant Files
# Delete tenant middleware
rm backend/src/core/middleware/tenant.ts
# Delete tenant configuration
rm backend/src/core/config/tenant.ts
# Delete tenant-management feature
rm -rf backend/src/features/tenant-management/
Step 2: Update backend/src/app.ts
Remove tenant imports and registration:
// REMOVE these lines:
import { tenantMiddleware } from './core/middleware/tenant';
fastify.register(tenantMiddleware);
fastify.register(tenantManagementRoutes, { prefix: '/api/tenant-management' });
Step 3: Update backend/src/core/plugins/auth.plugin.ts
Simplify JWT payload extraction:
// REMOVE tenant claim extraction:
// const tenantId = request.user?.['https://motovaultpro.com/tenant_id'];
// KEEP only:
request.user = {
sub: payload.sub, // user ID
roles: payload['https://motovaultpro.com/roles'] || []
};
Step 4: Verify No Tenant References in Features
cd backend/src/features
grep -r "tenant_id" .
grep -r "tenantId" .
# Expected: 0 results
Step 5: Rebuild Backend
cd backend
npm run build
# Expected: No errors
Step 6: Update Tests
# Remove tenant-management tests
rm -rf backend/src/features/tenant-management/tests/
# Update other test files
grep -r "tenant" backend/src/features/*/tests/
# Fix any remaining references
Validation Criteria
- backend/src/core/middleware/tenant.ts deleted
- backend/src/core/config/tenant.ts deleted
- backend/src/features/tenant-management/ deleted
- No tenant imports in app.ts
- JWT only extracts sub and roles
- Backend builds successfully
- No tenant_id references in features
Validation Command:
npm run build && grep -r "tenant_id" backend/src/features/ | wc -l
# Expected: 0
Update EXECUTION-STATE.json
{
"phases": {"2": {"status": "completed", "validation_passed": true}}
}