Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Global OCR API

Fast, accurate OCR extraction for document types using Google Gemini 2.5 Flash Lite. Optimized for speed with 1-2 second response times.

✨ Features

  • πŸ† High-Speed OCR: Optimized for 1-2 second response times
  • πŸ“„ Multi-Document Support: NID, BO Certificate, TIN Certificate, Bank Statements
  • πŸ€– AI-Powered: Google Gemini 2.5 Flash Lite with custom prompts
  • πŸ”§ Smart Processing: Automatic image optimization and compression
  • ⚑ Performance Optimized: Concurrent request handling and deduplication
  • πŸ“ Type-Safe: Full TypeScript support with strict typing
  • πŸ” Auto-Validation: Built-in response validation for each document type
  • πŸ“š API Documentation: Interactive Swagger UI at /api

🎯 Supported Document Types

Document Type Fields Extracted
NID name, date_of_birth, nid_number
BO bo_id (16 digits)
TIN tin_number (12 digits)
BANK account_number, routing_number

πŸ“‹ Requirements

  • Node.js: 18+
  • NPM: 8+
  • Google Gemini API Key: Get it here

βš™οΈ Setup & Installation

1. Clone and Install

git clone <repository-url>
cd ocr-global-api
npm install

2. Environment Configuration

Create a .env file in the root directory:

PORT=6060
GEMINI_API_KEY=your_gemini_api_key_here

3. Run the Application

# Development mode (with hot reload)
npm run start:dev

# Production mode
npm run start:prod

# Standard development
npm run start

The server will start at http://localhost:6060

πŸ“– API Documentation

Interactive Swagger UI available at: http://localhost:6060/api

πŸ”Œ API Usage

Endpoint

POST /api/ocr

Request Format

curl -X POST http://localhost:6060/api/ocr \
  -H "Content-Type: multipart/form-data" \
  -F "file=@document.jpg" \
  -F "type=NID"

Supported File Types

  • Images: JPG, PNG, WebP, BMP, TIFF
  • Documents: PDF
  • Max Size: 10MB

Document Types

  • NID - National ID Card
  • BO - BO Certificate
  • TIN - TIN Certificate
  • BANK - Bank Statement

Response Format

{
  "type": "NID",
  "details": {
    "name": "John Doe",
    "date_of_birth": "01/01/1990", 
    "nid_number": "1234567890123"
  }
}

Error Response

{
  "type": "NID",
  "details": {}
}

πŸ§ͺ Testing

# Run unit tests
npm run test

# Run e2e tests  
npm run test:e2e

# Test coverage
npm run test:cov

# Test with watch mode
npm run test:watch

πŸš€ Performance Features

  • ⚑ Sub-2 Second Response: Optimized prompts and model parameters
  • πŸ”„ Concurrent Processing: Handles multiple requests efficiently
  • πŸ“¦ Smart Caching: Deduplicates identical requests
  • πŸ–ΌοΈ Image Optimization: Automatic compression (800x800, 75% quality)
  • 🎯 Direct API Calls: No streaming overhead for maximum speed

πŸ—οΈ Architecture

src/
β”œβ”€β”€ common/
β”‚   β”œβ”€β”€ prompts/           # Optimized AI prompts
β”‚   └── utils/             # Image optimization utilities
β”œβ”€β”€ ocr/
β”‚   β”œβ”€β”€ dto/               # Request/response types
β”‚   β”œβ”€β”€ enums/             # Document type enums
β”‚   β”œβ”€β”€ ocr-helpers.ts     # Pure utility functions
β”‚   β”œβ”€β”€ ocr.service.ts     # Core OCR logic
β”‚   └── ocr.controller.ts  # API endpoints
└── main.ts                # Application bootstrap

πŸ”§ Configuration

Environment Variables

Variable Description Default
PORT Server port 3000
GEMINI_API_KEY Google Gemini API key Required

Model Configuration

  • Model: gemini-2.5-flash-lite
  • Temperature: 0 (deterministic)
  • Max Output Tokens: 256
  • Response Format: JSON with schema validation

πŸ› Troubleshooting

Common Issues

1. "API Key not found"

# Ensure .env file exists and contains:
GEMINI_API_KEY=your_actual_api_key

2. "Port already in use"

# Change port in .env file:
PORT=6060

3. "File too large"

  • Max file size: 10MB
  • Supported formats: JPG, PNG, WebP, BMP, TIFF, PDF

4. "Empty response"

  • Ensure document text is clear and readable
  • Check document type matches the type parameter
  • Verify image quality is sufficient

πŸ“š Development

Code Quality

# Lint code
npm run lint

# Fix lint issues
npm run lint:fix

# Format code
npm run format

Build

# Build for production
npm run build

# Start built version
npm run start:prod

πŸ“„ License

This project is MIT licensed.

NID-BO-BANK-TIN-Parser-With-AI

About

Fast, accurate OCR extraction for document types using **Google Gemini 2.5 Flash Lite**. Optimized for speed with 1-2 second response times.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages