Skip to content

YakoobHammouri/Image-Processing-API

Repository files navigation

Image Processing API - Project Requirements Document (PRD)

1. Project Overview

1.1 Project Name

Image Processing API

1.2 Project Description

A RESTful API service built with Node.js and TypeScript that provides image processing capabilities, specifically image resizing using the Sharp library. The API will accept image requests with specified dimensions and return processed images with caching for optimal performance.

1.3 Project Objectives

  • Create a scalable image processing API
  • Implement efficient image resizing functionality
  • Provide fast response times through caching
  • Ensure production-ready code quality and error handling
  • Demonstrate TypeScript and Node.js best practices

2. Technical Requirements

2.1 Technology Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Language: TypeScript
  • Image Processing: Sharp library
  • Testing Framework: Jasmine
  • Code Quality: ESLint + Prettier
  • Package Manager: npm

2.2 Dependencies

Production Dependencies

  • express: Web application framework
  • sharp: High-performance image processing library
  • typescript: TypeScript compiler

Development Dependencies

  • @types/express: TypeScript definitions for Express
  • @types/jasmine: TypeScript definitions for Jasmine
  • @types/node: TypeScript definitions for Node.js
  • jasmine: Testing framework
  • eslint: Code linting
  • prettier: Code formatting

2.3 Supported Image Formats

  • Primary: JPEG (.jpg, .jpeg)
  • Optional Extensions: PNG

3. Functional Requirements

3.1 Core Features

3.1.1 Image Processing Endpoint

  • Endpoint: /api/images
  • Method: GET
  • Parameters:
    • filename (required): Name of the source image
    • width (optional): Target width in pixels
    • height (optional): Target height in pixels
  • Response: Processed image file or error message

3.1.2 Image Resizing

  • Resize images to specified dimensions
  • Maintain aspect ratio when only one dimension provided
  • Support various resize strategies (fit, fill, cover)
  • Handle edge cases for invalid dimensions

3.1.3 Caching System

  • Cache processed images to avoid reprocessing
  • Implement cache key generation based on filename and dimensions
  • Serve cached images for identical requests
  • Cache invalidation strategies

3.1.4 Error Handling

  • Validate input parameters
  • Handle missing source images
  • Provide meaningful error messages
  • Return appropriate HTTP status codes

3.2 API Specifications

3.2.1 Request Format

GET /api/images?filename=example.jpg&width=300&height=200

3.2.2 Response Format

  • Success: Binary image data with appropriate headers
  • Error: JSON error message with status code

3.2.3 Status Codes

  • 200: Success - Image processed and returned
  • 400: Bad Request - Invalid parameters
  • 404: Not Found - Source image not found
  • 500: Internal Server Error - Processing failed

5. Project Structure

5.1 Directory Structure

assets/
│   ├── images/          # Source images
│   └── thumb/           # Processed images cache
dist/                    # Compiled JavaScript
spec/
src/
├── common/
|    └── BaseRoute.constants.ts
|    └── common.constants.ts
├── modules/
│   └── image.processing/
│       └── image.processing.controller.ts
│       └── image.processing.routes.ts
│       └── image.processing.types.ts
├── tests/
|
├── utils/
│   └── util.process.image.ts
|
├──
└── server.ts           # Main server file
.gitignore
eslint.config.mjs
package.json
README.md
tsconfig.json

5.2 Module Organization

  • Routes: API endpoint definitions
  • utils: Core business logic and image processing
  • Tests: Unit and integration tests
  • Assets: Image storage directories

6. Development Requirements

6.1 Scripts (package.json)

{
  "scripts": {
    "check-type": "tsc --noEmit",
    "dev": "tsx watch ./src/server.ts",
    "build": "tsc",
    "lint2": "npm run build && eslint 'index.js'",
    "lint3": "eslint src/**/*.ts",
    "lint": "eslint src/**/*.ts",
    "lint:fix": "eslint src/**/*.ts --fix",
    "prettier": "npx prettier src/**/*.ts --write",
    "test": "npm run build && npm run jasmine",
    "jasmine": "jasmine"
  }
}

6.2 Configuration Files

  • tsconfig.json: TypeScript compiler configuration
  • spec/support/jasmine.json: Test configuration

7. Testing Requirements

7.1 Unit Tests

  • Endpoint Testing: Validate API responses and status codes
  • Image Processing: Test resizing functionality with various inputs
  • Error Handling: Verify proper error responses
  • Utility Functions: Test helper functions

7.3 Testing Tools

  • Jasmine for test framework
  • Supertest for HTTP testing (optional enhancement)
  • Custom test utilities for image validation

8. Future Enhancements

8.1 Potential Extensions

  • Support for additional image formats (PNG, WebP, TIFF)
  • Advanced processing features (filters, compression, format conversion)
  • Batch processing capabilities
  • Database integration for metadata
  • Authentication and rate limiting
  • Cloud storage integration
  • Image optimization and compression options

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published