How templatedop/pli-issue works
Purpose and Entry Points
Go microservice for end-to-end India Post PLI/RPLI policy issuance: quote calculation, proposal capture, underwriting/QC/approval, issuance, documents, Aadhaar instant issuance, and FLC cancellation. Process entry is main.go; dependency assembly and server/Temporal worker registration are in bootstrap/bootstrapper.go. The HTTP contract is documented at nbf/swagger/policy_issue_swagger.yaml.
HTTP Application Boundary
N-API handlers expose versioned REST endpoints and convert validated request DTOs into domain/repository calls or Temporal signals. Major API surfaces are proposal/approval/policy (handler/proposal.go, handler/approval.go, handler/policy.go), quote/calculation (handler/quote.go, handler/calculation.go), and document/Aadhaar flows (handler/document.go, handler/aadhaar.go). Responses are separated under handler/response/; request models reside in handler/request.go.
Domain Lifecycle and Rules
The domain layer represents policy-issuance concepts and enforces core state transitions independently of infrastructure. core/domain/proposal.go defines proposal status/state-machine behavior; core/domain/quote.go and core/domain/calculation.go support rating and premium-related data; core/domain/document.go and core/domain/aadhaar.go model supporting lifecycle entities. Proposal progression is phase-oriented: indexing/data entry → QC → optional medical → approval → issuance/FLC.
Persistence and Phase Separation
PostgreSQL is the system of record, accessed through pgx, N-API DB, and Squirrel-backed repositories. Persistence implementations are grouped by aggregate: repo/postgres/proposal_repository.go, repo/postgres/quote_repository.go, and repo/postgres/document_repository.go; Aadhaar, products, medical fees, doctors, and batches have dedicated repositories. Schema migrations establish the phase-specific proposal tables and audit/configuration data in db/migrations/001_policy_issue_schema.sql, with later evolution in db/migrations/002_add_document_date.sql through db/migrations/005_add_aea_withdrawal_dates_to_proposal_issuance.sql.
Standard Issuance Workflow
Temporal owns long-running orchestration in workflows/policy_issuance_workflow.go. It invokes activities for validation, eligibility, premium persistence, routing, policy-number generation, issuance, bond generation, and notification, principally from workflows/activities/proposal_activities.go. QC, medical, approver, and resubmission decisions cross the HTTP/workflow boundary as Temporal signals, allowing workflows to wait for human actions while repositories persist durable status changes.
Instant and Operational Flows
Aadhaar-based instant issuance is separately orchestrated by workflows/instant_issuance_workflow.go, using workflows/activities/aadhaar_activities.go; ineligible cases fall back to standard issuance. Additional Temporal processes cover doctor handling and reconciliation: workflows/doctor_workflows.go and workflows/pm_reconciliation_workflow.go. Bulk ingestion is handled at the API/repository boundary by handler/bulk.go and repo/postgres/bulk_upload_repository.go.
Runtime, Infrastructure, and Integrations
The service runs on Go with Uber FX DI, N-API HTTP/config/logging libraries, PostgreSQL 15+, and a Temporal server/task queue. Runtime settings are supplied through configs/config.yaml and configs/config.dev.yaml. The architecture anticipates external customer, KYC, billing/payment, document storage, and notification services; explicit document transfer request validators reference MinIO operations, while workflow activities are the intended integration boundary.
Main entry points: policy_issue_swagger.yaml REST contract · proposal.go Proposal, approval & policy APIs · instant_issuance_workflow.go Aadhaar instant issuance · policy_issuance_workflow.go Standard issuance
Components 20
Runtime
- Service entrypoint
main.go - Bootstrap & registration · Assembles dependencies and registers HTTP server and Temporal workers.
bootstrap/bootstrapper.go
HTTP API
- REST contract
nbf/swagger/policy_issue_swagger.yaml - Proposal, approval & policy APIs
handler/proposal.go - Quote & calculation APIs
handler/quote.go - Document & Aadhaar APIs
handler/document.go - Bulk ingestion API
handler/bulk.go
Domain & Persistence
- Proposal lifecycle · Controls phase progression from indexing through issuance or FLC.
core/domain/proposal.go - Quote & premium rules
core/domain/quote.go - Proposal persistence · Persists proposal phase state and durable workflow decisions.
repo/postgres/proposal_repository.go - Quote persistence
repo/postgres/quote_repository.go - Document persistence
repo/postgres/document_repository.go - Bulk upload persistence
repo/postgres/bulk_upload_repository.go
Temporal Workflows
- Standard issuance · Orchestrates validation through issuance, bond generation, and notification.
workflows/policy_issuance_workflow.go - Issuance activities · Performs validation, eligibility, routing, premium persistence, and issuance operations.
workflows/activities/proposal_activities.go - Aadhaar instant issuance · Falls back to standard issuance for ineligible cases.
workflows/instant_issuance_workflow.go - Aadhaar activities
workflows/activities/aadhaar_activities.go
Infrastructure & Integrations
- PostgreSQL system of record · Schema includes phase-specific proposal tables, audit, and configuration data.
db/migrations/001_policy_issue_schema.sql - Temporal server & task queue
- Partner services · Customer, KYC, billing, document storage, and notification systems.
Connections 26
- Service entrypoint → Bootstrap & registration: starts
- Bootstrap & registration → REST contract: serves contract
- Bootstrap & registration → Temporal server & task queue: registers workers
- REST contract → Proposal, approval & policy APIs: documents
- REST contract → Quote & calculation APIs: documents
- REST contract → Document & Aadhaar APIs: documents
- Proposal, approval & policy APIs → Proposal lifecycle: applies lifecycle rules
- Proposal, approval & policy APIs → Proposal persistence: persists state
- Proposal, approval & policy APIs → Standard issuance: starts and signals · Human QC, medical, approval, and resubmission decisions are Temporal signals.
- Quote & calculation APIs → Quote & premium rules: calculates
- Quote & calculation APIs → Quote persistence: stores quotes
- Document & Aadhaar APIs → Document persistence: stores metadata
- Document & Aadhaar APIs → Aadhaar instant issuance: starts
- Bulk ingestion API → Bulk upload persistence: ingests
- Proposal persistence → PostgreSQL system of record: reads and writes
- Quote persistence → PostgreSQL system of record: reads and writes
- Document persistence → PostgreSQL system of record: reads and writes
- Bulk upload persistence → PostgreSQL system of record: reads and writes
- Standard issuance → Temporal server & task queue: executes on
- Standard issuance → Issuance activities: invokes
- Issuance activities → Proposal persistence: updates phases
- Issuance activities → Partner services: integrates
- Aadhaar instant issuance → Temporal server & task queue: executes on
- Aadhaar instant issuance → Aadhaar activities: invokes
- Aadhaar instant issuance → Standard issuance: falls back to
- Aadhaar activities → Partner services: uses KYC services