Skip to content

Commit d20f65a

Browse files
committed
Initial commit: DocAI Platform - AI-Powered Document Intelligence SaaS
0 parents  commit d20f65a

File tree

14 files changed

+1997
-0
lines changed

14 files changed

+1997
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Deploy DocAI Platform
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
AWS_REGION: us-east-1
11+
TF_VERSION: 1.6.0
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.11'
24+
25+
- name: Install dependencies
26+
run: |
27+
pip install -r requirements.txt
28+
pip install pytest pytest-cov
29+
30+
- name: Run tests
31+
run: pytest tests/ -v --cov=src
32+
33+
terraform-plan:
34+
name: Terraform Plan
35+
runs-on: ubuntu-latest
36+
needs: test
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Setup Terraform
41+
uses: hashicorp/setup-terraform@v3
42+
with:
43+
terraform_version: ${{ env.TF_VERSION }}
44+
45+
- name: Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v4
47+
with:
48+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
49+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
50+
aws-region: ${{ env.AWS_REGION }}
51+
52+
- name: Terraform Init
53+
working-directory: terraform/environments/dev
54+
run: terraform init
55+
56+
- name: Terraform Plan
57+
working-directory: terraform/environments/dev
58+
run: terraform plan -no-color
59+
continue-on-error: true
60+
61+
deploy-dev:
62+
name: Deploy to Dev
63+
runs-on: ubuntu-latest
64+
needs: terraform-plan
65+
if: github.ref == 'refs/heads/main'
66+
environment: development
67+
steps:
68+
- uses: actions/checkout@v4
69+
70+
- name: Setup Terraform
71+
uses: hashicorp/setup-terraform@v3
72+
with:
73+
terraform_version: ${{ env.TF_VERSION }}
74+
75+
- name: Configure AWS credentials
76+
uses: aws-actions/configure-aws-credentials@v4
77+
with:
78+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
79+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
80+
aws-region: ${{ env.AWS_REGION }}
81+
82+
- name: Terraform Apply
83+
working-directory: terraform/environments/dev
84+
run: |
85+
terraform init
86+
terraform apply -auto-approve
87+
88+
deploy-prod:
89+
name: Deploy to Production
90+
runs-on: ubuntu-latest
91+
needs: deploy-dev
92+
if: github.ref == 'refs/heads/main'
93+
environment: production
94+
steps:
95+
- uses: actions/checkout@v4
96+
97+
- name: Setup Terraform
98+
uses: hashicorp/setup-terraform@v3
99+
with:
100+
terraform_version: ${{ env.TF_VERSION }}
101+
102+
- name: Configure AWS credentials
103+
uses: aws-actions/configure-aws-credentials@v4
104+
with:
105+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }}
106+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }}
107+
aws-region: ${{ env.AWS_REGION }}
108+
109+
- name: Terraform Apply
110+
working-directory: terraform/environments/prod
111+
run: |
112+
terraform init
113+
terraform apply -auto-approve

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Terraform
2+
*.tfstate
3+
*.tfstate.*
4+
.terraform/
5+
.terraform.lock.hcl
6+
*.tfvars
7+
!example.tfvars
8+
9+
# Python
10+
__pycache__/
11+
*.py[cod]
12+
*$py.class
13+
*.so
14+
.Python
15+
venv/
16+
.venv/
17+
ENV/
18+
.egg-info/
19+
dist/
20+
build/
21+
22+
# IDE
23+
.idea/
24+
.vscode/
25+
*.swp
26+
*.swo
27+
28+
# OS
29+
.DS_Store
30+
Thumbs.db
31+
32+
# Secrets
33+
.env
34+
*.pem
35+
*.key
36+
37+
# Logs
38+
*.log
39+
logs/
40+
41+
# Test
42+
.coverage
43+
htmlcov/
44+
.pytest_cache/

