How hammad-asif/gcp-insightdocs works
Purpose and Scope
GCP InsightDocs is a Python backend for extracting structured key/value data from PDF and image documents. It is intended to support a React document viewer/sidebar client, though no frontend source is present. The implementation combines Google Cloud Document AI with OCR and document-specific post-processing.
Primary Entry Points
• BackEnd-main/BackEnd-main/main.py is the likely Flask application/API entry point and orchestration layer.
• BackEnd-main/BackEnd-main/OCR.py provides OCR-oriented extraction processing.
• BackEnd-main/BackEnd-main/search.py likely supports lookup, normalization, or extraction-result querying.
• BackEnd-main/BackEnd-main/warehouse.py and BackEnd-main/BackEnd-main/warehouse sir.py appear to implement separate document-format extraction paths.
Document Intake and Source Assets
Input documents are represented by checked-in PDFs: BackEnd-main/BackEnd-main/4.pdf, BackEnd-main/BackEnd-main/32.pdf, and BackEnd-main/BackEnd-main/53.pdf. The backend boundary is a supplied PDF/image file; it must preserve enough source context for a client-side document viewer while returning extracted fields and related details.
Extraction Pipeline
1. Flask receives or selects a document in BackEnd-main/BackEnd-main/main.py.
2. Cloud/OCR processing is invoked through logic in BackEnd-main/BackEnd-main/OCR.py.
3. Raw recognized text/entities are interpreted by document-specific modules, notably BackEnd-main/BackEnd-main/warehouse.py and BackEnd-main/BackEnd-main/warehouse sir.py.
4. Search or matching logic in BackEnd-main/BackEnd-main/search.py helps map recognized content to expected fields.
5. The service emits structured extraction output, exemplified by BackEnd-main/BackEnd-main/testresult.json.
Schema and Result Contract
BackEnd-main/BackEnd-main/schema.json is the central structured-data contract for extracted results or expected fields. BackEnd-main/BackEnd-main/test.json and BackEnd-main/BackEnd-main/testresult.json provide sample input/output representations. This schema boundary separates cloud OCR/DocAI’s raw response from the UI-facing key/value summary.
Runtime, Infrastructure, and External Services
The backend runs on Python with dependencies defined in BackEnd-main/BackEnd-main/requirements.txt, using Flask as the HTTP runtime. Google Cloud Document AI is the material external extraction service; OCR is a complementary recognition path. BackEnd-main/BackEnd-main/key.json is a Google Cloud credential artifact and should be treated as secret infrastructure configuration, not application data.
Architectural Considerations
The system is format-sensitive: the warehouse-specific modules indicate extraction behavior is coupled to particular document layouts. Keep API orchestration in main.py, cloud/OCR integration in OCR.py, and layout/business parsing in the warehouse modules. New document types should add isolated parsers and schema mappings rather than expanding the Flask route layer or hard-coding field logic into cloud-service calls.
Main entry points: main.py Flask orchestration · OCR.py OCR processing · search.py Field matching · schema.json Extraction schema
Components 15
Backend API
- Flask orchestration · Receives or selects documents and coordinates extraction.
BackEnd-main/BackEnd-main/main.py - Structured extraction result · UI-facing key/value summary with related details.
BackEnd-main/BackEnd-main/testresult.json - Python dependencies · Defines Flask and backend runtime dependencies.
BackEnd-main/BackEnd-main/requirements.txt
Extraction Pipeline
- OCR processing · Invokes OCR-oriented recognition processing.
BackEnd-main/BackEnd-main/OCR.py - Recognized text & entities
- Warehouse parser · Document-format-specific field interpretation.
BackEnd-main/BackEnd-main/warehouse.py - Warehouse SIR parser · Separate format-sensitive extraction path.
BackEnd-main/BackEnd-main/warehouse sir.py - Field matching · Maps recognized content to expected fields.
BackEnd-main/BackEnd-main/search.py
Contracts & Samples
- Checked-in PDF sample
BackEnd-main/BackEnd-main/4.pdf - Extraction schema · Separates raw recognition from UI-facing key/value results.
BackEnd-main/BackEnd-main/schema.json - Sample input representation
BackEnd-main/BackEnd-main/test.json
External Boundaries
- Document viewer client · External React-oriented consumer; source is not present.
- PDF or image input · Source context must remain available to the viewer client.
- Google Cloud Document AI · Material external document-recognition service.
- GCP credentials · Credential artifact for cloud-service access.
BackEnd-main/BackEnd-main/key.json
Connections 17
- Document viewer client → Flask orchestration: submits document / reads result
- Checked-in PDF sample → PDF or image input: representative input
- PDF or image input → Flask orchestration: received or selected
- Flask orchestration → OCR processing: starts extraction
- OCR processing → Google Cloud Document AI: requests recognition
- GCP credentials → Google Cloud Document AI: authenticates access
- Google Cloud Document AI → Recognized text & entities: returns text and entities
- OCR processing → Recognized text & entities: complementary OCR output
- Recognized text & entities → Warehouse parser: warehouse layout path
- Recognized text & entities → Warehouse SIR parser: SIR layout path
- Warehouse parser → Field matching: parsed candidate fields
- Warehouse SIR parser → Field matching: parsed candidate fields
- Field matching → Extraction schema: maps fields to contract
- Extraction schema → Structured extraction result: shapes structured output
- Flask orchestration → Structured extraction result: emits response
- Sample input representation → Extraction schema: illustrates expected data
- Python dependencies → Flask orchestration: provides Flask runtime