How thegondrol/nilam-ocr-npwp works
This repository implements a five-service Indonesian NPWP OCR product. A client submits a document to the orchestrator, which validates it, asks guardrails for a verdict, and starts OCR for accepted documents. The asynchronous stages then perform OCR, structure extracted text into NPWP fields, and score field confidence; the orchestrator polls stage status and returns the outcome. The shared library supplies web conventions and the background pipeline, persistence, callbacks, and handoffs. README and sampled entry points support these relationships; several service internals were not sampled, so uncertain implementation-level links are omitted.
Main entry points: app.py Web service toolkit · stage.py Stage pipeline · extract_service.py Extract service · ekstraksi_service.py OCR service
Components 24
Request orchestration
- Extract API
services/orchestrator/app/api/extract_ocr.py - Extract service
services/orchestrator/app/services/extract_service.py - Guardrails client
services/orchestrator/app/clients/guardrails.py - Ekstraksi client
services/orchestrator/app/clients/ekstraksi.py - Stage status clients
services/orchestrator/app/clients/stages.py - Pipeline waiter
services/orchestrator/app/services/pipeline_waiter.py
Document validation
- Guardrails API
services/guardrails/app/api/guardrails.py - Page and document verdict
services/guardrails/app/services/guardrails_service.py - Page classifier
services/guardrails/app/ml/efficientnet.py
OCR stages
- OCR job API
services/ekstraksi/app/api/jobs.py - OCR service
services/ekstraksi/app/services/ekstraksi_service.py - OCR engine
services/ekstraksi/app/ml/paddle.py - Structuring job API
services/structuring/app/api/jobs.py - Structuring service
services/structuring/app/services/structuring_service.py - NPWP rules
services/structuring/app/ml/npwp_rules.py - Scoring job API
services/scoring/app/api/jobs.py - Scoring service
services/scoring/app/services/scoring_service.py - Trust model
services/scoring/app/ml/trust_model.py
Shared runtime
- Stage pipeline
libs/ocr_common/ocr_common/pipeline/stage.py - Callbacks and outbox
libs/ocr_common/ocr_common/pipeline/callbacks.py - Web service toolkit
libs/ocr_common/ocr_common/web/app.py
Pipeline state
- Job and result store
libs/ocr_common/ocr_common/pipeline/repository_sql.py
Other components
- API caller
- Central orchestrator
Connections 30
- API caller → Extract API: submits document
- Extract API → Extract service: handles request
- Extract service → Guardrails client: requests verdict
- Guardrails client → Guardrails API: checks document
- Guardrails API → Page and document verdict: runs check
- Page and document verdict → Page classifier: classifies pages
- Extract service → Ekstraksi client: starts accepted job
- Ekstraksi client → OCR job API: submits OCR job
- Extract service → Pipeline waiter: waits for stages
- Pipeline waiter → Stage status clients: polls status
- OCR job API → OCR service: dispatches job
- OCR service → OCR engine: recognizes text
- OCR service → Stage pipeline: runs background stage
- Stage pipeline → Job and result store: stores stage state
- Stage pipeline → Callbacks and outbox: dispatches updates
- OCR service → Structuring job API: hands off OCR result
- Structuring job API → Structuring service: dispatches job
- Structuring service → NPWP rules: structures fields
- Structuring service → Stage pipeline: runs background stage
- Structuring service → Scoring job API: hands off fields
- Scoring job API → Scoring service: dispatches job
- Scoring service → Trust model: scores confidence
- Scoring service → Stage pipeline: runs background stage
- Callbacks and outbox → Central orchestrator: sends stage callback
- Central orchestrator → Extract API: calls entry point
- Web service toolkit → Extract API: provides web runtime
- Web service toolkit → Guardrails API: provides web runtime
- Web service toolkit → OCR job API: provides web runtime
- Web service toolkit → Structuring job API: provides web runtime
- Web service toolkit → Scoring job API: provides web runtime