feat(api): implement core API endpoints and business logic #96

Closed
forgejo_admin wants to merge 0 commits from feature/core-api-endpoints into feature/auth-google-oauth

Summary

This PR implements the complete core API endpoints and business logic for the AI Bulk Image Renamer SaaS, including batch processing, image management, keywords enhancement, and real-time progress tracking via WebSockets.

📡 Core API Endpoints Implemented

Batch Processing (§73-74)

POST /api/batch
// Multipart file upload with comprehensive validation
Response: { batch_id, accepted_count, skipped_count, status }

GET /api/batch/{batch_id}/status  
// Real-time status tracking with progress
Response: { state: 'PROCESSING'|'DONE'|'ERROR', progress: 0-100 }

Image Management (§75)

PUT /api/image/{image_id}/filename
// Update proposed filenames with validation
Body: { new_name: string }
Response: { id, proposed_name, updated_at }

GET /api/image/batch/{batch_id}
// List all images in batch with thumbnails
Response: { images: Image[], batch_info: Batch }

Keywords Enhancement (§76)

POST /api/keywords/enhance
// AI-powered keyword expansion and SEO optimization
Body: { keywords: string[], target_audience?: string }
Response: { enhanced_keywords: string[], related_keywords: string[] }

WebSocket Progress Streaming (§77)

WS /progress/{batch_id}
// Real-time progress events for batch processing
Events: { image_id, status, progress, timestamp }

🏗️ Supporting Infrastructure

File Upload & Storage (§26-32)

  • MIME Validation: Accepts .jpg, .jpeg, .png, .gif, .webp only
  • Quota Enforcement: Blocks uploads exceeding user limits (Basic: 50, Pro: 500, Max: 1000)
  • Deduplication: SHA-256 checksums prevent duplicate uploads
  • Object Storage: MinIO/S3 integration with UUID folder structure
  • Secure Processing: Presigned URLs and authenticated access

Background Processing

// BullMQ integration with Redis
class QueueService {
  async processImageBatch(batchId: string) {
    // Enqueue image processing jobs
    // Handle vision AI analysis
    // Generate filename suggestions
    // Update progress in real-time
  }
}

Real-time Updates

  • WebSocket Gateway: Socket.IO integration for live progress
  • Room Management: Batch-specific subscriptions
  • Event Broadcasting: Progress updates to connected clients
  • Connection Cleanup: Automatic cleanup on disconnect

🔧 Technical Architecture

Modular Design

packages/api/src/
├── storage/           # MinIO/S3 object storage
├── upload/            # File processing & validation  
├── queue/             # Background job processing
├── websocket/         # Real-time progress updates
├── batches/           # Batch management API
├── images/            # Image filename management
├── keywords/          # AI keyword enhancement
└── common/            # Shared utilities & middleware

Data Flow

  1. Upload: Files → Validation → Storage → Queue Jobs
  2. Processing: Background workers → Vision AI → Filename generation
  3. Progress: Real-time updates → WebSocket → Frontend
  4. Completion: Download URLs → ZIP creation → User notification

🛡️ Security & Validation

Input Validation

  • File Types: Strict MIME type validation
  • File Sizes: Configurable limits per plan tier
  • Quota Checks: Real-time quota validation
  • Filename Safety: Sanitization for filesystem compatibility
  • SHA-256 Checksums: Integrity verification and deduplication

Authentication Integration

  • JWT Guards: All endpoints protected with user authentication
  • Quota Enforcement: User plan limits strictly enforced
  • Rate Limiting: API throttling for resource protection
  • CORS Configuration: Secure cross-origin requests

📊 Issues Resolved

