robrob-creator/paraphraser-api

πŸš€ Modern paraphrasing API built with NestJS. Supports multiple writing styles, bulk processing, and AI-powered text transformation. Production-ready with rate limiting and comprehensive documentation.

0

stars

35

commits

Python

primary language

Oct 7, 2025

updated

README

Paraphraser API

A powerful NestJS-based API for text paraphrasing with multiple styles and strategies.

Features

  • πŸ”„ Multiple paraphrasing styles (Simple, Formal, Casual, Creative, Academic)
  • πŸš€ High-performance rule-based paraphrasing
  • πŸ€– Optional AI-powered paraphrasing (OpenAI, HuggingFace)
  • πŸ“¦ Bulk paraphrasing support
  • βœ… Input validation and sanitization
  • πŸ›‘οΈ Security features and rate limiting
  • πŸ“Š Processing metrics and confidence scores
  • 🌐 CORS support for web applications

Quick Start

Installation

npm install

Environment Setup

Copy the example environment file:

cp .env.example .env

Configure your environment variables in .env:

PORT=3000
USE_ADVANCED_PARAPHRASE=false
OPENAI_API_KEY=your_openai_api_key_here  # Optional
HUGGINGFACE_API_KEY=your_huggingface_api_key_here  # Optional

Running the Application

# Development
npm run start:dev

# Production
npm run build
npm run start:prod

The API will be available at http://localhost:3000

API Endpoints

POST /paraphrase

Paraphrase a single text.

Request Body:

{
  "text": "This is the text you want to paraphrase.",
  "style": "formal",
  "targetLanguage": "en"
}

Response:

{
  "originalText": "This is the text you want to paraphrase.",
  "paraphrasedText": "This is the content you wish to rephrase.",
  "style": "formal",
  "confidence": 0.85,
  "alternativeVersions": [
    "This is the content you desire to rephrase.",
    "This represents the text you wish to paraphrase."
  ],
  "processingTime": 145,
  "wordCount": 8,
  "characterCount": 42
}

POST /paraphrase/bulk

Paraphrase multiple texts at once (max 10 per request).

Request Body:

[
  {
    "text": "First text to paraphrase.",
    "style": "simple"
  },
  {
    "text": "Second text to paraphrase.",
    "style": "formal"
  }
]

GET /paraphrase/styles

Get available paraphrasing styles and their descriptions.

Response:

{
  "styles": ["simple", "formal", "casual", "creative", "academic"],
  "descriptions": {
    "simple": "Basic paraphrasing with synonym replacement",
    "formal": "Professional tone with complete sentences",
    "casual": "Conversational style with contractions",
    "creative": "Engaging language with varied structures",
    "academic": "Scholarly tone with precise vocabulary"
  }
}

GET /paraphrase/history

Get paraphrasing history (placeholder endpoint).

GET /paraphrase/health

Health check endpoint.

Paraphrasing Styles

StyleDescriptionExample
simpleBasic synonym replacement"big" β†’ "large"
formalProfessional, complete sentences"can't" β†’ "cannot"
casualConversational with contractions"cannot" β†’ "can't"
creativeVaried sentence structuresRestructures sentences creatively
academicScholarly vocabulary"show" β†’ "demonstrate"

Configuration

Environment Variables

VariableDescriptionDefault
PORTServer port3000
USE_ADVANCED_PARAPHRASEEnable AI paraphrasingfalse
OPENAI_API_KEYOpenAI API key-
HUGGINGFACE_API_KEYHuggingFace API key-
ALLOWED_ORIGINSCORS allowed originshttp://localhost:3000

Paraphrasing Strategies

The API supports two main strategies:

  1. Simple Strategy (Default): Rule-based paraphrasing using synonym replacement and style transformations
  2. Advanced Strategy: AI-powered paraphrasing using OpenAI or HuggingFace APIs

Input Validation

  • Text must be between 5 and 5000 characters
  • XSS protection against malicious scripts
  • Automatic sanitization of input

Rate Limiting

  • Default: 100 requests per 15 minutes per IP
  • Configurable via environment variables

Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

Development

Project Structure

src/
β”œβ”€β”€ paraphraser/
β”‚   β”œβ”€β”€ dto/                    # Data Transfer Objects
β”‚   β”œβ”€β”€ strategies/             # Paraphrasing strategies
β”‚   β”œβ”€β”€ paraphraser.controller.ts
β”‚   β”œβ”€β”€ paraphraser.service.ts
β”‚   └── paraphraser.module.ts
β”œβ”€β”€ app.module.ts
└── main.ts

