How cginside-rookies/hyundaihs works
Purpose and service boundaries
HyundaiHS Document QA is an internal scanned-document verification system. It separates:
• A document-processing orchestrator: ingestion, page understanding, OCR/layout, ROI/extraction, persistence, review integration.
• A workflow-validation API: rule-driven business validation, currently including WF1 and WF2.
• Operator/product-facing static frontends that consume these APIs.
Primary service entry points are main.py, orchestrator/api/server.py, orchestrator/server.py, and workflow_api/main.py.
Ingestion, job execution, and runtime state
The orchestrator accepts local documents and untrusted ZIP uploads, normalizes files into upload workspaces, creates jobs, and exposes job status/SSE updates. ZIP handling is a security boundary: archive contents are validated and flattened before pipeline execution.
Core paths:
• orchestrator/uploads.py
• orchestrator/runtime/app.py
• orchestrator/workflow_document_normalizer.py
• orchestrator/api/server.py
Run artifacts and canonical job/run state are persisted through the storage layer rather than being owned by the UI.
Document intelligence pipeline
Processing is staged from PDF/image decoding through per-page classification and analysis, layout/OCR, ROI generation, optional field extraction, and reconciliation. This is the central control flow: normalized document → pages/artifacts → candidate fields/evidence → canonical result.
Core paths:
• orchestrator/core/page_analysis.py
• orchestrator/core/layout_artifacts.py
• orchestrator/core/roi_strategy.py
• orchestrator/core/extraction.py
• orchestrator/core/reconcile.py
PaddleX provides layout/OCR integration, while image/PDF operations are isolated behind adapters, allowing pipeline logic to remain independent of concrete OCR/image providers.
Domain-pack policy boundary
Document-specific behavior is loaded as a domain pack rather than embedded in generic orchestration. The Hyundai Home pack defines document types, schemas, ROI behavior, canonicalization policy, cross-confirmation, and prompt assets. This is the main extension boundary for adding document families or changing extraction semantics.
Core paths:
• orchestrator/domain/loader.py
• domain_packs/hyundai_home/domain.py
• domain_packs/hyundai_home/schemas.py
• domain_packs/hyundai_home/canonical_policy.py
LLM-facing tasks and prompt rendering are kept separate from domain prompt content.
Persistence and external integrations
Postgres is the durable system of record for orchestrator results and Label Studio state. The orchestrator integrates with Label Studio to export review tasks and synchronize annotations. It also uses OpenAI-compatible/Gemma client paths for model-backed analysis or extraction and PaddleX for document vision.
Core paths:
• orchestrator/storage/store.py
• orchestrator/integrations/label_studio.py
• orchestrator/adapters/paddlex.py
• orchestrator/adapters/openai_compatible.py
• orchestrator/clients/gemma.py
Host runtime additionally requires Poppler (pdftoppm) for PDF rendering; upload, temporary, and output directories are environment-configured.
Workflow validation API
workflow_api is an independently deployable FastAPI service for rule evaluation over document/extraction payloads. WF1 encapsulates address-oriented rules; WF2 resolves requirements and evaluates conditions, ingredient evidence, labeling, consumption, and coverage against JSON rule packs. This service is a business-policy boundary and should not depend on OCR/layout internals.
Core paths:
• workflow_api/api.py
• workflow_api/wf1/engine.py
• workflow_api/wf2/engine.py
• workflow_api/wf2/resolver.py
• workflow_api/rule_packs/wf2_food_livestock.json
Presentation and operator review
The current interfaces are static JavaScript operator/debug clients, not server-rendered application logic. The v2 frontend supports upload, list/detail review, evidence, checks, labeling, document selection, and status views; it calls orchestrator APIs and can direct operators into Label Studio workflows. A build step produces the deployable dashboard artifact from source templates.
Core paths:
• frontend-v2/index.html
• frontend-v2/assets/detail/main.js
• frontend/src/dashboard/controller.js
• scripts/build_frontend.py
Main entry points: app.py Job Runtime · server.py Orchestrator API · layout_artifacts.py Layout & OCR · extraction.py ROI & Extraction
Components 21
Document Orchestrator
Ingestion, processing, review integration, and durable job state.
- Orchestrator API · Creates jobs and exposes status and SSE updates.
orchestrator/api/server.py - Upload Normalization · Validates ZIPs and prepares flattened workspaces.
orchestrator/uploads.py - Job Runtime · Coordinates job lifecycle and pipeline execution.
orchestrator/runtime/app.py - Document Normalizer · Normalizes workflow document inputs.
orchestrator/workflow_document_normalizer.py - Page Analysis · Decodes documents and classifies pages into artifacts.
orchestrator/core/page_analysis.py - Layout & OCR · Produces layout and text artifacts per page.
orchestrator/core/layout_artifacts.py - ROI & Extraction · Generates regions and candidate fields with evidence.
orchestrator/core/extraction.py - Reconciliation · Builds canonical document results from candidates.
orchestrator/core/reconcile.py - Postgres Store · Durable record for jobs, artifacts, results, and review state.
orchestrator/storage/store.py - Label Studio · Exports review tasks and synchronizes annotations.
orchestrator/integrations/label_studio.py - PaddleX · Concrete layout and OCR provider.
orchestrator/adapters/paddlex.py - OpenAI/Gemma Clients · Model-backed analysis and extraction integration.
orchestrator/adapters/openai_compatible.py
Domain Pack
Document-family policy and extraction semantics.
- Domain Loader · Loads document-specific packs into generic orchestration.
orchestrator/domain/loader.py - Hyundai Home Pack · Defines document types, schemas, ROI behavior, and prompts.
domain_packs/hyundai_home/domain.py - Canonical Policy · Applies canonicalization and cross-confirmation rules.
domain_packs/hyundai_home/canonical_policy.py
Workflow Validation API
Independent business-rule evaluation service.
- Workflow API · Evaluates business rules over document and extraction payloads.
workflow_api/api.py - WF1 Address Rules · Address-oriented validation rules.
workflow_api/wf1/engine.py - WF2 Rule Engine · Resolves requirements and evaluates evidence and coverage.
workflow_api/wf2/engine.py - WF2 Food/Livestock Pack
workflow_api/rule_packs/wf2_food_livestock.json
Operator Interfaces
Static upload and review clients.
- v2 Operator Dashboard · Upload, review, evidence, checks, and Label Studio navigation.
frontend-v2/index.html - Dashboard Build · Builds the deployable dashboard from source templates.
scripts/build_frontend.py
Connections 23
- v2 Operator Dashboard → Orchestrator API: uploads and reviews
- v2 Operator Dashboard → Workflow API: requests validation
- Dashboard Build → v2 Operator Dashboard: produces artifact
- Orchestrator API → Upload Normalization: accepts documents
- Upload Normalization → Document Normalizer: validated workspace
- Document Normalizer → Job Runtime: normalized input
- Orchestrator API → Job Runtime: creates jobs
- Job Runtime → Page Analysis: executes pipeline
- Page Analysis → Layout & OCR: page artifacts
- Layout & OCR → ROI & Extraction: layout and OCR
- ROI & Extraction → Reconciliation: candidate fields
- Reconciliation → Postgres Store: canonical results
- Job Runtime → Postgres Store: job and run state
- Job Runtime → Domain Loader: loads policy
- Domain Loader → Hyundai Home Pack: loads
- Hyundai Home Pack → Canonical Policy: defines
- Canonical Policy → Reconciliation: canonicalization rules
- Layout & OCR → PaddleX: uses
- ROI & Extraction → OpenAI/Gemma Clients: optional model tasks
- Postgres Store → Label Studio: review task sync
- Workflow API → WF1 Address Rules: routes WF1
- Workflow API → WF2 Rule Engine: routes WF2
- WF2 Rule Engine → WF2 Food/Livestock Pack: evaluates