This PR directly implements the core API requirements:

  • §26: Drag-and-drop zone accepts .jpg, .jpeg, .png, .gif, .webp MIME types
  • §27: Block drag events containing > N files (user's remaining quota)
  • §28: Compute SHA-256 checksums to avoid duplicate uploads
  • §29: POST multipart/form-data request to /api/batch
  • §30: Persist raw binary files to object-store bucket under UUID folder
  • §32: Server responds with batch_id and initial status "PROCESSING"
  • §73: POST /api/batch → { batch_id, accepted_count, skipped_count }
  • §74: GET /api/batch/{batch_id}/status → { state, progress }
  • §75: PUT /api/image/{image_id}/filename accepts { new_name }
  • §76: POST /api/keywords/enhance → { enhanced_keywords[] }
  • §77: WebSocket ws://…/progress/{batch_id} streams progress events

🚀 Production Features

Scalability

  • Background Processing: Non-blocking job queues
  • Object Storage: Distributed file storage with MinIO
  • Connection Pooling: Database and Redis connection optimization
  • Horizontal Scaling: Stateless API design for load balancing

Monitoring & Observability

  • Request Logging: Comprehensive API request/response logging
  • Error Tracking: Structured error handling with context
  • Performance Metrics: Processing time and throughput monitoring
  • Health Checks: Service availability endpoints

Development Experience

  • TypeScript: Full type safety across all modules
  • Swagger/OpenAPI: Auto-generated API documentation
  • Hot Reload: Development server with file watching
  • Testing Ready: Comprehensive test structure and utilities

🧪 Testing & Quality

API Testing

# Start development environment
npm run dev

# Test batch upload
curl -X POST http://localhost:3001/api/batch \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -F "files[]=@image1.jpg" \
  -F "files[]=@image2.png" \
  -F "keywords[]=SEO,optimization"

# Check batch status
curl http://localhost:3001/api/batch/{batch_id}/status \
  -H "Authorization: Bearer $JWT_TOKEN"

Environment Setup

# Required services
MINIO_ENDPOINT=localhost:9000
REDIS_HOST=localhost:6379
DATABASE_URL=postgresql://user:pass@localhost:5432/db

# AI Integration (optional for development)
OPENAI_API_KEY=your_key_here

This establishes a robust, scalable API foundation that handles the complete image processing workflow from upload through AI enhancement to real-time progress tracking.

🤖 Generated with Claude Code

## Summary This PR implements the complete core API endpoints and business logic for the AI Bulk Image Renamer SaaS, including batch processing, image management, keywords enhancement, and real-time progress tracking via WebSockets. ## 📡 Core API Endpoints Implemented ### **Batch Processing (§73-74)** ```typescript POST /api/batch // Multipart file upload with comprehensive validation Response: { batch_id, accepted_count, skipped_count, status } GET /api/batch/{batch_id}/status // Real-time status tracking with progress Response: { state: 'PROCESSING'|'DONE'|'ERROR', progress: 0-100 } ``` ### **Image Management (§75)** ```typescript PUT /api/image/{image_id}/filename // Update proposed filenames with validation Body: { new_name: string } Response: { id, proposed_name, updated_at } GET /api/image/batch/{batch_id} // List all images in batch with thumbnails Response: { images: Image[], batch_info: Batch } ``` ### **Keywords Enhancement (§76)** ```typescript POST /api/keywords/enhance // AI-powered keyword expansion and SEO optimization Body: { keywords: string[], target_audience?: string } Response: { enhanced_keywords: string[], related_keywords: string[] } ``` ### **WebSocket Progress Streaming (§77)** ```typescript WS /progress/{batch_id} // Real-time progress events for batch processing Events: { image_id, status, progress, timestamp } ``` ## 🏗️ Supporting Infrastructure ### **File Upload & Storage (§26-32)** - **MIME Validation**: Accepts .jpg, .jpeg, .png, .gif, .webp only - **Quota Enforcement**: Blocks uploads exceeding user limits (Basic: 50, Pro: 500, Max: 1000) - **Deduplication**: SHA-256 checksums prevent duplicate uploads - **Object Storage**: MinIO/S3 integration with UUID folder structure - **Secure Processing**: Presigned URLs and authenticated access ### **Background Processing** ```typescript // BullMQ integration with Redis class QueueService { async processImageBatch(batchId: string) { // Enqueue image processing jobs // Handle vision AI analysis // Generate filename suggestions // Update progress in real-time } } ``` ### **Real-time Updates** - **WebSocket Gateway**: Socket.IO integration for live progress - **Room Management**: Batch-specific subscriptions - **Event Broadcasting**: Progress updates to connected clients - **Connection Cleanup**: Automatic cleanup on disconnect ## 🔧 Technical Architecture ### **Modular Design** ``` packages/api/src/ ├── storage/ # MinIO/S3 object storage ├── upload/ # File processing & validation ├── queue/ # Background job processing ├── websocket/ # Real-time progress updates ├── batches/ # Batch management API ├── images/ # Image filename management ├── keywords/ # AI keyword enhancement └── common/ # Shared utilities & middleware ``` ### **Data Flow** 1. **Upload**: Files → Validation → Storage → Queue Jobs 2. **Processing**: Background workers → Vision AI → Filename generation 3. **Progress**: Real-time updates → WebSocket → Frontend 4. **Completion**: Download URLs → ZIP creation → User notification ## 🛡️ Security & Validation ### **Input Validation** - **File Types**: Strict MIME type validation - **File Sizes**: Configurable limits per plan tier - **Quota Checks**: Real-time quota validation - **Filename Safety**: Sanitization for filesystem compatibility - **SHA-256 Checksums**: Integrity verification and deduplication ### **Authentication Integration** - **JWT Guards**: All endpoints protected with user authentication - **Quota Enforcement**: User plan limits strictly enforced - **Rate Limiting**: API throttling for resource protection - **CORS Configuration**: Secure cross-origin requests ## 📊 Issues Resolved This PR directly implements the core API requirements: - **§26**: ✅ Drag-and-drop zone accepts .jpg, .jpeg, .png, .gif, .webp MIME types - **§27**: ✅ Block drag events containing > N files (user's remaining quota) - **§28**: ✅ Compute SHA-256 checksums to avoid duplicate uploads - **§29**: ✅ POST multipart/form-data request to /api/batch - **§30**: ✅ Persist raw binary files to object-store bucket under UUID folder - **§32**: ✅ Server responds with batch_id and initial status "PROCESSING" - **§73**: ✅ POST /api/batch → { batch_id, accepted_count, skipped_count } - **§74**: ✅ GET /api/batch/{batch_id}/status → { state, progress } - **§75**: ✅ PUT /api/image/{image_id}/filename accepts { new_name } - **§76**: ✅ POST /api/keywords/enhance → { enhanced_keywords[] } - **§77**: ✅ WebSocket ws://…/progress/{batch_id} streams progress events ## 🚀 Production Features ### **Scalability** - **Background Processing**: Non-blocking job queues - **Object Storage**: Distributed file storage with MinIO - **Connection Pooling**: Database and Redis connection optimization - **Horizontal Scaling**: Stateless API design for load balancing ### **Monitoring & Observability** - **Request Logging**: Comprehensive API request/response logging - **Error Tracking**: Structured error handling with context - **Performance Metrics**: Processing time and throughput monitoring - **Health Checks**: Service availability endpoints ### **Development Experience** - **TypeScript**: Full type safety across all modules - **Swagger/OpenAPI**: Auto-generated API documentation - **Hot Reload**: Development server with file watching - **Testing Ready**: Comprehensive test structure and utilities ## 🧪 Testing & Quality ### **API Testing** ```bash # Start development environment npm run dev # Test batch upload curl -X POST http://localhost:3001/api/batch \ -H "Authorization: Bearer $JWT_TOKEN" \ -F "files[]=@image1.jpg" \ -F "files[]=@image2.png" \ -F "keywords[]=SEO,optimization" # Check batch status curl http://localhost:3001/api/batch/{batch_id}/status \ -H "Authorization: Bearer $JWT_TOKEN" ``` ### **Environment Setup** ```env # Required services MINIO_ENDPOINT=localhost:9000 REDIS_HOST=localhost:6379 DATABASE_URL=postgresql://user:pass@localhost:5432/db # AI Integration (optional for development) OPENAI_API_KEY=your_key_here ``` This establishes a robust, scalable API foundation that handles the complete image processing workflow from upload through AI enhancement to real-time progress tracking. 🤖 Generated with [Claude Code](https://claude.ai/code)
Author
Owner

Issue Resolved in v1.0.0 Release

This issue has been successfully resolved and implemented in the v1.0.0 release of the AI Bulk Image Renamer SaaS platform.

Implementation Summary:

  • Complete REST API endpoints for batch processing, image management, and user operations
  • WebSocket integration for real-time progress updates
  • Upload handling with multipart form data support
  • Queue management with BullMQ for background processing
  • Storage integration with MinIO/S3 compatibility
  • Keywords module for AI-powered filename enhancement

Merge Commit: 46f7d47 - Merge branch 'feature/core-api-endpoints' into feature/production-complete

Release Tag: v1.0.0

All core API endpoints and business logic have been successfully implemented and are now production-ready with comprehensive error handling and validation.

## ✅ Issue Resolved in v1.0.0 Release This issue has been successfully resolved and implemented in the **v1.0.0 release** of the AI Bulk Image Renamer SaaS platform. **Implementation Summary:** - Complete REST API endpoints for batch processing, image management, and user operations - WebSocket integration for real-time progress updates - Upload handling with multipart form data support - Queue management with BullMQ for background processing - Storage integration with MinIO/S3 compatibility - Keywords module for AI-powered filename enhancement **Merge Commit:** `46f7d47` - Merge branch 'feature/core-api-endpoints' into feature/production-complete **Release Tag:** [v1.0.0](https://vibecodetogether.com/Vibecode-Together/SEO_iamge_renamer_starting_point/releases/tag/v1.0.0) All core API endpoints and business logic have been successfully implemented and are now production-ready with comprehensive error handling and validation.
forgejo_admin closed this pull request 2025-08-05 19:58:57 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Vibecode-Together/SEO_iamge_renamer_starting_point#96
No description provided.