kipchak / starter
Kipchak API Development Kit (ADK) Starter Project
Requires
- php: >=8.4
- kipchak/core: ^3.19
- kipchak/driver-config: ^1.33
- kipchak/driver-logger: ^1.38
- kipchak/driver-mcp: ^1.0
- kipchak/middleware-error: ^1.36
Requires (Dev)
- kipchak/cli: ^1.6
- phpunit/phpunit: ^12
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 4.16
- 4.15
- 4.14
- 4.13
- 4.12
- 4.11
- 4.10
- 4.9
- 4.8
- 4.7
- 4.6
- 4.5.1
- 4.5
- 4.4.1
- 4.4
- 4.3.1
- 4.3
- 4.2
- 4.1
- 4.0
- 3.19
- 3.18
- 3.17
- 3.16
- 3.15
- 3.14
- 3.13
- 3.12
- 3.11
- 3.10
- 3.9
- 3.8
- 3.7
- 3.6
- 3.5
- 3.4
- 3.3
- 3.2
- 3.1
- 3.0
- 2.29
- 2.28
- 2.27
- 2.26
- 2.25
- 2.24
- 2.23
- 2.22
- 2.21
- 2.20
- 2.19
- 2.18
- 2.17
- 2.16
- 2.15
- 2.14
- 2.13
- 2.12
- 2.11
- 2.10
- 2.9
- 2.8
- 2.7
- 2.6
- 2.5
- 2.4
- 2.3
- 2.2
- 2.1
- 2.0
- dev-work/build-ref-format
- dev-work/cors
- dev-work/mcp-example
This package is auto-updated.
Last update: 2026-11-24 04:02:34 UTC
README
Kipchak Starter
The starter project for Kipchak, a PHP API Development Kit built on Slim Framework 4 and run on FrankenPHP in worker mode. It runs on PHP 8.4 and 8.5.
It contains one versioned resource, with its route, controller, DTO and model, an OpenAPI document generated from the code, a health check and tests. Nothing else is installed: add the drivers and middleware your API needs.
Documentation: https://kipchak.dev
Upgrading an existing project? See the upgrade guide.
Create a project
With PHP 8.4 or later and Composer:
composer create-project kipchak/starter my-api
cd my-api
docker compose up --watch
With Docker alone:
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD":/app -w /app composer create-project kipchak/starter my-api cd my-api docker compose up --watch
The API is then on http://localhost:8080. --watch restarts the worker when a file changes. To use another port,
start it with PORT=8081 docker compose up --watch.
A browser application on another site, such as a front end on http://localhost:5173, can call the API only
once its origin is listed in CORS_ALLOWED_ORIGINS: in docker-compose.yml for local work, and in your deployment's
environment. Separate several with commas. Until then the API refuses those calls, and the first lines of the log
say so (CORS: no origins listed). Calls from the same site, from servers and from curl need nothing. See
config/kipchak.cors.php and https://kipchak.dev/docs/starter-project#cors.
| Request | Response |
|---|---|
GET /v1/sultans |
Every sultan |
GET /v1/sultans/4 |
One sultan; an unknown ID returns a 404 |
GET /openapi.json |
The OpenAPI document, generated from the code |
GET /status |
A health check |
Project structure
├── api/
│ ├── Controllers/ # Request handlers, versioned under v1/, v2/ and so on
│ ├── DataTransferObjects/ # The API contract: one DTO per shape of data, versioned with the controllers
│ ├── Middlewares/ # Middleware of your own
│ ├── Models/ # Business logic
│ ├── OpenApi/ # The top of the OpenAPI document: title, version, servers
│ └── Utils/ # Code shared across the API
├── bin/openapi # Writes the OpenAPI document to a file
├── config/ # One PHP file per driver or middleware, returning an array
├── drivers/drivers.php # The drivers the API initialises, in order
├── middlewares/middlewares.php # Middleware applied to every request
├── routes/ # Route files, loaded at boot and versioned by folder
├── html/
│ ├── index.php # FrankenPHP worker-mode entry point
│ └── index.nonworker.php # Entry point without worker mode
├── tests/ # PHPUnit tests, run against the booted API
└── AGENTS.md # Instructions for coding assistants
A request follows the folders in order: a route names the controller that handles it; the controller reads the request and calls a model; the model holds the business logic and returns DTOs; the controller returns them in Kipchak's response envelope:
{"code": 200, "status": "OK", "data": {"id": 4, "name": "Baybars", "reignFrom": 1260, "reignTo": 1277}}
Errors use the same envelope, from the Error middleware: throw one of Slim's HTTP exceptions, such as
HttpNotFoundException, and the client receives {"code": 404, "status": "RESOURCE_NOT_FOUND", "data": "..."}.
OpenAPI
The OpenAPI document is generated from PHP attributes: operations on controller methods, schemas on DTOs, and the
title in api/OpenApi/Definition.php. An operation declares only the data of each response;
api/Utils/OpenApi.php states the envelope around it, and gives an error response that declares no content the error
envelope. /openapi.json serves it, and
composer openapi
writes it to openapi.yaml for client generation or CI. A problem found while generating the document, such as a
reference to a schema that does not exist, is logged by /openapi.json, and printed by bin/openapi, which then
exits with 1.
vendor/bin/kipchak openapi:validate --strict
checks the document against the OpenAPI specification and against the routes the API registers: every route has an operation, every path parameter is declared, and every operation has an identifier, a summary and a tag. See the CLI.
Tests
composer test
The tests boot the API as a worker does and send requests to it without a web server; see tests/ApiTestCase.php.
Drivers and middleware
Drivers connect the API to other services: databases, caches, queues, object storage, AI models and more. Add one with the Kipchak CLI:
vendor/bin/kipchak add doctrine
It installs the package with Composer, copies its config file into config/, and initialises it in
drivers/drivers.php after the drivers it needs, adding those too. Middleware is added the same way, into
middlewares/middlewares.php between its two Error::initialise($app) lines: the first turns an exception from a
route into a JSON error response, and the last does the same for an exception from any middleware. The CLI writes
plain code into your files and nothing at run time depends on it; you can make the same changes by hand. Each
package's page on kipchak.dev gives its installation, configuration and use.
The examples repository has a working route for every free driver and middleware, with a Docker Compose service for each one that needs a server.
Worker mode
FrankenPHP's worker mode boots the API once and keeps it in memory across requests, which makes it fast, but means
anything stored in a static property or a global outlives the request. Keep request data in the request and in
local variables. Caddy and FrankenPHP describes the worker loop in
html/index.php and how to run without worker mode.
Metrics
Prometheus metrics, including FrankenPHP's worker and thread metrics, are served at /metrics on port 2019 by a
listener that answers nothing else. Set METRICS_PORT to use another port. Caddy's administration API is off
(admin off): a running API never needs to change its configuration, and the administration API has no
authentication. tests/CaddyfileTest.php fails if a Caddyfile turns it back on.
Build marker
An image built with the BUILD_REF build argument sends it as an X-Build header on every response, error pages
included, so that you can see which build answered a request and a deploy job can confirm that the new build is
serving:
docker build --build-arg BUILD_REF="$(git describe --tags)" -t my-api .
The value may be 1 to 64 letters, digits, dots, hyphens, plus signs and underscores, for example v1.4.2,
v1.4.2-3-gabc1234def56 or 2026-11-17-11-35+6d43f2f7e494. The build fails for any other value, so that no quote,
space or control character reaches the server configuration. An image built without the argument sends no X-Build header, so a project that does not use it sends the same
responses as before. tests/BuildMarkerTest.php checks the Dockerfile and both Caddyfiles.
Deployment shows how a pipeline sets the value and checks
it after a deploy.
Release notes
4.15
BUILD_REF accepts any value of 1 to 64 letters, digits, dots, hyphens, plus signs and underscores, such as a
release tag (v1.4.2) or the output of git describe --tags. In 4.14 it accepted only a date tag followed by a commit.
To adopt the change, copy the ARG BUILD_REF block from the Dockerfile.
4.14
An image built with --build-arg BUILD_REF=<date tag>+<12-character commit> sends that value as an X-Build header
on every response. Without the argument, nothing changes. To adopt it in an existing project, copy the ARG BUILD_REF
block from the Dockerfile and the two @build lines from the :80 block of etc/caddy/Caddyfile. Copy both
Caddyfile lines: a header line without the @build matcher sends an empty X-Build header when the argument is
not set.
4.12
Caddy's administration API is off, and Prometheus metrics stay on port 2019, served by a listener that answers
/metrics and returns 404 for every other path. Before 4.12, both Caddyfiles set admin :2019, which opened the
administration API on every network interface of the container. Monitoring keeps the same port and path. To adopt the
change in an existing project, replace admin :2019 with admin off as the last option of the global block, and add
the :{$METRICS_PORT:2019} block from etc/caddy/Caddyfile. Do not keep admin :2019 beside the new block: Caddy
lets the two share the port, and some connections would still reach the administration API. The steps are on
Upgrading.
4.11
A browser application on another site can now call the API with a sign-in token or a JSON body. The allowed sites
come from CORS_ALLOWED_ORIGINS (config/kipchak.cors.php), empty by default, which sends no CORS headers; a listed
origin is echoed, and * allows every origin without credentials. The list is checked when the worker starts, and
the log states the mode. The browser's preflight request is answered before the router for every path that has
routes, while /mcp keeps its own origin list and an unknown path still answers 404. Projects created from an
earlier version keep their own html/index.php; see https://kipchak.dev/docs/upgrades to adopt the change.
4.8
The commented Doctrine block in html/index.php, which checks the database connection with SELECT 1 before each
request, now skips that check for health paths (/livez and /status), so a liveness probe answers while the
database is down. The comments also say to give the web worker a short MySQL read timeout with
ini_set('mysqlnd.net_read_timeout', ...): PDO has no read-timeout attribute for MySQL, and without it a request
waits up to 86,400 seconds for a database that has stopped answering. Long-running commands, such as migrations, keep
the default. See the Doctrine driver. The block stays commented out, so
nothing changes for a project that has not enabled it.
Licence
MIT. See LICENSE.
