AI Assisted Code Generation

Apex offers AI assisted code generation via Chat GPT combined with in-house libraries that allow you to generate full packages and components including all necessary SQL code, models, views, controllers, REST API endpoints and everything else. Allthough not 100% and will be improved upon, it does save time by generating a solid base to begin with that writes much of the boiler plate code, allowing you to go through and tweak as necessary into the final product.

Initialize Client

First, you must register for an OpenAI account and generate an API key. Once you have the API key, run the gpt init CLI command such as:

apex gpt init <API_KEY>

Generate Package

The main code generation command is the gpt package CLI command, which is intended to generate the entire base of a new package including SQL database schema, plus all models, views, controllers, REST API end points, and more. To begin, simply run the command such as:

apex gpt package my-package

If the my-package package does not already exist, it will be automatically created. You will then be prompted for a plain text description of the package's functionality. Be as descriptive as possible, and once done put a single period on a new line and press enter to signify you are done.

An API call will be made to OpenAI generating the necessary SQL database schema, which is temporarily saved in the chat_gpt.sql file of the installation directory. Upon being prompted, open the chat_gpt.sql file, review the SQL code and make any necessary modifications. Be as complete as possible as it's used to determine model properties, fields in HTML forms, columns within data tables, etc.

Once satisfied with the database schema, press enter to continue. This will create the database tables, save the migrations, plus generate all necessary components. You may be prompted several times during the generation process, but once done a list of all generated files will be shown providing you a base system that you may go through and tweak as necessary into the final product.

REST API Endpoints

Another useful command is the gpt rest-api CLI command which will automatically generate REST API endpoints from a plain text description. First, ensure the rest-api package is installed on the system, which if necessary can be installed with:

apex install rest-api

Once installed, generate new REST API endpoint with the command:

apex gpt rest-api my-package

This will prompt you to describe the API endpoints you would like generated in plain text, and after confirmation automatically generate all necessary PHP classes plus add all needed routes.

Component Generation

It's also possible to automatically generate various components such as HTML forms, database tables and others with AI assistance. For full details, please visit the gpt CLI Commands section of the documentation.