Files
motovaultpro/docs/redesign/PHASE-02-REMOVE-TENANT.md
Eric Gullickson 046c66fc7d Redesign
2025-11-01 21:27:42 -05:00

99 lines
2.3 KiB
Markdown

# 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
1. Delete all tenant-related code files
2. Remove tenant middleware from application
3. Remove tenant context from features
4. Simplify JWT claims to user-only
## Step-by-Step Instructions
### Step 1: Delete Tenant Files
```bash
# 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:
```typescript
// 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:
```typescript
// 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
```bash
cd backend/src/features
grep -r "tenant_id" .
grep -r "tenantId" .
# Expected: 0 results
```
### Step 5: Rebuild Backend
```bash
cd backend
npm run build
# Expected: No errors
```
### Step 6: Update Tests
```bash
# 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:**
```bash
npm run build && grep -r "tenant_id" backend/src/features/ | wc -l
# Expected: 0
```
## Update EXECUTION-STATE.json
```json
{
"phases": {"2": {"status": "completed", "validation_passed": true}}
}
```