taphra / skeleton
Minimal Taphra app: one page, one JSON endpoint, SQLite ready. The starting point for a new Taphra project.
Requires
- php: ^8.2
- taphra/taphra: ^1.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Taphra's guides are at https://taphra.dev/docs/. Coding agents: read this app's AGENTS.md, and all the guides in one file at https://taphra.dev/llms-full.txt.
The minimal Taphra app: one HTML page, one JSON endpoint, one layout. It runs
as soon as Composer has installed it. Cache, sessions and logs use files under
app/tmp/, the database is a SQLite file under app/Database/, and nothing
connects to it until you use a DataStore.
Requirements
- PHP 8.2 or later, with the
pdo_sqliteextension for the default database (php -mlists your extensions) - Composer
Quick start
composer create-project taphra/skeleton my-app
cd my-app
php taphra serve
Open http://127.0.0.1:8000 for the home page and http://127.0.0.1:8000/health for the JSON endpoint. Stop the server with Ctrl+C.
composer create-project also writes a random APP_SECRET_KEY to .env and
creates the app/tmp/ folders. app/bootstrap.php reads .env on every
request and command; variables set in the real environment take precedence.
Modes
The mode comes from APP_ENV: dev (or development, local) for
development, stg (or staging) for staging, anything else for production.
An unset APP_ENV means production: no debug pages, errors go to the log and
visitors see app/Views/error404.tpl.php or error500.tpl.php.
php taphra serve sets APP_ENV=dev for its server when you have not set it,
so you get the debug error page while you develop. Other php taphra
commands run in production mode unless you set APP_ENV.
Each file in app/Config/ can have an all: section and per-mode dev:,
stg: and prod: sections that override it.
Docker
docker compose up --build
This runs the development server in a container on http://127.0.0.1:8080
(published on your machine only). The image is for development: it runs
php taphra serve, PHP's built-in server.
Production
Point the web server's document root at app/Static/. Under Apache,
app/Static/.htaccess sends every request that is not a file to index.php;
under nginx use try_files $uri /index.php$is_args$args;. For FrankenPHP's
worker mode see the comment at the top of app/Static/frankenphp-worker.php.
Before you go live, in app/Config/app.yml:
- set
base_urlunderprod:to your site's address (url()builds absolute links from it; it never trusts the Host header in production); - behind a load balancer or reverse proxy, list its addresses in
trusted_proxiesso the client IP and HTTPS are read from theX-Forwarded-*headers (they are ignored otherwise).
Then run php taphra optimize on each deploy to compile the config and routes.
Layout
my-app/
app/
Config/ app.yml, routes.yml, databases.yml, migrations.yml
Controllers/ HomeController (HTML), HealthController (JSON), AppController (base)
Database/ the SQLite file (created on first use)
DataStores/ AppDataStore (base class for your tables)
Layouts/ default.lyt.php
Migrations/ database migrations
Models/ AppModel (base)
Static/ document root: index.php, .htaccess, frankenphp-worker.php
Views/ home/index.tpl.php, error404.tpl.php, error500.tpl.php
tmp/ file cache and logs (not committed)
bootstrap.php runs on every request and command: .env, mode
composer.json
taphra the command line: php taphra list
Adding a page
-
Add an action to a controller. New classes go in files named after the class (
app/Controllers/PagesController.phpforApp\Controllers\PagesController), so Composer finds them withoutcomposer dump-autoload:<?php namespace App\Controllers; class PagesController extends AppController { public function about(): void { $this->viewTitle = 'About'; $this->autoRender = true; // renders app/Views/pages/about.tpl.php } }
-
Create the view
app/Views/pages/about.tpl.php. Print values withe(). -
The page answers at
/pages/about(controller/action). For your own URL, declare a route inapp/Config/routes.ymlunder the HTTP method:GET: /about: pages/about
Every public method of your controllers is an action. A URL can run it with
any HTTP method until a route declares which methods it takes, so give every
action that changes data a POST: (or PUT:, PATCH:, DELETE:) route:
the other methods then get a 405. Forms that post to AppController actions
need the CSRF token: put <?= $this->csrf() ?> inside each form.
Adding a database table
php taphra make:migration create posts table
# edit the new file in app/Migrations/, then:
php taphra migrate
A DataStore per table, in app/DataStores/PostDataStore.php:
<?php namespace App\DataStores; class PostDataStore extends AppDataStore { use \Taphra\Traits\Timestamps; public $objectName = 'posts'; protected $fillable = ['title', 'body']; }
To use MySQL, MariaDB or PostgreSQL, edit app/Config/databases.yml (an
example is at the end of the file).
Command line
php taphra list # every command php taphra serve # development server (--port=8080, --host=0.0.0.0) php taphra route:list # the routes from app/Config/routes.yml php taphra make:controller Name php taphra make:migration description php taphra migrate php taphra cache:clear
Licence
This starter, like Taphra, is open-source software under the MIT licence (Copyright 2019-2026 Prodacity LLC); see LICENSE.