Adding New Strategies

  1. Implement the ParaphraseStrategy interface
  2. Add the strategy to the ParaphraserModule providers
  3. Update the ParaphraserService to use the new strategy

Error Handling

The API returns structured error responses:

{
  "error": "Paraphrasing Failed",
  "message": "Text must be at least 5 characters long",
  "statusCode": 400,
  "timestamp": "2025-10-06T12:00:00.000Z"
}

Examples

Using cURL

# Simple paraphrasing
curl -X POST http://localhost:3000/paraphrase \
  -H "Content-Type: application/json" \
  -d '{
    "text": "The quick brown fox jumps over the lazy dog.",
    "style": "formal"
  }'

# Bulk paraphrasing
curl -X POST http://localhost:3000/paraphrase/bulk \
  -H "Content-Type: application/json" \
  -d '[
    {"text": "Hello world!", "style": "casual"},
    {"text": "Goodbye world!", "style": "formal"}
  ]'

Using JavaScript

const response = await fetch('http://localhost:3000/paraphrase', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    text: 'This is a test sentence.',
    style: 'creative',
  }),
});

const result = await response.json();
console.log(result.paraphrasedText);

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

This project is licensed under the MIT License.

Description

Nest framework TypeScript starter repository.

Project setup

$ npm install

Compile and run the project

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Run tests

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Deployment

When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

$ npm install -g mau
$ mau deploy

With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

Resources

Check out a few resources that may come in handy when working with NestJS:

  • Visit the NestJS Documentation to learn more about the framework.
  • For questions and support, please visit our Discord channel.
  • To dive deeper and get more hands-on experience, check out our official video courses.
  • Deploy your application to AWS with the help of NestJS Mau in just a few clicks.
  • Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
  • Need help with your project (part-time to full-time)? Check out our official enterprise support.
  • To stay in the loop and get updates, follow us on X and LinkedIn.
  • Looking for a job, or have a job to offer? Check out our official Jobs board.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

Contributors

robrob-creator

35 commits

robrob-creator/paraphraser-api

πŸš€ Modern paraphrasing API built with NestJS. Supports multiple writing styles, bulk processing, and AI-powered text transformation. Production-ready with rate limiting and comprehensive documentation.

0

stars

35

commits

Python

primary language

Oct 7, 2025

updated

README

Paraphraser API

A powerful NestJS-based API for text paraphrasing with multiple styles and strategies.

Features

  • πŸ”„ Multiple paraphrasing styles (Simple, Formal, Casual, Creative, Academic)
  • πŸš€ High-performance rule-based paraphrasing
  • πŸ€– Optional AI-powered paraphrasing (OpenAI, HuggingFace)
  • πŸ“¦ Bulk paraphrasing support
  • βœ… Input validation and sanitization
  • πŸ›‘οΈ Security features and rate limiting
  • πŸ“Š Processing metrics and confidence scores
  • 🌐 CORS support for web applications

Quick Start

Installation

npm install

Environment Setup

Copy the example environment file:

cp .env.example .env

Configure your environment variables in .env:

PORT=3000
USE_ADVANCED_PARAPHRASE=false
OPENAI_API_KEY=your_openai_api_key_here  # Optional
HUGGINGFACE_API_KEY=your_huggingface_api_key_here  # Optional

Running the Application

# Development
npm run start:dev

# Production
npm run build
npm run start:prod

The API will be available at http://localhost:3000

API Endpoints

POST /paraphrase

Paraphrase a single text.

Request Body:

{
  "text": "This is the text you want to paraphrase.",
  "style": "formal",
  "targetLanguage": "en"
}

Response:

{
  "originalText": "This is the text you want to paraphrase.",
  "paraphrasedText": "This is the content you wish to rephrase.",
  "style": "formal",
  "confidence": 0.85,
  "alternativeVersions": [
    "This is the content you desire to rephrase.",
    "This represents the text you wish to paraphrase."
  ],
  "processingTime": 145,
  "wordCount": 8,
  "characterCount": 42
}

POST /paraphrase/bulk

Paraphrase multiple texts at once (max 10 per request).

Request Body:

[
  {
    "text": "First text to paraphrase.",
    "style": "simple"
  },
  {
    "text": "Second text to paraphrase.",
    "style": "formal"
  }
]

