> ## Documentation Index
> Fetch the complete documentation index at: https://docs.khanhng.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 2.2 Runtime View

These flows describe the current backend code. They do not assert that a deployed end-to-end run has passed.

## Create claim and upload evidence

```mermaid theme={null}
sequenceDiagram
    autonumber
    actor Customer
    participant API as FastAPI
    participant Orders as Order repository
    participant Claims as Claim repository
    participant Blob as Quarantine Blob Storage
    Customer->>API: POST /v1/claims
    API->>Orders: Look up order for customer
    Orders-->>API: Paid amount and currency
    API->>Claims: Create draft claim
    API-->>Customer: 201 RefundClaim
    Customer->>API: POST /v1/claims/{claim_id}/uploads
    API->>Blob: Create short-lived upload grant
    API->>Claims: Add document record
    API-->>Customer: Upload URL and required headers
    Customer->>Blob: Upload bytes directly
    Customer->>API: POST /uploads/{document_id}/complete
    API->>Blob: Check size, type, and file content
    API->>Claims: Mark document verified
    API-->>Customer: 202 verified
```

The API accepts PDF, JPEG, PNG, and WebP, up to five files per claim and 4,194,304 bytes per file. The direct Blob PUT is outside the FastAPI OpenAPI contract.

## Submit and process

```mermaid theme={null}
sequenceDiagram
    autonumber
    actor Customer
    participant API as FastAPI
    participant Claims as Claim repository
    participant DF as Durable Functions
    participant Activities
    Customer->>API: POST /v1/claims/{claim_id}/submit
    API->>Claims: Check ownership, state, and verified documents
    API->>DF: Start or reuse refund-workflow:{claim_id}
    DF-->>API: Workflow instance ID
    API->>Claims: Store workflow ID and scanning status
    API-->>Customer: 202 scanning
    loop Each document
        DF->>Activities: Poll malware scan result
        Activities-->>DF: Clean, malicious, error, or pending
        DF->>Activities: Process clean document
    end
    DF->>Activities: Validate evidence bundle
    DF->>Activities: Run policy-grounded assessment
    DF->>Claims: Set pending_approval
```

The workflow polls pending malware scans every 30 seconds for up to 30 minutes. Malicious or scanner-error results reject the document; a scan timeout sets the claim to `needs_information`. Content safety can block a document, require review, or allow further processing. Evidence validation can reject the claim or request more information. The current code starts the Functions workflow from the API request; it does not implement the outbox proposed in the earlier design.

## Human decision and refund

```mermaid theme={null}
sequenceDiagram
    autonumber
    actor Reviewer
    participant API as FastAPI
    participant DF as Durable Functions
    participant Claims as Claim repository
    participant Stripe
    Reviewer->>API: GET /v1/reviews/{claim_id}
    API-->>Reviewer: Claim, assessment, documents, approvals
    Reviewer->>API: POST /v1/reviews/{claim_id}/decision
    API->>DF: Raise approval_received event
    DF->>Claims: Record reviewer decision
    alt Rejected
        DF->>Claims: Set rejected
    else Required distinct reviewers approved
        DF->>Claims: Set approved
        DF->>Stripe: Create idempotent refund
        DF->>Claims: Set refund_submitted
    end
    Stripe->>API: Signed webhook
    API->>Claims: Set refunded or refund_failed
```

The assessment determines whether one or two distinct reviewer approvals are needed; the current threshold is a proposed refund amount greater than 500. The workflow closes after seven days without enough approvals. Stripe refund creation uses `refundflow:{claim_id}` as its idempotency key and is retried up to three attempts. The webhook verifies `Stripe-Signature` before applying the final status.

## Known implementation boundary

The submission route has no transactional outbox between saving claim state and calling the Functions starter. The backend also has no separate safety-review queue for a `REVIEW` content-safety result. Those design items should not be presented as completed behavior.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.