Files
inbox-negotiator/APPWRITE_MIGRATION.md
2025-08-25 21:18:55 +00:00

5.2 KiB

Appwrite Migration Progress

Completed Migrations

1. Dependencies

  • Installed Appwrite SDK v16.0.2
  • Removed @supabase/supabase-js dependency
  • Updated package.json

2. Core Configuration

  • Created src/lib/appwrite.ts - Main client configuration
  • Created src/lib/appwrite-admin.ts - Server-side admin operations
  • Updated environment variables in .env.example

3. Authentication Components

  • src/components/AuthForm.tsx - Migrated to Appwrite Account API
  • src/components/AuthGuard.tsx - Updated session management
  • src/components/Navbar.tsx - Updated user state handling

4. Database Operations

  • src/components/Dashboard.tsx - Partially migrated database queries
  • src/pages/api/postmark.ts - Migrated webhook API to use Appwrite
  • src/components/DebtCard.tsx - Migrated debt operations and function calls
  • 🔄 src/components/Configuration.tsx - Partially migrated user data fetching

5. Function Calls

  • Updated function invocation from Supabase to Appwrite Functions API
  • Changed authentication headers from Bearer tokens to X-Appwrite-Project/X-Appwrite-Key

Required Appwrite Setup

Environment Variables

PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
PUBLIC_APPWRITE_PROJECT_ID=your_project_id
PUBLIC_APPWRITE_DATABASE_ID=your_database_id
APPWRITE_API_KEY=your_api_key

Auto-Deploy Functions Setup

1. Install Appwrite CLI

npm install -g appwrite-cli

2. Initialize Appwrite Project

pnpm run setup:appwrite
# or manually: appwrite init project --project-id your_project_id

3. Deploy Functions Automatically

# Deploy all functions to Appwrite
pnpm run deploy:functions

# Or run the script directly
./scripts/deploy-appwrite-functions.sh

4. GitHub Actions Auto-Deploy

The repository includes a GitHub Actions workflow (.github/workflows/deploy-appwrite-functions.yml) that automatically deploys functions when:

  • Changes are pushed to the main branch
  • Files in appwrite/functions/ or supabase/functions/ are modified
  • Manually triggered via workflow dispatch

Required GitHub Secrets:

  • APPWRITE_PROJECT_ID - Your Appwrite project ID
  • APPWRITE_API_KEY - Your Appwrite API key with Functions write permissions
  • APPWRITE_ENDPOINT - Your Appwrite endpoint (default: https://cloud.appwrite.io/v1)
  • GOOGLE_AI_API_KEY - For AI-powered functions
  • POSTMARK_SERVER_TOKEN - For email functions

Database Collections to Create

  1. debts - Main debt records
  2. audit_logs - Action logging
  3. user_profiles - User settings and preferences
  4. additional_emails - Secondary email addresses
  5. email_processing_usage - Monthly usage tracking
  6. debt_variables - Custom debt variables
  7. conversation_messages - Email conversation history
  8. users - User personal data

Functions to Migrate

  1. negotiate - AI debt negotiation logic
  2. approve-debt - Debt approval workflow
  3. send-email - Email sending functionality
  4. analyze-response - Email response analysis
  5. test-extraction - Debt information extraction testing

Remaining Tasks

Components Not Yet Migrated

  • src/components/ConversationTimeline.tsx
  • src/components/OnboardingDialog.tsx
  • src/components/ManualResponseDialog.tsx
  • src/components/DebtTimeline.tsx
  • src/components/RealtimeTestButton.tsx
  • src/components/ExtractionTester.tsx

Migration Notes

Authentication

  • Replaced supabase.auth.signUp() with account.create() + account.createEmailPasswordSession()
  • Replaced supabase.auth.signInWithPassword() with account.createEmailPasswordSession()
  • Replaced supabase.auth.getUser() with account.get()
  • Replaced supabase.auth.signOut() with account.deleteSession('current')

Database Operations

  • Replaced supabase.from().select() with databases.listDocuments()
  • Replaced supabase.from().insert() with databases.createDocument()
  • Replaced supabase.from().update() with databases.updateDocument()
  • Note: Appwrite queries use different syntax than Supabase filters

Function Calls

  • Replaced supabase.functions.invoke() with functions.createExecution()
  • Changed authentication from Authorization header to X-Appwrite-Project/X-Appwrite-Key headers

Real-time Updates

  • Supabase real-time subscriptions need to be replaced with Appwrite real-time
  • Currently using polling as a temporary fallback

Testing Required

  1. Authentication Flow

    • User registration
    • User login/logout
    • Session persistence
  2. Database Operations

    • Debt creation and updates
    • User profile management
    • Audit logging
  3. Function Execution

    • Email sending
    • AI negotiation
    • Response analysis
  4. API Endpoints

    • Postmark webhook processing
    • Email parsing and storage

Production Deployment Checklist

  1. Set up Appwrite project and database
  2. Create all required collections with proper schemas
  3. Deploy Appwrite Functions (migrated from Supabase Edge Functions)
  4. Configure environment variables
  5. Set up proper permissions and security rules
  6. Test all functionality end-to-end
  7. Migrate data from Supabase to Appwrite
  8. Update DNS/domain configuration if needed