GET /paraphrase/styles

Get available paraphrasing styles and their descriptions.

Response:

{
  "styles": ["simple", "formal", "casual", "creative", "academic"],
  "descriptions": {
    "simple": "Basic paraphrasing with synonym replacement",
    "formal": "Professional tone with complete sentences",
    "casual": "Conversational style with contractions",
    "creative": "Engaging language with varied structures",
    "academic": "Scholarly tone with precise vocabulary"
  }
}

GET /paraphrase/history

Get paraphrasing history (placeholder endpoint).

GET /paraphrase/health

Health check endpoint.

Paraphrasing Styles

StyleDescriptionExample
simpleBasic synonym replacement"big" β†’ "large"
formalProfessional, complete sentences"can't" β†’ "cannot"
casualConversational with contractions"cannot" β†’ "can't"
creativeVaried sentence structuresRestructures sentences creatively
academicScholarly vocabulary"show" β†’ "demonstrate"

Configuration

Environment Variables

VariableDescriptionDefault
PORTServer port3000
USE_ADVANCED_PARAPHRASEEnable AI paraphrasingfalse
OPENAI_API_KEYOpenAI API key-
HUGGINGFACE_API_KEYHuggingFace API key-
ALLOWED_ORIGINSCORS allowed originshttp://localhost:3000

Paraphrasing Strategies

The API supports two main strategies:

  1. Simple Strategy (Default): Rule-based paraphrasing using synonym replacement and style transformations
  2. Advanced Strategy: AI-powered paraphrasing using OpenAI or HuggingFace APIs

Input Validation

  • Text must be between 5 and 5000 characters
  • XSS protection against malicious scripts
  • Automatic sanitization of input

Rate Limiting

  • Default: 100 requests per 15 minutes per IP
  • Configurable via environment variables

Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

Development

Project Structure

src/
β”œβ”€β”€ paraphraser/
β”‚   β”œβ”€β”€ dto/                    # Data Transfer Objects
β”‚   β”œβ”€β”€ strategies/             # Paraphrasing strategies
β”‚   β”œβ”€β”€ paraphraser.controller.ts
β”‚   β”œβ”€β”€ paraphraser.service.ts
β”‚   └── paraphraser.module.ts
β”œβ”€β”€ app.module.ts
└── main.ts

Adding New Strategies

  1. Implement the ParaphraseStrategy interface
  2. Add the strategy to the ParaphraserModule providers
  3. Update the ParaphraserService to use the new strategy

Error Handling

The API returns structured error responses:

{
  "error": "Paraphrasing Failed",
  "message": "Text must be at least 5 characters long",
  "statusCode": 400,
  "timestamp": "2025-10-06T12:00:00.000Z"
}

Examples

Using cURL

# Simple paraphrasing
curl -X POST http://localhost:3000/paraphrase \
  -H "Content-Type: application/json" \
  -d '{
    "text": "The quick brown fox jumps over the lazy dog.",
    "style": "formal"
  }'

# Bulk paraphrasing
curl -X POST http://localhost:3000/paraphrase/bulk \
  -H "Content-Type: application/json" \
  -d '[
    {"text": "Hello world!", "style": "casual"},
    {"text": "Goodbye world!", "style": "formal"}
  ]'

Using JavaScript

const response = await fetch('http://localhost:3000/paraphrase', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    text: 'This is a test sentence.',
    style: 'creative',
  }),
});

const result = await response.json();
console.log(result.paraphrasedText);

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

This project is licensed under the MIT License.

Description

Nest framework TypeScript starter repository.

Project setup

$ npm install

Compile and run the project

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Run tests

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Deployment

When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

$ npm install -g mau
$ mau deploy

With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

Resources

Check out a few resources that may come in handy when working with NestJS:

  • Visit the NestJS Documentation to learn more about the framework.
  • For questions and support, please visit our Discord channel.
  • To dive deeper and get more hands-on experience, check out our official video courses.
  • Deploy your application to AWS with the help of NestJS Mau in just a few clicks.
  • Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
  • Need help with your project (part-time to full-time)? Check out our official enterprise support.
  • To stay in the loop and get updates, follow us on X and LinkedIn.
  • Looking for a job, or have a job to offer? Check out our official Jobs board.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

Contributors

robrob-creator

35 commits

Languages

Python

52.5%

TypeScript

43.7%

JavaScript

1.6%

Shell

1.5%