P0 Critical Workflows - Implementation Plan
Date: December 26, 2025 Status: Ready for Implementation Total P0 Workflows: 15 Estimated Effort: 168 hours (4.2 weeks with 2 engineers)
Executive Summary
This plan outlines the implementation strategy for 15 P0 (Critical) H.P.006-WORKFLOWS required for CODITECT Pilot Launch. These H.P.006-WORKFLOWS are essential for production readiness and must be completed before public launch.
Implementation Phases:
- Phase 1A: User Authentication (2 H.P.006-WORKFLOWS, 14 hours) - Week 1
- Phase 1B: Billing Operations (4 H.P.006-WORKFLOWS, 40 hours) - Week 1-2
- Phase 1C: Workstation Management (5 H.P.006-WORKFLOWS, 64 hours) - Week 2-3
- Phase 1D: Security & Operations (4 H.P.006-WORKFLOWS, 50 hours) - Week 3-4
Phase 1A: User Authentication (Week 1)
WF-009: Email Verification Flow
Priority: P0 | Effort: 8 hours | Dependencies: WF-001
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-009-email-verification.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-009-email-verification.md
Nodes (8):
- Webhook Trigger (GET
/verify-email?token=xxx) - Validate Token (PostgreSQL SELECT)
- Check Expiration (< 24 hours)
- Update User (SET email_verified = TRUE)
- Generate Access Token (JWT)
- Send Confirmation Email
- Publish Event (Pub/Sub:
user.verified) - Redirect to Dashboard
Success Criteria:
- ✅ Token validation < 500ms
- ✅ Email sent within 60 seconds
- ✅ 99.9% success rate
WF-010: Password Reset Flow
Priority: P0 | Effort: 6 hours | Dependencies: None
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-010-password-reset.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-010-password-reset.md
Nodes (9):
- Webhook Trigger (POST
/reset-password) - Validate Email (PostgreSQL SELECT)
- Generate Reset Token (UUID)
- Store Token (PostgreSQL INSERT, expires 1 hour)
- Send Reset Email (with link)
- Token Validation Endpoint (GET
/reset?token=xxx) - Update Password (Firebase Auth)
- Invalidate Token
- Send Confirmation Email
Success Criteria:
- ✅ Token expires after 1 hour
- ✅ Password strength validation
- ✅ Audit log created
Phase 1B: Billing Operations (Week 1-2)
WF-021: Subscription Upgrade
Priority: P0 | Effort: 12 hours | Dependencies: WF-002, WF-006
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-021-subscription-upgrade.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-021-subscription-upgrade.md
Nodes (11):
- Webhook Trigger (POST
/upgrade-subscription) - Get Current Subscription (Stripe API)
- Calculate Prorated Amount
- Create Stripe Invoice Item
- Update Subscription (Stripe)
- Process Payment
- Update Database (PostgreSQL)
- Trigger Workstation Resize (Pub/Sub)
- Send Upgrade Confirmation Email
- Log Billing Event
- Return Success Response
Success Criteria:
- ✅ Proration calculated correctly
- ✅ Immediate tier upgrade
- ✅ Workstation resources increased
WF-023: Subscription Cancellation
Priority: P0 | Effort: 10 hours | Dependencies: WF-007
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-023-subscription-cancellation.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-023-subscription-cancellation.md
Nodes (12):
- Webhook Trigger (POST
/cancel-subscription) - Show Retention Offer (discount modal)
- Capture Cancellation Reason
- Schedule Cancellation (end of billing period)
- Update Stripe Subscription (cancel_at_period_end)
- Update Database Status
- Send Cancellation Email
- Create Follow-up Task (check in 30 days)
- Preserve Data (flag for 90 days)
- Notify Admin (Email)
- Track Churn Metric (Analytics)
- Return Confirmation
Success Criteria:
- ✅ Access until period end
- ✅ Data retained 90 days
- ✅ Winback email sent
WF-024: Payment Method Update
Priority: P0 | Effort: 8 hours | Dependencies: WF-006
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-024-payment-method-update.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-024-payment-method-update.md
Nodes (9):
- Webhook Trigger (POST
/update-payment-method) - Create Stripe SetupIntent
- Return Client Secret
- Client Confirms (Stripe Elements)
- Webhook:
setup_intent.succeeded - Attach Payment Method to Customer
- Set as Default
- Retry Failed Invoices (if any)
- Send Confirmation Email
Success Criteria:
- ✅ PCI DSS compliant (no card data touches server)
- ✅ Auto-retry past-due invoices
- ✅ $1 auth verification
WF-025: Failed Payment Retry & Grace Period
Priority: P0 | Effort: 10 hours | Dependencies: WF-007
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-025-payment-failure-recovery.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-025-payment-failure-recovery.md
Nodes (14):
- Webhook Trigger (Stripe:
invoice.payment_failed) - Increment Retry Count
- Update Subscription Status (
past_due) - Wait 3 Days → Retry Payment
- If Failed → Wait 5 Days → Retry
- If Failed → Wait 7 Days → Final Retry
- Send Dunning Emails (3 tiers)
- If 3 Failures → Suspend Service
- Update Database (
subscription_status = suspended) - Send Final Notice Email
- Schedule Offboarding (30 days)
- Notify Admin (high-value customers)
- Track Recovery Metrics
- Log All Attempts
Success Criteria:
- ✅ 3 retry attempts (Smart Retries)
- ✅ 40% recovery rate
- ✅ Grace period 14 days total
Phase 1C: Workstation Management (Week 2-3)
WF-031: Workstation Start (from Stopped)
Priority: P0 | Effort: 10 hours | Dependencies: WF-003
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-031-workstation-start.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-031-workstation-start.md
Nodes (10):
- Webhook Trigger (POST
/workstation/start) - Validate User Has Access
- Check Subscription Active
- Get Workstation Config (PostgreSQL)
- Start Workstation (GCP API)
- Poll Status (every 5s, max 2 min)
- Update Database Status (
running) - Generate Access URL (signed)
- Send "Workstation Ready" Notification
- Return Access URL
Success Criteria:
- ✅ Start time < 90 seconds
- ✅ 99.5% success rate
- ✅ Access URL valid 8 hours
WF-032: Workstation Stop (Manual)
Priority: P0 | Effort: 8 hours | Dependencies: WF-003
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-032-workstation-stop.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-032-workstation-stop.md
Nodes (8):
- Webhook Trigger (POST
/workstation/stop) - Validate User Has Access
- Check for Unsaved Work (optional warning)
- Stop Workstation (GCP API)
- Poll Status (every 5s, max 1 min)
- Update Database Status (
stopped) - Log Stop Event (with reason)
- Return Success
Success Criteria:
- ✅ Graceful shutdown
- ✅ Data persistence verified
- ✅ Cost savings logged
WF-037: Workstation Deletion
Priority: P0 | Effort: 12 hours | Dependencies: WF-032
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-037-workstation-deletion.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-037-workstation-deletion.md
Nodes (13):
- Webhook Trigger (DELETE
/workstation/{id}) - Validate Admin Permission
- Check Workstation Stopped (if not, stop first)
- Create Final Backup (GCS snapshot)
- Verify Backup Complete
- Delete Persistent Disk (GCP API)
- Delete Workstation Config (GCP API)
- Update Database (
status = deleted) - Archive Metadata (keep 90 days)
- Send Deletion Confirmation Email
- Publish Event (Pub/Sub:
workstation.deleted) - Log Deletion (audit trail)
- Return Success
Success Criteria:
- ✅ Final backup created
- ✅ All resources deleted
- ✅ Metadata archived 90 days
WF-038: Workstation Access URL Generation
Priority: P0 | Effort: 8 hours | Dependencies: WF-003
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-038-workstation-access-url.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-038-workstation-access-url.md
Nodes (7):
- Webhook Trigger (GET
/workstation/{id}/access-url) - Validate User Has Access (RBAC)
- Check Workstation Running
- Get Workstation Details (PostgreSQL)
- Generate Signed URL (GCP IAM, TTL 8 hours)
- Log Access Attempt (audit)
- Return Access URL
Success Criteria:
- ✅ URL generation < 200ms
- ✅ Signed URLs expire 8 hours
- ✅ Access logged for compliance
WF-039: Workstation Idle Detection & Warning
Priority: P0 | Effort: 16 hours | Dependencies: WF-003, WF-032
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-039-idle-detection.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-039-idle-detection.md
Nodes (12):
- Scheduled Trigger (every 30 minutes)
- Query Running Workstations (PostgreSQL)
- Get CPU/Network Metrics (GCP Monitoring, last 2 hours)
- Calculate Idle Score (CPU < 5%, Network < 1MB)
- If Idle > 2 hours → Send Warning Notification
- Wait 30 Minutes for Response
- If No Activity → Stop Workstation (WF-032)
- Send "Workstation Stopped" Email
- Update Database
- Log Idle Event
- Track Cost Savings (Analytics)
- Return Summary Report
Success Criteria:
- ✅ Detect idle within 30 min
- ✅ 30 min warning before auto-stop
- ✅ 20-30% cost reduction
Phase 1D: Security & Operations (Week 3-4)
WF-054: GDPR Data Export (User Request)
Priority: P0 | Effort: 14 hours | Dependencies: WF-007 (existing)
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-054-gdpr-data-export.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-054-gdpr-data-export.md
Nodes (13):
- Webhook Trigger (POST
/gdpr/export) - Validate User Identity (2FA required)
- Create Export Job (PostgreSQL)
- Query User Data (users, orgs, workstations)
- Query Activity Logs (last 12 months)
- Query Billing History
- Compile JSON Export
- Encrypt Export (AES-256)
- Upload to GCS (user-specific bucket, 30-day TTL)
- Generate Signed Download URL
- Send Export Ready Email
- Log GDPR Request (audit)
- Return Download Link
Success Criteria:
- ✅ Export within 48 hours (GDPR compliance)
- ✅ Encrypted at rest and in transit
- ✅ Auto-delete after 30 days
WF-055: Security Incident Detection & Alert
Priority: P0 | Effort: 18 hours | Dependencies: None
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-055-security-incident-detection.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-055-security-incident-detection.md
Nodes (15):
- Pub/Sub Trigger (Topic:
security-events) - Parse Event Type (login anomaly, API abuse, etc.)
- Check Severity (Low, Medium, High, Critical)
- If Critical → Lock Account Immediately
- If High → Challenge with 2FA
- Query Recent Activity (last 24 hours)
- Calculate Threat Score (ML model)
- Create Incident Record (PostgreSQL)
- Send Alert Email to User
- Send Alert to Security Team (Email/PagerDuty)
- Log Security Event (immutable audit log)
- If Automated Response → Execute (block IP, etc.)
- Track Incident Metrics
- Update Security Dashboard
- Return Incident ID
Success Criteria:
- ✅ Detection within 1 minute
- ✅ Alert sent < 5 seconds
- ✅ Auto-remediation for known threats
WF-066: Incident Response & Communication
Priority: P0 | Effort: 10 hours | Dependencies: WF-055
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-066-incident-response.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-066-incident-response.md
Nodes (11):
- Webhook Trigger (POST
/incident/{id}/update) - Validate Admin Access
- Update Incident Status (PostgreSQL)
- Assess Impact (affected users, workstations)
- Create Status Page Update
- Send Email to Affected Users
- Post to Status Page (status.coditect.ai)
- Send Internal Alert (Email to ops team)
- Track Resolution Time (SLA)
- When Resolved → Post-mortem Created
- Return Updated Status
Success Criteria:
- ✅ First response < 15 minutes
- ✅ Status page updated < 5 min
- ✅ Post-mortem within 48 hours
WF-072: Database Backup & Point-in-Time Recovery
Priority: P0 | Effort: 8 hours | Dependencies: None
n8n Workflow: /H.P.006-WORKFLOWS/n8n/WF-072-database-backup.json
Narrative: /H.P.006-WORKFLOWS/narratives/WF-072-database-backup.md
Nodes (10):
- Scheduled Trigger (daily 2am UTC)
- Create PostgreSQL Snapshot (GCP Cloud SQL)
- Verify Snapshot Success
- Tag Snapshot (date, retention policy)
- Test Restore (random snapshot weekly)
- Delete Old Snapshots (> 30 days)
- Upload Backup Logs to GCS
- Send Backup Report Email (to ops team)
- Update Backup Dashboard (Grafana)
- Return Backup Summary
Success Criteria:
- ✅ Daily backups at 2am UTC
- ✅ 30-day retention
- ✅ Weekly restore test
- ✅ RPO < 24 hours, RTO < 4 hours
Implementation Schedule
Week 1: Authentication & Billing Foundations
Target: WF-009, WF-010, WF-021
- Day 1-2: Email Verification (WF-009)
- Day 3: Password Reset (WF-010)
- Day 4-5: Subscription Upgrade (WF-021)
Deliverables: 3 n8n JSONs, 3 narratives, testing complete
Week 2: Billing Operations & Workstation Start
Target: WF-023, WF-024, WF-025, WF-031, WF-032
- Day 1-2: Subscription Cancellation (WF-023)
- Day 2-3: Payment Method Update (WF-024)
- Day 3-4: Payment Retry (WF-025)
- Day 5: Workstation Start (WF-031)
- Day 5: Workstation Stop (WF-032)
Deliverables: 5 n8n JSONs, 5 narratives, integration testing
Week 3: Workstation Management & Security
Target: WF-037, WF-038, WF-039, WF-054
- Day 1-2: Workstation Deletion (WF-037)
- Day 2: Access URL Generation (WF-038)
- Day 3-4: Idle Detection (WF-039)
- Day 5: GDPR Export (WF-054)
Deliverables: 4 n8n JSONs, 4 narratives, security audit
Week 4: Security & Operations
Target: WF-055, WF-066, WF-072
- Day 1-3: Security Incident Detection (WF-055)
- Day 3-4: Incident Response (WF-066)
- Day 5: Database Backup (WF-072)
Deliverables: 3 n8n JSONs, 3 narratives, disaster recovery test
Success Metrics
| Metric | Target | Measurement |
|---|---|---|
| Implementation Completion | 100% of P0 H.P.006-WORKFLOWS | 15/15 H.P.006-WORKFLOWS live |
| Code Coverage | 80%+ | Unit + integration tests |
| Performance | P95 latency < 3s | New Relic monitoring |
| Reliability | 99.9% success rate | Error rate < 0.1% |
| Security | Zero breaches | Security audit pass |
Resource Requirements
| Resource | Quantity | Role |
|---|---|---|
| Backend Engineers | 2 | n8n workflow development, API integration |
| QA Engineers | 1 | Test automation, integration testing |
| DevOps Engineer | 0.5 | n8n deployment, monitoring setup |
| Product Manager | 0.5 | Requirements, acceptance criteria |
Total Effort: 168 hours Timeline: 4 weeks Cost: ~$25,000 (fully loaded cost)
Risk Mitigation
| Risk | Impact | Mitigation |
|---|---|---|
| Stripe API changes | High | Version pinning, webhook testing |
| GCP quota limits | Medium | Request increase proactively |
| Database migration issues | High | Blue-green deployment, rollback plan |
| Security vulnerabilities | Critical | Penetration testing, code review |
| Performance degradation | Medium | Load testing, auto-scaling |
Next Steps
- ✅ Review & Approve this implementation plan
- ⏸️ Assign H.P.006-WORKFLOWS to engineering team
- ⏸️ Setup n8n production environment
- ⏸️ Configure Stripe webhook endpoints
- ⏸️ Begin Week 1 implementation (WF-009, WF-010, WF-021)
Plan Status: ✅ Ready for Implementation Approval Required: Product, Engineering, Security Start Date: TBD Target Completion: 4 weeks from start