ApiLogicServer 15.0.52__py3-none-any.whl → 15.0.55__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.
Files changed (34) hide show
  1. api_logic_server_cli/api_logic_server.py +6 -3
  2. api_logic_server_cli/api_logic_server_info.yaml +3 -3
  3. api_logic_server_cli/create_from_model/api_logic_server_utils.py +9 -0
  4. api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md +49 -21
  5. api_logic_server_cli/prototypes/base/database/alembic/alembic_run.py +98 -0
  6. api_logic_server_cli/prototypes/base/database/alembic/readme_alembic.md +36 -0
  7. api_logic_server_cli/prototypes/base/docs/training/admin_app_1_context.prompt.md +40 -0
  8. api_logic_server_cli/prototypes/base/integration/mcp/mcp_client_executor.py +4 -4
  9. api_logic_server_cli/prototypes/base/readme.md +11 -13
  10. api_logic_server_cli/prototypes/base/security/readme_security.md +0 -1
  11. api_logic_server_cli/prototypes/basic_demo/README.md +267 -272
  12. api_logic_server_cli/prototypes/basic_demo/_config.yml +8 -0
  13. api_logic_server_cli/prototypes/basic_demo/_layouts/redirect.html +15 -0
  14. api_logic_server_cli/prototypes/basic_demo/docs/system-creation-vibe.md +158 -0
  15. api_logic_server_cli/prototypes/basic_demo/logic/declarative-vs-procedural-comparison.html +110 -0
  16. api_logic_server_cli/prototypes/basic_demo/logic/procedural/declarative-vs-procedural-comparison.md +295 -0
  17. api_logic_server_cli/prototypes/manager/samples/prompts/add_email.prompt +8 -0
  18. api_logic_server_cli/prototypes/manager/samples/prompts/elections.prompt +3 -0
  19. api_logic_server_cli/prototypes/manager/samples/prompts/emp_dept.prompt +4 -0
  20. api_logic_server_cli/prototypes/manager/samples/prompts/genai_demo.prompt +13 -0
  21. api_logic_server_cli/prototypes/manager/samples/readme_samples.md +3 -1
  22. api_logic_server_cli/prototypes/manager/system/genai/app_templates/app_learning/Admin-App-Resource-Learning-Prompt.md +1 -1
  23. api_logic_server_cli/prototypes/manager/system/genai/app_templates/react-admin-template/package.json +1 -0
  24. api_logic_server_cli/sqlacodegen_wrapper/sqlacodegen_wrapper.py +5 -2
  25. {apilogicserver-15.0.52.dist-info → apilogicserver-15.0.55.dist-info}/METADATA +1 -1
  26. {apilogicserver-15.0.52.dist-info → apilogicserver-15.0.55.dist-info}/RECORD +30 -23
  27. api_logic_server_cli/prototypes/base/.devcontainer-option/.copilot-instructions.md +0 -178
  28. api_logic_server_cli/prototypes/base/database/alembic/readme.md +0 -18
  29. api_logic_server_cli/prototypes/base/database/system/SAFRSBaseX.pyZ +0 -73
  30. api_logic_server_cli/prototypes/basic_demo/customizations/database/system/SAFRSBaseX.py +0 -139
  31. {apilogicserver-15.0.52.dist-info → apilogicserver-15.0.55.dist-info}/WHEEL +0 -0
  32. {apilogicserver-15.0.52.dist-info → apilogicserver-15.0.55.dist-info}/entry_points.txt +0 -0
  33. {apilogicserver-15.0.52.dist-info → apilogicserver-15.0.55.dist-info}/licenses/LICENSE +0 -0
  34. {apilogicserver-15.0.52.dist-info → apilogicserver-15.0.55.dist-info}/top_level.txt +0 -0
@@ -1,497 +1,492 @@
1
1
  ---
2
2
  title: Instant Microservices - with Logic and Security
3
3
  notes: gold is proto (-- doc); alert for apostrophe
4
- version: 0.21 from pip
4
+ version: 0.23 from docsite, for readme 7/11/2025
5
5
  ---
6
+ <style>
7
+ -typeset h1,
8
+ -content__button {
9
+ display: none;
10
+ }
11
+ </style>
6
12
 
7
- See how to build a complete database system -- in minutes instead of weeks or months:
13
+ # Product Tour (Start Here)
8
14
 
