Villa E-commerce Documentation¶
Technical documentation for the Villa Market e-commerce cost calculation engine.
calculatecost4¶
The core cost calculation service. Processes orders, looks up product prices from DynamoDB, calculates shipping fees, validates coupons and vouchers, and returns enriched order summaries with complete financial breakdowns.
Live endpoint: https://api.villaecommerce.com/calculatecost4
Architecture¶
Client --> API Gateway (api.villaecommerce.com)
|
v
handler.py (Lambda, account 017176210331)
|
+-------+-------+
| |
core/ (pure) adapters/ (AWS)
| |
interfaces/ <---implements
| |
| +-------+-------+-------+
| | | | |
| DynamoDB Lambda Lambda HTTP
| (pricing) (coupon)(voucher)(shipping)
| | | | |
+-------+-------+-------+-------+
|
Source Account (394922924679)
via STS AssumeRole
Core -- Pure Python, zero AWS imports. Models (Order, Product, Shipping, Voucher, Discount), calculation logic, formulas. Unit-testable without credentials.
Adapters -- DynamoDB, Lambda, HTTP implementations behind Protocol interfaces. Cross-account access via STS AssumeRole to source account.
See Architecture for the full diagram and component breakdown.
Quick Links¶
| Document | Description |
|---|---|
| API Reference | POST /calculatecost4 endpoint, request/response schemas, grand total formula |
| Architecture | System architecture with Mermaid diagrams |
| Business Logic | Processing pipeline with exact formulas for each step |
| Data Models | All model classes with fields, types, defaults, computed properties |
| Service Interfaces | Protocol interfaces, adapter mapping, mock examples |
| Test Inventory | All test files, fixtures, assertions, AWS dependencies |
| Test UI | Interactive browser-based API testing tool |
| Known Behaviors | Backward-compatible quirks preserved for equivalence |
| Migration Guide | calculatecost2 to calculatecost4 import mapping |
| Cross-Account Setup | IAM roles, STS, and cross-account access configuration |
| Coupon Rewrite Spec | Future coupon internalization specification |
| Contributing | How to contribute to this documentation |
Deployment¶
| Resource | Location |
|---|---|
| API Endpoint | https://api.villaecommerce.com/calculatecost4 |
| Lambda | calculate-cost-4-dev-manual in account 017176210331 |
| DynamoDB Tables | Account 394922924679 (price-database-2-dev-manual, product-table-dev-manual) |
| Source Code | thanakijwanavit/villaCalculateCost4 |
Test Results¶
Unit tests: 200 pass, 0 fail
Integration tests (27 total, all pass):
- 7 cross-account e2e tests (YAML fixtures + 11-product order)
- 10 real paid order core field tests (from order-table-dev)
- 10 real paid order product field tests
All tested against the deployed original endpoint (resolveCoupon) and confirmed to produce identical results.