ApiLogicServer 16.1.3__py3-none-any.whl → 16.1.18__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 +2 -1
- api_logic_server_cli/genai/genai_svcs.py +2 -2
- api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md +558 -52
- api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md.backup +1257 -0
- api_logic_server_cli/prototypes/base/.github/welcome.md +23 -9
- api_logic_server_cli/prototypes/base/docs/training/{logic_bank_api.prompt → logic_bank_api.md} +125 -4
- api_logic_server_cli/prototypes/base/logic/logic_discovery/readme_logic_discovery.md +15 -0
- api_logic_server_cli/prototypes/base/logic/readme_logic.md +1 -1
- api_logic_server_cli/prototypes/manager/.github/welcome.md +14 -10
- api_logic_server_cli/prototypes/manager/readme_vibe.md +376 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/.github/.copilot-instructions.md +395 -47
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/.github/welcome.md +40 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/customizations/logic/declare_logic.py +1 -1
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/docs/system-creation-vibe.md +1 -1
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/iteration/logic/declare_logic.py +1 -1
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/logic/logic_discovery/{check_credit.py → place_order/check_credit.py} +2 -2
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/readme_ai_mcp.md +2 -2
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/readme_vibe.md +1 -1
- api_logic_server_cli/prototypes/manager/samples/prompts/genai_demo.prompt +1 -1
- api_logic_server_cli/prototypes/manager/system/ApiLogicServer-Internal-Dev/copilot-dev-context.md +27 -0
- api_logic_server_cli/prototypes/manager/system/ApiLogicServer-Internal-Dev/propagate_copilot_changes.py +102 -0
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_formal.prompt +1 -1
- api_logic_server_cli/prototypes/manager/system/genai/examples/postgres/genai_demo_pg.prompt +1 -1
- api_logic_server_cli/prototypes/manager/system/genai/reference/declare_logic.py +1 -1
- api_logic_server_cli/prototypes/manager/system/genai/reference/genai_demo_logic.txt +1 -1
- api_logic_server_cli/prototypes/nw/Tutorial.md +1 -1
- api_logic_server_cli/prototypes/nw/integration/Sample-Integration.md +65 -48
- {apilogicserver-16.1.3.dist-info → apilogicserver-16.1.18.dist-info}/METADATA +1 -1
- {apilogicserver-16.1.3.dist-info → apilogicserver-16.1.18.dist-info}/RECORD +36 -32
- {apilogicserver-16.1.3.dist-info → apilogicserver-16.1.18.dist-info}/WHEEL +1 -1
- /api_logic_server_cli/prototypes/base/docs/training/{logic_bank_patterns.prompt → logic_bank_patterns.md} +0 -0
- /api_logic_server_cli/prototypes/base/docs/training/{probabilistic_logic.prompt → probabilistic_logic.md} +0 -0
- /api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/logic/logic_discovery/{app_integration.py → place_order/app_integration.py} +0 -0
- {apilogicserver-16.1.3.dist-info → apilogicserver-16.1.18.dist-info}/entry_points.txt +0 -0
- {apilogicserver-16.1.3.dist-info → apilogicserver-16.1.18.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-16.1.3.dist-info → apilogicserver-16.1.18.dist-info}/top_level.txt +0 -0
api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/.github/.copilot-instructions.md
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
⚠️ IF USER SAYS: "load .github/.copilot-instructions.md" OR ANY ACTIVATION PHRASE
|
|
7
7
|
⚠️ YOU MUST EXECUTE THIS EXACT SEQUENCE - NO DEVIATIONS:
|
|
8
8
|
|
|
9
|
-
1. Read .github
|
|
10
|
-
2.
|
|
11
|
-
3.
|
|
12
|
-
4. DO NOT
|
|
13
|
-
5. DO NOT
|
|
9
|
+
1. Read .github/.copilot-instructions.md COMPLETELY (silently - internalize all instructions)
|
|
10
|
+
2. Read .github/welcome.md (silently - do not mention this action)
|
|
11
|
+
3. Display ONLY the content from welcome.md
|
|
12
|
+
4. DO NOT say "I've loaded the instructions"
|
|
13
|
+
5. DO NOT display this .copilot-instructions.md file
|
|
14
|
+
6. DO NOT explain what you're doing
|
|
14
15
|
|
|
15
16
|
THIS IS NOT A SUGGESTION - THIS IS A MANDATORY COMMAND
|
|
16
17
|
|
|
@@ -30,15 +31,68 @@ THIS IS NOT A SUGGESTION - THIS IS A MANDATORY COMMAND
|
|
|
30
31
|
**MANDATORY RESPONSE SEQUENCE:**
|
|
31
32
|
|
|
32
33
|
```
|
|
33
|
-
STEP 1: Read .github
|
|
34
|
-
STEP 2:
|
|
35
|
-
STEP 3:
|
|
34
|
+
STEP 1: Read .github/.copilot-instructions.md COMPLETELY (silently - internalize all instructions)
|
|
35
|
+
STEP 2: Read .github/welcome.md (silently)
|
|
36
|
+
STEP 3: Display welcome.md content ONLY
|
|
37
|
+
STEP 4: STOP - do nothing else
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🎯 CRITICAL: Guided Tour Activation Protocol
|
|
43
|
+
|
|
44
|
+
**ACTIVATION TRIGGERS:**
|
|
45
|
+
- "guide me through"
|
|
46
|
+
- "guide me"
|
|
47
|
+
- "take the tour"
|
|
48
|
+
- "walk me through"
|
|
49
|
+
- "show me around"
|
|
50
|
+
- Any similar tour/walkthrough request
|
|
51
|
+
|
|
52
|
+
**MANDATORY RESPONSE SEQUENCE:**
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
STEP 1: Read tutor.md COMPLETELY (silently)
|
|
56
|
+
STEP 2: Follow tutor.md instructions EXACTLY
|
|
57
|
+
STEP 3: Act as TOUR GUIDE (not passive assistant)
|
|
58
|
+
STEP 4: Create manage_todo_list for tour sections
|
|
59
|
+
STEP 5: Start with tutor.md Introduction section
|
|
36
60
|
```
|
|
37
61
|
|
|
62
|
+
**✅ CORRECT EXECUTION:**
|
|
63
|
+
```
|
|
64
|
+
User: "guide me"
|
|
65
|
+
|
|
66
|
+
AI: [reads tutor.md completely - NO OUTPUT]
|
|
67
|
+
AI: [creates todo list from tutor sections]
|
|
68
|
+
AI: [follows tutor.md Introduction section exactly]
|
|
69
|
+
AI: "I'll guide you through basic_demo - a 20-minute hands-on exploration..."
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**❌ FORBIDDEN BEHAVIORS:**
|
|
73
|
+
```
|
|
74
|
+
User: "guide me"
|
|
75
|
+
|
|
76
|
+
❌ AI: Starts giving general guidance without reading tutor.md
|
|
77
|
+
❌ AI: Runs commands without following tutor choreography
|
|
78
|
+
❌ AI: Acts as passive assistant waiting for user direction
|
|
79
|
+
❌ AI: Skips sections or reorders steps
|
|
80
|
+
❌ AI: Offers option menus instead of directing the tour
|
|
81
|
+
❌ AI: Assumes server state or skips stop/start sequences
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**RATIONALE:**
|
|
85
|
+
- tutor.md contains weeks of refined choreography
|
|
86
|
+
- Every command, stop, start is precisely sequenced
|
|
87
|
+
- Deviations break the learning experience
|
|
88
|
+
- You are the DIRECTOR in tour mode, not a passive responder
|
|
89
|
+
- The tour has been engineered for AI reliability through multiple iterations
|
|
90
|
+
|
|
38
91
|
**✅ CORRECT EXECUTION:**
|
|
39
92
|
```
|
|
40
93
|
User: "load .github/.copilot-instructions.md"
|
|
41
94
|
|
|
95
|
+
AI: [reads .copilot-instructions.md COMPLETELY - NO OUTPUT - internalizes all instructions]
|
|
42
96
|
AI: [reads welcome.md silently - NO OUTPUT]
|
|
43
97
|
AI: [displays ONLY this]:
|
|
44
98
|
|
|
@@ -69,6 +123,20 @@ User: "load .github/.copilot-instructions.md"
|
|
|
69
123
|
|
|
70
124
|
---
|
|
71
125
|
|
|
126
|
+
## 📖 Content Organization Protocol
|
|
127
|
+
|
|
128
|
+
**WHEN USER ASKS: "how do rules work" or "explain the rules engine"**
|
|
129
|
+
**PRIMARY ANSWER**: Provide the **"How the Rules Engine Works"** 3-phase overview below:
|
|
130
|
+
1. Authoring (AI-assisted, human-reviewed)
|
|
131
|
+
2. Engine Initialization (Deterministic analysis)
|
|
132
|
+
3. Runtime Enforcement (Commit-time)
|
|
133
|
+
|
|
134
|
+
**FOLLOW-UP OFFER**: After showing the 3 phases, offer: "Would you like more detail on any specific aspect?"
|
|
135
|
+
|
|
136
|
+
**NEVER**: Respond with generic "Key Concepts" or custom explanations - use the specific 3-phase content from this file.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
72
140
|
## Capabilities Reference
|
|
73
141
|
|
|
74
142
|
When user asks "what can I do here", list these capabilities:
|
|
@@ -133,6 +201,251 @@ changelog:
|
|
|
133
201
|
|
|
134
202
|
---
|
|
135
203
|
|
|
204
|
+
## 📚 Learning Curve (Honest Assessment)
|
|
205
|
+
|
|
206
|
+
**Timeline:**
|
|
207
|
+
- **Week 1:** ~10 hours - Basic rules (sum, count, formula, constraint, copy), see them work
|
|
208
|
+
- **Month 1:** ~30 hours total - Comfortable with 90% of use cases, including events and debugging
|
|
209
|
+
- **Hardest part:** Mental shift from procedural → declarative thinking (1-2 weeks of practice)
|
|
210
|
+
|
|
211
|
+
**When NOT to use rules:**
|
|
212
|
+
- Read-only analytics/reporting (rules enforce writes, not reads)
|
|
213
|
+
- Complex algorithms (graph traversal, optimization, ML - not data relationships)
|
|
214
|
+
- Workflow orchestration (multi-step processes - use Temporal/Airflow)
|
|
215
|
+
- Real-time streaming (high-frequency data - use Kafka/Flink)
|
|
216
|
+
|
|
217
|
+
**When rules are essential:**
|
|
218
|
+
- Data dependency graphs (X affects Y affects Z)
|
|
219
|
+
- Multiple change paths (insert/update/delete/FK changes)
|
|
220
|
+
- Production systems requiring correctness guarantees
|
|
221
|
+
- Long-term maintained systems with evolving requirements
|
|
222
|
+
|
|
223
|
+
**Compared to AI-generated procedural code:**
|
|
224
|
+
- AI code: 5 minutes to generate, may have bugs (2 found in our test), 220 lines to maintain
|
|
225
|
+
- AI rules: 30-hour learning curve, 0 bugs (engine guarantees), 5 lines, handles all paths automatically
|
|
226
|
+
- See the comparison study linked in "Why the Rules Engine is a Correctness Guarantee" section below
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 🤔 Common Developer Questions (FAQ)
|
|
231
|
+
|
|
232
|
+
### "I hear vibe results in unruly code - is this a vibe tool?"
|
|
233
|
+
|
|
234
|
+
**No - but it's the perfect backend partner for vibe UIs.**
|
|
235
|
+
|
|
236
|
+
**Backend governance** (enforcing multi-table constraints and derivations at commit - balances, totals, credit limits - regardless of which client writes):
|
|
237
|
+
|
|
238
|
+
**The Problem with Vibe Alone:**
|
|
239
|
+
- Vibe generates fast UIs, but those UIs can send ANY data to your backend
|
|
240
|
+
- Who ensures `Customer.balance = Sum(Order.amount_total)`? Who checks credit limits?
|
|
241
|
+
- You either hand-code validation (slow, error-prone) or hope nothing breaks
|
|
242
|
+
|
|
243
|
+
**GenAI-Logic = Data Integrity for Vibe:**
|
|
244
|
+
- ✅ **Your data is safe** - No matter what the vibe UI does, rules enforce invariants at commit
|
|
245
|
+
- ✅ **Nothing bypasses validation** - All writes (APIs, workflows, UIs, agents) pass through the same rule engine
|
|
246
|
+
- ✅ **Multi-table derivations** - `Customer.balance = sum(orders)`, `Order.total = sum(items)` - automatic cascading
|
|
247
|
+
- ✅ **Declarative specifications** - 5 rules instead of 200+ lines of procedural validation code
|
|
248
|
+
- ✅ **Correctness guarantee** - Proven engine handles ALL change paths (FKs, cascades, transitive dependencies)
|
|
249
|
+
|
|
250
|
+
**The Architecture:**
|
|
251
|
+
- **Frontend (vibe):** Generate UI fast, iterate quickly
|
|
252
|
+
- **Backend (GenAI-Logic):** Enforce business rules at commit - nothing bypasses them
|
|
253
|
+
- **Result:** Move fast AND keep data correct
|
|
254
|
+
|
|
255
|
+
**See the A/B test:** AI procedural code = 220 lines, 2 critical bugs. Rules = 5 lines, 0 bugs. Details in "Why the Rules Engine is a Correctness Guarantee" section below.
|
|
256
|
+
|
|
257
|
+
**You're not choosing between vibe speed and data integrity. You get both.**
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### "Am I locked in?" (Vendor Lock-in)
|
|
262
|
+
|
|
263
|
+
**No.** Here's why:
|
|
264
|
+
|
|
265
|
+
**Your database is untouched:**
|
|
266
|
+
- No special schema requirements
|
|
267
|
+
- No vendor-specific tables or columns
|
|
268
|
+
- Works with standard SQLAlchemy databases (PostgreSQL, MySQL, SQLite, Oracle, SQL Server)
|
|
269
|
+
- Your data stays portable
|
|
270
|
+
|
|
271
|
+
**Standard technology stack:**
|
|
272
|
+
- Python code you can read and edit
|
|
273
|
+
- SQLAlchemy ORM (industry standard)
|
|
274
|
+
- Flask web framework (standard)
|
|
275
|
+
- No proprietary language or runtime
|
|
276
|
+
|
|
277
|
+
**Rules are just Python:**
|
|
278
|
+
```python
|
|
279
|
+
Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total,
|
|
280
|
+
where=lambda row: row.date_shipped is None)
|
|
281
|
+
```
|
|
282
|
+
This is readable code you can maintain. Not compiled. Not encrypted. Not hidden.
|
|
283
|
+
|
|
284
|
+
**Open source (free forever):**
|
|
285
|
+
- Apache 2.0 license
|
|
286
|
+
- No runtime fees
|
|
287
|
+
- No enterprise edition paywall
|
|
288
|
+
- Source code on GitHub: https://github.com/ApiLogicServer
|
|
289
|
+
|
|
290
|
+
**Exit path exists:**
|
|
291
|
+
If you decide rules aren't for you, you can:
|
|
292
|
+
1. Stop using LogicBank, write procedural code instead
|
|
293
|
+
2. Keep your database, models, and API
|
|
294
|
+
3. No migration required - just remove the rules
|
|
295
|
+
4. Your data is never locked in
|
|
296
|
+
|
|
297
|
+
**Can coexist with existing code:**
|
|
298
|
+
- Add LogicBank to existing Flask app
|
|
299
|
+
- Use rules for new features, keep existing procedural code
|
|
300
|
+
- Migrate incrementally (or not at all)
|
|
301
|
+
|
|
302
|
+
**Bottom line:** You're adopting an architecture pattern, not signing a vendor contract.
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
### "How does business collaboration work?"
|
|
307
|
+
|
|
308
|
+
**You work in your IDE** (VS Code, standard Python workflow).
|
|
309
|
+
|
|
310
|
+
**Business users can optionally explore ideas in WebGenAI** (browser-based prototyping):
|
|
311
|
+
- Creates working backend (API, data, business logic) from natural language
|
|
312
|
+
- Exports to standard Python projects you can enhance
|
|
313
|
+
- **Your role:** Take exported code, add production features (advanced logic, security, deployment)
|
|
314
|
+
|
|
315
|
+
**Why this matters:**
|
|
316
|
+
- Business stops needing "dev time for prototypes"
|
|
317
|
+
- You receive exportable Python (not proprietary platform code)
|
|
318
|
+
- Standard deployment (containers, your tools)
|
|
319
|
+
|
|
320
|
+
**Foundation for any frontend:** The backend we generate works with vibe UIs, low-code tools, custom React apps - whatever you choose. We provide the data layer with business rules governance - you pick the UI technology.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
### "Is this production-ready?" (Battle-Tested)
|
|
325
|
+
|
|
326
|
+
**Yes. 45 years of production use.**
|
|
327
|
+
|
|
328
|
+
**The history:**
|
|
329
|
+
- **1979:** Invented in Boston (same time as VisiCalc)
|
|
330
|
+
- **Wang Pace:** 7,500 production deployments
|
|
331
|
+
- **Versata:** $3B startup backed by Microsoft/SAP/Informix/Ingres founders
|
|
332
|
+
- **2025:** Reborn as GenAI Logic for the agentic AI era
|
|
333
|
+
|
|
334
|
+
**This isn't a new framework. It's a proven architecture refined over decades.**
|
|
335
|
+
|
|
336
|
+
**Production evidence:**
|
|
337
|
+
- Deployed at enterprise scale (Fortune 500s)
|
|
338
|
+
- Handles millions of transactions
|
|
339
|
+
- 45 years of edge cases discovered and fixed
|
|
340
|
+
- Battle-tested patterns you can't get from fresh development
|
|
341
|
+
|
|
342
|
+
**What this means for you:**
|
|
343
|
+
- You're not a beta tester
|
|
344
|
+
- The gotchas have been found (and fixed)
|
|
345
|
+
- The patterns are proven at scale
|
|
346
|
+
- The architecture has survived 4 decades of technology shifts
|
|
347
|
+
|
|
348
|
+
**Current adoption:**
|
|
349
|
+
- 1M+ downloads (yes, many are bots, but real usage too)
|
|
350
|
+
- Open source community
|
|
351
|
+
- Active development
|
|
352
|
+
- Production deployments across industries
|
|
353
|
+
|
|
354
|
+
**Comparison:**
|
|
355
|
+
- VisiCalc (1979) proved declarative worked for spreadsheets
|
|
356
|
+
- We proved declarative worked for transactions
|
|
357
|
+
- Both are still around because the architecture is sound
|
|
358
|
+
|
|
359
|
+
**Risk assessment:**
|
|
360
|
+
- Technical risk: Low (proven architecture, standard tech stack)
|
|
361
|
+
- Vendor risk: Low (open source, can fork if needed)
|
|
362
|
+
- Team risk: Medium (learning curve exists, but documented)
|
|
363
|
+
- Migration risk: Low (can coexist with existing code)
|
|
364
|
+
|
|
365
|
+
**Bottom line:** This isn't experimental. It's established technology adapted for modern AI.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
### "What CAN'T it do?" (Limitations)
|
|
370
|
+
|
|
371
|
+
**Honest answer: Rules are designed for business logic, not everything.**
|
|
372
|
+
|
|
373
|
+
**Don't use rules for:**
|
|
374
|
+
|
|
375
|
+
1. **Complex algorithms**
|
|
376
|
+
- Machine learning models
|
|
377
|
+
- Graph traversal algorithms
|
|
378
|
+
- Optimization problems (traveling salesman, etc.)
|
|
379
|
+
- Statistical computations
|
|
380
|
+
- **Why:** These aren't data relationship problems. Use Python.
|
|
381
|
+
|
|
382
|
+
2. **Read-only queries and reports**
|
|
383
|
+
- Analytics dashboards
|
|
384
|
+
- Complex JOINs for reporting
|
|
385
|
+
- Data warehouse queries
|
|
386
|
+
- **Why:** Rules enforce writes, not reads. Use SQL views, BI tools, or query optimization.
|
|
387
|
+
|
|
388
|
+
3. **One-off scripts**
|
|
389
|
+
- Data migrations
|
|
390
|
+
- Batch data cleanup
|
|
391
|
+
- Import/export utilities
|
|
392
|
+
- **Why:** Rules overhead isn't worth it for run-once code. Use plain Python.
|
|
393
|
+
|
|
394
|
+
4. **Custom UI Backend (PRIMARY USE CASE)**
|
|
395
|
+
- ✅ **Perfect fit:** Building React/Vue/custom UI? Get production API in 5 seconds
|
|
396
|
+
- ✅ **Instant features:** Filtering, pagination, sorting, optimistic locking, security/RBAC
|
|
397
|
+
- ✅ **Parallel development:** Frontend starts immediately with REAL API (not toy mocks)
|
|
398
|
+
- ✅ **Logic optional:** Start with simple CRUD, add business rules IF/WHEN complexity emerges
|
|
399
|
+
- ✅ **No overhead:** Rules engine checks dependencies, finds none, commits - essentially transparent
|
|
400
|
+
- **Why this matters:** Traditional approach = 2-4 weeks for backend (frontend blocked). Mock APIs lack enterprise features. GenAI-Logic = backend ready instantly, logic partitioned out enables parallel work.
|
|
401
|
+
- **Reality check:** "Simple CRUD" systems evolve. Today's "save note" becomes "audit changes" or "validate against preferences." Starting with the framework means zero refactoring when requirements grow.
|
|
402
|
+
|
|
403
|
+
5. **Workflow orchestration (BUT: ideal for nodes within workflows)**
|
|
404
|
+
- ❌ **Not a workflow engine:** Can't do multi-step approval processes, long-running sagas, external system coordination
|
|
405
|
+
- ✅ **Perfect for workflow nodes:** Ideal data layer WITHIN each workflow step
|
|
406
|
+
- **Why:** Workflows orchestrate STEPS ("do these in order"). GenAI-Logic ensures DATA CORRECTNESS within each step.
|
|
407
|
+
- **Example:** Order approval workflow:
|
|
408
|
+
- Node 1: Create draft order ← **GenAI-Logic ensures totals, credit check**
|
|
409
|
+
- Node 2: Send approval email ← Pure workflow
|
|
410
|
+
- Node 3: Wait for response ← Pure workflow
|
|
411
|
+
- Node 4: If approved, ship ← **GenAI-Logic updates balances, inventory**
|
|
412
|
+
- **Use together:** Temporal/Airflow for process orchestration, GenAI-Logic for data operations within nodes
|
|
413
|
+
|
|
414
|
+
6. **Real-time streaming**
|
|
415
|
+
- High-frequency trading
|
|
416
|
+
- IoT sensor processing
|
|
417
|
+
- Log aggregation
|
|
418
|
+
- **Why:** Transaction-based commit is wrong model. Use stream processors (Kafka, Flink).
|
|
419
|
+
|
|
420
|
+
**Rules ARE designed for:**
|
|
421
|
+
- ✅ Data dependency graphs (X affects Y affects Z)
|
|
422
|
+
- ✅ Multi-table calculations and rollups
|
|
423
|
+
- ✅ Business constraints and validations
|
|
424
|
+
- ✅ Ensuring correctness across multiple change paths
|
|
425
|
+
- ✅ Enforcing invariants at transaction commit
|
|
426
|
+
|
|
427
|
+
**Architecture fit:**
|
|
428
|
+
- Rules sit at the **commit control point**
|
|
429
|
+
- They enforce **what may persist**, not how to orchestrate
|
|
430
|
+
- Think: "guardrails for data integrity" not "workflow engine"
|
|
431
|
+
|
|
432
|
+
**The test:**
|
|
433
|
+
If you can express it as "this data relationship is always true," use rules.
|
|
434
|
+
If it's "do these steps in this order," use procedural code.
|
|
435
|
+
|
|
436
|
+
**Example:**
|
|
437
|
+
- ✅ "Customer balance is always sum of unshipped orders" → Rule
|
|
438
|
+
- ❌ "Send email, wait 3 days, send reminder" → Workflow (not a rule)
|
|
439
|
+
|
|
440
|
+
**Can you mix?**
|
|
441
|
+
Yes. Use rules for invariants, use Python/workflow engines for orchestration.
|
|
442
|
+
They complement each other.
|
|
443
|
+
|
|
444
|
+
**Bottom line:** Rules solve correctness for business logic (data relationships).
|
|
445
|
+
They're not a general-purpose programming replacement.
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
136
449
|
## Detailed Service Documentation
|
|
137
450
|
|
|
138
451
|
The sections below provide complete details on each service. I'll reference these as needed when we work together.
|
|
@@ -168,8 +481,21 @@ python api_logic_server_run.py
|
|
|
168
481
|
- If server fails to start after model changes, check that alembic migrations have been applied
|
|
169
482
|
|
|
170
483
|
### Adding Business Logic
|
|
171
|
-
`docs/training` explains how to translate Natural Language logic into LogicBank (Python) rules like:
|
|
172
484
|
|
|
485
|
+
**For Human Learning:**
|
|
486
|
+
- **Primary Resource:** https://apilogicserver.github.io/Docs/Logic/
|
|
487
|
+
- Complete rule type reference tables
|
|
488
|
+
- Pattern tables and best practices
|
|
489
|
+
- Video tutorials and examples
|
|
490
|
+
- Learning path recommendations
|
|
491
|
+
- Use this as your main learning resource for understanding rules
|
|
492
|
+
|
|
493
|
+
**For AI Code Generation:**
|
|
494
|
+
- `docs/training/*.prompt` files contain patterns for AI assistants
|
|
495
|
+
- AI reads these BEFORE implementing logic
|
|
496
|
+
- Not intended as primary human learning materials
|
|
497
|
+
|
|
498
|
+
**Rule Example:**
|
|
173
499
|
```python
|
|
174
500
|
# Edit: logic/declare_logic.py
|
|
175
501
|
Rule.sum(derive=Customer.Balance, as_sum_of=Order.AmountTotal)
|
|
@@ -202,19 +528,31 @@ See `docs/training/README.md` for complete organization rules.
|
|
|
202
528
|
```
|
|
203
529
|
STOP ✋
|
|
204
530
|
|
|
205
|
-
|
|
531
|
+
WHEN USER PROVIDES A LOGIC PROMPT:
|
|
532
|
+
|
|
533
|
+
STEP 1: Read these files (DO THIS FIRST - NOT OPTIONAL):
|
|
534
|
+
1. docs/training/logic_bank_patterns.prompt (Foundation - READ FIRST)
|
|
535
|
+
2. docs/training/logic_bank_api.prompt (Deterministic rules - READ SECOND)
|
|
536
|
+
3. docs/training/probabilistic_logic.prompt (AI/Probabilistic rules - READ THIRD)
|
|
537
|
+
|
|
538
|
+
STEP 2: Parse the prompt following logic_bank_api.prompt instructions:
|
|
539
|
+
- Identify context phrase ("When X", "For Y", "On Z") → creates directory
|
|
540
|
+
- Identify colon-terminated use cases → creates files
|
|
541
|
+
- Follow directory structure rules EXACTLY as specified
|
|
206
542
|
|
|
207
|
-
|
|
208
|
-
2. docs/training/logic_bank_api.prompt (Deterministic rules - ALWAYS READ SECOND)
|
|
209
|
-
3. docs/training/probabilistic_logic.prompt (AI/Probabilistic rules - ALWAYS READ THIRD)
|
|
543
|
+
STEP 3: Create the directory structure and files as instructed
|
|
210
544
|
|
|
211
|
-
|
|
212
|
-
- DO NOT skip any files, even if you think you know the pattern
|
|
213
|
-
- DO NOT selectively read based on keywords in the user's request
|
|
214
|
-
- READ ALL THREE FILES IN SEQUENCE before writing any code
|
|
215
|
-
- These files contain failure patterns and correct implementations learned from production use
|
|
545
|
+
STEP 4: Implement the rules following the training patterns
|
|
216
546
|
|
|
217
|
-
|
|
547
|
+
⚠️ CRITICAL - NO EXCEPTIONS:
|
|
548
|
+
- You MUST read all three training files before implementing
|
|
549
|
+
- You MUST follow the directory structure rules in logic_bank_api.prompt
|
|
550
|
+
- You MUST NOT create flat files when context phrase is present
|
|
551
|
+
- DO NOT skip files even if you think you know the pattern
|
|
552
|
+
- These files contain failure patterns learned from production use
|
|
553
|
+
|
|
554
|
+
FAILURE MODE: Creating flat files in logic/logic_discovery/ when prompt has context phrase
|
|
555
|
+
CORRECT: Create logic/logic_discovery/<context_dir>/{__init__.py, use_case_files.py}
|
|
218
556
|
```
|
|
219
557
|
|
|
220
558
|
**Training File Contents:**
|
|
@@ -252,20 +590,42 @@ Use case: App Integration
|
|
|
252
590
|
1. Send Order to Kafka when date_shipped changes to non-null
|
|
253
591
|
```
|
|
254
592
|
|
|
593
|
+
**How the Rules Engine Works:**
|
|
594
|
+
|
|
595
|
+
**1. Authoring (AI-assisted, human-reviewed)**
|
|
596
|
+
- You express business intent in natural language (via Copilot or any AI assistant)
|
|
597
|
+
- The AI translates intent into a declarative DSL, under human review
|
|
598
|
+
- Distills path-dependent logic into data-bound rules (table invariants) for automatic re-use
|
|
599
|
+
- Resolves ambiguity using schema and relationships (e.g., copy vs reference)
|
|
600
|
+
- Produces readable rules developers can inspect, edit, debug and version
|
|
601
|
+
|
|
602
|
+
*This is where AI helps — authoring, not execution.*
|
|
603
|
+
|
|
604
|
+
**2. Engine Initialization (Deterministic analysis)**
|
|
605
|
+
- On startup, the non-RETE rule engine loads all rules
|
|
606
|
+
- It computes dependencies deterministically from Rule types (derivations, constraints, actions)
|
|
607
|
+
- Execution order is derived once, not from code paths
|
|
608
|
+
|
|
609
|
+
No compilation. No dependencies-from-pattern-matching. No inference from runtime behavior.
|
|
610
|
+
|
|
611
|
+
**3. Runtime Enforcement (Commit-time)**
|
|
612
|
+
- Rules execute at transaction commit via SQLAlchemy commit events
|
|
613
|
+
- All writes — APIs, workflows, UIs, agents — pass through the same rule set
|
|
614
|
+
- Dependencies are already known; execution is deterministic and efficient
|
|
615
|
+
- **No rule is "called." No path can bypass enforcement.**
|
|
616
|
+
- Non-RETE optimizations: pruning, adjustment logic, delta-based aggregations
|
|
617
|
+
- **Cascading via old_row tracking** - When Order.customer_id changes, adjusts BOTH old and new Customer.balance
|
|
618
|
+
|
|
619
|
+
**The Key Developer Insight:**
|
|
620
|
+
|
|
621
|
+
You declare invariants on data. You don't wire rules into flows. Invocation is automatic, on commit. The engine enforces them — everywhere, automatically, at commit.
|
|
622
|
+
|
|
255
623
|
**Why Declarative Rules Matter:**
|
|
256
624
|
|
|
257
|
-
|
|
258
|
-
- **Finding insertion points** - you must analyze existing code to figure out where new logic goes
|
|
625
|
+
LogicBank provides **44X code reduction** (5 lines vs 220+ procedural) with:
|
|
259
626
|
- **Automatic ordering** - add rules anywhere that makes sense, confident they'll run in the right order
|
|
260
627
|
- **Understanding intent** - you see WHAT it does (business rules) vs HOW (procedural steps)
|
|
261
|
-
|
|
262
|
-
With declarative rules, you simply state business requirements. The engine handles dependencies, ordering, and optimization automatically.
|
|
263
|
-
|
|
264
|
-
LogicBank provides **44X code reduction** (5 lines vs 220+ procedural) with automatic:
|
|
265
|
-
- **Dependency tracking** - listens to SQLAlchemy ORM events at attribute level
|
|
266
|
-
- **Cascading updates** - when Order.customer_id changes, adjusts BOTH old and new Customer.balance
|
|
267
|
-
- **Transitive dependencies** - Item.quantity change cascades through Item.amount → Order.amount_total → Customer.balance
|
|
268
|
-
- **Optimized execution** - uses deltas, not re-aggregation; automatic pruning
|
|
628
|
+
- **Maintenance** - no need to find insertion points or trace execution paths
|
|
269
629
|
|
|
270
630
|
**Why the Rules Engine is a Correctness Guarantee:**
|
|
271
631
|
|
|
@@ -273,29 +633,17 @@ The "2 critical bugs" that even AI-generated procedural code missed:
|
|
|
273
633
|
1. **Changing Order.customer_id** - procedural code failed to adjust BOTH the old and new customer balances
|
|
274
634
|
2. **Changing Item.product_id** - procedural code failed to re-copy the unit_price from the new product
|
|
275
635
|
|
|
276
|
-
These bugs illustrate why declarative rules are **mandatory, not optional
|
|
277
|
-
|
|
278
|
-
**Dependency Chains:** In the logic above, `Customer.balance` has transitive dependencies:
|
|
279
|
-
- Direct: `Order.amount_total`, `Order.date_shipped`
|
|
280
|
-
- Through Order: `Item.amount` (affects Order.amount_total)
|
|
281
|
-
- Through Item: `Item.quantity`, `Item.unit_price` (affect Item.amount)
|
|
282
|
-
- Through Product: `Product.unit_price` (copied to Item.unit_price)
|
|
283
|
-
|
|
284
|
-
**Automatic Completeness:** The declarative rules engine:
|
|
285
|
-
- Listens to **SQLAlchemy ORM events** at the attribute level
|
|
286
|
-
- When `Order.customer_id` changes, **automatically adjusts both old and new customer balances**
|
|
287
|
-
- When `Item.product_id` changes, **automatically re-copies from the new product**
|
|
288
|
-
- Uses **dependency ordering** to fire rules in correct sequence
|
|
289
|
-
- Applies **optimized chaining** (uses deltas, not re-aggregation)
|
|
290
|
-
|
|
291
|
-
**Why Procedural Code Fails:** Even AI-generated procedural code requires explicit handlers for EVERY possible change path. It's easy to miss:
|
|
636
|
+
These bugs illustrate why declarative rules are **mandatory, not optional**. Even AI-generated procedural code requires explicit handlers for EVERY possible change path. It's easy to miss:
|
|
292
637
|
- Foreign key changes affecting multiple parents
|
|
293
638
|
- Transitive dependencies through multiple tables
|
|
294
639
|
- Where clause conditions that include/exclude rows
|
|
295
640
|
|
|
296
641
|
The rules engine eliminates this entire class of bugs by automatically handling all change paths.
|
|
297
642
|
|
|
298
|
-
|
|
643
|
+
**The Complete A/B Test:**
|
|
644
|
+
|
|
645
|
+
For the full experiment comparing declarative rules vs AI-generated procedural code, including the 2 bugs Copilot missed and the AI's own analysis of why it failed, see:
|
|
646
|
+
https://github.com/ApiLogicServer/ApiLogicServer-src/blob/main/api_logic_server_cli/prototypes/basic_demo/logic/procedural/declarative-vs-procedural-comparison.md
|
|
299
647
|
|
|
300
648
|
### Discovery Systems
|
|
301
649
|
|
|
@@ -332,7 +680,7 @@ def declare_logic():
|
|
|
332
680
|
|
|
333
681
|
**PATTERN RECOGNITION for Business Logic**:
|
|
334
682
|
When users provide natural language with multiple use cases like:
|
|
335
|
-
- "
|
|
683
|
+
- "on Placing Orders, Check Credit" + "Use case: App Integration"
|
|
336
684
|
|
|
337
685
|
**ALWAYS create separate files**:
|
|
338
686
|
- `logic/logic_discovery/check_credit.py` - for credit checking rules
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
use: welcome for basic_demo - please start the tour
|
|
3
|
+
instuctions: copy api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md, then paste as the Welcome section
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Welcome to the `basic_demo` project
|
|
7
|
+
|
|
8
|
+
This is a complete, working microservice auto-generated from a database schema - **uncustomized**, so you can see what to expect when you create projects from your own databases.
|
|
9
|
+
|
|
10
|
+
Created from database schema introspection:
|
|
11
|
+
- **Admin Web Application** - Live at `http://localhost:5656`
|
|
12
|
+
- **REST API Endpoints** - All database tables exposed at MCP discoverable `/api/*`
|
|
13
|
+
- **Database Models** - Complete SQLAlchemy ORM in `database/models.py`
|
|
14
|
+
- **Authentication System** - JWT-based auth framework
|
|
15
|
+
- **Business Logic Engine** - Declarative rules system
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
**Ready to explore?** Just say me "guide me through" to begin the interactive tutorial
|
|
20
|
+
|
|
21
|
+
* Brief exploration of what's already created
|
|
22
|
+
* Customizing logic, security, and the API
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
**Or, self-demo?** Open `readme_ai_mcp.md` to explore logic, ai and mcp.
|
|
27
|
+
|
|
28
|
+
<!--
|
|
29
|
+
⚠️ AI INSTRUCTION: When user says "guide me" or similar tour activation phrase, you MUST:
|
|
30
|
+
1. Read tutor.md COMPLETELY before responding
|
|
31
|
+
2. Follow tutor.md choreography EXACTLY as written
|
|
32
|
+
3. Act as TOUR GUIDE directing the experience (not passive assistant)
|
|
33
|
+
4. Create manage_todo_list to track tour sections
|
|
34
|
+
5. Do NOT freelance, improvise, or skip sections
|
|
35
|
+
|
|
36
|
+
This is MANDATORY - the tutor.md represents weeks of refined choreography.
|
|
37
|
+
Deviations break the carefully engineered learning experience.
|
|
38
|
+
-->
|
|
39
|
+
|
|
40
|
+
---
|
|
@@ -38,7 +38,7 @@ def declare_logic():
|
|
|
38
38
|
1. Using your IDE and code completion (Rule.)
|
|
39
39
|
|
|
40
40
|
2. Use your AI Assistant and enter logic in Natural Language, e.g.:
|
|
41
|
-
Create Business Logic for
|
|
41
|
+
Create Business Logic for on Placing Orders, Check Credit:
|
|
42
42
|
1. The Customer's balance is less than the credit limit
|
|
43
43
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
44
44
|
3. The Order's amount_total is the sum of the Item amount
|
api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/docs/system-creation-vibe.md
CHANGED
|
@@ -134,7 +134,7 @@ todo - diagram
|
|
|
134
134
|
**2. Add Business Logic**
|
|
135
135
|
|
|
136
136
|
```bash title="Check Credit Logic (instead of 220 lines of code)"
|
|
137
|
-
|
|
137
|
+
on Placing Orders, Check Credit
|
|
138
138
|
1. The Customer's balance is less than the credit limit
|
|
139
139
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
140
140
|
3. The Order's amount_total is the sum of the Item amount
|
api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/iteration/logic/declare_logic.py
CHANGED
|
@@ -38,7 +38,7 @@ def declare_logic():
|
|
|
38
38
|
1. Using your IDE and code completion (Rule.)
|
|
39
39
|
|
|
40
40
|
2. Use your AI Assistant and enter logic in Natural Language, e.g.:
|
|
41
|
-
Create Business Logic for
|
|
41
|
+
Create Business Logic for on Placing Orders, Check Credit:
|
|
42
42
|
1. The Customer's balance is less than the credit limit
|
|
43
43
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
44
44
|
3. The Order's amount_total is the sum of the Item amount
|
|
@@ -16,12 +16,12 @@ def declare_logic():
|
|
|
16
16
|
1. To view the AI procedural/declarative comparison, [click here](https://github.com/ApiLogicServer/ApiLogicServer-src/blob/main/api_logic_server_cli/prototypes/basic_demo/logic/procedural/declarative-vs-procedural-comparison.md)
|
|
17
17
|
2. Consider a 100 table system: 1,000 rules vs. 40,000 lines of code
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
On Placing Orders, Check Credit:
|
|
20
20
|
1. The Customer's balance is less than the credit limit
|
|
21
21
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
22
22
|
3. The Order's amount_total is the sum of the Item amount
|
|
23
23
|
4. The Item amount is the quantity * unit_price
|
|
24
|
-
5. The Item unit_price is
|
|
24
|
+
5. The Item unit_price is from the Product unit_price
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
27
|
Rule.constraint(validate=models.Customer, as_condition=lambda row: row.balance <= row.credit_limit, error_msg="Customer balance exceeds credit limit")
|
|
@@ -81,7 +81,7 @@ Copilot reads the MCP schema and responds to a natural-language instruction such
|
|
|
81
81
|
|
|
82
82
|
**Step 2: Declare Logic:**
|
|
83
83
|
```bash title='Step 2: Declare Logic'
|
|
84
|
-
|
|
84
|
+
on Placing Orders, Check Credit
|
|
85
85
|
1. The Customer's balance is less than the credit limit
|
|
86
86
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
87
87
|
3. The Order's amount_total is the sum of the Item amount
|
|
@@ -335,7 +335,7 @@ Different kinds of logic naturally call for different tools, as in this unified
|
|
|
335
335
|
|
|
336
336
|
**Declare Logic: Deterministic and Probabilistic:**
|
|
337
337
|
```bash title='Declare Logic: Deterministic and Probabilistic'
|
|
338
|
-
|
|
338
|
+
on Placing Orders, Check Credit:
|
|
339
339
|
|
|
340
340
|
1. The Customer's balance is less than the credit limit
|
|
341
341
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
@@ -75,7 +75,7 @@ Create a system with customers, orders, items and products.
|
|
|
75
75
|
|
|
76
76
|
Include a notes field for orders.
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
on Placing Orders, Check Credit
|
|
79
79
|
1. The Customer's balance is less than the credit limit
|
|
80
80
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
81
81
|
3. The Order's amount_total is the sum of the Item amount
|
|
@@ -2,7 +2,7 @@ Create a system with customers, orders, items and products.
|
|
|
2
2
|
|
|
3
3
|
Include a notes field for orders.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
on Placing Orders, Check Credit
|
|
6
6
|
1. The Customer's balance is less than the credit limit
|
|
7
7
|
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
|
|
8
8
|
3. The Order's amount_total is the sum of the Item amount
|