Document Splitter Service:-Architecture Design
1. Background & Problem Statement
Once the classifier service has identified the document types present in an uploaded file, the platform must logically separate those document segments so they can be routed to the correct extractor independently. Today this responsibility sits inside ClassifyFileTool.ts in Paperboy — classification and splitting are tightly coupled in a service. This creates several challenges:
- The split logic cannot be scaled or replaced independently
- Failures in splitting silently swallow errors and leave the parent file in a partial state
2. Current State (As-Is) in Paperboy
2.1 Where Splitting Lives Today
2.2 Current Split Data Flow
2.3 Classification JSON Schema (Current Output)
2.4 FileData Table (Split Records)
3. Challenges with the Current Architecture
4. Recommended Architecture
4.1 Design Principles
- Single Responsibility — The Document Splitter receives a classification result and emits addressable split documents. It does not classify.
- Contract-Driven — Input is a well-defined
FileClassifiedEventmessage. Output is aFileSplitEventmessage and a split manifest persisted to blob storage. - Fault Isolated — Splitting failures must not corrupt the parent file record; errors are surfaced explicitly via a
ProblemEventpublished to theproblemtopic. - Independently Scalable — The splitter is callable independently of classification, enabling re-split on demand.
4.2 Proposed Service Boundary
Classification and Document Splitter become independent with a well-defined handoff.
4.3 New Service: fluxx-document-splitter
Location: https://github.com/CLADevOps/fluxx-document-splitter
Consumed message (FileClassifiedEvent) — published by classifier:
Processing steps (ClassifiedFileHandler):
- Download and parse the classification JSON from blob using
classificationResultURL - If
is_multi_form === falseorforms.length <= 1, exit gracefully — no split needed - Download the original PDF from blob using
internalURL - Build a timestamp prefix (
YYYYMMDDHHmmss) and derivebaseName/extfrom the filename - For each form in
forms[]:- Non-contiguous
page_ranges: create one split PDF per segment, named{timestamp}_{baseName}_{formType}_Part{n}.pdf— uploaded to{clientApplicationID}/files_splitted/ - Contiguous
page_start/page_end: create one split PDF named{timestamp}_{baseName}_{formType}.pdf— uploaded to{clientApplicationID}/files_splitted/ - Forms with neither field are logged as a warning and skipped
- Non-contiguous
- Build and upload a split manifest JSON to
{clientApplicationID}/splits/{timestamp}_{baseName}_splitResult.json - Publish a
FileSplitEventto thesplit-filetopic - On any error: publish a
ProblemEventto theproblemtopic and re-throw
Note: The current implementation does not write to any database. There are no
FileDatarow inserts or status updates. All output is blob-resident (split PDFs + manifest) and message-resident (FileSplitEvent).
Published message (FileSplitEvent) — consumed by downstream (e.g. extractor):
Split manifest (blob artifact):
Error event (ProblemEvent) — published on failure:
4.4 Updated fluxx-classifier
fluxx-classifier is simplified to classification only:
- Removes all split logic
- Sets
FileData.status = 'classified'on success - Returns the classification result; the agentic loop decides whether to call
SplitDocumentToolnext
This makes the agentic loop’s workflow explicit:
4.5 Service Bus Topology
The service uses Azure Service Bus for all inter-service communication. Topic and subscription names are sourced from Azure App Configuration at runtime.
Retry behaviour:
MaxDeliveryCount: 3on all subscriptions- Success path: message is
completedafter the handler returns - Failure path: message is
abandoned, making it eligible for retry up to the max delivery count
4.6 Blob Storage Layout
All split artifacts are written to the files container under paths scoped to clientApplicationID:
{timestamp}format:YYYYMMDDHHmmss
{FormType}is sanitized to[a-zA-Z0-9_-]characters only
4.7 End-to-End Data Flow (To-Be)
5. Component Diagram
7. Open Questions
8. Risks
9. References Repository PaperBoy
https://github.com/MWChapelCLA/Paperboy