Skip to main content

CV Upload and Processing Refactoring - Final Summary

Overview

This document summarizes the complete refactoring of the CV upload and processing flow to use a unified, production-ready WebSocket-based service. All legacy hooks have been replaced with a single, comprehensive solution.

Completed Refactoring

✅ Core Infrastructure

  1. Unified WebSocket Service (usePipeline)

    • Hardcoded production URLs (no environment variables)
    • Production: wss://pipeline.aiqlick.com
    • Development: ws://localhost:8000 (aligned with integration guide)
    • Smart reconnection with exponential backoff (max 5 attempts)
    • Support for all pipeline types: cv_extraction, cv_processing, job_parsing, matching
  2. Unified CV Processor (useCvProcessor)

    • Single hook for all CV upload and processing needs
    • MinIO upload flow with presigned URLs
    • WebSocket-based processing (no GraphQL dependencies for processing)
    • Support for both temporary extraction and persistent processing
    • Comprehensive error handling and progress tracking

✅ Reusable Components

  1. ConnectionStatus Component

    • Real-time WebSocket connection indicator
    • Used across all CV processing UIs
  2. ProcessingIndicator Component

    • Progress tracking and status display
    • Upload progress bars and processing states

✅ UI Integration Points Refactored

  1. Company Pipeline - Add Candidate

    • /app/company/pipeline/addCandidate/page.tsx
    • /app/company/candidates/candidateAdd.tsx
    • Uses unified hook with persistent processing
  2. Job Seeker Onboarding

    • /app/onboarding/jobseeker/steps/UploadCvStep.tsx
    • Uses unified hook with temporary extraction
  3. CV Demo/Extractor

    • /components/cv/CVExtractor.tsx
    • Updated for testing and demonstration

✅ Legacy Code Status

Deprecated Hooks (still available for backward compatibility):

  • useCvUploadAndParse.ts - GraphQL-based, deprecated — prefer useCvProcessor for new code
  • useCvManager.ts - GraphQL-based, deprecated — prefer useCvProcessor for new code

Removed Hooks:

  • useCvExtraction.ts - Limited WebSocket, replaced
  • useCvUploadAndParseWebSocket.ts - Duplicate functionality, replaced

Mutation Status:

  • PARSE_CV mutation in graphql/operations/cv/mutations.ts — still available, used by legacy hooks

Files Status:

  • New code should use the unified WebSocket-based system (useCvProcessor)
  • Legacy GraphQL hooks remain available for existing callers

✅ Documentation

  1. CV_UNIFIED_WEBSOCKET_SERVICE.md - Comprehensive integration guide
  2. CV_REFACTORING_SUMMARY.md - This summary document
  3. Inline code documentation - Updated across all components

Technical Implementation Details

WebSocket Message Flow

// Hardcoded URLs - no env variables needed (aligned with integration guide)
const PIPELINE_URLS = {
production: 'wss://pipeline.aiqlick.com',
development: 'ws://localhost:8000'
};

// Message types supported (aligned with integration guide)
type PipelineType = 'cv_extraction' | 'cv_processing' | 'job_parsing' | 'matching';

MinIO Upload Pattern

All file uploads follow the same pattern:

  1. Generate presigned URL via GraphQL mutation
  2. Upload file to MinIO using presigned URL
  3. Send file path to WebSocket pipeline for processing
  4. Receive processed results via WebSocket

Processing Options

interface CvProcessingOptions {
companyId?: string; // Company context
persistent?: boolean; // false = cv_extraction, true = cv_processing
}

DRY Principles Applied

  1. Single Upload Logic - All file uploads use the same MinIO pattern
  2. Unified Error Handling - Consistent error states and messaging
  3. Reusable Components - Status indicators used across all flows
  4. Consolidated State Management - Single hook manages all processing states

Production Readiness Features

  1. Hardcoded URLs - No dependency on environment variables
  2. Auto-reconnection - WebSocket reconnects automatically on failure
  3. Progress Tracking - Real-time upload and processing progress
  4. Error Recovery - Graceful handling of all error scenarios
  5. Type Safety - Full TypeScript coverage with proper interfaces

Development Setup Requirements

Pipeline Service

For development testing, ensure the AIQlick pipeline service is running on:

ws://localhost:8000/ws/pipeline/{client_id}

If you see connection errors like:

WebSocket connection to 'ws://localhost:8000/ws/pipeline/...' failed: WebSocket is closed before the connection is established.

This means the pipeline service is not running. To resolve:

  1. Start the pipeline service on port 8000
  2. Or use production URLs by updating the getPipelineUrl() function in usePipeline.ts
  3. Or mock the service for UI development only

The system will automatically stop reconnection attempts after 5 failed tries to prevent infinite loops.

Quality Assurance

  1. Type Checking - All code is properly typed
  2. Error Handling - Comprehensive error scenarios covered
  3. User Experience - Progress indicators and status messages
  4. Code Consistency - DRY principles applied throughout

Migration Complete

All new code paths should use the unified WebSocket service. Legacy GraphQL-based hooks (useCvManager, useCvUploadAndParse) remain available for backward compatibility. The system is ready for production deployment with:

  • ✅ Hardcoded pipeline URLs
  • ✅ MinIO upload pattern compliance
  • ✅ WebSocket-based processing
  • ✅ DRY code architecture
  • ✅ Comprehensive error handling
  • ✅ Production-ready components
  • ✅ Complete documentation

Next Steps (Optional Enhancements)

While the refactoring is complete and production-ready, the following enhancements could be added in the future:

  1. Health Monitoring - Pipeline service health checks
  2. Message Filtering - Advanced WebSocket message routing
  3. Batch Processing - Multiple file processing capabilities
  4. Analytics Integration - Processing metrics and monitoring
  5. Caching Layer - Results caching for improved performance

Files Modified

Core Infrastructure

  • /lib/hooks/usePipeline.ts - WebSocket connection management
  • /lib/hooks/useCvProcessor.ts - Unified CV processing

Components

  • /components/cv/ConnectionStatus.tsx - Connection indicator
  • /components/cv/ProcessingIndicator.tsx - Progress display
  • /components/cv/CVExtractor.tsx - Demo component

UI Integration

  • /app/company/pipeline/addCandidate/page.tsx - Candidate addition
  • /app/company/candidates/candidateAdd.tsx - Candidate modal
  • /app/onboarding/jobseeker/steps/UploadCvStep.tsx - Onboarding flow

Documentation

  • /docs/CV_UNIFIED_WEBSOCKET_SERVICE.md - Integration guide
  • /docs/CV_REFACTORING_SUMMARY.md - This summary

Status: COMPLETE AND PRODUCTION READY