Skip to content

Repository files navigation

Document Processing API

This project is a backend service for populating PDF forms from structured application data. It uses a ports-and-adapters design so business rules stay independent from infrastructure integrations.

What This Service Handles

  • Selects required forms based on case inputs (bank, product, and profile type)
  • Loads field mapping rules from YAML schemas
  • Pulls values from multiple data providers with priority fallback
  • Writes resolved values into PDF fields
  • Returns a per-form execution result (filled, flagged, or error)

High-Level Design

The codebase follows hexagonal architecture:

  • domain/: core models, ports, and business services
  • application/: workflow orchestration (ProcessingPipeline)
  • mapping/: schema loader, resolvers, strategy implementations
  • infrastructure/: concrete adapters (PDF reader/writer)
  • stubs/: local test doubles for running without external systems
  • config/: form registry and environment-related settings

Data Resolution Priority

When resolving values for form fields, sources are checked in this order:

  1. Info sheet source
  2. Document source
  3. CRM source

For each field key, the first non-null value wins.

Run Locally

Requirements

  • Python 3.11+

Install dependencies

pip install -r requirements.txt

Run pipeline with stub data

This executes a sample case using local in-memory data sources.

python run.py

Run API server

uvicorn main:app --reload

API Example

Request

POST /manifest
Content-Type: application/json

{
  "case_id": "CASE-001",
  "applicant_id": "APP-001",
  "bank": "dib",
  "product": "conventional",
  "profile_type": "salaried_resident"
}

Response (shape)

{
  "case_id": "CASE-001",
  "total_forms": 2,
  "filled": 2,
  "flagged": 0,
  "errors": 0,
  "forms": [
    {
      "form_id": "App Form",
      "status": "filled",
      "pdf_bytes": "..."
    }
  ]
}

Extending Mappings

To add support for additional form variants:

  1. Add schema file in mapping/schemas/{bank}_{product}.yaml
  2. Implement or update strategy in mapping/strategies/
  3. Register strategy in dependency wiring
  4. Update config/form_registry.yaml with required forms

Stack

  • FastAPI
  • Pydantic
  • PyPDFForm
  • PyYAML

About

FastAPI service that auto-fills PDF forms from structured case data using configurable YAML mappings and a clean hexagonal architecture.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages