# templatedop/pli-issue architecture

> Architecture diagram of the GitHub repository templatedop/pli-issue, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/templatedop/pli-issue
- Repository: https://github.com/templatedop/pli-issue

## Overview

#### 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: [`nbf/swagger/policy_issue_swagger.yaml`](https://github.com/templatedop/pli-issue/blob/main/nbf/swagger/policy_issue_swagger.yaml) (REST contract), [`handler/proposal.go`](https://github.com/templatedop/pli-issue/blob/main/handler/proposal.go) (Proposal, approval & policy APIs), [`workflows/instant_issuance_workflow.go`](https://github.com/templatedop/pli-issue/blob/main/workflows/instant_issuance_workflow.go) (Aadhaar instant issuance), [`workflows/policy_issuance_workflow.go`](https://github.com/templatedop/pli-issue/blob/main/workflows/policy_issuance_workflow.go) (Standard issuance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Service entrypoint<br/>Go entrypoint<br/>[main.go]"]
  node_bootstrap["Bootstrap &amp; registration<br/>FX composition root<br/>[bootstrapper.go]"]
end

subgraph group_api["HTTP API"]
  node_swagger["REST contract<br/>OpenAPI spec"]
  node_proposal_api["Proposal, approval &amp; policy APIs<br/>HTTP handlers<br/>[proposal.go]"]
  node_quote_api["Quote &amp; calculation APIs<br/>HTTP handlers<br/>[quote.go]"]
  node_document_api["Document &amp; Aadhaar APIs<br/>HTTP handlers<br/>[document.go]"]
  node_bulk_api["Bulk ingestion API<br/>HTTP handler<br/>[bulk.go]"]
end

subgraph group_domain["Domain &amp; Persistence"]
  node_proposal_domain{{"Proposal lifecycle<br/>Domain state machine<br/>[proposal.go]"}}
  node_rating_domain{{"Quote &amp; premium rules<br/>Domain models<br/>[quote.go]"}}
  node_proposal_repo[("Proposal persistence<br/>Postgres repository")]
  node_quote_repo[("Quote persistence<br/>Postgres repository")]
  node_document_repo[("Document persistence<br/>Postgres repository")]
  node_bulk_repo[("Bulk upload persistence<br/>Postgres repository")]
end

subgraph group_workflow["Temporal Workflows"]
  node_issuance_workflow["Standard issuance<br/>Temporal workflow"]
  node_proposal_activities["Issuance activities<br/>Temporal activities"]
  node_instant_workflow["Aadhaar instant issuance<br/>Temporal workflow"]
  node_aadhaar_activities["Aadhaar activities<br/>Temporal activities"]
end

subgraph group_external["Infrastructure &amp; Integrations"]
  node_postgres[("PostgreSQL system of record<br/>PostgreSQL 15+")]
  node_temporal["Temporal server &amp; task queue<br/>Workflow runtime"]
  node_partner_services["Partner services<br/>External integrations"]
end

node_main -->|"starts"| node_bootstrap
node_bootstrap -->|"serves contract"| node_swagger
node_bootstrap -->|"registers workers"| node_temporal
node_swagger -.->|"documents"| node_proposal_api
node_swagger -.->|"documents"| node_quote_api
node_swagger -.->|"documents"| node_document_api
node_proposal_api -->|"applies lifecycle rules"| node_proposal_domain
node_proposal_api -->|"persists state"| node_proposal_repo
node_proposal_api -->|"starts and signals"| node_issuance_workflow
node_quote_api -->|"calculates"| node_rating_domain
node_quote_api -->|"stores quotes"| node_quote_repo
node_document_api -->|"stores metadata"| node_document_repo
node_document_api -->|"starts"| node_instant_workflow
node_bulk_api -->|"ingests"| node_bulk_repo
node_proposal_repo -->|"reads and writes"| node_postgres
node_quote_repo -->|"reads and writes"| node_postgres
node_document_repo -->|"reads and writes"| node_postgres
node_bulk_repo -->|"reads and writes"| node_postgres
node_issuance_workflow -->|"executes on"| node_temporal
node_issuance_workflow -->|"invokes"| node_proposal_activities
node_proposal_activities -->|"updates phases"| node_proposal_repo
node_proposal_activities -->|"integrates"| node_partner_services
node_instant_workflow -->|"executes on"| node_temporal
node_instant_workflow -->|"invokes"| node_aadhaar_activities
node_instant_workflow -.->|"falls back to"| node_issuance_workflow
node_aadhaar_activities -->|"uses KYC services"| node_partner_services

click node_main "https://github.com/templatedop/pli-issue/blob/main/main.go"
click node_bootstrap "https://github.com/templatedop/pli-issue/blob/main/bootstrap/bootstrapper.go"
click node_swagger "https://github.com/templatedop/pli-issue/blob/main/nbf/swagger/policy_issue_swagger.yaml"
click node_proposal_api "https://github.com/templatedop/pli-issue/blob/main/handler/proposal.go"
click node_quote_api "https://github.com/templatedop/pli-issue/blob/main/handler/quote.go"
click node_document_api "https://github.com/templatedop/pli-issue/blob/main/handler/document.go"
click node_bulk_api "https://github.com/templatedop/pli-issue/blob/main/handler/bulk.go"
click node_proposal_domain "https://github.com/templatedop/pli-issue/blob/main/core/domain/proposal.go"
click node_rating_domain "https://github.com/templatedop/pli-issue/blob/main/core/domain/quote.go"
click node_proposal_repo "https://github.com/templatedop/pli-issue/blob/main/repo/postgres/proposal_repository.go"
click node_quote_repo "https://github.com/templatedop/pli-issue/blob/main/repo/postgres/quote_repository.go"
click node_document_repo "https://github.com/templatedop/pli-issue/blob/main/repo/postgres/document_repository.go"
click node_bulk_repo "https://github.com/templatedop/pli-issue/blob/main/repo/postgres/bulk_upload_repository.go"
click node_postgres "https://github.com/templatedop/pli-issue/blob/main/db/migrations/001_policy_issue_schema.sql"
click node_issuance_workflow "https://github.com/templatedop/pli-issue/blob/main/workflows/policy_issuance_workflow.go"
click node_proposal_activities "https://github.com/templatedop/pli-issue/blob/main/workflows/activities/proposal_activities.go"
click node_instant_workflow "https://github.com/templatedop/pli-issue/blob/main/workflows/instant_issuance_workflow.go"
click node_aadhaar_activities "https://github.com/templatedop/pli-issue/blob/main/workflows/activities/aadhaar_activities.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_bootstrap toneBlue
class node_swagger,node_proposal_api,node_quote_api,node_document_api,node_bulk_api toneAmber
class node_proposal_domain,node_rating_domain,node_proposal_repo,node_quote_repo,node_document_repo,node_bulk_repo toneMint
class node_issuance_workflow,node_proposal_activities,node_instant_workflow,node_aadhaar_activities toneRose
class node_postgres,node_temporal,node_partner_services toneIndigo
```

## Components

### Runtime

- [Service entrypoint](https://github.com/templatedop/pli-issue/blob/main/main.go): Go entrypoint · `main.go`
- [Bootstrap & registration](https://github.com/templatedop/pli-issue/blob/main/bootstrap/bootstrapper.go): FX composition root · Assembles dependencies and registers HTTP server and Temporal workers. · `bootstrap/bootstrapper.go`

### HTTP API

- [REST contract](https://github.com/templatedop/pli-issue/blob/main/nbf/swagger/policy_issue_swagger.yaml): OpenAPI spec · `nbf/swagger/policy_issue_swagger.yaml`
- [Proposal, approval & policy APIs](https://github.com/templatedop/pli-issue/blob/main/handler/proposal.go): HTTP handlers · `handler/proposal.go`
- [Quote & calculation APIs](https://github.com/templatedop/pli-issue/blob/main/handler/quote.go): HTTP handlers · `handler/quote.go`
- [Document & Aadhaar APIs](https://github.com/templatedop/pli-issue/blob/main/handler/document.go): HTTP handlers · `handler/document.go`
- [Bulk ingestion API](https://github.com/templatedop/pli-issue/blob/main/handler/bulk.go): HTTP handler · `handler/bulk.go`

### Domain & Persistence

- [Proposal lifecycle](https://github.com/templatedop/pli-issue/blob/main/core/domain/proposal.go): Domain state machine · Controls phase progression from indexing through issuance or FLC. · `core/domain/proposal.go`
- [Quote & premium rules](https://github.com/templatedop/pli-issue/blob/main/core/domain/quote.go): Domain models · `core/domain/quote.go`
- [Proposal persistence](https://github.com/templatedop/pli-issue/blob/main/repo/postgres/proposal_repository.go): Postgres repository · Persists proposal phase state and durable workflow decisions. · `repo/postgres/proposal_repository.go`
- [Quote persistence](https://github.com/templatedop/pli-issue/blob/main/repo/postgres/quote_repository.go): Postgres repository · `repo/postgres/quote_repository.go`
- [Document persistence](https://github.com/templatedop/pli-issue/blob/main/repo/postgres/document_repository.go): Postgres repository · `repo/postgres/document_repository.go`
- [Bulk upload persistence](https://github.com/templatedop/pli-issue/blob/main/repo/postgres/bulk_upload_repository.go): Postgres repository · `repo/postgres/bulk_upload_repository.go`

### Temporal Workflows

- [Standard issuance](https://github.com/templatedop/pli-issue/blob/main/workflows/policy_issuance_workflow.go): Temporal workflow · Orchestrates validation through issuance, bond generation, and notification. · `workflows/policy_issuance_workflow.go`
- [Issuance activities](https://github.com/templatedop/pli-issue/blob/main/workflows/activities/proposal_activities.go): Temporal activities · Performs validation, eligibility, routing, premium persistence, and issuance operations. · `workflows/activities/proposal_activities.go`
- [Aadhaar instant issuance](https://github.com/templatedop/pli-issue/blob/main/workflows/instant_issuance_workflow.go): Temporal workflow · Falls back to standard issuance for ineligible cases. · `workflows/instant_issuance_workflow.go`
- [Aadhaar activities](https://github.com/templatedop/pli-issue/blob/main/workflows/activities/aadhaar_activities.go): Temporal activities · `workflows/activities/aadhaar_activities.go`

### Infrastructure & Integrations

- [PostgreSQL system of record](https://github.com/templatedop/pli-issue/blob/main/db/migrations/001_policy_issue_schema.sql): PostgreSQL 15+ · Schema includes phase-specific proposal tables, audit, and configuration data. · `db/migrations/001_policy_issue_schema.sql`
- **Temporal server & task queue**: Workflow runtime
- **Partner services**: External integrations · Customer, KYC, billing, document storage, and notification systems.

## Connections

- 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
