Skip to content

wahIndra/idp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intelligent Document Processing (IDP) – Documents Validator

This project is a Spring Boot application integrated with Spring AI and OpenAI to classify and validate document images based on training data stored in a database (Oracle, PostgreSQL, MongoDB, MariaDB). It utilizes OCR/Image interpretation via OpenAI Vision models to validate if an image is one of the expected document types.

✨ Features

  • Accepts file input via REST API (JPEG, PNG, PDF, etc.)
  • Extracts and encodes images into Base64
  • Uses Spring AI (OpenAI) for visual classification
  • Validates against dynamically loaded document types from database with thresholds
  • Supports intelligent classification: strict prompt engineering to reduce hallucination
  • Configurable for multiple database types via application.yml

📁 Supported Document Types

Stored in COMMAND_PARAMETER table with:

  • COMMAND_CODE = 'DOCUMENTS'
  • Includes COMMAND_PARAMETER (document name) and THRESHOLD (threshold)

Example:

| COMMAND_PARAMETER           | THRESHOLD            |
|-----------------------------|----------------------|
| Foto KTP                    | 90                   |
| Foto Selfie                 | 80                   |
| Foto Selfie KTP             | 85                   |

⚙️ Technology Stack

  • Java 21
  • Spring Boot 3.5.x
  • Spring AI (OpenAI integration)
  • MyBatis with Lombok
  • Oracle / PostgreSQL / MongoDB / MariaDB support

📦 API Example

POST /api/validate-document
multipart/form-data field: file

Response:

{
  "result": "Foto KTP",
  "valid": true
}

📄 application.yml Example

spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY}

  datasource:
    oracle:
      url: jdbc:oracle:thin:@localhost:1521:orcl
      username: user
      password: pass
    postgres:
      url: jdbc:postgresql://localhost:5432/db
      username: user
      password: pass
    mariadb:
      url: jdbc:mariadb://localhost:3306/db
      username: user
      password: pass

🧠 Prompt Engineering (Spring AI)

The prompt used includes:

  • A system message guiding the AI with rules
  • A list of valid document types and thresholds
  • A strict user instruction to prevent guessing
  • The image as Base64

🚀 Running the Project

mvn clean install
java -jar target/document-validator-0.0.1-SNAPSHOT.jar

Or use Dockerfile (if provided) for containerized deployment.

✅ TODO

  • Unit tests with mock Spring AI
  • UI front-end for upload
  • PDF OCR integration
  • Result caching or DB store

Built for intelligent and scalable document classification in enterprise-level systems.

About

document-validator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages