270 lines
13 KiB
Markdown
270 lines
13 KiB
Markdown
# Document Management System
|
|
|
|
## 1. Introduction and Objectives
|
|
|
|
The goal is to develop a lean, server-based document management system focused on implementing an interface first rather than a frontend. Initial usage will be entirely programmatic via an API; a frontend is intentionally scheduled for a later expansion phase.
|
|
|
|
The system shall process PDF documents, capture their contents via OCR, provide full-text search capabilities, and enable LLM-supported content enrichment. Additionally, automated file import from a monitored folder shall be supported.
|
|
|
|
Key quality objectives:
|
|
- Simple and lean solution.
|
|
- Minimal frameworks and external systems; external components only where they provide clear added value.
|
|
- Testable architecture with comprehensive unit test support.
|
|
- Traceability and consistency of state changes through Event Sourcing.
|
|
- Clear, maintainable, and extensible structure.
|
|
- Simple installation, operation, and automation.
|
|
- Reliable import and consistent processing.
|
|
- Reliable searchability of documents.
|
|
|
|
## 2. Constraints and Boundary Conditions
|
|
|
|
- The implementation language is Go.
|
|
- The architecture shall be described in a technology-agnostic way to avoid unnecessary constraints on specific tools or products.
|
|
- The system shall initially be usable without a frontend; access is provided via the API.
|
|
- Automation for build, test, and deployment shall consider the existing Gitea and Actions environment.
|
|
- Documentation shall follow the arc42 structure.
|
|
- Unit tests shall be provided for all essential architectural components and behaviors.
|
|
|
|
## 3. Context and Scope
|
|
|
|
### Business Context
|
|
|
|
The system manages incoming documents, particularly PDF files. Documents can be actively submitted via the API or automatically ingested from a defined import folder. Later, it shall also be possible to send documents via email to the system for import.
|
|
|
|
After import, documents are processed, analyzed, made searchable, and transferred to a final storage structure. Processing also includes enrichment with additional information from LLM-supported analysis.
|
|
|
|
### Technical Context
|
|
|
|
External or adjacent systems and interfaces:
|
|
- File system for import folder, temporary processing, and final storage structure.
|
|
- API clients for using the system interface.
|
|
- LLM integration for semantic analysis, tagging, or similar content processing.
|
|
- OCR processing for text recognition from documents.
|
|
- Automation environment with Gitea and Actions for build, test, and deployment processes.
|
|
|
|
## 4. Solution Strategy
|
|
|
|
The solution shall be implemented incrementally and with minimal complexity:
|
|
|
|
1. First, the backend with a clear API shall be implemented.
|
|
2. Then import, parsing, OCR, search indexing, and event processing shall be integrated.
|
|
3. A frontend is intentionally deferred and considered only after stabilization of the interface.
|
|
|
|
Core principles of the solution:
|
|
- API-first approach.
|
|
- Lean, modularly designed components.
|
|
- Clear separation of domain logic, infrastructure, and application logic.
|
|
- Event Sourcing for traceability of changes and support of data consistency.
|
|
- Testability as an architectural guiding principle, not an afterthought.
|
|
- Automated file-based import as an integral part of the solution.
|
|
|
|
## 5. Building Block View
|
|
|
|
### 5.1 Overview of Main Components
|
|
|
|
The system consists of the following central building blocks:
|
|
|
|
- API Layer
|
|
- Application Logic
|
|
- Document Management
|
|
- Import and Watcher Component
|
|
- Processing Pipeline
|
|
- OCR Component
|
|
- LLM Integration Component
|
|
- Full-Text Search Component
|
|
- Event and Consistency Component
|
|
- Storage and Structuring Logic
|
|
- Test Layer
|
|
|
|
### 5.2 Building Block Descriptions
|
|
|
|
#### API Layer
|
|
Provides the interface through which documents can be imported, searched, queried, and managed. Since the frontend is not initially implemented, the API is the primary entry point of the system.
|
|
|
|
#### Application Logic
|
|
Coordinates use cases such as import, processing, search, relocation, and retrieval. This layer encapsulates workflow logic and shall be independently testable from infrastructure components.
|
|
|
|
#### Document Management
|
|
Manages metadata, status, identities, and the business lifecycle of a document. This includes states such as newly imported, in processing, processed, archived, or failed.
|
|
|
|
#### Import and Watcher Component
|
|
Monitors a defined folder for newly deposited documents. When a document is saved there, automatic processing shall be triggered.
|
|
|
|
Additional requirements:
|
|
- Documents from the import folder are automatically detected.
|
|
- Imported files can receive a timestamp in the filename documenting the import time.
|
|
- Automatic processing starts without manual intervention.
|
|
|
|
#### Processing Pipeline
|
|
Responsible for the overall flow of a document after ingestion. This includes reading, parsing, OCR, content enrichment, search indexing, status changes, and final storage.
|
|
|
|
#### OCR Component
|
|
Extracts text from imported PDF documents where text is not directly or fully machine-readable. OCR results serve as a foundation for search and further analysis.
|
|
|
|
#### LLM Integration Component
|
|
Enables content analysis of documents through an LLM. The goal is particularly semantic enrichment, such as through tagging, classification, structuring, or similar additional information.
|
|
|
|
#### Full-Text Search Component
|
|
Provides full-text search over processed document contents. This is based on extracted and potentially OCR-derived text content as well as relevant metadata.
|
|
|
|
#### Event and Consistency Component
|
|
Implements Event Sourcing at the business level. Relevant state changes in documents are recorded as events so that changes remain traceable and state can be consistently reconstructed.
|
|
|
|
Important requirements:
|
|
- No commitment to specific technologies in this documentation.
|
|
- Events shall be expressed in business-understandable terms.
|
|
- The sequence of events shall support auditability and recoverability.
|
|
|
|
#### Storage and Structuring Logic
|
|
Processed documents are transferred from the import context to the final storage structure. The following requirements shall be considered:
|
|
|
|
- Processed documents shall not remain in the import folder.
|
|
- Processed documents shall be transferred to a processed target area.
|
|
- The final folder structure shall reflect actual storage.
|
|
- Imported and processed files shall be moved to year-based folders.
|
|
- The filename can be supplemented with an import timestamp.
|
|
|
|
#### Test Layer
|
|
All relevant layers and components shall be secured through unit tests. The architecture shall be designed so that business logic remains independently testable and infrastructure dependencies are interchangeable or encapsulated.
|
|
|
|
## 6. Runtime View
|
|
|
|
### 6.1 Import via Monitored Folder
|
|
|
|
1. A document is saved in the defined import folder.
|
|
2. The watcher component detects the new document.
|
|
3. The system takes over the document for processing.
|
|
4. It is parsed and, if necessary, made textually accessible via OCR.
|
|
5. The LLM enriches the document semantically.
|
|
6. Contents are indexed for full-text search.
|
|
7. Business-relevant steps are captured as events.
|
|
8. The document is moved to the final storage structure.
|
|
9. The file is sorted into a year-based folder.
|
|
10. Optionally, the filename receives an import timestamp.
|
|
|
|
### 6.2 Import via API
|
|
|
|
1. A client submits a document via the API.
|
|
2. The system creates the document and starts processing.
|
|
3. Subsequently, the same processing flow as file-based import is followed.
|
|
4. The document is finally made searchable and archived.
|
|
|
|
### 6.3 Search
|
|
|
|
1. A client sends a search query to the API.
|
|
2. Full-text search queries indexed document contents and relevant metadata.
|
|
3. The system returns matching results.
|
|
|
|
### 6.4 Traceability of State Changes
|
|
|
|
1. Each significant action on a document generates a business event.
|
|
2. These events form the foundation for traceability and consistency.
|
|
3. The status of a document can be derived or reconstructed from recorded events.
|
|
|
|
## 7. Deployment View
|
|
|
|
The system is intended for operation on a personal or dedicated server. It shall require minimal external dependencies and be deployable in a simple operating environment.
|
|
|
|
Essential deployment view:
|
|
- Backend service for providing the API and orchestrating processing.
|
|
- Access to file system areas for import, processing, and final storage.
|
|
- Integration of required components for OCR, search, and LLM usage.
|
|
- Build, test, and deployment automation via Gitea and Actions.
|
|
|
|
## 8. Cross-Cutting Concepts
|
|
|
|
### 8.1 Testability
|
|
|
|
Testability is a central architectural principle. The architecture shall be designed so that core business logic can be tested independently of infrastructure.
|
|
|
|
Requirements:
|
|
- Unit tests for all essential modules.
|
|
- Clear interfaces between business logic and infrastructure.
|
|
- Good mocking or stubbing capability for external dependencies.
|
|
- Reproducible tests for import, processing, search indexing, and event processing.
|
|
|
|
### 8.2 Event-Orientation and Consistency
|
|
|
|
Business state consistency shall be supported through an Event Sourcing concept. Changes to documents are considered not only as current state but also as a traceable sequence of business events.
|
|
|
|
### 8.3 File Import and Document Lifecycle
|
|
|
|
Documents can be actively imported or passively ingested from a monitored folder. After successful processing, they shall be orderly transferred to the final folder structure.
|
|
|
|
Rules:
|
|
- Automatic processing when saved to the import folder.
|
|
- Marking or renaming with import timestamp is possible.
|
|
- Organization by year in the target storage.
|
|
|
|
### 8.4 Search Concept
|
|
|
|
Full-text search is an integral part of the system. It shall ensure discoverability through document contents and consider both directly readable and OCR-derived contents.
|
|
|
|
### 8.5 LLM-Supported Enrichment
|
|
|
|
LLM integration serves semantic processing of documents. This can include tagging, content structuring, classification, or similar forms of enrichment.
|
|
|
|
### 8.6 API-First
|
|
|
|
The roadmap provides for initially making the interface exclusively operationally usable. A frontend is intentionally deferred so that core functionality can be built independently and stably.
|
|
|
|
### 8.7 Documentation
|
|
|
|
Architecture and system documentation shall be maintained in an arc42-oriented form. The documentation shall clearly depict essential decisions, components, processes, risks, and quality requirements.
|
|
|
|
## 9. Architectural Decisions
|
|
|
|
- The system is initially implemented as a backend and API-centric solution.
|
|
- A frontend is part of a later expansion phase and not part of the initial roadmap.
|
|
- The solution shall intentionally be kept simple.
|
|
- Frameworks and external systems shall be used sparingly.
|
|
- Event Sourcing is considered as a business concept for traceability and consistency.
|
|
- Technological commitments to Event Sourcing mechanisms are intentionally avoided in this documentation.
|
|
- The architecture is consistently designed for testability.
|
|
- Unit tests are not optional but a binding part of the implementation.
|
|
- Full-text search is a mandatory component of the system.
|
|
- Automatic import from a monitored folder is a mandatory component of the system.
|
|
- Processed documents are transferred to a final, structured target storage.
|
|
- Final storage considers year-based folders and optionally import timestamps in filenames.
|
|
- Automation in development and deployment processes shall consider the existing Gitea/Actions environment.
|
|
|
|
## 10. Quality Requirements
|
|
|
|
Essential quality requirements are:
|
|
|
|
- Simplicity: The system shall be designed with minimal unnecessary complexity.
|
|
- Maintainability: Components shall be clearly separated and understandably structured.
|
|
- Testability: Every essential function shall be unit-testable.
|
|
- Traceability: Document changes and state transitions shall remain traceable through events.
|
|
- Consistency: States and transitions shall be robust and reconstructible.
|
|
- Automatability: Import, processing, testing, and deployment shall be automatable.
|
|
- Extensibility: A later frontend shall be able to build on the existing API and architecture.
|
|
- Searchability: Document contents shall be reliably discoverable via full-text search.
|
|
- Reliability: Automatic folder monitoring and processing shall function stably.
|
|
|
|
## 11. Risks and Technical Debt
|
|
|
|
Possible risks:
|
|
- Event Sourcing increases business and technical complexity if implemented too broadly or too early.
|
|
- OCR quality can vary depending on document quality.
|
|
- LLM-supported enrichment can yield varying results and must be understood in business context.
|
|
- Automatic file monitoring and relocation require robust error handling to avoid duplicates or inconsistent states.
|
|
- Without early testing, the risk increases that file processing, search indexing, and event flows become difficult to maintain.
|
|
|
|
Open items to be clarified later:
|
|
- Exact event model.
|
|
- Precise metadata model.
|
|
- Error handling strategy for partially failed processing.
|
|
- Detailed rules for the final folder structure.
|
|
- Search and ranking behavior of full-text search.
|
|
|
|
## 12. Glossary
|
|
|
|
- API: Application Programming Interface for using system functions.
|
|
- OCR: Optical Character Recognition; text recognition from documents or image contents.
|
|
- LLM: Large Language Model for semantic processing and enrichment of document contents.
|
|
- Event Sourcing: Business concept in which state changes are recorded as events.
|
|
- Full-Text Search: Search across the complete textual contents of documents.
|
|
- Import Folder: Monitored folder from which documents are automatically ingested.
|
|
- Year Folder: Target folder structure where processed documents are stored by year.
|
|
- Final Storage Structure: Final structured storage of processed documents. |