{"id":28646707,"url":"https://github.com/apilogicserver/basic_demo","last_synced_at":"2025-07-06T01:39:16.603Z","repository":{"id":297845003,"uuid":"998077302","full_name":"ApiLogicServer/basic_demo","owner":"ApiLogicServer","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-07T20:25:02.000Z","size":2500,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-07T21:26:05.683Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ApiLogicServer.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security/__init__.py","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-07T20:17:44.000Z","updated_at":"2025-06-07T20:25:05.000Z","dependencies_parsed_at":"2025-06-07T21:37:12.863Z","dependency_job_id":null,"html_url":"https://github.com/ApiLogicServer/basic_demo","commit_stats":null,"previous_names":["apilogicserver/basic_demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ApiLogicServer/basic_demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fbasic_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fbasic_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fbasic_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fbasic_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ApiLogicServer","download_url":"https://codeload.github.com/ApiLogicServer/basic_demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApiLogicServer%2Fbasic_demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259565563,"owners_count":22877347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-13T02:06:36.767Z","updated_at":"2025-06-13T02:06:37.527Z","avatar_url":"https://github.com/ApiLogicServer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: Instant Microservices - with Logic and Security\nnotes: gold is proto (-- doc); alert for apostrophe\nversion: 0.22 from docsite, for readme 5/24/2025\n---\nWe'll illustrate [API Logic Server](https://www.genai-logic.com/product/key-features) basic GenAI-Logic operation: creating projects from new or existing databases, adding logic and security, and customizing your project using your IDE and Python.\n\nThe entire process takes 20 minutes; usage notes:\n\n* Important: look for **readme files** in created projects.\n* You may find it more convenient to view this [in your Browser](https://apilogicserver.github.io/Docs/Sample-Basic-Tour).\n\n\u0026nbsp;\n\n## 1. Automation: Project Creation\n\nAPI Logic Server can create projects from existing databases, or use GenAI to create projects with new databases.  Let's see how.\n\n\u0026nbsp;\n### From Existing Database\n\nCreate the project - use the CLI (**Terminal \u003e New Terminal**), :\n\n```bash\n$ ApiLogicServer create --project_name=basic_demo --db_url=basic_demo\n```\n\n\u003e 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.\n\n\n\u003cdetails markdown\u003e\n\n\u003csummary\u003e The database is Customer, Orders, Items and Product\u003c/summary\u003e\n\n![basic_demo_data_model](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/basic_demo_data_model.jpeg?raw=true)\n\n\u003c/details\u003e\n\u003cbr\u003e\n\u0026nbsp;\n\n### GenAI: New Database\n\nYou can create a project *and a new database* from a prompt using GenAI, either by:\n\n* [WebGenAI - in the Browser](https://apilogicserver.github.io/Docs/WebGenAI), or\n* [GenAI - docker](https://apilogicserver.github.io/Docs/WebGenAI-install), or \n* [GenAI CLI](https://apilogicserver.github.io/Docs/WebGenAI-CLI) \n\nHere we use the GenAI CLI:\n\n1. 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):\n\n```bash\nals genai --using=system/genai/examples/genai_demo/genai_demo.prompt --project-name=genai_demo\n```\n\n2. ***Or,*** you can simulate the process (no signup) using:\n\n```bash\n\nals genai --repaired-response=system/genai/examples/genai_demo/genai_demo.response_example --project-name=genai_demo\n\n```\n\nFor background on how it works, [click here](Sample-Genai#how-does-it-work).\n\n\u0026nbsp;\n\n## 2. Working Software Now\n\n### Open in your IDE and Run\n\nYou can open with VSCode, and run it as follows:\n\n1. **Create Virtual Environment:** automated in most cases; see the Appendix (Procedures / Detail Procedures) for details.\n\n2. **Start the Server:** F5 (also described in the Appendix).\n\n3. **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.\n\nThe sections below explore the system that has been created (which would be similar for your own database).\n\u003cbr\u003e\u003cbr\u003e\n\n### API with Swagger\n\nThe 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.**\n\n\u003cdetails markdown\u003e\n\n\u003csummary\u003eSee the Swagger \u003c/summary\u003e\n\n![swagger](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/api-swagger.jpeg?raw=true)\n\u003c/details\u003e\n\u003cbr\u003e\n\n### Admin App\n\nIt 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.\n\nYou can click Customer Alice, and see their Orders, and Items.\n\n\u003cdetails markdown\u003e\n\n\u003csummary\u003eSee the Admin App \u003c/summary\u003e\n![admin-app-initial](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/admin-app-initial.jpeg?raw=true)\n\u003c/details\u003e\n\n\u0026nbsp;\n\n### MCP, Vibe, Collaboration\n\nIn little more than a minute, you've used either\n\n* **GenAI** to create a database and project using Natural Language, or \n* 1 CLI command to create a project from an existing database\n\nThe project is standard Python, which you can customize in a standard IDE.\n\nThis means you are ready for:\n\n* **Vibe:**  unblock UI dev\n\n    * Instead of creating data mockups, use GenAI to create real data\n    * Use you favorite Vibe tools with your running API\n    * And, you'll have projects that are architecurally correct: shared logic, enforced in the server,\navailable for both User Interfaces and services.\n\n* **MCP:** your project is MCP-ready: `python integration/mcp/mcp_client_executor.py`.\nWe'll explore more interesting examples below.\n\n* **Collaboration to Get Requirements Right:** Business Users can use GenAI to create systems, and the Admin app to verify their business idea.  And iterate.\n\n\u003e But automated direct access to the database is a terrible architecture.  A key feature of GenAI-Logic is logic automation, using declarative, spreadsheet-like **business rules.**  Let's now explore those.\n\n\n\u0026nbsp;\n\n## 3. Declare Logic And Security\n\nWhile API/UI automation is a great start, it's critical to enforce logic and security.  You do this in your IDE.  Here's how.\n\nThe following `add_customizations` process simulates:\n\n* Adding security to your project, and\n* Using your IDE to declare logic and security in `logic/declare_logic.sh` and `security/declare_security.py`.\n\n\u003e Declared security and logic are shown in the screenshots below.\u003cbr\u003eIt's quite short - 5 rules, 7 security settings.\n\nTo add customizations, in a terminal window for your project:\n\n**1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)\n\n**2. Add Customizations**\n\n```bash\nals add-cust\nals add-auth --db_url=auth\n```\n\u0026nbsp;\n\n### Security: Role Based Access\n\nThe `add_customizations` process above has simulated using your IDE to declare security in `logic/declare_logic.sh`.\n\nTo see security in action:\n\n**1. Start the Server**  F5\n\n**2. Start the Admin App:** [http://localhost:5656/](http://localhost:5656/)\n\n**3. Login** as `s1`, password `p`\n\n**4. Click Customers**\n\n\u003cbr\u003e\nObserve:\n\n**1. Login now required**\n\n**2. Role-Based Filtering**\n\nObserve you now see fewer customers, since user `s1` has role `sales`.  This role has a declared filter, as shown in the screenshot below.\n\n**3. Transparent Logging**\n\n\u003cdetails markdown\u003e\n\n\u003csummary\u003eSee Security Declarations \u003c/summary\u003e\n\n\u003cbr\u003eThe screenshot below illustrates security declaration and operation:\n\n* The declarative Grants in the upper code panel, and\n\n*  The logging in the lower panel, to assist in debugging by showing which Grants (`+ Grant:`) are applied:\n\n![security-filters](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/security-filters.jpeg?raw=true)\n\n\u003c/details\u003e\n\n\u0026nbsp;\n\n### Logic: Derivations, Constraints\n\nLogic (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.\n\nRules are declared in Python, simplified with IDE code completion.  The screen below shows the 5 rules for **Check Credit Logic.**\n\nThe `add_customizations` process above has simulated the process of using your IDE to declare logic in `logic/declare_logic.sh`.\n\nTo see logic in action:\n\n**1. In the admin app, Logout (upper right), and login as admin, p**\n\n**2. Use the Admin App to add an Order and Item for `Customer Alice`** (see Appendix)\n\nObserve the rules firing in the console log - see Logic In Action, below.\n\n\u003cbr\u003e\n\u003e 💡 Logic: Multi-table Derivations and Constraint Declarative Rules.\u003cbr\u003e\u0026emsp;\u0026emsp;Declarative Rules are 40X More Concise than procedural code.\u003cbr\u003e\u0026emsp;\u0026emsp;For more information, [click here](https://apilogicserver.github.io/Docs/Logic-Why).\n\n\u003cbr\u003e\n\n\u003cdetails markdown\u003e\n\n\u003csummary\u003eSee Logic In Action \u003c/summary\u003e\n\n\u003cbr\u003e[Declare logic](Logic#declaring-rules) with WebGenAI, or in your IDE using code completion or Natural Language:\n\n![Nat Lang Logic](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/sample-ai/copilot/copilot-logic-chat.png?raw=true)\n\n**a. Chaining**\n\nThe 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.\n\nNote that it's a `Multi-Table Transaction`, as indicated by the indentation.  This is because - like a spreadsheet - **rules automatically chain, *including across tables.***\n\n![logic-chaining](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/logic-chaining.jpeg?raw=true)\n\n**b. 40X More Concise**\n\nThe 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.\n\n\u003e 💡 No FrankenCode\u003cbr\u003eNote 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).\n\n\u003cbr\u003e\u003cbr\u003e\n\n**c. Automatic Re-use**\n\nThe 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).\n\u003cbr\u003e\u003cbr\u003e\n\n**d. Automatic Optimizations**\n\nSQL overhead is minimized by pruning, and by elimination of expensive aggregate queries.  These can result in orders of magnitude impact.\n\u003cbr\u003e\u003cbr\u003e\n\n**e. Transparent**\n\nRules are an executable design.  Note they map exactly to our natural language design (shown in comments) - readable by business users.  \n\nOptionally, 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/).\n\n\u003c/details\u003e\n\n\u0026nbsp;\n\n### Logic-Enabled MCP\n\nLogic is automatically executed in your MCP-enabled API.  For example, consider the following MCP orchestration:\n\n```\nList the orders date_shipped is null and CreatedOn before 2023-07-14,\nand send a discount email (subject: 'Discount Offer') to the customer for each one.\n```\n\nWhen sending email, we require a business rules to ensure it respects the opt-out policy:\n\n![email request](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/3a-email-logic.png?raw=true)\n\nWith the server running, test it by posting to `SysMCP` like this:\n\n```bash\ncurl -X 'POST' 'http://localhost:5656/api/SysMcp/' -H 'accept: application/vnd.api+json' -H 'Content-Type: application/json' -d '{ \"data\": { \"attributes\": {\"request\": \"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.\"}, \"type\": \"SysMcp\"}}'\n```\n\nFor more on MCP, [click here](https://apilogicserver.github.io/Docs/Integration-MCP).\n\n\u0026nbsp;\n\n## 4. Iterate with Rules and Python\n\nNot only are spreadsheet-like rules 40X more concise, they meaningfully simplify maintenance.  Let's take an example:\n\n\u003e\u003e Give a 10% discount for carbon-neutral products for 10 items or more.\n\u003cbr\u003e\n\nThe following `add-cust` process simulates an iteration:\n\n* acquires a new database with `Product.CarbonNeutral`\n\n* issues the `ApiLogicServer rebuild-from-database` command that rebuilds your project (the database models, the api), while preserving the customizations we made above.\n\n* acquires a revised `ui/admin/admin.yaml` that shows this new column in the admin app\n\n* 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):\n\n```python\n    def derive_amount(row: models.Item, old_row: models.Item, logic_row: LogicRow):\n        amount = row.Quantity * row.UnitPrice\n        if row.Product.CarbonNeutral and row.Quantity \u003e= 10:\n           amount = amount * Decimal(0.9)  # breakpoint here\n        return amount\n\n    Rule.formula(derive=models.Item.Amount, calling=derive_amount)\n```\n\n\u0026nbsp;\n\nTo add this iteration, repeat the process above - in a terminal window for your project:\n\n**1. Stop the Server** (Red Stop button, or Shift-F5 -- see Appendix)\n\n**2. Add Iteration**\n\n```bash\nals add-cust\nals rebuild-from-database --db_url=sqlite:///database/db.sqlite\n```\n\n**3. Set the breakpoint as shown in the screenshot below**\n\n**4. Test: Start the Server, login as Admin**\n\n**5. Use the Admin App to update your Order by adding 12 `Green` Items**\n\nAt the breakpoint, observe you can use standard debugger services to debug your logic (examine `Item` attributes, step, etc).\n\n![logic-debugging](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/basic_demo/logic-debugging.jpeg?raw=true)\n\n\u0026nbsp;\n\nThis simple example illustrates some significant aspects of iteration, described in the sub-sections below.\n\n\u003cbr\u003e\n\u003e 💡 Iteration: Automatic Invocation/Ordering, Extensible, Rebuild Preserves Customizations\n\u003cbr\u003e\n\n**a. Dependency Automation**\n\nAlong 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.\n\nRules 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.**\n\u003cbr\u003e\u003cbr\u003e\n\n**b. Extensibile with Python**\n\nIn 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.\n\nOf course, you have the full object-oriented power of Python and its many libraries, so there are *no automation penalty* restrictions.  \n\u003cbr\u003e\n\n**c. Debugging: IDE, Logging**\n\nThe 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.\n\u003cbr\u003e\u003cbr\u003e\n\n**d. Customizations Retained**\n\nNote we rebuilt the project from our altered database, illustrating we can **iterate, while *preserving customizations.***\n\n\u0026nbsp;\n\n### API Customization: Standard\n\nOf 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:\n\n* standard Python\n\n* using Flask\n\n* and, for database access, SQLAlchemy.  Note all updates from custom APIs also enforce your logic.\n\n\u0026nbsp;\n\n### Messaging With Kafka\n\nAlong 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).\n\n![order-to-shipping](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/order-to-shipping.jpg?raw=true)\n\u0026nbsp;\n\n## 5. Deploy Containers: No Fees\n\nAPI Logic Server also creates scripts for deployment.  While these are ***not required at this demo,*** this means you can enable collaboration with Business Users:\n\n1. Create a container from your project -- see `devops/docker-image/build_image.sh`\n2. Upload to Docker Hub, and\n3. Deploy for agile collaboration.\n\n\u0026nbsp;","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapilogicserver%2Fbasic_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapilogicserver%2Fbasic_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapilogicserver%2Fbasic_demo/lists"}