askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/calculate_shipping_config.yaml
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
calculate_shipping_config.yaml · 4.0 KB · 163 lines
1# DBBasic Config: Shipping Calculator Service
2# Generated from: "Calculate shipping cost based on weight, dimensions, destination zip code, and shipping speed. Use USPS rates for standard, UPS for express. Add $5 handling fee for fragile items. Free shipping over $100."
3
4service:
5 name: calculate_shipping_config
6 version: "1.0"
7 description: "Config-driven shipping calculator with carrier rates and business rules"
8
9# Data sources - could pull from external APIs or local tables
10data_sources:
11 carrier_rates:
12 usps_standard:
13 base_fee: 3.50
14 per_pound: 2.25
15 delivery_days: 5
16 ups_express:
17 base_fee: 6.00
18 per_pound: 3.75
19 delivery_days: 2
20 fedex_overnight:
21 base_fee: 12.00
22 per_pound: 7.50
23 delivery_days: 1
24
25# Business logic as executable rules
26rules:
27 # Primary calculation
28 base_shipping:
29 formula: "carrier_rates[shipping_speed].base_fee + (weight * carrier_rates[shipping_speed].per_pound)"
30
31 # Business rule modifiers
32 free_shipping_threshold:
33 condition: "order_total >= 100"
34 action: "shipping_cost = 0; free_shipping_applied = true"
35 priority: 1
36
37 fragile_handling:
38 condition: "is_fragile == true"
39 action: "shipping_cost += 5.00"
40 priority: 2
41
42 dimensional_weight:
43 condition: "dimensions.length * dimensions.width * dimensions.height > weight * 194"
44 action: "weight = (dimensions.length * dimensions.width * dimensions.height) / 194"
45 priority: 3
46
47# Input validation schema
48inputs:
49 weight:
50 type: number
51 min: 0.1
52 max: 150
53 required: true
54 dimensions:
55 type: object
56 properties:
57 length: {type: number, min: 1}
58 width: {type: number, min: 1}
59 height: {type: number, min: 1}
60 zip_code:
61 type: string
62 pattern: "^[0-9]{5}(-[0-9]{4})?$"
63 shipping_speed:
64 type: string
65 enum: [usps_standard, ups_express, fedex_overnight]
66 default: usps_standard
67 is_fragile:
68 type: boolean
69 default: false
70 order_total:
71 type: number
72 min: 0
73 default: 0
74
75# Output schema
76outputs:
77 shipping_cost:
78 type: number
79 format: currency
80 carrier:
81 type: string
82 estimated_days:
83 type: integer
84 free_shipping_applied:
85 type: boolean
86 default: false
87
88# Carrier mapping
89carrier_mapping:
90 usps_standard: "USPS"
91 ups_express: "UPS"
92 fedex_overnight: "FedEx"
93
94# Zone-based pricing (future enhancement)
95zones:
96 zone_1: ["90210", "90211", "90212"] # Local delivery
97 zone_2: ["91*", "92*"] # Regional
98 zone_3: ["*"] # National
99
100zone_modifiers:
101 zone_1: 0.8 # 20% discount for local
102 zone_2: 1.0 # Standard rate
103 zone_3: 1.2 # 20% surcharge for distant
104
105# Test cases embedded in config
106test_cases:
107 basic_shipping:
108 input:
109 weight: 2.5
110 shipping_speed: usps_standard
111 is_fragile: false
112 order_total: 75
113 expected:
114 shipping_cost: 9.125 # 3.50 + (2.5 * 2.25)
115 carrier: "USPS"
116 estimated_days: 5
117 free_shipping_applied: false
118
119 free_shipping_case:
120 input:
121 weight: 5.0
122 shipping_speed: ups_express
123 order_total: 150
124 expected:
125 shipping_cost: 0
126 free_shipping_applied: true
127
128 fragile_handling:
129 input:
130 weight: 1.0
131 shipping_speed: usps_standard
132 is_fragile: true
133 order_total: 50
134 expected:
135 shipping_cost: 10.75 # 3.50 + (1.0 * 2.25) + 5.00
136 carrier: "USPS"
137
138 dimensional_weight:
139 input:
140 weight: 2.0
141 dimensions: {length: 20, width: 20, height: 20}
142 shipping_speed: usps_standard
143 expected:
144 weight_used: 41.24 # (20*20*20)/194 = 41.24 > 2.0, so use dimensional
145 shipping_cost: 96.29 # 3.50 + (41.24 * 2.25)
146
147# Deployment configuration
148deployment:
149 endpoint: "/api/shipping/calculate"
150 rate_limit: "1000/hour"
151 cache_ttl: 300 # 5 minutes
152 monitoring: true
153
154# Integration hooks
155integrations:
156 before_calculate:
157 - validate_zip_code
158 - lookup_carrier_rates
159 after_calculate:
160 - log_calculation
161 - update_metrics
162
163# This config replaces 80+ lines of Python code with 40 lines of declarative rules