File Upload Service

Service managing file uploads, downloads, archival, and deletion for policy-related documents across Claims, Policy, and Quote contexts.

Service Supporting Service

Overview

The File Upload Service is a supporting domain service within the Capstone PAS responsible for managing the complete lifecycle of file uploads. It provides secure file storage using AWS S3 and supports both direct upload (base64) and pre-signed URL upload patterns.

Architecture

  • Event Sourcing: File state changes are persisted as events
  • CQRS: Separate read and write models for optimized queries
  • S3 Integration: Direct integration with AWS S3 for file storage
  • Pre-signed URLs: Secure, time-limited URLs for direct S3 access
  • Kinesis Publishing: Domain events published to Kinesis streams with Avro serialization

Infrastructure

AWS Lambda Handlers

HandlerTriggerPurpose
UploadFileLambdaHandlerAPI GatewayDirect file upload with base64 content
GeneratePreSignedUrlLambdaHandlerAPI GatewayGenerate pre-signed URL for S3 upload
S3FileUploadCompletedEventLambdaHandlerS3 EventProcess upload completion from S3
GetFileLambdaHandlerAPI GatewayRetrieve file metadata
GetBinaryStreamLambdaHandlerAPI GatewayDownload file content
DeleteFileLambdaHandlerAPI GatewayDelete a file
ArchiveFileLambdaHandlerAPI GatewayArchive a file
SetFileOriginationLambdaHandlerAPI GatewayUpdate file origination
GetFileUploadCommandStatusQueryLambdaHandlerAPI GatewayCheck command status

Event Publishing

Events are serialized using Avro format and published to Kinesis:

  • Registry: AWS Glue Schema Registry (sft-capstone-file-upload-event-stream-registry)
  • Stream: sft-capstone-file-upload-{env}-event-stream

Capabilities

File Upload

  • Upload files via base64 encoded content (UploadFile command)
  • Generate pre-signed URLs for direct S3 uploads (GeneratePreSignedUrl command)
  • Support for multiple file types: PDF, DOC, DOCX, XLS, XLSX, JPEG, PNG
  • File size validation enforced (DomainConstants.MAX_FILE_SIZE_KB)

File Retrieval

  • Retrieve file metadata by file ID (GetFile query)
  • Download file binary content as stream (GetBinaryStream query)
  • Generate pre-signed download URLs

File Lifecycle

  • Archive files based on retention policy (ArchiveFile command)
  • Delete files permanently (DeleteFile command)
  • Track file status through lifecycle states: NEW -> UPLOADED -> ARCHIVED/DELETED

Origination Management

  • Associate files with business contexts: CLAIMS, POLICY, QUOTE
  • Update file origination post-upload (SetFileOrigination command)
  • Emit FileOriginationSetEventV1 for downstream processing

Event Flow

Direct Upload Flow

UploadFile Command -> FileAggregateRoot -> FileUploadedEventV1 -> Kinesis

Pre-signed URL Upload Flow

GeneratePreSignedUrl -> File (NEW) -> S3 Upload -> S3Event ->
FileUploadCompletedEvent -> FileAggregateRoot -> FileUploadedEventV1 -> Kinesis

File Status Lifecycle

NEW ---------> UPLOADED ---------> ARCHIVED
|
+--------------> DELETED

Integration Points

Receives From

  • AWS S3: S3Event notifications when pre-signed URL uploads complete
  • API Gateway: REST commands and queries from clients

Publishes To

  • Kinesis Stream: Domain events for downstream consumers
    • Policy Service: Document attachments for policies
    • Quote Service: Supporting documents during quoting
    • Claims Service: Claim evidence and documentation