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.
- 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
Stored in COMMAND_PARAMETER table with:
COMMAND_CODE = 'DOCUMENTS'- Includes
COMMAND_PARAMETER(document name) andTHRESHOLD(threshold)
Example:
| COMMAND_PARAMETER | THRESHOLD |
|-----------------------------|----------------------|
| Foto KTP | 90 |
| Foto Selfie | 80 |
| Foto Selfie KTP | 85 |
- Java 21
- Spring Boot 3.5.x
- Spring AI (OpenAI integration)
- MyBatis with Lombok
- Oracle / PostgreSQL / MongoDB / MariaDB support
POST /api/validate-document
multipart/form-data field: file
Response:
{
"result": "Foto KTP",
"valid": true
}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: passThe 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
mvn clean install
java -jar target/document-validator-0.0.1-SNAPSHOT.jarOr use Dockerfile (if provided) for containerized deployment.
- 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.