Exploring the architecture of a database-backed, self-hosted AI Document Processing application built with Java, MongoDB, configurable OCR engines and Generative AI.
1. Document AI Is More Than OCR, Parsing and LLM Inference
The open-source Document AI ecosystem is expanding rapidly. Libraries and toolkits such as Docling, PaddleOCR, Tesseract and Unstructured provide increasingly sophisticated capabilities for document recognition, layout parsing, information analysis and content transformation.
Developers can convert complex PDFs into structured representations, recognise text within scanned images, reconstruct tables and invoke large language models (LLMs) to extract semantically meaningful information.
But what happens after an OCR engine or an LLM returns its response?
What happens when thousands of documents need to be uploaded, classified, processed, stored, reviewed, corrected and exported?
Where are processing results persisted? How can users return to previously processed documents? How can extracted information be corrected without necessarily repeating the entire AI processing cycle? How are different recognition engines, AI models and human interactions coordinated within a single application?
These requirements introduce an entirely different dimension of software architecture.
Recognising a document is a computational task. Managing its entire processing lifecycle is an application engineering challenge.
Standalone document processing libraries provide powerful computational capabilities. However, transforming these capabilities into an operational AI Document Processing application introduces additional requirements, including database persistence, processing orchestration, application services and human-in-the-loop validation.
elDoc IDP Open Source demonstrates how MongoDB, PaddleOCR, Tesseract, LangChain4j, large language models, vision-language models and Java-based application services can be brought together within a unified, self-hosted application.
Rather than introducing another document parsing toolkit, the project addresses the architectural challenge of transforming unstructured documents into validated, business-ready data.
2. From Document Processing Libraries to Database-Backed AI Applications
A typical OCR engine or document conversion library can operate without a dedicated application database.
It receives an input, performs computational operations and returns a result through an in-memory object or an output file.
This architecture is highly effective for document conversion, content ingestion, batch processing and Retrieval-Augmented Generation (RAG) preparation.
However, operational AI Document Processing introduces additional requirements.
The processing result is no longer simply an output artifact. It becomes part of an application-managed lifecycle involving multiple computational stages, persistent information and human interaction.
Figure 1. Standalone document processing toolkits versus an integrated MongoDB-backed AI Document Processing application.
Where do Docling, PaddleOCR and other technologies fit?
| Technology | Primary architectural responsibility | Persistence architecture |
|---|---|---|
| Tesseract | Optical character recognition | No dedicated application database required |
| PaddleOCR core toolkit | OCR, layout analysis and information extraction | Application persistence generally managed separately |
| Docling core library | Document conversion, parsing and structured information extraction | No dedicated database required for core conversion |
| Unstructured open-source library | Document partitioning and content preparation | Storage depends on surrounding integrations |
| LangChain4j | Java-based Generative AI integration | Persistence depends on application configuration |
| MongoDB | Document-oriented database management | Native database infrastructure |
| elDoc IDP OSS | Integrated AI Document Processing application | Integrated MongoDB persistence |
The broader Docling ecosystem also includes persistence integrations, asynchronous processing services and database-backed ingestion capabilities.
The architectural distinction is therefore not that document processing libraries cannot integrate with databases. It is that elDoc IDP OSS brings database persistence, configurable recognition, field-level extraction, processing orchestration and human validation together within an existing operational application.
3. Application Architecture: Bringing Specialised Technologies Together
A complete AI Document Processing architecture requires multiple technological layers, each responsible for a specific function.
elDoc IDP OSS combines established application engineering technologies with modern AI components.
Figure 2. elDoc IDP OSS orchestrated document AI architecture with integrated MongoDB persistence, configurable recognition engines, GenAI processing, human validation and structured CSV export.
Figure 2. elDoc IDP OSS orchestrated document AI architecture.
| Technology | Architectural responsibility |
|---|---|
| Java 21 / Jakarta EE | Application services and processing orchestration |
| Payara Micro | Application runtime and deployment |
| MongoDB | Application data persistence |
| Apache PDFBox | PDF processing and rendering |
| TwelveMonkeys ImageIO | Extended image format handling, including TIFF |
| OpenCV / Bytedeco | Computer vision and native image processing |
| Tesseract | Embedded OCR engine |
| PaddleOCR | Configurable recognition engine |
| LangChain4j | Generative AI model integration |
| LLMs | Semantic classification and field-level extraction |
| VLMs | Multimodal document understanding |
| Jakarta Faces / PrimeFaces | Browser-based application interface |
The important architectural principle is separation of responsibilities.
4. Why MongoDB Is Relevant to AI Document Processing
Document AI applications deal with inherently heterogeneous information.
An invoice, bank statement, insurance claim, utility bill and purchase order may have completely different structures, data types and extraction requirements.
Even documents belonging to the same category may contain different fields, nested information and repeating data elements.
This heterogeneity makes document-oriented database architectures particularly relevant to AI Document Processing.
Figure 3. Conceptual representation of heterogeneous business information and MongoDB document-oriented persistence. This illustration does not represent the physical elDoc database schema.
Figure 3. Conceptual representation of heterogeneous business information and document-oriented persistence.
MongoDB's BSON-based data model provides several architectural advantages.
| MongoDB capability | Relevance to document AI |
|---|---|
| Flexible document structures | Accommodating different information requirements |
| Nested objects | Representing hierarchical business information |
| Arrays | Representing repeating information such as transactions or line items |
| Variable field sets | Supporting heterogeneous document categories |
| Persistent identifiers | Associating information throughout an application lifecycle |
| Atomic document updates | Supporting consistent updates to individual database documents |
| Indexing | Supporting efficient retrieval of application records |
| Replica sets | Supporting replication and database availability |
| Transactions | Supporting atomic operations across multiple records when required |
These are general MongoDB capabilities relevant to the design of document processing applications, rather than a description of the physical elDoc database schema.
It is also important to distinguish between two meanings of the word document:
- A business document is an input artifact, such as a PDF invoice or scanned bank statement.
- A MongoDB document is a BSON database record used to represent application information.
In elDoc IDP OSS, MongoDB is an integral application component rather than merely an optional destination for exported OCR results.
5. Persistent Processing Instead of Transient AI Responses
A simple OCR-to-LLM implementation frequently ends when the model returns its response.
The caller then becomes responsible for storing the result, presenting it to users, managing corrections and determining how it will be used.
A database-backed IDP application introduces a broader architectural model.
Figure 4. MongoDB as a cross-cutting persistence layer rather than a final pipeline destination, supporting document ingestion, recognition, semantic extraction, human validation and structured data export.
Figure 4. MongoDB as a cross-cutting persistence layer rather than a final pipeline destination.
Persistent application information enables document processing to extend beyond individual computational requests.
This becomes particularly important when AI processing and human validation occur at different times.
The application must support an operational lifecycle rather than treating every interaction as an isolated inference request.
6. Embedded MongoDB vs. Externally Managed MongoDB
One particularly interesting architectural decision in elDoc IDP OSS is its support for both application-managed embedded MongoDB and externally managed MongoDB deployments.
This reduces infrastructure complexity during initial evaluation while retaining flexibility for more advanced deployment scenarios.
Figure 5. Embedded versus externally managed MongoDB deployment models in elDoc IDP OSS, illustrating infrastructure flexibility, database connectivity, persistence and configurable security controls.
Figure 5. Embedded versus independently managed MongoDB deployment models.
Embedded MongoDB
When an external MongoDB connection is not configured, elDoc IDP OSS can automatically launch a local MongoDB replica set.
This approach simplifies the initial deployment process because developers do not need to provision and configure a separate database installation before evaluating the application.
The embedded database binds to the loopback interface and operates without authentication in its evaluation configuration.
The application provides environment variables for overriding embedded database storage and binary-cache locations:
export ELDOC_EMBEDDED_MONGODB_DATA_DIR=/opt/eldoc/data export ELDOC_EMBEDDED_MONGODB_BINARY_CACHE_DIR=/opt/eldoc/cache Explicit storage paths are important when application data must survive operating-system temporary-directory cleanup.
The embedded configuration is particularly useful for local development, proof-of-concept implementations, application evaluation and experimentation with different OCR engines and AI models.
It should not be treated as a hardened production database environment.
External MongoDB
For independently managed database infrastructure, elDoc IDP OSS supports external MongoDB connectivity.
A representative configuration is:
export ELDOC_MONGODB_URI='mongodb://mongo1:27017,mongo2:27017,mongo3:27017/eldoc_idposs?replicaSet=rs0&tls=true' export ELDOC_MONGODB_USER='eldoc_app' export ELDOC_MONGODB_PASSWORD='<your-secret>' Providing an external MongoDB connection URI disables the automatic embedded database fallback.
The application configuration also documents options for database authentication, TLS, truststores and client certificate-based connectivity.
| Infrastructure characteristic | Embedded MongoDB | External MongoDB |
|---|---|---|
| Initial setup | Application-managed | Independently configured |
| Database installation | Automated local startup | Separate database infrastructure |
| Authentication | Disabled in evaluation configuration | Configurable |
| Network connectivity | Loopback interface | Configurable infrastructure |
| Replication | Local replica-set configuration | Independently managed topology |
| Backup strategy | Locally managed | Organisation-defined |
| Infrastructure monitoring | Local evaluation | Organisation-defined |
| Typical deployment | Development and evaluation | Production-oriented environments |
The advantage is architectural flexibility: developers can start with a simplified deployment and subsequently adopt independently managed database infrastructure.
Configuration reference: elDoc IDP OSS application configuration.
7. PaddleOCR as a Configurable Recognition Component
PaddleOCR provides sophisticated capabilities for optical character recognition, layout understanding and information extraction.
However, recognition is only one component of an integrated document processing architecture.
Within elDoc IDP OSS, PaddleOCR can operate as part of the underlying recognition pipeline.
Figure 6. Configurable recognition engines within the elDoc IDP OSS processing architecture. PaddleOCR, Tesseract and vision-language models operate as alternative recognition components within the orchestrated document processing pipeline.
Figure 6. Alternative recognition engines within the elDoc processing architecture.
| Recognition engine | Configuration selector | Recognition approach |
|---|---|---|
| Tesseract | tess | Embedded OCR |
| PaddleOCR | pddl | OCR through a configured API endpoint |
| Vision-language model | vl | AI-powered multimodal recognition |
To configure PaddleOCR:
idp.ocr.type=pddl idp.ocr.url=http://localhost:8050 The endpoint must implement the API interface expected by elDoc IDP OSS. An arbitrary PaddleOCR service is not necessarily a compatible replacement.
Alternatively, embedded Tesseract can be selected:
idp.ocr.type=tess Vision-language recognition can be selected using:
idp.ocr.type=vl This architectural separation makes the recognition engine a configurable processing component.
Developers can evaluate different recognition approaches without replacing the complete application architecture, database infrastructure or human validation interface.
PaddleOCR and elDoc IDP OSS should therefore not always be evaluated as competing technologies. PaddleOCR can operate directly as a recognition component within the broader elDoc AI Document Processing architecture.
8. Document Preprocessing: PDF, TIFF and Computer Vision
Document recognition begins before an OCR engine receives an image.
Real-world document collections frequently contain heterogeneous file formats, inconsistent page orientations, skewed scans and multipage documents.
Figure 7. Conceptual document preprocessing architecture integrating PDF rendering, multipage TIFF handling and computer vision operations preceding OCR and multimodal AI recognition.
Figure 7. Conceptual document preprocessing stages preceding OCR and multimodal recognition.
| Technology | Technical responsibility |
|---|---|
| Apache PDFBox | PDF processing and page rendering |
| TwelveMonkeys ImageIO | Extended image format support, including TIFF |
| OpenCV | Computer vision and image transformations |
| Bytedeco / JavaCPP | Integration of native computational libraries into Java |
Multipage TIFF and document-level context
A single TIFF file may contain numerous page images representing one logical business document.
For example, a financial document may contain account information on the first page, transaction records across intermediate pages and final balances on the last page.
Figure 8. Multipage document understanding and semantic information extraction across multiple pages of a single logical business document, preserving document-level context rather than treating each page as an isolated image.
Figure 8. Information distributed across multiple pages of a logical business document.
The processing objective is not simply to recognise each page independently, but to capture the relevant business information from the complete document.
This is particularly important for financial statements, historical archives, insurance documentation, logistics records and other document-intensive workflows.
9. Bringing LLMs and Vision-Language Models into the Pipeline
OCR converts document content into machine-readable information.
Generative AI introduces an additional semantic processing layer.
For business-oriented document processing, the objective is frequently not to extract every character but to identify information according to its meaning.
Consider the following example.
Figure 9. Semantic field-level data extraction within the elDoc IDP OSS processing pipeline, illustrating how Generative AI transforms recognised document content into predefined, structured business fields rather than simply extracting raw text.
Figure 9. Illustrative semantic mapping of recognised invoice content to configured business fields.
An LLM can help distinguish an invoice reference from a purchase order number or determine whether a monetary value represents a subtotal, tax amount or final payable amount.
Vision-language models can additionally interpret visual relationships between labels, values, tables and document regions.
This is the distinction between generic document recognition and semantic field-level data extraction.
10. LangChain4j: Integrating Generative AI into a Java Application
Much of the contemporary AI ecosystem is Python-oriented. However, integrating AI models does not require the entire application architecture to be implemented in Python.
LangChain4j provides a Java-oriented foundation for incorporating language models and AI capabilities into application services.
Within the elDoc processing environment, AI configuration distinguishes between two model roles.
Figure 10. LangChain4j-based Generative AI integration within the elDoc IDP OSS architecture, illustrating the separation of agent and vision-language model roles, configurable AI providers and support for compatible locally hosted AI models.
Figure 10. Conceptual separation of agent and vision-language model roles with configurable AI providers.
Separating these roles allows developers to evaluate different models according to the requirements of individual processing tasks.
The project provides configuration options for AI providers including OpenRouter, AWS Bedrock and OpenAI-compatible endpoints. Compatible locally hosted model servers can also be evaluated.
However, AI models are not automatically interchangeable. Developers must evaluate tool-calling compatibility, multimodal capabilities, context-window limitations, extraction accuracy, inference latency and computational resource requirements.
The application architecture remains responsible for coordinating these AI capabilities within the document processing lifecycle.
11. Orchestrating the Complete Document Processing Lifecycle
The value of an integrated AI Document Processing application emerges from the orchestration of its individual components.
Figure 11. Conceptual orchestration of document processing stages with integrated MongoDB persistence.
From a software engineering perspective, each architectural component has different execution characteristics.
| Processing component | Operational characteristics |
|---|---|
| Document preprocessing | CPU-intensive file and image operations |
| OCR | CPU- or GPU-intensive recognition |
| LLM inference | Model-dependent latency and computational requirements |
| MongoDB | Persistence, retrieval and consistency requirements |
| Application services | Coordination of processing operations |
| Human validation | Asynchronous user interaction |
| CSV export | Transformation into structured downstream data |
Combining these capabilities requires considerably more than a function that submits OCR output to an LLM.
12. Why Persistent Data Matters for Human-in-the-Loop AI
AI-generated results may contain missing fields, recognition inaccuracies, incorrect semantic associations or unsupported information.
Consider an invoice where OCR incorrectly recognises a total of 1500.00 as 1508.00.
An integrated IDP application needs a mechanism for users to inspect and correct the resulting information.
Instead of treating the AI response as the final result, elDoc IDP OSS provides an environment in which users can review extracted information before it is exported.
The integrated web UI allows users to work with source documents and extracted fields without requiring a separately developed frontend application.
The objective is to shift human effort from repetitive manual data entry towards AI-assisted information verification.
13. From Unstructured Documents to Structured Business Data
Document conversion frameworks frequently produce text, Markdown, HTML or structured representations of document content.
These formats are valuable for knowledge ingestion, content analysis, search and RAG applications.
However, many operational business workflows require a different output: a predefined set of business fields that can be transferred into spreadsheets or other applications.
For example, a reviewed invoice extraction result may be represented as:
invoice_number,supplier_name,currency,net_amount,tax_amount,total_amount INV-2026-0042,ABC INDUSTRIES LTD,EUR,1250.00,250.00,1500.00 The open-source edition of elDoc IDP provides structured CSV export through its web interface.
The architectural objective is not simply to digitise a document or prepare its content for retrieval.
It is to capture specific business information, make it available for review and deliver structured data for subsequent operational use.
14. Self-Hosted Document AI: MongoDB, Local OCR and Local LLMs
An increasingly important requirement for document processing applications is the ability to control where sensitive information is processed.
Financial statements, contracts, insurance documentation and supporting business records may contain commercially sensitive or personally identifiable information.
The combination of self-hosted application services, locally deployed OCR, MongoDB and compatible local AI models provides an architectural basis for reducing external data processing dependencies.
This deployment model can provide organisations with greater control over document storage, recognition infrastructure, AI inference endpoints, database connectivity and network boundaries.
However, self-hosting alone does not guarantee that all document information remains within the organisation's infrastructure.
If an external AI provider is configured, document information may be transmitted to that provider.
MongoDB security considerations
| Security consideration | Deployment objective |
|---|---|
| Database authentication | Restrict unauthorised database access |
| TLS | Protect data in transit |
| Network isolation | Limit database and AI endpoint exposure |
| Credential management | Protect application and database secrets |
| Storage encryption | Protect sensitive information at rest |
| Database backups | Support recovery and operational continuity |
| Infrastructure monitoring | Identify operational and security issues |
| Dependency management | Address vulnerabilities |
| AI endpoint security | Protect document information during inference |
These controls represent deployment responsibilities rather than automatic security guarantees provided by the application.
Conclusion: Orchestration Is the Missing Layer in Many Document AI Implementations
MongoDB, PaddleOCR, Tesseract, Docling, LangChain4j and modern Generative AI models provide powerful technological capabilities.
However, practical document automation requires more than deploying these technologies independently.
The real engineering challenge lies in bringing document ingestion, recognition, semantic understanding, database persistence, application services, human interaction and structured output together within a coherent processing architecture.
elDoc IDP Open Source demonstrates how MongoDB, configurable OCR engines, Java application services and Generative AI can be combined into an integrated, self-hosted AI Document Processing application.
Its distinguishing characteristic is not the invention of another OCR algorithm, document parser or foundation model.
It is the orchestration of established technologies into a database-backed application that supports the complete journey from unstructured documents to reviewed, business-ready data.
For developers interested in building practical Generative AI applications, the project provides an opportunity to explore how traditional software engineering, document-oriented database architectures and modern AI technologies can work together.
Fork it. Explore the MongoDB architecture. Experiment with PaddleOCR and different LLMs. Improve the processing pipeline. Contribute back to the community.
elDocAI / elDoc-idp-oss
elDoc IDP OSS is an open-source, AI-powered Intelligent Document Processing platform featuring OCR, document classification, structured data extraction, LLM integration, human-in-the-loop validation, and CSV export for PDFs and scanned documents.
elDoc IDP OSS
Turn documents into structured data with AI and human review.
elDoc IDP OSS is the open-source edition of elDoc's AI-powered intelligent document processing system, offering a focused set of core features. Ingest documents, use AI to understand and classify them, extract structured data, and let people validate the results in a web UI before exporting them.
Try it with your own PDFs and scanned images: upload → understand → extract → review → export CSV.
Application Screenshots
Explore the elDoc IDP user interface. Click any screenshot to view it in full resolution.
Features
- Document ingestion: upload documents through the web UI.
- OCR and image processing: recognize text and prepare scanned documents for processing.
- PDF and image support: process machine-generated and scanned PDFs, multiple image formats, and multipage TIFFs.
- AI-assisted understanding: classify documents, extract fields, and validate results with AI.
- Human in the loop: review and validate…
Technical References
- elDoc IDP Open Source — GitHub repository
- elDoc IDP OSS — Application configuration
- MongoDB Documentation
- PaddleOCR — GitHub repository
- Docling — GitHub repository
- Tesseract OCR
- LangChain4j Documentation
- Apache PDFBox
- OpenCV
- Payara Micro
Licensing clarification: elDoc IDP OSS is free, open-source software distributed under the GNU Affero General Public License v3.0 (AGPL-3.0-only). MongoDB Community Server is a separately licensed infrastructure component distributed under the Server Side Public License (SSPL), which is not an OSI-approved open-source licence. The open-source licence of elDoc IDP OSS does not extend to MongoDB or other third-party dependencies. For MongoDB-specific licensing terms, usage conditions and obligations, refer to the official MongoDB Licensing FAQ and the Server Side Public License (SSPL). All other third-party components remain subject to their respective licences.






