9
- 1. **An API**, and, we'll add ui and logic to make it a microservice...
10
- 2. **Logic and Security:** multi-table constraints and derivations, role-based security, and application integration
11
- 3. **An Admin App:** a multi-page, multi-table web app
12
- 4. **Customizable:** use your IDE to customize with declarative rules and standard Python
15
+ This illustrates basic [GenAI-Logic](https://www.genai-logic.com/product/key-features) operation:
13
16
 
14
- &nbsp;
17
+ 1. Creating projects from new or existing databases, providing a MCP-enabled API and an Admin App
18
+ 2. Adding declarative logic and security, and
19
+ 3. Customizing your project using your IDE and Python<br><br>
15
20
 
16
- We'll illustrate [API Logic Server](https://www.genai-logic.com/product/key-features){:target="_blank" rel="noopener"} basic GenAI-Logic operation: creating projects from new or existing databases, adding logic and security, and customizing your project using your IDE and Python.
21
+ > 🤖 **Bootstrap Copilot by pasting the following into the chat:**
22
+ ```
23
+ Please find and read `.github/.copilot-instructions.md`.
24
+ ```
17
25
 
18
- The entire process takes 20 minutes, instead of several weeks using traditional development.
26
+ <br>
19
27
 
20
- You can use this article in several ways:
28
+ The entire process takes 20 minutes; usage notes:
21
29
 
22
- * Conceptual Overview - the main article focuses on the concepts and basic process. Operational details are moved to the Appendix to retain focus.
30
+ * Important: look for **readme files** in created projects
31
+ * You may find it more convenient to view this [in your Browser](https://apilogicserver.github.io/Docs/Sample-Basic-Tour)
32
+ * A slide show summary is available [on our Web Site](https://www.genai-logic.com/product/tour)
23
33
 
24
- * Self-demo - [install](Install-Express.md){:target="_blank" rel="noopener"} and create this system yourself.
34
+ ![product-tour](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/product-tour.png?raw=true)
25
35
 
26
- * Self-demo with video - you can also use [this video](https://www.youtube.com/watch?v=sD6RFp8S6Fg) (it's the same system, but the database is created with ChatGPT).
27
36
 
28
37
  &nbsp;
29
38
 
30
- ## 1. Automation: Project Creation
39
+ ## 1. Create and Run
31
40
 
32
- API Logic Server can create projects from existing databases, or use GenAI to create projects with new databases. See the sub-sections below.
41
+ API Logic Server can create projects from existing databases, or use GenAI to create projects with new databases. Let's see how.
33
42
 
34
43
  &nbsp;
35
- ### Create From Existing Database
44
+ ### From Existing Database
36
45
 
37
- This project was created with a command like:
46
+ This is the best way to start:
38
47
 
48
+ 1. Open a terminal window: **Terminal > New Terminal**
49
+ 2. **Create Project from Existing Database:**
39
50
  ```bash
40
- $ ApiLogicServer create --project_name=basic_demo --db_url=basic_demo
51
+ genai-logic create --project_name=basic_demo --db_url=sqlite:///samples/dbs/basic_demo.sqlite
41
52
  ```
42
53
 
43
- > Note: the `db_url` value is [an abbreviation](https://apilogicserver.github.io/Docs/Data-Model-Examples/){:target="_blank" rel="noopener"} for a test database provided as part of the installation. You would normally supply a SQLAlchemy URI to your existing database.
54
+ > Note: the `db_url` value is [an abbreviation](https://apilogicserver.github.io/Docs/Data-Model-Examples/) for a test database provided as part of the installation. You would normally supply a SQLAlchemy URI to your existing database, e.g. <br>`genai-logic create --project_name=basic_demo --db_url=sqlite:///samples/dbs/basic_demo.sqlite`.
55
+
56
+
57
+ <details markdown>
58
+
59
+ <summary> The database is Customer, Orders, Items and Product</summary>
44
60
 
45
- This creates a project by reading your schema. The database is Customer, Orders, Items and Product, as shown in the Appendix.
61
+ ![basic_demo_data_model](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/basic_demo_data_model.jpeg?raw=true)
46
62
 
63
+ </details>
64
+ <br>
47
65
  &nbsp;
48
66
 
49
- ### Create With New Database
67
+ ### GenAI: New Database
50
68
 
51
- You can create a project from a prompt using GenAI, either by [WebGenAI](WebGenAI.md), or the the [GenAI CLI](WebGenAI-CLI.md){:target="_blank" rel="noopener"} as shown here.
69
+ Alternatively, you can create a project *and a new database* from a prompt, using GenAI.
70
+ > ***Don't*** do this if you are executing the basic Product Tour.
52
71
 
53
- Use the GenAI CLI with or without signup:
72
+ There are 3 ways to use GenAI:
54
73
 
55
- 1. If you have signed up (see *Obtain a OpenAI API Key*, below), this will create and open a project called `genai_demo` from `genai_demo.prompt` (available in left Explorer pane):
74
+ * WebGenAI - in the Browser, via pubic website - [click here](https://apilogicserver.github.io/Docs/WebGenAI), or
75
+ * GenAI - in the Browser, via docker - [click here](https://apilogicserver.github.io/Docs/WebGenAI-install), or
76
+ * GenAI CLI - [click here](https://apilogicserver.github.io/Docs/WebGenAI-CLI)
77
+
78
+ To use the GenAI CLI:
79
+
80
+ 1. If you have signed up (see *Get an OpenAI Key*, below), this will create and open a project called `genai_demo` from `genai_demo.prompt` (available in left Explorer pane):
56
81
 
57
82
  ```bash
58
- als genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
83
+ genai-logic genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo
59
84
  ```
60
85
 
61
-
62
-
63
86
  2. ***Or,*** you can simulate the process (no signup) using:
64
87
 
65
88
  ```bash
66
-
67
- als genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
68
-
89
+ genai-logic genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo
69
90
  ```
70
91
 
92
+ For background on how it works, [click here](Sample-Genai#how-does-it-work).
93
+
71
94
  &nbsp;
95
+
96
+
72
97
  ### Open in your IDE and Run
73
98
 
74
99
  You can open with VSCode, and run it as follows:
75
100
 
76
- 1. **Create Virtual Environment:** as shown in the Appendix.
101
+ 1. **Start the Server:** F5 (also described in the Appendix).
77
102
 
78
- 2. **Start the Server:** F5 (also described in the Appendix).
103
+ * Your virtual environment is automatically configured in most cases; see the Appendix (Procedures / Detail Procedures) if that's not working.
79
104
 
80
- 3. **Start the Admin App:** either use the links provided in the IDE console, or click [http://localhost:5656/](http://localhost:5656/). The screen shown below should appear in your Browser.
105
+ 2. **Start the Admin App:** either use the links provided in the IDE console, or click [http://localhost:5656/](http://localhost:5656/). The Admin App screen shown below should appear in your Browser.
81
106
 
82
107
  The sections below explore the system that has been created (which would be similar for your own database).
83
108
  <br><br>
84
109
 
85
- !!! pied-piper ":bulb: Automation: Instant API, Admin App (enable UI dev, agile collaboration)"
110
+ ### API with Swagger
86
111
 
87
- ### a. API with Swagger
112
+ The system creates an API with end points for each table, with filtering, sorting, pagination, optimistic locking and related data access -- **[self-serve](https://apilogicserver.github.io/Docs/API-Self-Serve/), ready for custom app dev.**
88
113
 
89
- The system creates an API with end points for each table, with filtering, sorting, pagination, optimistic locking and related data access -- **[self-serve](https://apilogicserver.github.io/Docs/API-Self-Serve/), ready for custom app dev.**
114
+ <details markdown>
90
115
 
91
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/api-swagger.jpeg?raw=true">
116
+ <summary>See the Swagger </summary>
92
117
 
93
- ### b. Admin App
118
+ ![swagger](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/api-swagger.jpeg?raw=true)
119
+ </details>
120
+ <br>
94
121
 
95
- It also creates an Admin App: multi-page, multi-table -- ready for **[business user agile collaboration](https://apilogicserver.github.io/Docs/Tech-AI/),** and back office data maintenance. This complements custom UIs created with the API.
122
+ ### Admin App
96
123
 
97
- You can click Customer 2, and see their Orders, and Items.
124
+ It also creates an Admin App: multi-page, multi-table -- ready for **[business user agile collaboration](https://apilogicserver.github.io/Docs/Tech-AI/),** and back office data maintenance. This complements custom UIs created with the API.
98
125
 
99
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/admin-app-initial.jpeg?raw=true">
126
+ You can click Customer Alice, and see their Orders, and Items.
100
127
 
101
- &nbsp;
128
+ <details markdown>
102
129
 
103
- ## 2. Declare Logic And Security
130
+ <summary>See the Admin App </summary>
131
+ ![admin-app-initial](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/admin-app-initial.jpeg?raw=true)
132
+ </details>
104
133
 
105
- While API/UI automation is a great start, it's critical to enforce logic and security. You do this in your IDE. Here's how.
134
+ <br>
106
135
 
107
- The following `add_customizations` process simulates:
136
+ ## 2. Custom UI: GenAI, Vibe
108
137
 
109
- * Adding security to your project, and
110
- * Using your IDE to declare logic and security in `logic/declare_logic.sh` and `security/declare_security.py`.
138
+ The app above is suitable for collaborative iteration to nail down the requirements, and back office data maintenance. It's also easy to make simple customizations, using the yaml file.
111
139
 
112
- > Declared security and logic are shown in the screenshots below.<br>It's quite short - 5 rules, 7 security settings.
113
-
114
- To add customizations, in a terminal window for your project:
115
-
116
- **1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)
117
-
118
- **2. Add Customizations**
140
+ For more custom apps, you get complete control by generating app source code, which you can then customize in your IDE, e.g. using Vibe Natural Language:
119
141
 
120
142
  ```bash
121
- als add-cust
143
+ # create react source (requires OpenAI key)
144
+ genai-logic genai-add-app --vibe
145
+ cd ui/react-app
146
+ npm install
147
+ npm start
122
148
  ```
123
- &nbsp;
124
-
125
- ### Declare Security
126
149
 
127
- The `add_customizations` process above has simulated the `ApiLogicServer add-auth` command, and using your IDE to declare security in `logic/declare_logic.sh`.
150
+ And you are ready to Vibe:
128
151
 
129
- To see security in action:
152
+ * Instead of creating data mockups, you have a **running API server with real data**
153
+ * Instead of starting from scratch, you have a **running multi-page app**
154
+ * And, you'll have projects that are **architecturally correct:** shared logic, enforced in the server, available for both User Interfaces and services.
155
+ * Then, use you favorite Vibe tools with your running API
130
156
 
131
- **1. Start the Server** F5
132
-
133
- **2. Start the Admin App:** [http://localhost:5656/](http://localhost:5656/)
134
-
135
- **3. Login** as `s1`, password `p`
136
157
 
137
- **4. Click Customers**
158
+ ```txt title='Customize using Natural Language'
159
+ In the ui/react app, Update the Product list to provide users an option to see results in a list, or in cards.
160
+ ```
161
+ <br>
138
162
 
139
- &nbsp;
163
+ > Below is an example from Northwind: [click here](https://apilogicserver.github.io/Docs/Admin-Vibe-Sample)
140
164
 
141
- !!! pied-piper ":bulb: Security: Authentication, Role-based Filtering, Logging"
165
+ ![vibe-cards](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/ui-vibe/nw/vibe-gallery.png?raw=true)
142
166
 
143
- #### 1. Login now required
167
+ <br>
144
168
 
145
- #### 2. Role-Based Filtering
169
+ ## 3. MCP-Ready APIs
146
170
 
147
- Observe you now see fewer customers, since user `s1` has role `sales`. This role has a declared filter, as shown in the screenshot below.
171
+ Your project is MCP-ready - this will run a simple query *List customers with credit_limit > 1000* (we'll explore more interesting examples below, including provisions for user input):
148
172
 
149
- #### 3. Transparent Logging
173
+ ```bash
174
+ Create a table SysEmail in `database/db.sqlite` as a child of customer,
175
+ with columns id, message, subject, customer_id and CreatedOn.
176
+ ```
150
177
 
151
- The screenhot below illustrates security declaration and operation:
178
+ Follow the suggestions to update the admin app.
152
179
 
153
- * The declarative Grants in the upper code panel, and
180
+ TODO: add mcp client here, and test
154
181
 
155
- * The logging in the lower panel, to assist in debugging by showing which Grants (`+ Grant:`) are applied:
182
+ TODO: test the service
156
183
 
157
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/security-filters.jpeg?raw=true">
184
+ ```bash
185
+ List the orders date_shipped is null and CreatedOn before 2023-07-14, and send a discount email (subject: 'Discount Offer') to the customer for each one.
186
+ ```
158
187
 
159
- &nbsp;
188
+ ![mcp-retrieval](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/mcp-retrieval.png?raw=true)
160
189
 
161
- ### Declare Logic
190
+ <br>
162
191
 
163
- Logic (multi-table derivations and constraints) is a significant portion of a system, typically nearly half. API Logic server provides **spreadsheet-like rules** that dramatically simplify and accelerate logic development.
192
+ ## 4. Declare Logic And Security
164
193
 
165
- Rules are declared in Python, simplified with IDE code completion. The screen below shows the 5 rules for **Check Credit Logic.**
194
+ While API/MCP/UI automation is a great start, it's **critical to enforce logic and security.** You do this in your IDE. Here's how.
166
195
 
167
- The `add_customizations` process above has simulated the process of using your IDE to declare logic in `logic/declare_logic.sh`.
196
+ The following `add_customizations` process simulates:
168
197
 
169
- To see logic in action:
198
+ * Adding security to your project, and
199
+ * Using your IDE to declare logic and security in `logic/declare_logic.sh` and `security/declare_security.py`.
170
200
 
171
- **1. In the admin app, Logout (upper right), and login as admin, p**
201
+ > Declared security and logic are shown in the screenshots below.<br>It's quite short - 5 rules, 7 security settings.
172
202
 
173
- **2. Use the Admin App to add an Order and Item for `Customer 1`** (see Appendix)
203
+ To add customizations, in a terminal window for your project:
174
204
 
175
- Observe the rules firing in the console log, as shown in the next screenshot.
205
+ **1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)
176
206
 
177
- Logic provides significant improvements over procedural logic, as described below.
207
+ **2. Add Customizations**
178
208
 
209
+ ```bash
210
+ genai-logic add-cust
211
+ genai-logic add-auth --db_url=auth
212
+ ```
179
213
  &nbsp;
180
214
 
181
- !!! pied-piper ":bulb: Logic: Multi-table Derivations and Constraint Rules, 40X More Concise"
215
+ ### Security: Role Based Access
182
216
 
183
- #### a. Chaining
217
+ The `add_customizations` process above has simulated using your IDE to declare security in `logic/declare_logic.sh`.
184
218
 
185
- The screenshot below shows our logic declarations, and the logging for inserting an `Item`. Each line represents a rule firing, and shows the complete state of the row.
219
+ To see security in action:
186
220
 
187
- Note that it's a `Multi-Table Transaction`, as indicated by the indentation. This is because - like a spreadsheet - **rules automatically chain, *including across tables.***
221
+ **1. Start the Server** F5
188
222
 
189
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/logic-chaining.jpeg?raw=true">
223
+ **2. Start the Admin App:** [http://localhost:5656/](http://localhost:5656/)
224
+
225
+ **3. Login** as `s1`, password `p`
190
226
 
191
- #### b. 40X More Concise
227
+ **4. Click Customers**
192
228
 
193
- The 5 spreadsheet-like rules represent the same logic as 200 lines of code, [shown here](https://github.com/valhuber/LogicBank/wiki/by-code). That's a remarkable 40X decrease in the backend half of the system.
194
- <br><br>
229
+ <br>
230
+ Observe:
195
231
 
196
- #### c. Automatic Re-use
232
+ **1. Login now required**
197
233
 
198
- The logic above, perhaps conceived for Place order, applies automatically to all transactions: deleting an order, changing items, moving an order to a new customer, etc. This reduces code, and promotes quality (no missed corner cases).
199
- <br><br>
234
+ **2. Role-Based Filtering**
200
235
 
201
- #### d. Automatic Optimizations
236
+ Observe you now see fewer customers, since user `s1` has role `sales`. This role has a declared filter, as shown in the screenshot below.
202
237
 
203
- SQL overhead is minimized by pruning, and by elimination of expensive aggregate queries. These can result in orders of magnitude impact.
204
- <br><br>
238
+ **3. Transparent Logging**
205
239
 
206
- #### e. Transparent
240
+ <details markdown>
207
241
 
208
- Rules are an executable design. Note they map exactly to our natural language design (shown in comments) - readable by business users.
242
+ <summary>See Security Declarations </summary>
209
243
 
210
- Optionally, you can use the Behave TDD approach to define tests, and the Rules Report will show the rules that execute for each test. For more information, [click here](https://apilogicserver.github.io/Docs/Behave-Logic-Report/).
244
+ <br>The screenshot below illustrates security declaration and operation:
211
245
 
212
- &nbsp;
246
+ * The declarative Grants in the upper code panel, and
213
247
 
214
- ## 3. Iterate with Rules and Python
248
+ * The logging in the lower panel, to assist in debugging by showing which Grants (`+ Grant:`) are applied:
215
249
 
216
- Not only are spreadsheet-like rules 40X more concise, they meaningfully simplify maintenance. Let's take an example:
250
+ ![security-filters](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/security-filters.jpeg?raw=true)
217
251
 
218
- >> Give a 10% discount for carbon-neutral products for 10 items or more.
252
+ </details>
219
253
 
220
254
  &nbsp;
221
255
 
222
- The following `add_iteration` process simulates an iteration:
256
+ ### Logic: Derivations, Constraints
223
257
 
224
- * acquires a new database with `Product.CarbonNeutral`
258
+ Logic (multi-table derivations and constraints) is a significant portion of a system, typically nearly half. API Logic Server provides **spreadsheet-like rules** that dramatically simplify and accelerate logic development.
225
259
 
226
- * issues the `genai-logic rebuild-from-database` command that rebuilds your project (the database models, the api), while preserving the customizations we made above.
260
+ Rules are declared in Python, simplified with IDE code completion. The screen below shows the 5 rules for **Check Credit Logic.**
227
261
 
228
- * acquires a revised `ui/admin/admin.yaml` that shows this new column in the admin app
262
+ The `add_customizations` process above has simulated the process of using your IDE to declare logic in `logic/declare_logic.sh`.
229
263
 
230
- * acquires this revised logic - in `logic/declare_logic.py`, we replaced the 2 lines for the `models.Item.Amount` formula with this (next screenshot shows revised logic executing with breakpoint):
264
+ To see logic in action:
231
265
 
232
- ```python
233
- def derive_amount(row: models.Item, old_row: models.Item, logic_row: LogicRow):
234
- amount = row.Quantity * row.UnitPrice
235
- if row.Product.CarbonNeutral and row.Quantity >= 10:
236
- amount = amount * Decimal(0.9) # breakpoint here
237
- return amount
266
+ **1. In the admin app, Logout (upper right), and login as admin, p**
238
267
 
239
- Rule.formula(derive=models.Item.Amount, calling=derive_amount)
240
- ```
268
+ **2. Use the Admin App to access the first order for `Customer Alice`**
241
269
 
242
- &nbsp;
270
+ **3. Edit its first item to a very high quantity**
243
271
 
244
- To add this iteration, repeat the process above - in a terminal window for your project:
272
+ The update is properly rejected because it exceeds the credit limit. Observe the rules firing in the console log - see Logic In Action, below.
245
273
 
246
- **1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)
274
+ <br>
275
+ > 💡 Logic: Multi-table Derivations and Constraint Declarative Rules.<br>&emsp;&emsp;Declarative Rules are 40X More Concise than procedural code.<br>&emsp;&emsp;For more information, [click here](https://apilogicserver.github.io/Docs/Logic-Why).
247
276
 
248
- **2. Add Iteration**
277
+ <br>
249
278
 
250
- ```bash
251
- als add-cust
252
- ```
253
- &nbsp;
279
+ <details markdown>
254
280
 
255
- **3. Set the breakpoint as shown in the screenshot below**
281
+ <summary>See Logic In Action </summary>
256
282
 
257
- **4. Test: Start the Server, login as Admin**
283
+ <br>[Declare logic](Logic#declaring-rules) with WebGenAI, or in your IDE using code completion or Natural Language:
258
284
 
259
- **5. Use the Admin App to update your Order by adding 12 `Green` Items**
285
+ ![Nat Lang Logic](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/copilot/copilot-logic-chat.png?raw=true)
260
286
 
261
- At the breakpoint, observe you can use standard debugger services to debug your logic (examine `Item` attributes, step, etc).
287
+ **a. Chaining**
262
288
 
263
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/logic-debugging.jpeg?raw=true">
289
+ The screenshot below shows our logic declarations, and the logging for inserting an `Item`. Each line represents a rule firing, and shows the complete state of the row.
264
290
 
265
- &nbsp;
291
+ Note that it's a `Multi-Table Transaction`, as indicated by the indentation. This is because - like a spreadsheet - **rules automatically chain, *including across tables.***
266
292
 
267
- This simple example illustrates some significant aspects of iteration, described in the sub-sections below.
268
-
269
- !!! pied-piper ":bulb: Iteration: Automatic Invocation/Ordering, Extensible, Rebuild Preserves Customizations"
270
-
271
- ### a. Dependency Automation
293
+ ![logic-chaining](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/logic-chaining.jpeg?raw=true)
272
294
 
273
- Along with perhaps documentation, one of the tasks programmers most loathe is maintenance. That's because it's not about writing code, but it's mainly archaeology - deciphering code someone else wrote, just so you can add 4 or 5 lines that will hopefully be called and function correctly.
295
+ **b. 40X More Concise**
274
296
 
275
- Rules change that, since they **self-order their execution** (and pruning) based on system-discovered dependencies. So, to alter logic, you just "drop a new rule in the bucket", and the system will ensure it's called in the proper order, and re-used over all the Use Cases to which it applies. Maintenance is **faster, and higher quality.**
276
- <br><br>
297
+ The 5 spreadsheet-like rules represent the same logic as 200 lines of code, [shown here](https://github.com/valhuber/LogicBank/wiki/by-code). That's a remarkable 40X decrease in the backend half of the system.
277
298
 
278
- ### b. Extensibile with Python
299
+ > 💡 No FrankenCode<br>Note the rules look like syntactically correct requirements. They are not turned into piles of unmanageable "frankencode" - see [models not frankencode](https://www.genai-logic.com/faqs#h.3fe4qv21qtbs).
279
300
 
280
- In this case, we needed to do some if/else testing, and it was convenient to add a pinch of Python. Using "Python as a 4GL" is remarkably simple, even if you are new to Python.
301
+ <br><br>
281
302
 
282
- Of course, you have the full object-oriented power of Python and its many libraries, so there are *no automation penalty* restrictions.
283
- <br>
303
+ **c. Automatic Re-use**
284
304
 
285
- ### c. Debugging: IDE, Logging
305
+ The logic above, perhaps conceived for Place order, applies automatically to all transactions: deleting an order, changing items, moving an order to a new customer, etc. This reduces code, and promotes quality (no missed corner cases).
306
+ <br><br>
286
307
 
287
- The screenshot above illustrates that debugging logic is what you'd expect: use your IDE's debugger. This "standard-based" approach applies to other development activities, such as source code management, and container-based deployment.
288
- <br><br>
308
+ **d. Automatic Optimizations**
289
309
 
290
- ### d. Customizations Retained
310
+ SQL overhead is minimized by pruning, and by elimination of expensive aggregate queries. These can result in orders of magnitude impact.
311
+ <br><br>
291
312
 
292
- Note we rebuilt the project from our altered database, illustrating we can **iterate, while *preserving customizations.***
313
+ **e. Transparent**
293
314
 
294
- &nbsp;
315
+ Rules are an executable design. Note they map exactly to our natural language design (shown in comments) - readable by business users.
295
316
 
296
- ## 4. API Customization: Standard
317
+ Optionally, you can use the Behave TDD approach to define tests, and the Rules Report will show the rules that execute for each test. For more information, [click here](https://apilogicserver.github.io/Docs/Behave-Logic-Report/).
297
318
 
298
- Of course, we all know that all businesses the world over depend on the `hello world` app. This is provided in `api/customize_api`. Observe that it's:
319
+ </details>
299
320
 
300
- * standard Python
321
+ &nbsp;
301
322
 
302
- * using Flask
323
+ ### MCP: Logic, User Interface
303
324
 
304
- * and, for database access, SQLAlchemy. Note all updates from custom APIs also enforce your logic.
325
+ Logic is automatically executed in your MCP-enabled API. For example, consider the following MCP orchestration:
305
326
 
306
- &nbsp;
327
+ ![mcp-ui](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/mcp-ui.png?raw=true)
307
328
 
308
- ### Messaging With Kafka
309
329
 
310
- Along with APIs, messaging is another technology commonly employed for application integration. See the screenshot below; for more information, see [Sample Integration](Sample-Integration.md##produce-ordershipping-message){:target="_blank" rel="noopener"}.
330
+ When sending email, we require ***business rules*** to ensure it respects the opt-out policy:
311
331
 
312
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/order-to-shipping.jpg?raw=true">
332
+ ![email request](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/3a-email-logic.png?raw=true)
313
333
 
314
- &nbsp;
334
+ The server is automatically mcp-enabled, but we might also want an mcp user-interface client:
315
335
 
316
- ## 5. Deploy Containers: Collaborate
336
+ **1. Stop the Server**
317
337
 
318
- API Logic Server also creates scripts for deployment. While these are ***not required at this demo,*** this means you can enable collaboration with Business Users:
338
+ **2. Create an MCP Client Executor like this:**
319
339
 
320
- 1. Create a container from your project -- see `devops/docker-image/build_image.sh`
321
- 2. Upload to Docker Hub, and
322
- 3. Deploy for agile collaboration.
340
+ ```
341
+ genai-logic genai-add-mcp-client
342
+ ```
323
343
 
324
- &nbsp;
344
+ **3. Restart the Server**
325
345
 
326
- ## Summary
346
+ <br>
327
347
 
328
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/summary.jpeg?raw=true">
348
+ With the server running, test it like this:
329
349
 
330
- !!! pied-piper ":bulb: Instant Creation, Rules, Open Standards"
331
-
332
- In minutes - not days or weeks - you've used API Logic Server to convert an idea into **working software**, customized using **rule-based logic and security**, and **iterated** to meet new requirements.
333
-
334
- To dive deeper, you can install [API Logic Server](https://apilogicserver.github.io/Docs) and execute this demo - or create a system from your own databases.
350
+ 1. **Test MCP**
335
351
 
336
- &nbsp;
352
+ You can do this in the command line, or via the admin app.
337
353
 
338
- ---
354
+ Use the **Admin App:** (shown above), and follow step 4 on the Home page to see a Business-User-friendly example.
339
355
 
340
- ## Appendix: Database Schema
356
+ Or, use the command line.
341
357
 
342
- Initial version:
358
+ > Since the CLI does not pass an auth token,
359
+ you must first stop the server and disable security.
343
360
 
344
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/basic_demo_data_model.jpeg?raw=true" width="500">
361
+ ```bash title='MCP from the command line'
362
+ python integration/mcp/mcp_client_executor.py mcp
363
+ ```
345
364
 
346
- End version:
365
+ <br>
347
366
 
348
- <img src="https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/basic_demo_data_model_end.png?raw=true" width="500">
367
+ For more on MCP, [click here](https://apilogicserver.github.io/Docs/Integration-MCP).
349
368
 
350
- &nbsp;
369
+ <br>
351
370
 
352
- ## Appendix: Quick Basic Demo
371
+ ## 5. Iterate with Rules and Python
353
372
 
354
- This is a "cheat sheet" for experienced ALS users, e.g., to show your colleagues:
373
+ Not only are spreadsheet-like rules 40X more concise, they meaningfully simplify maintenance. Let's take an example:
355
374
 
356
- ```bash title="Quick Basic Demo"
375
+ >> Give a 10% discount for carbon-neutral products for 10 items or more.
376
+ <br>
357
377
 
358
- # Microservice Automation
359
- # Admin App, API, Project
360
- als create --project-name=basic_demo --db-url=basic_demo
378
+ The following `add-cust` process simulates an iteration:
361
379
 
362
- # Logic, Security and MCP example
363
- # see logic (logic/declare_logic.py, logic/cocktail-napkin.jpg); add an Order and Item
364
- # see security (security/declare_security.py); compare customers, s1 vs. admin
365
- als add-cust
366
- als add-auth --db_url=auth
380
+ * acquires a new database with `Product.CarbonNeutral`
367
381
 
368
- # Python Extensibility, Kafka Integration, Rebuild Iteration
369
- # see logic/declare_logic.py (breakpoint for Kafka)
370
- # Swagger: ServicesEndPoint.OrderB2B
371
- als add-cust
372
- als rebuild-from-database --db_url=sqlite:///database/db.sqlite
373
- ```
382
+ * issues the `genai-logic rebuild-from-database` command that rebuilds your project (the database models, the api), while preserving the customizations we made above.
374
383
 
375
- &nbsp;
384
+ * acquires a revised `ui/admin/admin.yaml` that shows this new column in the admin app
376
385
 
377
- ## Appendix: Procedures
386
+ * acquires this revised logic - in `logic/declare_logic.py`, we replaced the 2 lines for the `models.Item.Amount` formula with this (next screenshot shows revised logic executing with breakpoint):
378
387
 
379
- Specific procedures for running the demo are here, so they do not interrupt the conceptual discussion above.
388
+ ```python
389
+ def derive_amount(row: models.Item, old_row: models.Item, logic_row: LogicRow):
390
+ amount = row.Quantity * row.UnitPrice
391
+ if row.Product.CarbonNeutral and row.Quantity >= 10:
392
+ amount = amount * Decimal(0.9) # breakpoint here
393
+ return amount
380
394
 
381
- You can use either VSCode or Pycharm.
395
+ Rule.formula(derive=models.Item.Amount, calling=derive_amount)
396
+ ```
382
397
 
383
398
  &nbsp;
384
399
 
385
- **1. Establish your Virtual Environment**
386
-
387
- Python employs a virtual environment for project-specific dependencies. Create one as shown below, depending on your IDE.
400
+ To add this iteration, repeat the process above - in a terminal window for your project:
388
401
 
389
- For VSCode:
402
+ **1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)
390
403
 
391
- Establish your `venv`, and run it via the first pre-built Run Configuration. To establish your venv:
404
+ **2. Add Iteration**
392
405
 
393
406
  ```bash
394
- python -m venv venv; venv\Scripts\activate # win
395
- python3 -m venv venv; . venv/bin/activate # mac/linux
396
-
397
- pip install -r requirements.txt
407
+ genai-logic add-cust
408
+ genai-logic rebuild-from-database --db_url=sqlite:///database/db.sqlite
398
409
  ```
399
410
 
400
- For PyCharm, you will get a dialog requesting to create the `venv`; say yes.
411
+ * You can ignore the warning regarding *'mcp-SysMcp' - not present*
401
412
 
402
- See [here](https://apilogicserver.github.io/Docs/Install-Express/) for more information.
403
-
404
- &nbsp;
413
+ **3. Set the breakpoint as shown in the screenshot below**
405
414
 
406
- **2. Start and Stop the Server**
415
+ **4. Test: Start the Server, login as Admin**
407
416
 
408
- Both IDEs provide Run Configurations to start programs. These are pre-built by `ApiLogicServer create`.
417
+ **5. Use the Admin App to update your Order by adding 12 `Green` Items**
409
418
 
410
- For VSCode, start the Server with F5, Stop with Shift-F5 or the red stop button.
419
+ At the breakpoint, observe you can use standard debugger services to debug your logic (examine `Item` attributes, step, etc).
411
420
 
412
- For PyCharm, start the server with CTL-D, Stop with red stop button.
421
+ ![logic-debugging](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/logic-debugging.jpeg?raw=true)
413
422
 
414
423
  &nbsp;
415
424
 
416
- **3. Entering a new Order**
417
-
418
- To enter a new Order:
419
-
420
- 1. Click `Customer 1``
425
+ This simple example illustrates some significant aspects of iteration, described in the sub-sections below.
421
426
 
422
- 2. Click `+ ADD NEW ORDER`
427
+ <br>
428
+ > 💡 Iteration: Automatic Invocation/Ordering, Extensible, Rebuild Preserves Customizations
423
429
 
424
- 3. Set `Notes` to "hurry", and press `SAVE AND SHOW`
430
+ <br>
425
431
 
426
- 4. Click `+ ADD NEW ITEM`
432
+ **a. Dependency Automation**
427
433
 
428
- 5. Enter Quantity 1, lookup "Product 1", and click `SAVE AND ADD ANOTHER`
434
+ Along with perhaps documentation, one of the tasks programmers most loathe is maintenance. That's because it's not about writing code, but it's mainly archaeology - deciphering code someone else wrote, just so you can add 4 or 5 lines that will hopefully be called and function correctly.
429
435
 
430
- 6. Enter Quantity 2000, lookup "Product 2", and click `SAVE`
436
+ Rules change that, since they **self-order their execution** (and pruning) based on system-discovered dependencies. So, to alter logic, you just "drop a new rule in the bucket", and the system will ensure it's called in the proper order, and re-used over all the Use Cases to which it applies. Maintenance is **faster, and higher quality.**
437
+ <br><br>
431
438
 
432
- 7. Observe the constraint error, triggered by rollups from the `Item` to the `Order` and `Customer`
439
+ **b. Extensibile with Python**
433
440
 
434
- 8. Correct the quantity to 2, and click `Save`
441
+ In this case, we needed to do some if/else testing, and it was convenient to add a pinch of Python. Using "Python as a 4GL" is remarkably simple, even if you are new to Python.
435
442
 
443
+ Of course, you have the full object-oriented power of Python and its many libraries, so there are *no automation penalty* restrictions.
444
+ <br>
436
445
 
437
- **4. Update the Order**
446
+ **c. Debugging: IDE, Logging**
438
447
 
439
- To explore our new logic for green products:
448
+ The screenshot above illustrates that debugging logic is what you'd expect: use your IDE's debugger. This "standard-based" approach applies to other development activities, such as source code management, and container-based deployment.
449
+ <br><br>
440
450
 
441
- 1. Access the previous order, and `ADD NEW ITEM`
451
+ **d. Customizations Retained**
442
452
 
443
- 2. Enter quantity 11, lookup product `Green`, and click `Save`.
453
+ Note we rebuilt the project from our altered database, illustrating we can **iterate, while *preserving customizations.***
444
454
 
445
455
  &nbsp;
446
456
 
447
- ## Appendix: Add Database Column
448
-
449
- The database here is SQLite. You can use the SQLite CLI to add a column using the terminal window of your IDE:
450
-
451
- ```bash
452
- $ sqlite3 database/db.sqlite
453
- > alter table Products Add CarbonNeutral Boolean;
454
- > .exit
455
- ```
456
-
457
- The SQLite DBMS is installed with API Logic Server, but the **CLI** is not provided on all systems. If it's not installed, [you can install it like this](https://apilogicserver.github.io/Docs/Database-Connectivity/#sqlite).
458
-
459
- ## Appendix: Setup Codespaces
460
-
461
- Codespaces enables you to run in the cloud: VSCode via your Browser, courtesy GitHub. You can use codespaces on your GenAI project:
462
-
463
- __1. Open your project on GitHub__
464
-
465
- ![API Logic Server Intro](images/sample-ai/genai/open-github.png)
466
-
467
- __2. Open it in Codespaces (takes a minute or 2):__
457
+ ### API Customization: Standard
468
458
 
469
- ![API Logic Server Intro](images/sample-ai/genai/start-codespaces.png)
459
+ Of course, we all know that all businesses the world over depend on the `hello world` app. This is provided in `api/customize_api`. Observe that it's:
470
460
 
471
- > You will now see your project - running in VSCode, _in the Browser._ But that's just what you _see..._
461
+ * standard Python
472
462
 
473
- > Behind the scenes, Codespaces has requisitioned a cloud machine, and loaded your project - with a _complete development environment_ - Python, your dependencies, git, etc.
463
+ * using Flask
474
464
 
475
- > You are attached to this machine in your Browser, running VSCode.
465
+ * and, for database access, SQLAlchemy. Note all updates from custom APIs also enforce your logic.
476
466
 
477
- > :trophy: Pretty remarkable.
467
+ Explore the custom API in `api/api_discovery/order_b2b.py`, and test it using swagger:
478
468
 
479
- __3. Start the Server and open the App in the Browser__
469
+ 1. **Access the Home page of the Admin App**
470
+ 2. **Access the swagger**
471
+ 3. **Test the b2b API / Logic, as shown below:**
480
472
 
481
- * Use the pre-defined Launch Configuration
473
+ ![b2b_swagger](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/b2b_swagger.png?raw=true)
482
474
 
483
- ![API Logic Server Intro](images/git-codespaces/start-codespaces.png)
475
+ &nbsp;
484
476
 
477
+ ### Messaging With Kafka
485
478
 
486
- We think you'll find Codespaces pretty amazing - check it out!
479
+ Along with APIs, messaging is another technology commonly employed for application integration. See the screenshot below; for more information, see [Sample Integration](Sample-Integration#produce-ordershipping-message).
487
480
 
481
+ ![order-to-shipping](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/order-to-shipping.jpg?raw=true)
488
482
  &nbsp;
489
483
 
490
- ## Appendix: Obtain an OpenAI ApiKey
484
+ ## 6. Deploy Containers: No Fees
491
485
 
492
- To obtain a ChatGPT API Key
493
- <br>GenAI-Logic uses OpenAI, which requires an Open API Key:
486
+ API Logic Server also creates scripts for deployment. While these are ***not required at this demo,*** this means you can enable collaboration with Business Users:
494
487
 
495
- 1. Obtain one from [here](https://platform.openai.com/account/api-keys) or [here](https://platform.openai.com/api-keys)
488
+ 1. Create a container from your project -- see `devops/docker-image/build_image.sh`
489
+ 2. Upload to Docker Hub, and
490
+ 3. Deploy for agile collaboration.
496
491
 
497
- 2. Authorize payments [here](https://platform.openai.com/settings/organization/billing/overview)
492
+ &nbsp;