Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
enterprise_system.dbbasic · 3.6 KB · 116 lines
| 1 | # Enterprise System - 100 lines replaces SAP |
| 2 | # Shows real-time, agents, integrations - what Rails couldn't do |
| 3 | |
| 4 | name: "Enterprise System" |
| 5 | version: 2.0 |
| 6 | |
| 7 | model: |
| 8 | customers: |
| 9 | fields: [id, name, email, company, revenue, tier, created] |
| 10 | indexes: [email, created] |
| 11 | computed: |
| 12 | lifetime_value: "SELECT SUM(total) FROM orders WHERE customer_id = customers.id" |
| 13 | |
| 14 | orders: |
| 15 | fields: [id, customer_id, total, status, created] |
| 16 | relations: |
| 17 | customer_id: customers.id |
| 18 | workflow: |
| 19 | states: [draft, confirmed, processing, shipped, delivered] |
| 20 | transitions: |
| 21 | draft: [confirmed] |
| 22 | confirmed: [processing] |
| 23 | processing: [shipped] |
| 24 | shipped: [delivered] |
| 25 | |
| 26 | products: |
| 27 | fields: [id, sku, name, description, price, cost, stock, reorder_point] |
| 28 | indexes: [sku] |
| 29 | computed: |
| 30 | in_stock: "stock > 0" |
| 31 | margin: "price - cost" |
| 32 | needs_reorder: "stock < reorder_point" |
| 33 | |
| 34 | inventory_movements: |
| 35 | fields: [id, product_id, quantity, type, reason, created] |
| 36 | relations: |
| 37 | product_id: products.id |
| 38 | |
| 39 | views: |
| 40 | # Executive Dashboard |
| 41 | executive: |
| 42 | revenue_today: "SELECT SUM(total) FROM orders WHERE DATE(created) = CURRENT_DATE" |
| 43 | revenue_mtd: "SELECT SUM(total) FROM orders WHERE MONTH(created) = MONTH(CURRENT_DATE)" |
| 44 | new_customers: "SELECT COUNT(*) FROM customers WHERE DATE(created) = CURRENT_DATE" |
| 45 | |
| 46 | # Operations Dashboard |
| 47 | operations: |
| 48 | pending_orders: "SELECT COUNT(*) FROM orders WHERE status = 'confirmed'" |
| 49 | low_stock: "SELECT * FROM products WHERE stock < reorder_point" |
| 50 | shipments_today: "SELECT COUNT(*) FROM orders WHERE status = 'shipped' AND DATE(created) = CURRENT_DATE" |
| 51 | |
| 52 | # Customer Analytics |
| 53 | analytics: |
| 54 | top_customers: "SELECT c.*, SUM(o.total) as total_spent FROM customers c JOIN orders o ON c.id = o.customer_id GROUP BY c.id ORDER BY total_spent DESC LIMIT 10" |
| 55 | product_performance: "SELECT p.name, COUNT(oi.id) as units_sold, SUM(oi.quantity * oi.price) as revenue FROM products p JOIN order_items oi ON p.id = oi.product_id GROUP BY p.id ORDER BY revenue DESC" |
| 56 | |
| 57 | forms: |
| 58 | customer: |
| 59 | fields: [name, email, company, tier] |
| 60 | validation: |
| 61 | email: "email_format" |
| 62 | tier: "in:bronze,silver,gold,platinum" |
| 63 | |
| 64 | order: |
| 65 | fields: [customer_id, products, total] |
| 66 | actions: |
| 67 | on_submit: "calculate_total, update_inventory, send_confirmation" |
| 68 | |
| 69 | product: |
| 70 | fields: [sku, name, description, price, cost, stock, reorder_point] |
| 71 | validation: |
| 72 | sku: "unique" |
| 73 | price: "min:0" |
| 74 | cost: "min:0" |
| 75 | |
| 76 | agents: |
| 77 | inventory_manager: |
| 78 | trigger: "products.stock < products.reorder_point" |
| 79 | task: "Generate purchase order for low stock items" |
| 80 | output: "email:purchasing@company.com" |
| 81 | |
| 82 | daily_reporter: |
| 83 | schedule: "0 9 * * *" # 9 AM daily |
| 84 | task: "Generate executive summary with revenue, orders, and customer metrics" |
| 85 | output: "email:executives@company.com" |
| 86 | |
| 87 | customer_scorer: |
| 88 | trigger: "new customer" |
| 89 | task: "Calculate customer score based on company size and industry" |
| 90 | output: "update:customers.tier" |
| 91 | |
| 92 | order_processor: |
| 93 | trigger: "orders.status = 'confirmed'" |
| 94 | task: "Process payment, update inventory, schedule shipping" |
| 95 | |
| 96 | integrations: |
| 97 | stripe: |
| 98 | api_key: "${STRIPE_KEY}" |
| 99 | webhook: "/webhooks/stripe" |
| 100 | events: [payment_intent.succeeded, payment_intent.failed] |
| 101 | |
| 102 | sendgrid: |
| 103 | api_key: "${SENDGRID_KEY}" |
| 104 | from: "noreply@company.com" |
| 105 | |
| 106 | slack: |
| 107 | webhook_url: "${SLACK_WEBHOOK}" |
| 108 | channels: |
| 109 | alerts: "#ops-alerts" |
| 110 | orders: "#new-orders" |
| 111 | |
| 112 | permissions: |
| 113 | admin: "*" |
| 114 | manager: "read:*, write:orders, write:customers" |
| 115 | sales: "read:products, read:customers, write:orders" |
| 116 | customer: "read:own_orders, write:own_profile" |