askrobots / dbbasic Public

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

0 downloads

dbbasic/templates/ecommerce/products_crud.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
products_crud.yaml · 10.1 KB · 415 lines
1# DBBasic E-Commerce Template - Products
2# Complete product catalog with inventory, pricing, and multi-variant support
3
4resource: products
5database: ecommerce.db
6
7fields:
8 id:
9 type: primary_key
10 name:
11 type: string
12 required: true
13 searchable: true
14 max_length: 200
15 slug:
16 type: string
17 unique: true
18 max_length: 200
19 description:
20 type: text
21 required: true
22 ui:
23 component: rich_editor
24 toolbar: [bold, italic, list, link]
25 short_description:
26 type: text
27 max_length: 500
28 ui:
29 component: textarea
30 rows: 3
31 sku:
32 type: string
33 unique: true
34 required: true
35 max_length: 50
36 ui:
37 help_text: "Stock Keeping Unit - unique product identifier"
38 category_id:
39 type: foreign_key
40 references: categories
41 required: true
42 brand_id:
43 type: foreign_key
44 references: brands
45 price:
46 type: decimal
47 precision: 10
48 scale: 2
49 required: true
50 min: 0
51 ui:
52 prefix: "$"
53 step: 0.01
54 cost_price:
55 type: decimal
56 precision: 10
57 scale: 2
58 min: 0
59 ui:
60 prefix: "$"
61 help_text: "Internal cost for profit calculations"
62 compare_at_price:
63 type: decimal
64 precision: 10
65 scale: 2
66 min: 0
67 ui:
68 prefix: "$"
69 help_text: "Original price for showing discounts"
70 weight:
71 type: decimal
72 precision: 8
73 scale: 3
74 ui:
75 suffix: "lbs"
76 help_text: "Product weight for shipping calculations"
77 dimensions:
78 type: json
79 ui:
80 component: dimension_input
81 fields: [length, width, height]
82 suffix: "inches"
83
84 # Inventory Management
85 track_inventory:
86 type: boolean
87 default: true
88 inventory_quantity:
89 type: integer
90 default: 0
91 min: 0
92 ui:
93 help_text: "Current stock level"
94 low_stock_threshold:
95 type: integer
96 default: 10
97 min: 0
98 allow_backorders:
99 type: boolean
100 default: false
101
102 # Product Status and Visibility
103 status:
104 type: select
105 options: [draft, active, inactive, discontinued]
106 default: draft
107 required: true
108 visibility:
109 type: select
110 options: [public, private, hidden, password_protected]
111 default: public
112 featured:
113 type: boolean
114 default: false
115
116 # SEO and Media
117 seo_title:
118 type: string
119 max_length: 60
120 seo_description:
121 type: string
122 max_length: 160
123 images:
124 type: json
125 ui:
126 component: image_gallery
127 max_files: 10
128 accept: [jpg, jpeg, png, webp]
129 max_size: 5MB
130
131 # Pricing and Promotions
132 on_sale:
133 type: boolean
134 default: false
135 sale_price:
136 type: decimal
137 precision: 10
138 scale: 2
139 min: 0
140 sale_start_date:
141 type: date
142 sale_end_date:
143 type: date
144
145 # Product Attributes
146 attributes:
147 type: json
148 ui:
149 component: key_value_editor
150 help_text: "Custom product attributes (color, size, material, etc.)"
151
152 # Analytics and Performance
153 view_count:
154 type: integer
155 default: 0
156 ui:
157 readonly: true
158 sales_count:
159 type: integer
160 default: 0
161 ui:
162 readonly: true
163 rating_average:
164 type: decimal
165 precision: 3
166 scale: 2
167 default: 0
168 ui:
169 readonly: true
170 component: star_rating
171 review_count:
172 type: integer
173 default: 0
174 ui:
175 readonly: true
176
177 # Timestamps
178 created_at:
179 type: timestamp
180 auto_now_add: true
181 updated_at:
182 type: timestamp
183 auto_now: true
184
185# Complex E-Commerce Business Logic Hooks
186hooks:
187 before_create:
188 - validate_product_data # Comprehensive product validation
189 - generate_sku_if_empty # Auto-generate SKU from category + name
190 - calculate_profit_margins # Validate pricing vs costs
191 - optimize_product_images # Resize, compress, generate thumbnails
192
193 after_create:
194 - create_inventory_record # Initialize inventory tracking
195 - generate_product_variants # Create size/color variants if specified
196 - index_product_for_search # Add to search index
197 - create_product_feed_entry # Add to Google Shopping feed
198 - trigger_reorder_notification # Notify if low stock
199
200 before_update:
201 - validate_inventory_changes # Prevent negative inventory
202 - check_active_orders # Warn if product has pending orders
203 - preserve_sales_history # Maintain historical pricing data
204 - validate_price_changes # Check minimum profit margins
205
206 after_update:
207 - update_inventory_levels # Sync inventory across warehouses
208 - recalculate_order_totals # Update cart totals if price changed
209 - invalidate_product_cache # Clear cached product pages
210 - update_search_index # Refresh search results
211 - sync_to_marketplace # Update Amazon, eBay listings
212 - notify_price_change_subscribers # Email users watching this product
213
214 before_delete:
215 - check_order_dependencies # Prevent deletion if in active orders
216 - backup_product_data # Archive for compliance
217 - check_inventory_movements # Ensure no pending stock transfers
218
219 after_delete:
220 - cleanup_product_images # Remove uploaded files
221 - remove_from_search_index # Remove from search
222 - update_category_counts # Recalculate category statistics
223 - cancel_pending_orders # Handle orphaned cart items
224
225# Advanced Permission System
226permissions:
227 create:
228 - role: admin
229 - role: catalog_manager
230 read:
231 active: public # Active products visible to all
232 draft: owner_or_admin # Drafts only to creators/admins
233 inactive: admin_only # Inactive products admin-only
234 update:
235 - role: admin
236 - role: catalog_manager
237 - condition: owner_and_draft # Owners can edit their drafts
238 delete:
239 - role: admin
240 - condition: no_orders # Only if no order history
241
242# Advanced API Configuration
243api:
244 base_path: /api/products
245 enable_bulk: true
246 enable_export: true
247 rate_limiting:
248 read: 2000/hour
249 write: 500/hour
250
251 # Custom E-Commerce Endpoints
252 custom_endpoints:
253 - path: /featured
254 method: GET
255 filter: {featured: true, status: active}
256 cache_ttl: 3600
257
258 - path: /on-sale
259 method: GET
260 filter: {on_sale: true, status: active}
261 ordering: [sale_price]
262
263 - path: /category/{category_slug}
264 method: GET
265 join: categories
266 filter: {status: active}
267
268 - path: /{id}/variants
269 method: GET
270 related: product_variants
271
272 - path: /{id}/reviews
273 method: GET
274 related: reviews
275 ordering: [-created_at]
276
277 - path: /{id}/inventory
278 method: GET
279 action: get_inventory_status
280 permissions: [admin, inventory_manager]
281
282 - path: /{id}/reserve
283 method: POST
284 action: reserve_inventory
285 permissions: [authenticated]
286
287 - path: /search
288 method: GET
289 action: search_products
290 parameters: [q, category, min_price, max_price, in_stock]
291
292# Rich User Interface Configuration
293interface:
294 # Admin Product List
295 list_display: [name, sku, category, price, inventory_quantity, status, featured]
296 list_filters: [status, category_id, brand_id, featured, on_sale, created_at]
297 search_fields: [name, description, sku, attributes]
298 ordering: [-created_at]
299 per_page: 25
300
301 # Advanced Product Form
302 form_layout:
303 - section: "Basic Information"
304 fields: [name, slug, description, short_description]
305 columns: 1
306
307 - section: "Product Details"
308 fields: [sku, category_id, brand_id, weight, dimensions]
309 columns: 2
310
311 - section: "Pricing"
312 fields: [price, cost_price, compare_at_price, on_sale, sale_price]
313 columns: 3
314
315 - section: "Inventory"
316 fields: [track_inventory, inventory_quantity, low_stock_threshold, allow_backorders]
317 columns: 2
318
319 - section: "Visibility & Status"
320 fields: [status, visibility, featured]
321 columns: 3
322
323 - section: "Media & SEO"
324 fields: [images, seo_title, seo_description]
325 columns: 1
326
327 - section: "Attributes"
328 fields: [attributes]
329 columns: 1
330
331 # Public Product Display
332 detail_template: product_page
333 detail_layout:
334 gallery: [images]
335 info: [name, price, rating_average, short_description]
336 details: [description, attributes, specifications]
337 actions: [add_to_cart, add_to_wishlist, share]
338 related: [similar_products, recently_viewed]
339
340# Bootstrap E-Commerce Theme
341ui:
342 theme: bootstrap
343 variant: ecommerce
344
345 components:
346 list:
347 variant: table-hover
348 density: compact
349 bulk_actions: [export, bulk_edit, bulk_delete, feature, unfeature]
350
351 form:
352 variant: tabbed
353 save_options: [save_draft, save_active, save_and_continue]
354
355 detail:
356 variant: product_showcase
357 image_zoom: true
358 variant_selector: true
359 quantity_input: true
360 stock_indicator: true
361
362 # E-Commerce Specific Styling
363 css_classes:
364 price: "h4 text-primary font-weight-bold"
365 sale_price: "h4 text-danger font-weight-bold"
366 compare_price: "text-muted text-decoration-line-through"
367 stock_status: "badge badge-success"
368 out_of_stock: "badge badge-danger"
369 low_stock: "badge badge-warning"
370
371# E-Commerce Analytics
372analytics:
373 track_views: true
374 track_cart_additions: true
375 track_purchases: true
376 track_search_queries: true
377 conversion_tracking: true
378
379 # Key Performance Indicators
380 kpis:
381 - conversion_rate
382 - average_order_value
383 - cart_abandonment_rate
384 - product_page_views
385 - inventory_turnover
386
387# Search and Filtering
388search:
389 engine: elasticsearch
390 index_fields: [name, description, sku, attributes, category.name, brand.name]
391 facets: [category, brand, price_range, rating, availability]
392 autocomplete: true
393 typo_tolerance: true
394
395# Product Recommendations
396recommendations:
397 enable: true
398 algorithms:
399 - collaborative_filtering # "Customers who bought this also bought"
400 - content_based # Similar products by attributes
401 - trending # Popular products
402 - cross_sell # Complementary products
403 - upsell # Higher-value alternatives
404
405# Inventory Management Integration
406inventory:
407 multi_warehouse: true
408 real_time_sync: true
409 low_stock_alerts: true
410 reorder_points: automatic
411
412 integrations:
413 - warehouse_management_system
414 - dropshipping_suppliers
415 - marketplace_sync