Orientation
Lab-Focused Training
A recommended approach for learning GenAI-Logic is:
- Basic Orientation - use the list below, in conjunction with your AI Assistant
- Key Samples - list provided on the Manager Readme, and docs
- Logic - drill down on learning logic - click here
Orientation Checklist
Before running the key samples, make sure you understand:
Python
- [ ] Virtual environment (venv) — required for running the server and CLI commands. Default shared from Manager; see also venv docs.
- [ ] Python path — libs not in the venv
- [ ] App Settings — see the app
configdirectory (security, db location etc) - [ ] VS Code — see
.vscode--.settings, `.launch' - [ ] Python for Java Developers — see this short guide.
Architecture - click What Is ApiLogicServer
IDE Instances - Manager vs Project
- [ ] Manager Context/Prompt Engineering for creating projects, organizes projects
- [ ] Project Standard project (folder of your code and rules), and PE for AI Assistant
AI Assistant
- [ ] The 3-Legged Stool — ask your assistant
- [ ] Prompt Engineering (pe) — used by
genai-logic genai*CLI commands, and WebGenAI - [ ] Context Engineering (ce) — ask CoPilot: how can you help me?
-
[ ] App — Behavior is determinstic, unless you use
AI Rules- so, govern these with other rules
Initial Background
Review the GenAI Architecture, and take a quick scan of Python for Java programmers.
Concepts and Facilities
Command Line Basics
The command line (cli) is the key to use all of the features of ApiLogicServer. Note that each command may have a set of additional arguments: use --help to see the additional features (e.g. als genai --help).
als --help
Welcome to API Logic Server {version}
Usage: als [OPTIONS] COMMAND [ARGS]...
Creates [and runs] logic-enabled Python database API Logic Projects.
Creation is from your database (--db-url identifies a SQLAlchemy database)
Doc: https://apilogicserver.github.io/Docs
And: https://apilogicserver.github.io/Docs/Database-Connectivity/
Suggestions:
ApiLogicServer start # create and manage projects
ApiLogicServer create --db-url= --project-name= # defaults to Northwind sample
Options:
--help Show this message and exit.
Commands:
about Recent Changes, system information.
add-auth Adds authorization/authentication to curr project.
add-cust Adds customizations to northwind, genai,...
add-db Adds db (model, binds, api, app) to curr project.
app-build Builds runnable app from: ui/<app>/app-model.yaml
app-create Creates Ontomize app model: ui/<app>/app-model.yaml
create Creates new customizable project (overwrites).
create-and-run Creates new project and runs it (overwrites).
create-ui Creates models.yaml from models.py (internal).
curl Execute cURL command, providing auth headers...
curl-test Test curl commands (nw only; must be r)
examples Example commands, including SQLAlchemy URIs.
genai Creates new customizable project (overwrites).
genai-create Create new project from --using prompt text.
genai-iterate Iterate current project from --using prompt text.
genai-logic Adds (or suggests) logic to current project.
genai-utils Utilities for GenAI.
login Login and save token for curl command.
rebuild-from-database Updates database, api, and ui from changed db.
rebuild-from-model Updates database, api, and ui from changed models.
run Runs existing project.
start Create and Manage API Logic Projects.
tutorial Creates (updates) Tutorial.
welcome Just print version and exit.
Connect to SQL
If the project has an existing SQL DBMS (MySQL, PostgreSQL, SQL Server, Oracle) - ApiLogicServer can connect to SQL and build a detailed API. Review the documentation of Data-Model design, examples, keys, quoted identifiers, etc. In this lab - we will connect to the northwind database.
Open database/models.py- Data-Model-Design
- Primary Keys on each table
- Relationships (foreign keys) many-to-one (parent), one-to-many (children) (or many-to-many)
- Accented characters (als create --db-url=... --quote) quoted identifiers
- SQLAlchemy ORM model.py
- Run Server (F5) with or without security
- Start React Application (http://localhost:5656)
- Review OpenAI (Swagger) (http://localhost:5656/api) JSON API
Integration
Some applications may require integration with other services (e.g. email, payment, workflow, etc) In this lab - explore how to use the existing services to integration with Kafka or Workflow.
- Integration and Configuration Kafka
- Send a message to Kafka (event driven) by topic
- Listen for incoming Kafka message by topic
- Integration with Workflow (n8n) - Using WebHooks
- Configuration of Kafka or n8n (config.py)
Ontimize Angular Application
OntimizeWeb from Imatia is an Angular application that is automatically created from the command line. In this lab - review the Ontimize process here
Start ApiLogicServer first (note: must enable security: als add-auth --provider-type=sql)
als app-create --app=app
als app-build --help
example:
ApiLogicServer app-build —app=name=app1
ApiLogicServer app-build —app=name=app1 —api-endpoint=Orders
# only build Orders This creates app1/app-model.yml.
Options:
--project-name TEXT Project containing App
--app TEXT App directory name
--api-endpoint TEXT API endpoint name
--template-dir TEXT Directory of user defined Ontimize templates
--help Show this message and exit.
als app-build --app=app
cd ui/app
npm install && npm start # http://localhost:4299
- Create an Ontimize application
- Build (rebuild) Ontimize Application or Page
- Yaml File Basics
- Working with Templates
- Application Model Editor
- Advanced Filters (enable)
Note: This version uses the Ontimize API Bridge - work is being done to use JSON API
Configure Security
The ability to secure your application is an important part of the creation of any API Microservice application. In this lab - review and try:
- Who Can Access - Authentication
- What can they Do - Authorization (role-based access control)
- Use KeyCloak local docker image
- Use SQL login
Deployment (devops)
ApiLogicServer has a suite of tools for devops to build and deploy Docker containers.
Adv Project
- Adding attributes if they are not added automatically
- SQLIte to PostgreSQL migration (sqlite3 db.sqlite .dump > postgres.sql)
- Rebuild test data (?)
Be Aware Of
- Behave Testing (optional)
- Alembic Schema Migration
Appendices
Start the Manager
The Manager is a pre-configured VSCode with samples used to help new developers learn about ApiLogicServer. See the Manager documentation.
Recall you installed the manager when you installed API Logic Server. In a terminal window or powershell:
mkdir ApiLogicServer
cd ApiLogicServer
python -m venv venv
source venv/bin/activate # windows: venv\Scripts\activate
pip install ApiLogicServer
ApiLogicServer start
Explore the NorthWind (nw) example to learn about ApiLogicServer. Each folder represents a key concepts (e.g. config, api, database, logic, security, devops, test, ui)
Later, when you exit VSCode, you can restart the Manager:
Explore the folders
- Config/config.py - runtime settings
- Database/models.py - SQLAlchemy ORM
- Api/custom_api.py - Custom API endpoints
- logic/declare_logic.py
- security declare_security.py and security/system/authentication.py
- devops containers - various docker scripts
- ui/admin admin.yaml - React back office
- test - behave testing