README.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# DocAI Platform
2+
3+
**AI-Powered Document Intelligence API** - A production-ready SaaS platform for document processing, OCR, and data extraction.
4+
5+
[Live Demo](https://docai-demo.example.com) | [API Docs](https://api.docai.example.com/docs) | [Pricing](https://docai.example.com/pricing)
6+
7+
## What is DocAI?
8+
9+
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.
10+
11+
### Use Cases
12+
- **Invoice Processing** - Extract vendor, amounts, line items, dates
13+
- **Receipt Digitization** - Capture expenses automatically
14+
- **Contract Analysis** - Pull key terms, dates, parties
15+
- **Form Processing** - Digitize any structured form
16+
17+
## Architecture
18+
19+
```
20+
┌─────────────────────────────────────────┐
21+
│ DocAI Platform │
22+
┌──────────────┐ ├─────────────────────────────────────────┤
23+
│ │ HTTPS │ │
24+
│ Customer │───────────────────▶│ ┌─────────────┐ ┌──────────────┐ │
25+
│ App/SDK │ │ │ API Gateway │───▶│ Cognito │ │
26+
│ │◀───────────────────│ │ (REST/WS) │ │ (Auth) │ │
27+
└──────────────┘ JSON Response │ └──────┬──────┘ └──────────────┘ │
28+
│ │ │
29+
│ ▼ │
30+
│ ┌─────────────────────────────────┐ │
31+
│ │ Lambda Functions │ │
32+
│ │ ┌─────────┐ ┌──────────────┐ │ │
33+
│ │ │ Upload │ │ Process │ │ │
34+
│ │ │ Handler │ │ Document │ │ │
35+
│ │ └────┬────┘ └──────┬───────┘ │ │
36+
│ └───────┼──────────────┼──────────┘ │
37+
│ │ │ │
38+
│ ▼ ▼ │
39+
│ ┌────────────┐ ┌─────────────────┐ │
40+
│ │ S3 │ │ Textract │ │
41+
│ │ (Docs) │ │ (AI/OCR) │ │
42+
│ └────────────┘ └─────────────────┘ │
43+
│ │ │ │
44+
│ └──────┬───────┘ │
45+
│ ▼ │
46+
│ ┌──────────────────────────────────┐ │
47+
│ │ DynamoDB │ │
48+
│ │ - Users/Tenants │ │
49+
│ │ - Documents │ │
50+
│ │ - Usage/Billing │ │
51+
│ └──────────────────────────────────┘ │
52+
│ │ │
53+
│ ▼ │
54+
│ ┌──────────────────────────────────┐ │
55+
│ │ Webhooks (EventBridge) │ │
56+
│ │ → Notify customer on completion │ │
57+
│ └──────────────────────────────────┘ │
58+
│ │
59+
└─────────────────────────────────────────┘
60+
```
61+
62+
## Features
63+
64+
### For Customers
65+
| Feature | Description |
66+
|---------|-------------|
67+
| REST API | Simple JSON API for document upload and retrieval |
68+
| Async Processing | Upload documents, get webhook when ready |
69+
| Multi-format Support | PDF, PNG, JPG, TIFF |
70+
| Confidence Scores | AI confidence for each extracted field |
71+
| Custom Templates | Define extraction schemas for your documents |
72+
| SDKs | Python, Node.js, Go client libraries |
73+
74+
### Platform Capabilities
75+
| Capability | Implementation |
76+
|------------|----------------|
77+
| Multi-tenancy | Cognito user pools + DynamoDB tenant isolation |
78+
| Authentication | JWT tokens via AWS Cognito |
79+
| Rate Limiting | API Gateway throttling per pricing tier |
80+
| Usage Tracking | DynamoDB counters + CloudWatch metrics |
81+
| Webhooks | EventBridge → SNS/HTTP for async notifications |
82+
| High Availability | Multi-AZ Lambda, DynamoDB on-demand |
83+
84+
## Pricing Tiers (Example)
85+
86+
| Tier | Pages/Month | Rate Limit | Price |
87+
|------|-------------|------------|-------|
88+
| Free | 100 | 10 req/min | $0 |
89+
| Starter | 1,000 | 60 req/min | $49/mo |
90+
| Business | 10,000 | 300 req/min | $299/mo |
91+
| Enterprise | Unlimited | Custom | Contact us |
92+
93+
## API Example
94+
95+
### Upload Document
96+
```bash
97+
curl -X POST https://api.docai.example.com/v1/documents \
98+
-H "Authorization: Bearer YOUR_API_KEY" \
99+
-H "Content-Type: multipart/form-data" \
100+
-F "file=@invoice.pdf" \
101+
-F "document_type=invoice"
102+
```
103+
104+
### Response
105+
```json
106+
{
107+
"document_id": "doc_abc123",
108+
"status": "processing",
109+
"webhook_url": "https://your-app.com/webhook",
110+
"estimated_completion": "2024-01-15T10:30:00Z"
111+
}
112+
```
113+
114+
### Extraction Result (via webhook or polling)
115+
```json
116+
{
117+
"document_id": "doc_abc123",
118+
"status": "completed",
119+
"document_type": "invoice",
120+
"extracted_data": {
121+
"vendor": {
122+
"value": "Acme Corp",
123+
"confidence": 0.98
124+
},
125+
"invoice_number": {
126+
"value": "INV-2024-001",
127+
"confidence": 0.99
128+
},
129+
"total_amount": {
130+
"value": 1250.00,
131+
"currency": "USD",
132+
"confidence": 0.97
133+
},
134+
"line_items": [
135+
{
136+
"description": "Widget Pro",
137+
"quantity": 5,
138+
"unit_price": 250.00,
139+
"confidence": 0.95
140+
}
141+
]
142+
},
143+
"processing_time_ms": 2340
144+
}
145+
```
146+
147+
## Project Structure
148+
149+
```
150+
docai-platform/
151+
├── terraform/
152+
│ ├── modules/
153+
│ │ ├── networking/ # VPC configuration
154+
│ │ ├── cognito/ # User authentication
155+
│ │ ├── api-gateway/ # REST API with throttling
156+
│ │ ├── lambda/ # Processing functions
157+
│ │ ├── dynamodb/ # Data storage
158+
│ │ ├── s3/ # Document storage
159+
│ │ └── monitoring/ # CloudWatch dashboards
160+
│ └── environments/
161+
│ ├── dev/
162+
│ └── prod/
163+
├── src/
164+
│ ├── api/ # API handlers
165+
│ ├── document-processor/ # AI extraction logic
166+
│ └── webhooks/ # Notification handlers
167+
├── docs/
168+
│ ├── api-reference.md
169+
│ └── integration-guide.md
170+
└── .github/workflows/ # CI/CD
171+
```
172+
173+
## Technical Decisions
174+
175+
| Decision | Choice | Why |
176+
|----------|--------|-----|
177+
| Compute | Lambda | Pay-per-use, scales to zero, no ops overhead |
178+
| Database | DynamoDB | Serverless, scales automatically, pay-per-request |
179+
| Auth | Cognito | Managed user pools, JWT, integrates with API Gateway |
180+
| OCR/AI | Textract | Managed, no ML ops, high accuracy |
181+
| IaC | Terraform | Reproducible, multi-environment, team-friendly |
182+
| Storage | S3 | Cheap, durable, lifecycle policies |
183+
184+
## Deployment
185+
186+
```bash
187+
# Deploy to dev
188+
cd terraform/environments/dev
189+
terraform init
190+
terraform apply
191+
192+
# Deploy to prod
193+
cd terraform/environments/prod
194+
terraform init
195+
terraform apply
196+
```
197+
198+
## Monitoring
199+
200+
### Key Metrics
201+
- Request latency (p50, p95, p99)
202+
- Error rate by endpoint
203+
- Documents processed per tenant
204+
- Textract API costs
205+
- Monthly active users
206+
207+
### Alerts
208+
- Error rate > 1%
209+
- Latency p99 > 5s
210+
- Cost anomaly detection
211+
- Failed webhook deliveries
212+
213+
## Security
214+
215+
- All data encrypted at rest (S3, DynamoDB)
216+
- TLS 1.2+ for all API traffic
217+
- Tenant data isolation at database level
218+
- API keys rotatable per customer
219+
- SOC 2 Type II compliant architecture
220+
221+
## License
222+
223+
MIT
224+
225+
---
226+
227+
**Built by**: Venkata Subramanian
228+
**Stack**: AWS Lambda, API Gateway, DynamoDB, S3, Textract, Cognito, Terraform

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
boto3>=1.28.0
2+
botocore>=1.31.0
3+
python-json-logger>=2.0.0
4+
aws-lambda-powertools>=2.0.0

0 commit comments

Comments
 (0)