Quick Start

From an empty folder to a generated, running API in a few commands.

Requirements

  • PHP 8.2+ and Composer. The generator is written in PHP, whichever backend you pick.
  • MySQL or MariaDB. PostgreSQL is optional.
  • Node.js 18+ if you generate a frontend.
  • Deno 2 if you pick the Deno backend.

1. Create the project

composer create-project puneetxp/the_template_php my-app
cd my-app

The template contains setup.php, config.json, the auth models in database/Model/ (users, role, active_role), and view and asset scaffolding under Resource/.

2. Configure

Edit config.json. Set the database credentials and choose what to generate:

{
  "env": {
    "host": "localhost", "sslhost": "localhost",
    "dbhost": "localhost", "dbname": "my_app",
    "dbuser": "root", "dbpwd": "secret",
    "samesite": "Strict", "httponly": true, "secure": false
  },
  "fresh": true,
  "back-end": ["php"],
  "front-end": ["angular"],
  "table": {}
}

Accepted values are back-end: php, deno or python, and front-end: angular or solidjs. See Config → for every key.

3. Describe your tables

Add one JSON file per table to database/Model/:

database/
└── Model/
    ├── users.json
    ├── role.json
    ├── active_role.json
    └── brand.json        ← yours
{
  "name": "brand",
  "table": "brands",
  "crud": { "isuper": ["c", "r", "u", "d", "a", "p"], "ipublic": ["r", "a"] },
  "enable": 1,
  "additional": ["slug"],
  "data": [{ "name": "name", "mysql_data": "varchar(255)", "datatype": "string" }],
  "relations": [{ "name": "photo", "default": "NULL" }]
}

See Schema → for the full format.

4. Generate

php setup.php

This writes database/*.sql and the backend and frontend code. Apply the SQL to your database:

mysql -u root -p my_app < database/Migration.sql

You can also let the generator apply it by calling $setup->migrate() from setup.php. See Generator →.

5. Run

PHP backend

cd php && composer install && cd ..
ln -s ../php/index.php public/index.php        # web root → front controller
ln -s ../storage/public public/storage         # uploads
php php/set.php                                # compile Routes/pre → Routes/web.php
php -S localhost:8000 -t public public/index.php   # built-in server ignores .htaccess, so route everything to index.php

Deno backend

cd deno && deno run --watch --allow-all --unstable-kv index.ts   # serves :9000

Frontend

cd angular && npm install && npx ng serve       # or: cd solidjs && npm install && npm run dev

Your API is now at /api/ipublic/brand, /api/isuper/brand, and so on. Log in with POST /api/login using {email, password}. The user with id = 1 is always isuper.

Next