Skip to content

AI-Powered Document Intelligence SaaS - End-to-end ML platform architecture on AWS with Terraform

Notifications You must be signed in to change notification settings

venkata-srinivasan/docai-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocAI Platform

AI-Powered Document Intelligence API - A production-ready SaaS platform for document processing, OCR, and data extraction.

Live Demo | API Docs | Pricing

What is DocAI?

DocAI is a B2B SaaS product that enables businesses to extract structured data from documents using AI. Upload invoices, receipts, contracts, or forms - get back structured JSON.

Use Cases

  • Invoice Processing - Extract vendor, amounts, line items, dates
  • Receipt Digitization - Capture expenses automatically
  • Contract Analysis - Pull key terms, dates, parties
  • Form Processing - Digitize any structured form

Architecture

DocAI Platform Architecture

Edit in draw.io

Data Flow

  1. Customer sends document via HTTPS to CloudFront CDN
  2. API Gateway authenticates request via Cognito JWT
  3. Upload Handler generates presigned URL, stores metadata in DynamoDB
  4. Customer uploads document directly to S3
  5. S3 Event triggers Document Processor Lambda
  6. Textract performs OCR and data extraction
  7. Results stored in DynamoDB, event sent to EventBridge
  8. Webhook delivers results to customer's callback URL

Features

For Customers

Feature Description
REST API Simple JSON API for document upload and retrieval
Async Processing Upload documents, get webhook when ready
Multi-format Support PDF, PNG, JPG, TIFF
Confidence Scores AI confidence for each extracted field
Custom Templates Define extraction schemas for your documents
SDKs Python, Node.js, Go client libraries

Platform Capabilities

Capability Implementation
Multi-tenancy Cognito user pools + DynamoDB tenant isolation
Authentication JWT tokens via AWS Cognito
Rate Limiting API Gateway throttling per pricing tier
Usage Tracking DynamoDB counters + CloudWatch metrics
Webhooks EventBridge → SNS/HTTP for async notifications
High Availability Multi-AZ Lambda, DynamoDB on-demand

Pricing Tiers (Example)

Tier Pages/Month Rate Limit Price
Free 100 10 req/min $0
Starter 1,000 60 req/min $49/mo
Business 10,000 300 req/min $299/mo
Enterprise Unlimited Custom Contact us

API Example

Upload Document

curl -X POST https://api.docai.example.com/v1/documents \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@invoice.pdf" \
  -F "document_type=invoice"

Response

{
  "document_id": "doc_abc123",
  "status": "processing",
  "webhook_url": "https://your-app.com/webhook",
  "estimated_completion": "2024-01-15T10:30:00Z"
}

Extraction Result (via webhook or polling)

{
  "document_id": "doc_abc123",
  "status": "completed",
  "document_type": "invoice",
  "extracted_data": {
    "vendor": {
      "value": "Acme Corp",
      "confidence": 0.98
    },
    "invoice_number": {
      "value": "INV-2024-001",
      "confidence": 0.99
    },
    "total_amount": {
      "value": 1250.00,
      "currency": "USD",
      "confidence": 0.97
    },
    "line_items": [
      {
        "description": "Widget Pro",
        "quantity": 5,
        "unit_price": 250.00,
        "confidence": 0.95
      }
    ]
  },
  "processing_time_ms": 2340
}

Project Structure

docai-platform/
├── terraform/
│   ├── modules/
│   │   ├── networking/      # VPC configuration
│   │   ├── cognito/         # User authentication
│   │   ├── api-gateway/     # REST API with throttling
│   │   ├── lambda/          # Processing functions
│   │   ├── dynamodb/        # Data storage
│   │   ├── s3/              # Document storage
│   │   └── monitoring/      # CloudWatch dashboards
│   └── environments/
│       ├── dev/
│       └── prod/
├── src/
│   ├── api/                 # API handlers
│   ├── document-processor/  # AI extraction logic
│   └── webhooks/            # Notification handlers
├── docs/
│   ├── api-reference.md
│   └── integration-guide.md
└── .github/workflows/       # CI/CD

Technical Decisions

Decision Choice Why
Compute Lambda Pay-per-use, scales to zero, no ops overhead
Database DynamoDB Serverless, scales automatically, pay-per-request
Auth Cognito Managed user pools, JWT, integrates with API Gateway
OCR/AI Textract Managed, no ML ops, high accuracy
IaC Terraform Reproducible, multi-environment, team-friendly
Storage S3 Cheap, durable, lifecycle policies

Deployment

# Deploy to dev
cd terraform/environments/dev
terraform init
terraform apply

# Deploy to prod
cd terraform/environments/prod
terraform init
terraform apply

Monitoring

Key Metrics

  • Request latency (p50, p95, p99)
  • Error rate by endpoint
  • Documents processed per tenant
  • Textract API costs
  • Monthly active users

Alerts

  • Error rate > 1%
  • Latency p99 > 5s
  • Cost anomaly detection
  • Failed webhook deliveries

Security

  • All data encrypted at rest (S3, DynamoDB)
  • TLS 1.2+ for all API traffic
  • Tenant data isolation at database level
  • API keys rotatable per customer
  • SOC 2 Type II compliant architecture

License

MIT


Built by: Venkata Subramanian Stack: AWS Lambda, API Gateway, DynamoDB, S3, Textract, Cognito, Terraform

About

AI-Powered Document Intelligence SaaS - End-to-end ML platform architecture on AWS with Terraform

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published