Skip to content

ApiLogicServer/basic_demo

Repository files navigation

GenAI-Logic basic_demo

Use this to explore thebasic_demo, created from this procedure.

🚀 Ready to Run: This is a complete, working system.

  • To Run:
    • Local IDE:
      1. Press F5 or run python api_logic_server_run.py
    • GitHub:
      1. Open this project
      2. At top, click Code >> dropdown and click tab Codespaces >> Create codespace on main
      3. Wait for it to load, then click F5
  • Set a breakpoint, e.g.
    • Line 26 in logic/logic_discovery/check_credit.py
  • In the Admin App, access Customer Alice, order 2 (Second Order)
    • Change the quantity to a very large value - observe the constraint
    • Lookup product Thingamajig - constraint (rule) is re-used for this transaction

🎯 What's Automatically Created:

  • Admin Web App - Multi-page React app at http://localhost:5656
    • See the automatic Admin App at ui/admin/admin.yaml
    • And, see the customized react app: ui/my-react-app-cards
  • JSON:API Endpoints - REST API for all database tables at /api/* (mcp enabled)
  • Swagger Documentation - Interactive API docs at /api
  • Business Logic Engine - Declarative rules in logic/logic_discovery
    • See check_credit.py and app_integration.py
    • Contrast to logic/procedural
  • Security Framework - Authentication/authorization in security/
  • Database Models - SQLAlchemy ORM in database/models.py

See readme files under api, logic and security.

Standard Automatic Readme, shown below.


🚀 Quick Start - How This Project Was Created

Bootstrap Copilot by pasting the following into the chat:

Please find and read `.github/.copilot-instructions.md`.

Microservice Automation Complete -- run to verify: for VSCode projects except those downloaded from Web/GenAI:

  1. Press F5 to Run (your venv is defaulted)

    For other IDEs, please follow the Setup and Run procedure, below.


💡 Tip: Create the sample app for customization examples:
ApiLogicServer create --project-name=nw_sample --db_url=nw+

 

Using this readme

This readme contains the following sections:

Section Info
1. Setup and Run Information about API Logic Server, and setting up your venv
2. Key Customization Files Quick idea of the key files you'll alter
3. Procedures Key Procedures
4. Deployment Deploy early previews to the cloud - enable team collaboration
5. Project Requirements Options for capturing requirements
6. Project Information Creation dates, versions
Appendix - Key Technologies Doc links of key libraries

 

1. Setup and Run

To run your project, the system requires various runtime systems for data access, api, and logic. These are included with API Logic Server (architecture doc here).

So, to run your project:

 

1.1 Establish Your Python Environment - Other Environments

Your requirements.txt has already been created, so...

python -m venv venv                        # may require python3 -m venv venv
venv\Scripts\activate                      # mac/linux: source venv/bin/activate
python -m pip install -r requirements.txt  # accept "new Virtual environment"

Notes:

  • See also the venv_setup directory in this API Logic Project.

  • If using SqlServer, install pyodbc. Not required for docker-based projects. For local installs, see the Quick Start.

 

Docker or VSCode - nothing to do

Nothing to do here:

  • VSCode: projects automatically use installed API Logic Server venv, so this step is not required until you want to create a local venv for additional packages.

  • Docker: Your runtime systems are part of Dev Container, which you probably activated when you opened the project.

    • If you did not accept the "Open in Container" option when you started VSCode, use View > Command Palette > Remote-Containers: Reopen in Container.

 

 

1.2 Run

The ApiLogicServer create command creates Run Configurations for PyCharm and VSCode:

  • For PyCharm, press Ctl-D
  • For VSCode,  press F5:

Start Project

As shown above:

  1. Use the pre-supplied Run Configurations; use either...
    • ApiLogicServer to run with security
    • ApiLogicServer - No Security (simplifies use of Swagger)
  2. Click the url in the console to start the Admin App
    • Use it to explore your data (shown below)
    • And your API (via Swagger)

Admin App

 

2. Key Customization Files

Your project is ready to run, but it's likely you'll want to customize it - declare logic, new endpoints, etc.

Important: explore customization examples
In particular, use the sample app to explore the value of declarative logic and security. Unique to API Logic Server, these are critical to unlocking the full value of API Logic Server.

To create the sample app for customization examples:

  • ApiLogicServer create --project-name=nw_sample --db_url=nw+
  • Or, open it in GitHub (use Shift + "." to view in project mode) - click here

To make customizations easy to explore, search for:

  • #als will reveal key customization examples
  • Your Code Goes Here to find key files to customize, summarized in the table below.

 

The Key Customization Files listed in the table below are created as stubs, intended for you to add customizations that extend the created API, Logic and Web App.

  • Since they are separate files, the project can be rebuilt (e.g., synchronized with a revised schema), preserving your customizations.

Directory Usage Key Customization File Typical Customization
api JSON:API
Ready to Run
api/customize_api.py Add new end points / services
ui Multi-Page Admin App
Ready to Run
ui/admin/admin.yaml Control field display - order, captions etc.
database SQLAlchemy Data Model Classes database/customize_models.py Add derived attributes, and relationships missing in the schema
logic Transactional Logic
spreadsheet-like rules
logic/declare_logic.py Declare multi-table derivations, constraints, and Python events such as send mail / messages
security Authentication, Authorization security/declare_security.py Control login, role-based row access
integration Consume Kafka Messages integration/kafka/kafka_consumer.py Application Integration
test Behave Test Suite test/api_logic_server_behave/features Declare and implement Behave Tests

Notes:

  1. API Logic Server CLI provides commands you can use to ugrade your project, e.g., to add security. See the next section.
  2. You will observe the project is small. That is because the app, logic and api are represented as models:
    • The web app is a YAML file (about 150 lines - no html or JavaScript)
    • The api is essentially 1 line per data model (table)

 

3. Procedures

Several CLI commands are provided to operate on your current project.

  1. Use your IDE's terminal window to access these
  2. Use ApiLogicServer --help to discover these

Procedures Notes
1. Database Migration See alembic for database migration procedures.
1. Activating Security See Security Activation for activating security.

 

4. Deployment

The devops directory contains several scripts for creating container images, testing them, and deploying them.

Since API Logic Server creates working software (UI, API), you can do this after creating your project, to collaborate with your team.

 

5. Project Requirements

Optionally, you can document requirements as part of an executable test plan. Test plan execution creates documentation (in markdown), including requirements traceability into implementation. See example here.

 

6. Project Information

This API Logic Project was created with the ApiLogicServer create command. For information on Managing API Logic Projects, click here.

About Info
Created July 06, 2025 22:11:00
API Logic Server Version 15.00.38
Created in directory nw_database_project
API Name api
Execution begins with api_logic_server_run.py

 

Appendix: Key Technologies

API Logic Server is based on the projects shown below. Consult their documentation for important information.

 

SARFS JSON:API Server

SAFRS: Python OpenAPI & JSON:API Framework

SAFRS is an acronym for SqlAlchemy Flask-Restful Swagger. The purpose of this framework is to help python developers create a self-documenting JSON API for sqlalchemy database objects and relationships.

These objects are serialized to JSON and created, retrieved, updated and deleted through the JSON API. Optionally, custom resource object methods can be exposed and invoked using JSON.

Class and method descriptions and examples can be provided in yaml syntax in the code comments.

The description is parsed and shown in the swagger web interface. The result is an easy-to-use swagger/OpenAPI and JSON:API compliant API implementation.

 

LogicBank

Transaction Logic for SQLAlchemy Object Models

Use Logic Bank to govern SQLAlchemy update transaction logic - multi-table derivations, constraints, and actions such as sending mail or messages. Logic consists of both:

  • Rules - 40X more concise using a spreadsheet-like paradigm, and

  • Python - control and extensibility, using standard tools and techniques

Logic Bank is based on SQLAlchemy - it handles before_flush events to enforce your logic. Your logic therefore applies to any SQLAlchemy-based access - JSON:Api, Admin App, etc.

 

SQLAlchemy

Object Relational Mapping for Python.

SQLAlchemy provides Python-friendly database access for Python.

It is used by JSON:Api, Logic Bank, and the Admin App.

SQLAlchemy processing is based on Python model classes, created automatically by API Logic Server from your database, and saved in the database directory.

 

Admin App

This generated project also contains a React Admin app:

  • Multi-page - including page transitions to "drill down"
  • Multi-table - master / details (with tab sheets)
  • Intelligent layout - favorite fields first, predictive joins, etc
  • Logic Aware - updates are monitored by business logic

 

Python Tips

If you are new to Python, check out these tips.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published