ApiLogicServer 15.2.0__py3-none-any.whl → 15.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- api_logic_server_cli/api_logic_server.py +3 -2
- api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md +115 -31
- api_logic_server_cli/prototypes/base/docs/training/testing.md +116 -18
- api_logic_server_cli/prototypes/base/test/api_logic_server_behave/behave_logic_report.py +55 -29
- api_logic_server_cli/prototypes/base/test/api_logic_server_behave/behave_logic_report.py.bak +285 -0
- api_logic_server_cli/prototypes/{base/.github/.copilot-instructionsZ.mdx → basic_demo/.github/.copilot-instructions.md} +111 -30
- api_logic_server_cli/prototypes/basic_demo/customizations/test/api_logic_server_behave/reports/Behave Logic Report Intro micro.md +35 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/test/api_logic_server_behave/reports/Behave Logic Report Intro.md +35 -0
- api_logic_server_cli/prototypes/basic_demo/readme.md +12 -4
- api_logic_server_cli/prototypes/basic_demo/tutor.md +1196 -0
- api_logic_server_cli/prototypes/manager/.github/.copilot-instructions.md +50 -23
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/.github/.copilot-instructions.md +3 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/docs/training/testing.md +305 -21
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/behave_logic_report.py +13 -84
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/behave_logic_report.py.bak +282 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/features/order_processing.feature +59 -50
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/features/steps/order_processing_steps.py +395 -248
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/behave.log +66 -62
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Carbon_Neutral_Discount_A.log +51 -41
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Change_Order_Customer.log +29 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Change_Product_in_Item.log +35 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Delete_Item_Reduces_Order.log +39 -19
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Exceed_Credit_Limit_Rejec.log +36 -45
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Good_Order_Placed_via_B2B.log +50 -40
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Item_Quantity_Change.log +33 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Multi-Item_Order_via_B2B_.log +67 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Ship_Order_Excludes_from_.log +24 -14
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Transaction_Processing.log +26 -17
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/logs/scenario_logic_logs/Unship_Order_Includes_in_.log +24 -14
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/test/api_logic_server_behave/reports/Behave Logic Report.md +361 -146
- api_logic_server_cli/prototypes/manager/system/ApiLogicServer-Internal-Dev/copilot-dev-context.md +275 -4
- api_logic_server_cli/prototypes/manager/system/app_model_editor/test/api_logic_server_behave/behave_logic_report.py +13 -75
- api_logic_server_cli/prototypes/manager/system/app_model_editor/test/api_logic_server_behave/behave_logic_report.py.bak +256 -0
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_docs_logic/test/api_logic_server_behave/behave_logic_report.py +13 -75
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_docs_logic/test/api_logic_server_behave/behave_logic_report.py.bak +256 -0
- api_logic_server_cli/prototypes/nw/test/api_logic_server_behave/reports/Behave Logic Report Intro micro.md +17 -0
- api_logic_server_cli/prototypes/nw/test/api_logic_server_behave/reports/Behave Logic Report Intro.md +17 -0
- {apilogicserver-15.2.0.dist-info → apilogicserver-15.2.7.dist-info}/METADATA +103 -23
- {apilogicserver-15.2.0.dist-info → apilogicserver-15.2.7.dist-info}/RECORD +43 -30
- {apilogicserver-15.2.0.dist-info → apilogicserver-15.2.7.dist-info}/WHEEL +0 -0
- {apilogicserver-15.2.0.dist-info → apilogicserver-15.2.7.dist-info}/entry_points.txt +0 -0
- {apilogicserver-15.2.0.dist-info → apilogicserver-15.2.7.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-15.2.0.dist-info → apilogicserver-15.2.7.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,1196 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI Guided Tour Instructions
|
|
3
|
+
Description: Message in a bottle for AI assistants - how to conduct hands-on guided tours
|
|
4
|
+
Source: org_git/ApiLogicServer-src/api_logic_server_cli/prototypes/basic_demo/tutor.md
|
|
5
|
+
Propagation: BLT copies to Manager samples/basic_demo_sample/tutor.md
|
|
6
|
+
Usage: AI reads this when user says "Guide me through basic_demo"
|
|
7
|
+
version: 2.1 (10/25/2025)
|
|
8
|
+
last_updated: 2025-10-25
|
|
9
|
+
changelog: |
|
|
10
|
+
v2.1 (10/25/2025):
|
|
11
|
+
- Corrected section ordering: Security (Section 2) before Logic (Section 3) to match readme
|
|
12
|
+
- Enhanced Security section with Authentication vs Authorization distinction
|
|
13
|
+
- Added customer count observation (5 before, 6 after commands)
|
|
14
|
+
- Fixed Logic ordering provocation: "Perhaps order of rules?" → "No, procedural approach"
|
|
15
|
+
- Clarified file organization: declare_logic.py vs logic_discovery/*.py
|
|
16
|
+
- Section 4: Removed incorrect --using='discount', added proper server stop
|
|
17
|
+
- Section 4: Fixed UI navigation (Alice → first Order → Add New Item → Lookup)
|
|
18
|
+
- Section 4: Console log shows "how did I get here" - complete execution chain
|
|
19
|
+
- Section 5: Removed incorrect --using='B2B', API already exists from first add-cust
|
|
20
|
+
- Added "reuse over transactions and sources" throughout
|
|
21
|
+
- Updated link to learning-rules section
|
|
22
|
+
- Emphasized "more than one rule" for pattern combinations
|
|
23
|
+
v2.0 (10/25/2025):
|
|
24
|
+
- Added provocation method (show working → ask "how did it know ORDER?" → explain dependency discovery)
|
|
25
|
+
- Added spreadsheet analogy for dependency discovery (Excel formulas for multi-table databases)
|
|
26
|
+
- Moved procedural comparison to active learning moment (after 40X claim, not homework)
|
|
27
|
+
- Clarified add-cust context (why during tours: schema variability, new users, debugging difficulty)
|
|
28
|
+
- Added best practices (discovery + use-case organization in logic/logic_discovery/)
|
|
29
|
+
- Replaced hardcoded line numbers with function/section names
|
|
30
|
+
- Added timing checkpoints (15 min at Security, 35 min at Q&A) and escape hatches
|
|
31
|
+
- Added MCP server mention in Section 1 (Claude Desktop integration)
|
|
32
|
+
- Added code metrics to wrap-up (48 vs 200+ lines with concrete breakdown)
|
|
33
|
+
- Added security pre-configuration note (add-auth)
|
|
34
|
+
- Added explicit add-cust parameters (--using='discount', --using='B2B')
|
|
35
|
+
- Added reference to logic/readme_logic.md for complete details
|
|
36
|
+
- Validated "message in a bottle" concept through live tour execution
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
# AI Guided Tour: basic_demo Walkthrough
|
|
40
|
+
|
|
41
|
+
**Purpose:** Instructions for AI assistants conducting hands-on guided tours with basic_demo.
|
|
42
|
+
|
|
43
|
+
**Target Audience:** New users exploring GenAI-Logic for the first time.
|
|
44
|
+
|
|
45
|
+
**Duration:** 30-45 minutes (20 min tour, 10-25 min Q&A)
|
|
46
|
+
|
|
47
|
+
**Philosophy:** Provoke questions, reveal patterns, build pattern recognition.
|
|
48
|
+
|
|
49
|
+
**User Activation Phrases:**
|
|
50
|
+
- "Guide me through basic_demo"
|
|
51
|
+
- "Take the guided tour"
|
|
52
|
+
- "Show me around basic_demo"
|
|
53
|
+
- "Walk me through this"
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Guided Tour Flow Overview
|
|
58
|
+
|
|
59
|
+
1. **Walk Around the Block** (20 min) - Follow readme.md sections 1, 4, 5
|
|
60
|
+
2. **Provoke & Reveal** - Use questioning to create "aha moments"
|
|
61
|
+
3. **Pattern Recognition** - Introduce the 5 key rule patterns
|
|
62
|
+
4. **Open Q&A** - Address parked questions, explore curiosity
|
|
63
|
+
5. **Readiness Check** - Conversational validation (not quiz)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Section-by-Section Guide
|
|
68
|
+
|
|
69
|
+
### **Introduction (2 min)**
|
|
70
|
+
|
|
71
|
+
**What to Say:**
|
|
72
|
+
```
|
|
73
|
+
"I'll guide you through basic_demo - a 20-minute hands-on exploration.
|
|
74
|
+
We'll DO each step from the readme together.
|
|
75
|
+
|
|
76
|
+
When you have questions, we'll handle them in two ways:
|
|
77
|
+
- Quick explanations now if it helps understanding
|
|
78
|
+
- 'Park it' for after the tour if it's a deep dive
|
|
79
|
+
|
|
80
|
+
Sound good? Let's start the server..."
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Key Points:**
|
|
84
|
+
- Set expectation of "walk first, deep dives later"
|
|
85
|
+
- ❌ **Never assume server is already running**
|
|
86
|
+
- ❌ **Don't offer option menus** - guide users through the specific experience following readme flow
|
|
87
|
+
- ✅ **Emphasize automatic generation** - stress that entire microservice was created from database introspection
|
|
88
|
+
- Keep responses SHORT - one idea per interaction (users often have Copilot in side panel with limited vertical space)
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### **Section 1: Create and Run (3 min)**
|
|
93
|
+
|
|
94
|
+
**Starting the Server:**
|
|
95
|
+
|
|
96
|
+
**What to Say:**
|
|
97
|
+
```
|
|
98
|
+
"First, let's start the server with debugging enabled.
|
|
99
|
+
|
|
100
|
+
Press F5 (or use Run menu → Start Debugging).
|
|
101
|
+
|
|
102
|
+
This uses the launch configuration that genai-logic created for you."
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Why F5:**
|
|
106
|
+
- ✅ Uses proper `.vscode/launch.json` configuration (first config is default)
|
|
107
|
+
- ✅ Enables debugging automatically
|
|
108
|
+
- ✅ Standard VS Code workflow
|
|
109
|
+
- ❌ Don't use terminal commands to start the server
|
|
110
|
+
|
|
111
|
+
**Python Environment Note:**
|
|
112
|
+
- Environment is typically already configured
|
|
113
|
+
- Either in the project or in Manager's venv (one or two directories up)
|
|
114
|
+
- ❌ Don't make users create venvs during the tour
|
|
115
|
+
|
|
116
|
+
**After Server Starts:**
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
"Great! Server is running at http://localhost:5656
|
|
120
|
+
|
|
121
|
+
Open that in your browser - you'll see the admin app."
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Explore the Admin UI:**
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
"What you're looking at was created automatically - this ENTIRE web application
|
|
128
|
+
was generated just by introspecting your database schema.
|
|
129
|
+
|
|
130
|
+
Try this now:
|
|
131
|
+
1. Click on 'Customer' in the left menu
|
|
132
|
+
2. Click on a customer (like Alice) to see their details
|
|
133
|
+
3. See the Orders list at the bottom? Click an order to drill down
|
|
134
|
+
4. See the Items? Notice how it shows Product NAME, not just an ID number
|
|
135
|
+
|
|
136
|
+
This is what's worth noting: Complete CRUD operations, automatic relationships,
|
|
137
|
+
search and filtering - all generated. No configuration files, no manual endpoint creation,
|
|
138
|
+
no UI components to build."
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Key Insight:**
|
|
142
|
+
- Multi-page, multi-table UI with complete CRUD operations
|
|
143
|
+
- Parent-child-grandchild relationships (Customer → Orders → Items)
|
|
144
|
+
- Automatic joins (shows product name, not just foreign key IDs)
|
|
145
|
+
- Responsive design works on desktop and mobile
|
|
146
|
+
- **All from database introspection - zero manual coding**
|
|
147
|
+
|
|
148
|
+
**Explore the API:**
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
"Now let's see the API that's powering this:
|
|
152
|
+
1. Click 'Home' in the left menu
|
|
153
|
+
2. Click the 'Swagger' link
|
|
154
|
+
3. Scroll through - every table has full CRUD endpoints automatically
|
|
155
|
+
|
|
156
|
+
The system introspected your schema and generated a complete, working microservice with
|
|
157
|
+
JSON:API standard endpoints, filtering, sorting, pagination, and automatic relationship handling.
|
|
158
|
+
|
|
159
|
+
Also generated: an MCP (Model Context Protocol) server in integration/mcp/ -
|
|
160
|
+
that's for Claude Desktop integration, lets AI agents query your data and invoke operations.
|
|
161
|
+
|
|
162
|
+
That's a decent start, but here's the thing - this is a fresh project with no business logic yet."
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**What to Park:**
|
|
166
|
+
- "How does discovery work in detail?"
|
|
167
|
+
- "Can I customize the admin app?"
|
|
168
|
+
- "How does JSON:API work?"
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### **Section 2: Security (8 min)**
|
|
173
|
+
|
|
174
|
+
**Follow readme.md Section 4 (Security first, then Logic)**
|
|
175
|
+
|
|
176
|
+
#### **Part A: Add Security (3 min)**
|
|
177
|
+
|
|
178
|
+
**CRITICAL: Use add-cust and add-auth**
|
|
179
|
+
|
|
180
|
+
**What to Say:**
|
|
181
|
+
```
|
|
182
|
+
"Let's add security and logic to this project.
|
|
183
|
+
|
|
184
|
+
First, in the admin app, go to Customers - count how many you see. [They'll see 5]
|
|
185
|
+
|
|
186
|
+
Now stop the server (Red Stop button or Shift-F5).
|
|
187
|
+
|
|
188
|
+
Run these two commands:"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Run the commands:**
|
|
192
|
+
```bash
|
|
193
|
+
genai-logic add-cust
|
|
194
|
+
genai-logic add-auth --db_url=auth
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Why these commands?**
|
|
198
|
+
- ✅ Handles schema variations (different column names, etc.)
|
|
199
|
+
- ✅ Restores database integrity (fixes any broken data from earlier changes)
|
|
200
|
+
- ✅ Demonstrates working logic and security immediately
|
|
201
|
+
- ❌ Don't use natural language during tour - too error-prone with unknown schemas
|
|
202
|
+
|
|
203
|
+
**What NOT to mention:**
|
|
204
|
+
- Internal details about DB restore
|
|
205
|
+
- Schema complexity
|
|
206
|
+
- Just focus on: "This adds role-based security and check credit logic"
|
|
207
|
+
|
|
208
|
+
**After commands complete:**
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
"Done! Security and logic are now active.
|
|
212
|
+
|
|
213
|
+
Restart the server (F5).
|
|
214
|
+
|
|
215
|
+
[Wait for them to say 'ok' or confirm server is running]"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### **Part B: Demonstrate Security (5 min)**
|
|
219
|
+
|
|
220
|
+
**Show Login Required:**
|
|
221
|
+
```
|
|
222
|
+
"Go to the admin app - refresh the page.
|
|
223
|
+
|
|
224
|
+
Notice what changed? Login is now required.
|
|
225
|
+
|
|
226
|
+
Login with:
|
|
227
|
+
- Username: admin
|
|
228
|
+
- Password: p
|
|
229
|
+
|
|
230
|
+
Click on Customers.
|
|
231
|
+
|
|
232
|
+
Click the first customer (ALFKI) to see the detail - notice the sales_rep field.
|
|
233
|
+
|
|
234
|
+
Go back to the list - see all 6 customers? That's one more than before.
|
|
235
|
+
|
|
236
|
+
[Wait for confirmation]
|
|
237
|
+
|
|
238
|
+
Now logout (upper right) and login as:
|
|
239
|
+
- Username: s1
|
|
240
|
+
- Password: p
|
|
241
|
+
|
|
242
|
+
Click Customers again - now you only see 3 customers.
|
|
243
|
+
|
|
244
|
+
[Wait for them to observe this]
|
|
245
|
+
|
|
246
|
+
Same app, different user, filtered data automatically."
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Show the Security Code:**
|
|
250
|
+
```
|
|
251
|
+
"Open security/declare_security.py and find the Grant for Customer.
|
|
252
|
+
|
|
253
|
+
See this line?
|
|
254
|
+
|
|
255
|
+
filter=lambda : models.Customer.sales_rep == Security.current_user().id
|
|
256
|
+
|
|
257
|
+
One declarative Grant statement filters the entire Customer table for sales reps.
|
|
258
|
+
|
|
259
|
+
This is RBAC - Role-Based Access Control. This worked because user s1 has role 'sales'.
|
|
260
|
+
|
|
261
|
+
This Grant works for:
|
|
262
|
+
- Admin UI (what you just saw)
|
|
263
|
+
- API endpoints (try Swagger with different users)
|
|
264
|
+
- Any query through the system
|
|
265
|
+
|
|
266
|
+
Pattern: Declare once, enforces everywhere.
|
|
267
|
+
|
|
268
|
+
[Wait for them to absorb this]"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**Authentication vs Authorization:**
|
|
272
|
+
```
|
|
273
|
+
"Important distinction:
|
|
274
|
+
|
|
275
|
+
**Authentication** verifies user/password and returns their roles.
|
|
276
|
+
- User s1 logs in → system verifies password → returns role 'sales'
|
|
277
|
+
|
|
278
|
+
**Authorization (RBAC)** uses those roles to control access.
|
|
279
|
+
- User has role 'sales' → Grant filters data based on that role
|
|
280
|
+
|
|
281
|
+
Authentication can use different providers:
|
|
282
|
+
- SQL (what this example uses) - good for early development
|
|
283
|
+
- Keycloak (industry standard) - for production
|
|
284
|
+
- Your own custom authentication provider
|
|
285
|
+
|
|
286
|
+
The key: Your Grant declarations stay the same regardless of authentication provider.
|
|
287
|
+
|
|
288
|
+
See security/readme_security.md for Keycloak setup and custom providers.
|
|
289
|
+
|
|
290
|
+
Pattern: Authentication verifies WHO you are, Authorization controls WHAT you can access.
|
|
291
|
+
|
|
292
|
+
[Pause - let them ask questions if they have any]"
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### **Section 3: Logic (12 min) - THE CRITICAL SECTION**
|
|
298
|
+
|
|
299
|
+
**Follow readme.md Section 4 (Logic portion)**
|
|
300
|
+
|
|
301
|
+
#### **Part A: Observe Logic in Action (5 min)**
|
|
302
|
+
|
|
303
|
+
**STOP HERE - The Provocation:**
|
|
304
|
+
```
|
|
305
|
+
"Now let's see the business logic in action.
|
|
306
|
+
|
|
307
|
+
Make sure you're logged in as admin (logout/login if you're still s1).
|
|
308
|
+
|
|
309
|
+
Go to admin app, find Customer Alice, drill into Orders, pick an Order, drill into Items.
|
|
310
|
+
Change an Item quantity to 100 and save.
|
|
311
|
+
|
|
312
|
+
BEFORE looking at VS Code console - what do you THINK will happen?
|
|
313
|
+
|
|
314
|
+
[Wait for answer]
|
|
315
|
+
|
|
316
|
+
NOW look at the console - see the Logic Bank log?
|
|
317
|
+
|
|
318
|
+
👉 THIS IS YOUR DEBUGGING TOOL - you'll use it constantly."
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Observe What Happened:**
|
|
322
|
+
```
|
|
323
|
+
"Look at the Logic Bank log in VS Code console.
|
|
324
|
+
|
|
325
|
+
Notice what happened:
|
|
326
|
+
- Item.amount updated
|
|
327
|
+
- Order.amount_total updated
|
|
328
|
+
- Customer.balance updated
|
|
329
|
+
- ERROR: balance exceeds credit limit
|
|
330
|
+
|
|
331
|
+
The key observation: Logic is now running automatically when you change data."
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### **Part D: Show the Rules (3 min)**
|
|
335
|
+
|
|
336
|
+
**Open the Logic File:**
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
"Now let's see the actual rules that made this happen:
|
|
340
|
+
|
|
341
|
+
Open logic/declare_logic.py and look for the comment '# Logic from GenAI:'.
|
|
342
|
+
|
|
343
|
+
See those 5 rules between the GenAI comments? That's what you just watched execute:
|
|
344
|
+
- Customer balance constraint (the error you saw)
|
|
345
|
+
- Customer balance sum (sum of orders)
|
|
346
|
+
- Order amount_total sum (sum of items)
|
|
347
|
+
- Item amount formula (quantity × price)
|
|
348
|
+
- Item unit_price copy (from product)
|
|
349
|
+
|
|
350
|
+
This is declarative - you say WHAT, engine figures out WHEN and ORDER."
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
**Provoke Question 1: Ordering**
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
"Notice the ordering in the console log - Item first, then Order, then Customer.
|
|
357
|
+
|
|
358
|
+
How do you suppose that happened? Perhaps the order of the rules?
|
|
359
|
+
|
|
360
|
+
[Natural pause for them to think]
|
|
361
|
+
|
|
362
|
+
No, that's a procedural approach - rules are declarative.
|
|
363
|
+
|
|
364
|
+
The rule engine analyzed the dependencies when the server started -
|
|
365
|
+
saw that Order.amount_total depends on Item.amount, Customer.balance depends on
|
|
366
|
+
Order.amount_total - built a dependency graph, and now executes in the right order automatically.
|
|
367
|
+
|
|
368
|
+
**What this means for you? Simpler Maintenance.** No more archaeology to find insertion points.
|
|
369
|
+
You know that tedious work of figuring out where to hook your logic into existing code?
|
|
370
|
+
Instead, you just add or alter rules, and the engine works out the sequence at startup."
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**Provoke Question 2: Invocation**
|
|
374
|
+
|
|
375
|
+
```
|
|
376
|
+
"Now another question: Where were these rules called from?
|
|
377
|
+
|
|
378
|
+
You changed Item quantity in the UI - what code explicitly invoked these rules?
|
|
379
|
+
|
|
380
|
+
[Natural pause]
|
|
381
|
+
|
|
382
|
+
None. The engine does automatic invocation.
|
|
383
|
+
|
|
384
|
+
**What this means for you? Quality.** If the rule is declared, you can be confident it will
|
|
385
|
+
be called, in the right order, for every change. No missing calls, no wrong sequence,
|
|
386
|
+
no forgotten edge cases."
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**Provoke Question 3: Reuse**
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
"One more thing to notice: These rules aren't specific to insert, update, or delete operations.
|
|
393
|
+
|
|
394
|
+
**Automatic Reuse.** The logic applies to all operations automatically.
|
|
395
|
+
|
|
396
|
+
**What this means for you?** Reduces your work from 200 lines to 5, just as a spreadsheet does.
|
|
397
|
+
You don't need to code all the check-for-changes logic. You declare the formula once, it works everywhere.
|
|
398
|
+
|
|
399
|
+
**This is the key to unlocking the value:** Learn to 'think spreadsheet' - declare what should be true,
|
|
400
|
+
not how to make it true. The rules engine handles the ordering, invocation, and reuse.
|
|
401
|
+
This gives you the 40X conciseness, quality guarantees, simpler maintenance, and requirements traceability
|
|
402
|
+
(rules drive test generation - see https://apilogicserver.github.io/Docs/Behave-Creation/).
|
|
403
|
+
|
|
404
|
+
This credit check is an example of the 'Constrain a Derived Result' pattern - you'll use these patterns repeatedly.
|
|
405
|
+
|
|
406
|
+
When you're ready to dive deeper: https://apilogicserver.github.io/Docs/Logic/#learning-rules
|
|
407
|
+
|
|
408
|
+
See the A/B comparison at logic/declarative-vs-procedural-comparison.md -
|
|
409
|
+
it shows the actual code difference."
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
**Excel Analogy**
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
"Think of it like Excel formulas for multi-table databases:
|
|
416
|
+
- In Excel: cell C1 = A1 + B1, cell D1 = C1 * 2
|
|
417
|
+
- Change A1 → C1 recalcs → D1 recalcs
|
|
418
|
+
- You don't call the formulas, they just fire when inputs change
|
|
419
|
+
|
|
420
|
+
Same here:
|
|
421
|
+
- Item.amount = quantity × price
|
|
422
|
+
- Order.total = sum(Item.amount)
|
|
423
|
+
- Customer.balance = sum(Order.total)
|
|
424
|
+
- Change quantity → Item recalcs → Order recalcs → Customer recalcs
|
|
425
|
+
|
|
426
|
+
Spreadsheet thinking, but for relational data."
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### **Part E: How YOU Would Add Logic (3 min)**
|
|
430
|
+
|
|
431
|
+
**CRITICAL: Explain AFTER showing it working**
|
|
432
|
+
|
|
433
|
+
```
|
|
434
|
+
"So you saw the add-cust command add logic for this tour.
|
|
435
|
+
|
|
436
|
+
To speed things up and avoid confusing errors, we created the logic for you.
|
|
437
|
+
|
|
438
|
+
In real life, you have TWO ways to add rules:
|
|
439
|
+
|
|
440
|
+
1. **Logic Discovery (RECOMMENDED)** - Describe requirements in natural language:
|
|
441
|
+
'Customer balance equals sum of order totals for unshipped orders'
|
|
442
|
+
'Balance must not exceed credit limit'
|
|
443
|
+
|
|
444
|
+
AI generates the rules for YOUR schema, whatever column names you have.
|
|
445
|
+
Creates logic/logic_discovery/your_use_case.py
|
|
446
|
+
|
|
447
|
+
Rules auto-activate when server restarts (discovery folder is auto-loaded).
|
|
448
|
+
|
|
449
|
+
2. **IDE Code Completion** - Type 'Rule.' in logic/declare_logic.py and see all patterns:
|
|
450
|
+
- Rule.formula
|
|
451
|
+
- Rule.sum
|
|
452
|
+
- Rule.constraint
|
|
453
|
+
- Rule.copy
|
|
454
|
+
|
|
455
|
+
Use this when you know exactly what you want and want full control.
|
|
456
|
+
|
|
457
|
+
**Best Practice for file organization:**
|
|
458
|
+
|
|
459
|
+
- **logic/declare_logic.py** - Your main rules file (what we showed you)
|
|
460
|
+
- **logic/logic_discovery/*.py** - Auto-generated rules by use case:
|
|
461
|
+
- logic/logic_discovery/check_credit.py
|
|
462
|
+
- logic/logic_discovery/pricing_rules.py
|
|
463
|
+
- logic/logic_discovery/approval_workflow.py
|
|
464
|
+
|
|
465
|
+
Each discovery file represents one business requirement. Self-documenting, easy to find.
|
|
466
|
+
Both locations work - discovery files load automatically at startup.
|
|
467
|
+
|
|
468
|
+
The key: You declare WHAT, engine handles WHEN and ORDER.
|
|
469
|
+
|
|
470
|
+
For complete details, see logic/readme_logic.md in this project."
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
#### **Part F: Introduce Rule Patterns (4 min)**
|
|
474
|
+
|
|
475
|
+
**CRITICAL: This is what makes it learnable**
|
|
476
|
+
|
|
477
|
+
```
|
|
478
|
+
"That credit limit error you just saw?
|
|
479
|
+
|
|
480
|
+
It's an example of a RULE PATTERN called 'Constrain a Derived Result':
|
|
481
|
+
1. Derive an aggregate (Customer.balance = sum of orders)
|
|
482
|
+
2. Constrain the result (balance <= credit_limit)
|
|
483
|
+
|
|
484
|
+
This pattern appears EVERYWHERE in business apps:
|
|
485
|
+
- Department salary budgets (sum salaries, constrain to budget)
|
|
486
|
+
- Product inventory (sum quantities, ensure minimum stock)
|
|
487
|
+
- Student graduation (sum credits, require minimum)
|
|
488
|
+
|
|
489
|
+
Same pattern, different domain.
|
|
490
|
+
|
|
491
|
+
Here's your reference guide - open this now:"
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
**Show the Patterns Table:**
|
|
495
|
+
|
|
496
|
+
https://apilogicserver.github.io/Docs/Logic/#learning-rules
|
|
497
|
+
|
|
498
|
+
```
|
|
499
|
+
"Scroll to the Rule Patterns table. See these 5 key patterns:
|
|
500
|
+
|
|
501
|
+
1. Chain Up - parent aggregates from children
|
|
502
|
+
2. Constrain a Derived Result - what you just saw
|
|
503
|
+
3. Chain Down - parent changes cascade to children
|
|
504
|
+
4. State Transition Logic - using old_row vs new_row
|
|
505
|
+
5. Counts as Existence Checks - 'can't ship empty orders'
|
|
506
|
+
|
|
507
|
+
Don't memorize them - just scan the pattern names.
|
|
508
|
+
|
|
509
|
+
👉 THIS is your go-to reference.
|
|
510
|
+
👉 Customer says 'I need X' → you think 'which pattern?'
|
|
511
|
+
|
|
512
|
+
Keep this tab open - you'll use it constantly."
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
**Show a Second Pattern (Optional, if time):**
|
|
516
|
+
|
|
517
|
+
```
|
|
518
|
+
"Quick example - pattern #5: 'Counts as Existence Checks'
|
|
519
|
+
|
|
520
|
+
Requirement: 'Can't ship orders with no items'
|
|
521
|
+
|
|
522
|
+
Two rules:
|
|
523
|
+
1. Rule.count(derive=Order.item_count, as_count_of=Item)
|
|
524
|
+
2. Rule.constraint: if shipping, item_count must be > 0
|
|
525
|
+
|
|
526
|
+
See the pattern? Count something, use count in constraint.
|
|
527
|
+
|
|
528
|
+
Notice it often takes more than one rule to satisfy a requirement. Combining rules is a key skill -
|
|
529
|
+
you'll see this in many patterns.
|
|
530
|
+
|
|
531
|
+
Same pattern applies to:
|
|
532
|
+
- Students need minimum credits
|
|
533
|
+
- Products need required notices
|
|
534
|
+
- Shipments must have packages
|
|
535
|
+
|
|
536
|
+
Pattern recognition is the key skill here."
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
### **Section 4: Iterate with Python (8 min)**
|
|
542
|
+
|
|
543
|
+
**Follow readme.md Section 5**
|
|
544
|
+
|
|
545
|
+
**What to Emphasize:**
|
|
546
|
+
```
|
|
547
|
+
"Section 4 - mixing rules with Python for complex logic.
|
|
548
|
+
|
|
549
|
+
New requirement: Give a 10% discount for carbon-neutral products for 10 items or more.
|
|
550
|
+
|
|
551
|
+
We're going to:
|
|
552
|
+
1. Add a schema change (CarbonNeutral column)
|
|
553
|
+
2. Rebuild models from database
|
|
554
|
+
3. Add discount logic mixing rules + Python
|
|
555
|
+
4. Debug it with breakpoints
|
|
556
|
+
|
|
557
|
+
First, stop the server (Red Stop button or Shift-F5).
|
|
558
|
+
|
|
559
|
+
Now run these commands:"
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
**Run the commands:**
|
|
563
|
+
```bash
|
|
564
|
+
genai-logic add-cust
|
|
565
|
+
genai-logic rebuild-from-database --db_url=sqlite:///database/db.sqlite
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
**After commands complete:**
|
|
569
|
+
```
|
|
570
|
+
"Done! This:
|
|
571
|
+
- Updated database with Product.CarbonNeutral column
|
|
572
|
+
- Rebuilt models.py to include the new column
|
|
573
|
+
- Updated logic/declare_logic.py with the discount logic
|
|
574
|
+
|
|
575
|
+
Notice: no manual schema changes, no migrations to write - it handles schema evolution cleanly.
|
|
576
|
+
|
|
577
|
+
You can ignore the warning about 'mcp-SysMcp' - not present."
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
**Set Breakpoint and Debug:**
|
|
581
|
+
```
|
|
582
|
+
"Open logic/declare_logic.py, scroll to the derive_amount function.
|
|
583
|
+
|
|
584
|
+
Set a breakpoint on the line with 'if row.Product.CarbonNeutral...'
|
|
585
|
+
|
|
586
|
+
Start the server (F5).
|
|
587
|
+
|
|
588
|
+
Now go to admin app, login as admin.
|
|
589
|
+
|
|
590
|
+
Find Customer Alice, drill into her first Order, and click 'Add New Item'.
|
|
591
|
+
|
|
592
|
+
Use the Lookup function to select a Green product (Product ID 1 or 5).
|
|
593
|
+
|
|
594
|
+
Set quantity to 12 and save.
|
|
595
|
+
|
|
596
|
+
Breakpoint hits!
|
|
597
|
+
|
|
598
|
+
👉 Look at VS Code LOCALS pane (left side).
|
|
599
|
+
👉 See row, row.quantity, row.Product, row.Product.CarbonNeutral?
|
|
600
|
+
|
|
601
|
+
This is live debugging with real data. Not magic - transparent Python code you can step through.
|
|
602
|
+
|
|
603
|
+
👉 Open DEBUG CONSOLE (bottom panel).
|
|
604
|
+
Type: row.Product.CarbonNeutral
|
|
605
|
+
Type: row.quantity
|
|
606
|
+
|
|
607
|
+
You're inspecting the exact state that triggered this rule.
|
|
608
|
+
|
|
609
|
+
Press F10 to step through - see the 10% discount calculation.
|
|
610
|
+
Press F5 to continue.
|
|
611
|
+
|
|
612
|
+
Check the Item amount - it got the discount automatically."
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
**The Key Teaching Moments:**
|
|
616
|
+
```
|
|
617
|
+
"Three big insights here:
|
|
618
|
+
|
|
619
|
+
1. **Rules + Python Mix**:
|
|
620
|
+
- Rule.formula calls Python function (derive_amount)
|
|
621
|
+
- Python has complex if/else logic inside
|
|
622
|
+
- Still gets automatic chaining (no explicit calls needed)
|
|
623
|
+
|
|
624
|
+
2. **Parent References Work Automatically**:
|
|
625
|
+
- row.Product.CarbonNeutral does the SQL join for you
|
|
626
|
+
- No query writing, no ORM gymnastics
|
|
627
|
+
- Think in business terms, engine handles SQL
|
|
628
|
+
|
|
629
|
+
3. **Debugging Transparency**:
|
|
630
|
+
- Set breakpoints, inspect locals, use debug console
|
|
631
|
+
- Not a black box - you SEE the data, STEP through logic
|
|
632
|
+
- Check the console log - see the rules that already fired
|
|
633
|
+
- Answers "how did I get here?" - the complete execution chain
|
|
634
|
+
- This is how you'll diagnose issues in YOUR projects
|
|
635
|
+
|
|
636
|
+
The pattern: Use rules for 90% (sums, copies, formulas), use Python for complex 10% (conditionals, API calls).
|
|
637
|
+
You get best of both: declarative power + procedural flexibility."
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
**Schema Evolution Note:**
|
|
641
|
+
```
|
|
642
|
+
"Notice what just happened with rebuild-from-database:
|
|
643
|
+
- Database had new column added (by add-cust)
|
|
644
|
+
- Rebuild regenerated models.py automatically
|
|
645
|
+
- No manual ALTER TABLE, no migration scripts
|
|
646
|
+
- Database integrity maintained (foreign keys, constraints intact)
|
|
647
|
+
|
|
648
|
+
This is the workflow for schema changes:
|
|
649
|
+
1. Modify database (SQL, add-cust, or DB tool)
|
|
650
|
+
2. Run rebuild-from-database
|
|
651
|
+
3. Models.py updated, relationships preserved
|
|
652
|
+
4. Continue coding
|
|
653
|
+
|
|
654
|
+
Handles real-world evolution without breaking things."
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
---
|
|
658
|
+
|
|
659
|
+
### **Section 5: B2B Integration (10 min)**
|
|
660
|
+
|
|
661
|
+
**Two Big Ideas to Cover:**
|
|
662
|
+
|
|
663
|
+
#### **Part A: Custom APIs (5 min)**
|
|
664
|
+
|
|
665
|
+
**What to Emphasize:**
|
|
666
|
+
```
|
|
667
|
+
"Section 5 - B2B Integration. Two big patterns here:
|
|
668
|
+
|
|
669
|
+
First: CUSTOM APIs for partner integrations.
|
|
670
|
+
|
|
671
|
+
The first add-cust command already created api/api_discovery/order_b2b.py -
|
|
672
|
+
a custom endpoint that accepts partner-specific JSON format and maps it to our Order/Item structure.
|
|
673
|
+
|
|
674
|
+
Let's test it..."
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
**Test the Endpoint:**
|
|
678
|
+
```
|
|
679
|
+
"Open Swagger (Home → Swagger link).
|
|
680
|
+
|
|
681
|
+
Find 'ServicesEndPoint' section, expand POST /ServicesEndPoint/OrderB2B.
|
|
682
|
+
|
|
683
|
+
Click 'Try it out', use the prefilled example JSON, Execute.
|
|
684
|
+
|
|
685
|
+
See the response? Order created with Items, rules fired automatically.
|
|
686
|
+
|
|
687
|
+
Now check the logic log in VS Code console - see all those 'Logic Bank' lines?
|
|
688
|
+
|
|
689
|
+
👉 The custom API mapped partner format to our models
|
|
690
|
+
👉 Rules enforced automatically - whether from UI app or custom API
|
|
691
|
+
👉 Zero duplication of logic - reuse over transactions and sources
|
|
692
|
+
|
|
693
|
+
This is the pattern for integrations:
|
|
694
|
+
- Custom endpoint for partner format
|
|
695
|
+
- Map to your models (integration/row_dict_maps/)
|
|
696
|
+
- Logic enforces automatically
|
|
697
|
+
- No separate 'integration logic' to maintain"
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
**Show the Code (Optional):**
|
|
701
|
+
```
|
|
702
|
+
"Quick look at api/api_discovery/order_b2b.py:
|
|
703
|
+
|
|
704
|
+
See how it:
|
|
705
|
+
1. Accepts partner JSON structure
|
|
706
|
+
2. Calls RowDictMapper to transform
|
|
707
|
+
3. Inserts Order/Items
|
|
708
|
+
4. Returns response
|
|
709
|
+
|
|
710
|
+
The mapping is in integration/row_dict_maps/OrderB2B.py -
|
|
711
|
+
separates API shape from business logic.
|
|
712
|
+
|
|
713
|
+
Pattern: Custom APIs + row mappers + automatic rule enforcement."
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
#### **Part B: Logic Extensions (5 min)**
|
|
717
|
+
|
|
718
|
+
**What to Emphasize:**
|
|
719
|
+
```
|
|
720
|
+
"Second big idea: LOGIC EXTENSIONS for side effects.
|
|
721
|
+
|
|
722
|
+
Open logic/declare_logic.py, scroll to the send_order_to_shipping function.
|
|
723
|
+
|
|
724
|
+
See this function?
|
|
725
|
+
|
|
726
|
+
This uses after_flush_row_event - triggers AFTER transaction commits.
|
|
727
|
+
|
|
728
|
+
Pattern:
|
|
729
|
+
- Order placed, items added, rules fire (balance check, totals)
|
|
730
|
+
- Transaction about to commit
|
|
731
|
+
- This extension fires: 'hey, send message to shipping system'
|
|
732
|
+
- Uses Kafka producer (commented out here, but shows the pattern)
|
|
733
|
+
|
|
734
|
+
Why after_flush? Because you only want to notify AFTER data is committed.
|
|
735
|
+
If transaction rolls back, message never sends. Transactional consistency."
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
**The Integration Pattern:**
|
|
739
|
+
```
|
|
740
|
+
"This is how you integrate with external systems:
|
|
741
|
+
|
|
742
|
+
1. Core logic as rules (balance, totals, constraints)
|
|
743
|
+
2. Extensions for side effects (send message, call API, write audit log)
|
|
744
|
+
3. Extensions use row_events: before_flush, after_flush, etc.
|
|
745
|
+
|
|
746
|
+
Examples:
|
|
747
|
+
- after_flush: Send Kafka message (like here)
|
|
748
|
+
- after_flush: Call shipping API
|
|
749
|
+
- before_flush: Write audit trail
|
|
750
|
+
- after_update: Sync to data warehouse
|
|
751
|
+
|
|
752
|
+
The pattern keeps business logic (rules) separate from integration glue (extensions).
|
|
753
|
+
|
|
754
|
+
Both automatic, both declarative, both in same file."
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
**The Big Picture:**
|
|
758
|
+
```
|
|
759
|
+
"So B2B integration has two patterns:
|
|
760
|
+
|
|
761
|
+
1. **Custom APIs**: Accept partner formats, map to models, rules enforce
|
|
762
|
+
2. **Logic Extensions**: After core logic, trigger side effects
|
|
763
|
+
|
|
764
|
+
Together they handle:
|
|
765
|
+
- Multiple client formats (REST, GraphQL, partners)
|
|
766
|
+
- External system notifications (Kafka, webhooks, APIs)
|
|
767
|
+
- All using same rule enforcement (no duplication)
|
|
768
|
+
|
|
769
|
+
That's why logic is reusable - write once, works everywhere."
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
---
|
|
773
|
+
|
|
774
|
+
### **Post-Tour: Wrap-Up & Metrics (5 min)**
|
|
775
|
+
|
|
776
|
+
**The Transition:**
|
|
777
|
+
```
|
|
778
|
+
"Okay, you just walked around the block.
|
|
779
|
+
|
|
780
|
+
Quick recap of what you SAW:
|
|
781
|
+
✅ Auto-generated API and Admin App (with MCP server for Claude Desktop)
|
|
782
|
+
✅ 5 declarative rules = check credit logic
|
|
783
|
+
✅ Rules fired automatically with dependency ordering (logic log showed the chain)
|
|
784
|
+
✅ Pattern: Constrain a Derived Result (aggregate up, constrain at top)
|
|
785
|
+
✅ Security role-based filtering (6 customers → 3 for sales role)
|
|
786
|
+
✅ Rules + Python mix (discount logic with debugging)
|
|
787
|
+
✅ Schema evolution (CarbonNeutral column, rebuild-from-database)
|
|
788
|
+
✅ Custom APIs (B2B OrderB2B endpoint with partner format)
|
|
789
|
+
✅ Logic Extensions (Kafka send_order_to_shipping pattern)
|
|
790
|
+
|
|
791
|
+
Now here's the question that ties it all together:
|
|
792
|
+
|
|
793
|
+
👉 How much custom code was actually introduced?"
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
**The Code Metrics Reveal:**
|
|
797
|
+
```
|
|
798
|
+
"Let's count. Open logic/declare_logic.py:
|
|
799
|
+
|
|
800
|
+
Lines 39-63: The 5 declarative rules + comments ≈ 23 lines
|
|
801
|
+
Lines 51-58: derive_amount Python function ≈ 8 lines
|
|
802
|
+
Lines 68-84: send_order_to_shipping Python function ≈ 17 lines
|
|
803
|
+
|
|
804
|
+
Total custom logic: ~48 lines (23 declarative + 25 Python)
|
|
805
|
+
|
|
806
|
+
Now think about the procedural equivalent:
|
|
807
|
+
- Handle Item insert/update/delete → recalc amount
|
|
808
|
+
- Find parent Order → recalc total
|
|
809
|
+
- Handle Item FK changes (moves to different Order)
|
|
810
|
+
- Find parent Customer → recalc balance
|
|
811
|
+
- Handle Order FK changes (moves to different Customer)
|
|
812
|
+
- Check constraint on every balance change
|
|
813
|
+
- Handle all 3 operations (insert/update/delete) × 3 entities
|
|
814
|
+
- Discount logic with product join
|
|
815
|
+
- Kafka integration with transaction coordination
|
|
816
|
+
|
|
817
|
+
Conservative estimate: 200+ lines of procedural code.
|
|
818
|
+
|
|
819
|
+
You just saw 48 lines replace 200+. That's the 40X productivity claim - with concrete numbers.
|
|
820
|
+
|
|
821
|
+
And remember:
|
|
822
|
+
- Zero corner case bugs (automatic chaining handles all FK changes)
|
|
823
|
+
- Zero maintenance archaeology (declarative rules are self-documenting)
|
|
824
|
+
- Debugging transparency (breakpoints, locals, debug console)
|
|
825
|
+
|
|
826
|
+
That's why it's called declarative logic - you declare WHAT, engine handles WHEN and HOW.
|
|
827
|
+
|
|
828
|
+
---
|
|
829
|
+
|
|
830
|
+
**Want to see the actual procedural version?**
|
|
831
|
+
|
|
832
|
+
```
|
|
833
|
+
"We ran an experiment - asked AI to rebuild this same logic procedurally, without rules.
|
|
834
|
+
|
|
835
|
+
Open logic/procedural/declarative-vs-procedural-comparison.md - let's look at it real quick.
|
|
836
|
+
|
|
837
|
+
[Wait for them to open it]
|
|
838
|
+
|
|
839
|
+
See the TL;DR table? 5 lines declarative vs 220+ procedural. That's the code volume.
|
|
840
|
+
|
|
841
|
+
But scroll down to the actual procedural code sample...
|
|
842
|
+
|
|
843
|
+
See those comments - 'CRITICAL BUG FIX'?
|
|
844
|
+
|
|
845
|
+
AI initially MISSED product-id changes. Fixed it.
|
|
846
|
+
Then MISSED order-id changes. Fixed that too.
|
|
847
|
+
Multiple bug cycles just to get basic logic working.
|
|
848
|
+
|
|
849
|
+
The declarative version? Zero bugs. Worked first time.
|
|
850
|
+
|
|
851
|
+
Why? Because you listed WHAT you want (5 rules).
|
|
852
|
+
Engine handles ALL the scenarios - insert, update, delete, FK changes, old/new values.
|
|
853
|
+
|
|
854
|
+
You don't forget edge cases. The engine doesn't forget them either.
|
|
855
|
+
|
|
856
|
+
That's 2 minutes - we can dig deeper in Q&A if you want,
|
|
857
|
+
but this shows why automatic chaining isn't just convenient - it's CORRECT."
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
---
|
|
861
|
+
|
|
862
|
+
## Post-Tour: Open Q&A (10-25 min)
|
|
863
|
+
|
|
864
|
+
### **The Transition:**
|
|
865
|
+
```
|
|
866
|
+
"Okay - you just walked through the complete tour. We're about 35 minutes in.
|
|
867
|
+
|
|
868
|
+
Now - parked questions. What do you want to dig into?
|
|
869
|
+
- How engine discovers dependencies?
|
|
870
|
+
- When to use Python vs pure rules?
|
|
871
|
+
- How to add new rules?
|
|
872
|
+
- Testing approach?
|
|
873
|
+
- Something else?"
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
### **Common Follow-up Questions:**
|
|
877
|
+
|
|
878
|
+
#### **Q: "How does the engine know the order?"**
|
|
879
|
+
```
|
|
880
|
+
A: "Dependency discovery - analyzes what attributes each rule uses.
|
|
881
|
+
|
|
882
|
+
Example:
|
|
883
|
+
- Item.amount uses quantity, unit_price
|
|
884
|
+
- Order.amount_total uses Item.amount
|
|
885
|
+
- Customer.balance uses Order.amount_total
|
|
886
|
+
|
|
887
|
+
Engine builds dependency graph: Item → Order → Customer
|
|
888
|
+
|
|
889
|
+
When Item.quantity changes:
|
|
890
|
+
1. Item.amount recalcs (depends on quantity)
|
|
891
|
+
2. Order.amount_total recalcs (depends on Item.amount)
|
|
892
|
+
3. Customer.balance recalcs (depends on Order.amount_total)
|
|
893
|
+
4. Constraint checks (depends on balance)
|
|
894
|
+
|
|
895
|
+
That's the automatic ordering. You don't specify it - engine discovers it.
|
|
896
|
+
|
|
897
|
+
Want to see the dependency graph? There's a rules report..."
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
#### **Q: "When should I use Python instead of rules?"**
|
|
901
|
+
```
|
|
902
|
+
A: "Rule of thumb:
|
|
903
|
+
|
|
904
|
+
USE RULES for:
|
|
905
|
+
- Derivations (sum, count, formula, copy)
|
|
906
|
+
- Simple constraints (balance <= credit_limit)
|
|
907
|
+
- Parent references (Item.unit_price from Product)
|
|
908
|
+
|
|
909
|
+
USE PYTHON for:
|
|
910
|
+
- Complex conditionals (if this AND that OR other)
|
|
911
|
+
- External API calls
|
|
912
|
+
- String parsing/formatting
|
|
913
|
+
- Date calculations beyond simple stamps
|
|
914
|
+
- Custom algorithms
|
|
915
|
+
|
|
916
|
+
The discount example shows the mix:
|
|
917
|
+
- Rules handle the formula trigger
|
|
918
|
+
- Python handles the if/else logic
|
|
919
|
+
- Rules handle the chaining
|
|
920
|
+
|
|
921
|
+
Most systems: 40% rules, 5% Python, 55% auto-generated."
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
#### **Q: "How do I test this?"**
|
|
925
|
+
```
|
|
926
|
+
A: "Two approaches:
|
|
927
|
+
|
|
928
|
+
1. Manual testing (what you just did)
|
|
929
|
+
- Use admin app or Swagger
|
|
930
|
+
- Watch logic log in console
|
|
931
|
+
- Verify expected behavior
|
|
932
|
+
|
|
933
|
+
2. Automated testing (Behave)
|
|
934
|
+
- Write scenarios in plain English
|
|
935
|
+
- Tests execute against running server
|
|
936
|
+
- Generates logic report showing which rules fired
|
|
937
|
+
|
|
938
|
+
Check readme section on testing, or:
|
|
939
|
+
docs/training/testing.md in the project.
|
|
940
|
+
|
|
941
|
+
Want to write a test together?"
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
#### **Q: "Can I see the rule patterns again?"**
|
|
945
|
+
```
|
|
946
|
+
A: "Yes - keep this open as reference:
|
|
947
|
+
https://apilogicserver.github.io/Docs/Logic/#rule-patterns
|
|
948
|
+
|
|
949
|
+
The 'Rule Patterns' table is your cheat sheet.
|
|
950
|
+
|
|
951
|
+
Also check the 'Rules Case Study' section below it -
|
|
952
|
+
shows how to design solutions using patterns.
|
|
953
|
+
|
|
954
|
+
And in your project: system/genai/examples/ folder
|
|
955
|
+
shows training examples for these patterns."
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
---
|
|
959
|
+
|
|
960
|
+
## Readiness Check (Conversational)
|
|
961
|
+
|
|
962
|
+
### **Not a Quiz - A Scenario:**
|
|
963
|
+
|
|
964
|
+
```
|
|
965
|
+
"Let's try a scenario together - conversational, not a test.
|
|
966
|
+
|
|
967
|
+
Scenario:
|
|
968
|
+
'Sales reps earn commission:
|
|
969
|
+
- 3% of order total
|
|
970
|
+
- Only on shipped orders
|
|
971
|
+
- Rep.total_commission = sum of their order commissions'
|
|
972
|
+
|
|
973
|
+
Don't write code yet - just tell me your approach.
|
|
974
|
+
What rules would you use? What pattern is this?"
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
### **What You're Listening For:**
|
|
978
|
+
|
|
979
|
+
✅ **They get it:**
|
|
980
|
+
```
|
|
981
|
+
"Need Rep.total_commission column...
|
|
982
|
+
Then Rule.sum with where shipped...
|
|
983
|
+
And Rule.formula for 3% of order total...
|
|
984
|
+
That's Chain Up - aggregate then use it."
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
✅ **Needs more time:**
|
|
988
|
+
```
|
|
989
|
+
"I'd write a function that loops through orders..."
|
|
990
|
+
→ They're thinking procedurally, not declaratively
|
|
991
|
+
→ Needs more pattern examples
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
✅ **Partial understanding:**
|
|
995
|
+
```
|
|
996
|
+
"Use a sum rule? But how do I calculate commission?"
|
|
997
|
+
→ They get aggregation, need formula pattern
|
|
998
|
+
→ Show: Rule.formula for commission, then sum the formulas
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
### **The Follow-up:**
|
|
1002
|
+
|
|
1003
|
+
```
|
|
1004
|
+
"Good! You're thinking in patterns.
|
|
1005
|
+
|
|
1006
|
+
Here's the code (roughly):
|
|
1007
|
+
|
|
1008
|
+
# Pattern: Chain Down (copy rep to order)
|
|
1009
|
+
Rule.copy(derive=Order.sales_rep_id, from_parent=Rep.id)
|
|
1010
|
+
|
|
1011
|
+
# Pattern: Formula (calculate commission)
|
|
1012
|
+
Rule.formula(derive=Order.commission,
|
|
1013
|
+
as_expression=lambda row: row.amount_total * Decimal('0.03')
|
|
1014
|
+
if row.date_shipped else 0)
|
|
1015
|
+
|
|
1016
|
+
# Pattern: Chain Up (aggregate commissions)
|
|
1017
|
+
Rule.sum(derive=Rep.total_commission,
|
|
1018
|
+
as_sum_of=Order.commission,
|
|
1019
|
+
where=lambda row: row.date_shipped is not None)
|
|
1020
|
+
|
|
1021
|
+
See how patterns compose?
|
|
1022
|
+
- Copy (Chain Down) links order to rep
|
|
1023
|
+
- Formula calculates individual commission
|
|
1024
|
+
- Sum (Chain Up) aggregates to rep total
|
|
1025
|
+
|
|
1026
|
+
That's the power - patterns are building blocks."
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
---
|
|
1030
|
+
|
|
1031
|
+
## Level-2: Next Steps
|
|
1032
|
+
|
|
1033
|
+
### **When They're Ready:**
|
|
1034
|
+
|
|
1035
|
+
```
|
|
1036
|
+
"You've got the basics:
|
|
1037
|
+
✅ Rules fire automatically
|
|
1038
|
+
✅ Pattern recognition (Chain Up, Counts, etc.)
|
|
1039
|
+
✅ Rules + Python mix
|
|
1040
|
+
✅ Logic log debugging
|
|
1041
|
+
✅ Security basics
|
|
1042
|
+
|
|
1043
|
+
Ready for more advanced patterns? There's nw_sample with:
|
|
1044
|
+
- B2B integration APIs (RowDictMapper)
|
|
1045
|
+
- Kafka row events
|
|
1046
|
+
- State transition logic (old_row)
|
|
1047
|
+
- Audit logging (copy_row)
|
|
1048
|
+
- Testing with Behave
|
|
1049
|
+
|
|
1050
|
+
Want to continue, or need more time with basic_demo?"
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
### **Level-2 Readiness Signals:**
|
|
1054
|
+
|
|
1055
|
+
✅ **They're asking about:**
|
|
1056
|
+
- "How do I integrate with external systems?"
|
|
1057
|
+
- "Can I track changes to data?"
|
|
1058
|
+
- "How do I handle workflows?"
|
|
1059
|
+
- "What about event-driven architecture?"
|
|
1060
|
+
|
|
1061
|
+
✅ **They're comfortable with:**
|
|
1062
|
+
- Reading logic logs without help
|
|
1063
|
+
- Naming patterns when they see them
|
|
1064
|
+
- Designing simple scenarios independently
|
|
1065
|
+
- Mixing rules and Python appropriately
|
|
1066
|
+
|
|
1067
|
+
⏸️ **They're NOT ready if:**
|
|
1068
|
+
- Still confused about automatic invocation
|
|
1069
|
+
- Can't read logic log output
|
|
1070
|
+
- Don't understand pattern names
|
|
1071
|
+
- Think they need to "call" the rules
|
|
1072
|
+
|
|
1073
|
+
**Recommendation:** If not ready, do 1-2 more scenarios together in basic_demo before advancing.
|
|
1074
|
+
|
|
1075
|
+
---
|
|
1076
|
+
|
|
1077
|
+
## Key Principles for AI Tour Guides
|
|
1078
|
+
|
|
1079
|
+
### **Use Conversational Tone:**
|
|
1080
|
+
|
|
1081
|
+
✅ **DO:** Use "I" and "you" - personal and engaging
|
|
1082
|
+
- "I'll show you..."
|
|
1083
|
+
- "You'll see..."
|
|
1084
|
+
- "Let's explore..."
|
|
1085
|
+
|
|
1086
|
+
❌ **DON'T:** Use third-person references
|
|
1087
|
+
- "The user will..."
|
|
1088
|
+
- "Users should..."
|
|
1089
|
+
- "One can observe..."
|
|
1090
|
+
|
|
1091
|
+
### **Keep Responses Short:**
|
|
1092
|
+
|
|
1093
|
+
✅ **DO:** One idea/insight per interaction
|
|
1094
|
+
- Users often have Copilot in side panel (limited vertical space)
|
|
1095
|
+
- Avoid walls of text that scroll off screen
|
|
1096
|
+
- Make each response fit on a 16" laptop screen with side panel
|
|
1097
|
+
|
|
1098
|
+
❌ **DON'T:** Dump multiple concepts at once
|
|
1099
|
+
- Long explanations that require scrolling
|
|
1100
|
+
- Multiple sections in one response
|
|
1101
|
+
|
|
1102
|
+
### **Balance Questions:**
|
|
1103
|
+
|
|
1104
|
+
**Explain Now:**
|
|
1105
|
+
- Clarifies current step
|
|
1106
|
+
- Simple, quick answer
|
|
1107
|
+
- Helps understanding of what they're seeing
|
|
1108
|
+
|
|
1109
|
+
**Park for Later:**
|
|
1110
|
+
- Deep technical details
|
|
1111
|
+
- Unrelated to current section
|
|
1112
|
+
- Would derail momentum
|
|
1113
|
+
|
|
1114
|
+
### **Provocations Work:**
|
|
1115
|
+
|
|
1116
|
+
Don't just show → Make them discover:
|
|
1117
|
+
- "What do you think happened?"
|
|
1118
|
+
- "Where's the code that did that?"
|
|
1119
|
+
- "How would YOU solve this?"
|
|
1120
|
+
- "See the pattern?"
|
|
1121
|
+
|
|
1122
|
+
### **Name the Patterns:**
|
|
1123
|
+
|
|
1124
|
+
Every time you show something, name it:
|
|
1125
|
+
- "That's Chain Up"
|
|
1126
|
+
- "This is the Counts pattern"
|
|
1127
|
+
- "Here's Chain Down in action"
|
|
1128
|
+
|
|
1129
|
+
Repetition builds recognition.
|
|
1130
|
+
|
|
1131
|
+
### **Logic Log is Sacred:**
|
|
1132
|
+
|
|
1133
|
+
Always emphasize:
|
|
1134
|
+
- "Look at the logic log"
|
|
1135
|
+
- "See the indentation?"
|
|
1136
|
+
- "Count the rules firing"
|
|
1137
|
+
|
|
1138
|
+
They MUST learn to read this - it's their debugging tool.
|
|
1139
|
+
|
|
1140
|
+
### **Pattern Reference is Key:**
|
|
1141
|
+
|
|
1142
|
+
Keep pointing back to:
|
|
1143
|
+
- Rule Patterns doc table
|
|
1144
|
+
- "You'll use this constantly"
|
|
1145
|
+
- "Which pattern applies here?"
|
|
1146
|
+
|
|
1147
|
+
Build the habit of pattern-first thinking.
|
|
1148
|
+
|
|
1149
|
+
---
|
|
1150
|
+
|
|
1151
|
+
## Success Criteria
|
|
1152
|
+
|
|
1153
|
+
### **They're Ready When They Can:**
|
|
1154
|
+
|
|
1155
|
+
□ Explain automatic rule invocation ("engine discovers dependencies")
|
|
1156
|
+
□ Read logic log and identify rule chaining
|
|
1157
|
+
□ Name at least 2 patterns (Chain Up, Counts)
|
|
1158
|
+
□ Explain when to use Python vs rules
|
|
1159
|
+
□ Design a simple scenario using patterns
|
|
1160
|
+
□ Know where to find pattern reference docs
|
|
1161
|
+
□ Use breakpoint debugging with rules
|
|
1162
|
+
|
|
1163
|
+
### **They Need More Time When They:**
|
|
1164
|
+
|
|
1165
|
+
□ Say "I'd write a function to loop through..."
|
|
1166
|
+
□ Ask "How do I call the rules?"
|
|
1167
|
+
□ Can't identify patterns in scenarios
|
|
1168
|
+
□ Don't understand logic log output
|
|
1169
|
+
□ Think rules are just "shortcuts for code"
|
|
1170
|
+
|
|
1171
|
+
**If more time needed:** Do another scenario walkthrough using pattern lens.
|
|
1172
|
+
|
|
1173
|
+
---
|
|
1174
|
+
|
|
1175
|
+
## Notes for Future Updates
|
|
1176
|
+
|
|
1177
|
+
### **What Works Well:**
|
|
1178
|
+
- The provocation approach (forces discovery)
|
|
1179
|
+
- Logic log emphasis (builds debugging habit)
|
|
1180
|
+
- Pattern naming repetition (builds vocabulary)
|
|
1181
|
+
- Conversational readiness check (better than quiz)
|
|
1182
|
+
|
|
1183
|
+
### **What to Improve:**
|
|
1184
|
+
- [Add learnings from actual guided tour sessions]
|
|
1185
|
+
- [Common stumbling points to address]
|
|
1186
|
+
- [Additional scenarios that worked well]
|
|
1187
|
+
|
|
1188
|
+
### **Resources to Add:**
|
|
1189
|
+
- Video walkthrough following this script
|
|
1190
|
+
- Printable pattern reference card
|
|
1191
|
+
- Common mistakes cheat sheet
|
|
1192
|
+
- Level-2 guided tour checklist
|
|
1193
|
+
|
|
1194
|
+
---
|
|
1195
|
+
|
|
1196
|
+
**Remember:** You're the experienced guide walking them around the neighborhood. You've been here 1000 times. They're seeing it for the first time. Your job: make them DISCOVER the insights, not just hear them.
|