# Implementation Plan

- [x] 1. Audit and analyze current codebase configuration issues
  - Identify all environment files and their conflicts
  - Document current local dependencies (storage and database)
  - Analyze upload error patterns from logs
  - Map current deployment artifacts and scripts
  - _Requirements: 1.1, 1.2, 1.3, 1.4_

- [x] 2. Remove redundant and conflicting configuration files
  - Delete duplicate .env files (.env.backup, .env.backup.hybrid, .env.development, .env.document-ai-template)
  - Consolidate environment variables into single .env.example and production configs
  - Remove local PostgreSQL configuration references from env.ts
  - Update config validation schema to require only cloud services
  - _Requirements: 1.1, 4.1, 4.2_

- [x] 3. Implement Google Cloud Storage service integration
  - Create / confirm GCS-only file storage service replacing current local storage
  - Implement GCS bucket operations (upload, download, delete, list)
  - Add proper error handling and retry logic for GCS operations
  - Configure GCS authentication using service account
  - _Requirements: 2.1, 2.2, 4.3_

- [ ] 4. Migrate existing files from local storage to GCS
  - Create migration script to upload all files from backend/uploads to GCS
  - Update database file_path references to use GCS URLs instead of local paths
  - Verify file integrity after migration
  - Create backup of local files before cleanup
  - _Requirements: 2.1, 2.2_

- [x] 5. Update file storage service to use GCS exclusively
  - Replace fileStorageService.ts to use only Google Cloud Storage
  - Remove all local file system operations (fs.readFileSync, fs.writeFileSync, etc.)
  - Update upload middleware to work with GCS temporary URLs
  - Remove local upload directory creation and management
  - _Requirements: 2.1, 2.2, 2.3_

- [x] 6. Fix document upload route UUID validation errors
  - Analyze and fix invalid UUID errors in document routes
  - Add proper UUID validation middleware for document ID parameters
  - Improve error messages for invalid document ID requests
  - Add request correlation IDs for better error tracking
  - _Requirements: 2.2, 3.1, 3.2, 3.3_

- [x] 7. Remove all local storage dependencies and cleanup
  - Delete backend/uploads directory and all local file references
  - Remove local storage configuration from env.ts and related files
  - Update upload middleware to remove local file system operations
  - Remove cleanup functions for local files
  - _Requirements: 2.1, 2.4_

- [x] 8. Standardize deployment configurations for cloud-only architecture
  - Update Firebase deployment configurations for both frontend and backend
  - Remove any local deployment scripts and references
  - Standardize Cloud Run deployment configuration
  - Update package.json scripts to remove local development dependencies
  - _Requirements: 1.1, 1.4, 4.1_

- [x] 9. Enhance error logging and monitoring for upload pipeline
  - Add structured logging with correlation IDs throughout upload process
  - Implement better error categorization and reporting
  - Add monitoring for upload success/failure rates
  - Create error dashboards for upload pipeline debugging
  - _Requirements: 3.1, 3.2, 3.3_

- [x] 10. Update frontend to handle GCS-based file operations
  - Update DocumentUpload component to work with GCS URLs
  - Modify file progress monitoring to work with cloud storage
  - Update error handling for GCS-specific errors
  - Test upload functionality with new GCS backend
  - _Requirements: 2.1, 2.2, 3.4_

- [x] 11. Create comprehensive tests for cloud-only architecture
  - Write unit tests for GCS file storage service
  - Create integration tests for complete upload pipeline
  - Add tests for error scenarios and recovery
  - Test deployment configurations in staging environment
  - _Requirements: 1.4, 2.1, 2.2, 2.3_

- [x] 12. Validate and test complete system functionality
  - Perform end-to-end testing of document upload and processing
  - Validate all environment configurations work correctly
  - Test error handling and user feedback mechanisms
  - Verify no local dependencies remain in the system
  - _Requirements: 1.1, 1.2, 1.4, 2.1, 2.2, 2.3, 2.4_