Skip to content

PAM HTTP Starter

pushinbr/pam-skeleton is a ready-to-run API built with PAM HTTP. It shows the structure the package recommends, end to end: a thin controller, a form request that hydrates a DTO, a service, a repository backed by the Arcano ORM, a JSON resource, an explicit migration and an in-memory test.

Install PAM, then create the project with PAM’s Composer:

Terminal window
pam composer create-project pushinbr/pam-skeleton my-api
cd my-api

Prepare a SQLite database and run the migrations:

Terminal window
mkdir -p storage && touch storage/database.sqlite
export DB_CONNECTION=sqlite DB_DATABASE=$PWD/storage/database.sqlite
pam composer migrate

Start the development server:

Terminal window
pam dev index.php

The API listens on http://127.0.0.1:3000; set PAM_PORT to change it. Try it:

Terminal window
curl http://127.0.0.1:3000/api/ping
# {"data":{"status":1,"message":"pong","requestId":null}}
curl -X POST http://127.0.0.1:3000/api/products \
-H 'content-type: application/json' \
-d '{"name":"Mechanical keyboard","priceInCents":34990}'
# 201 {"data":{"id":1,"name":"Mechanical keyboard","priceInCents":34990,"status":1}}
curl http://127.0.0.1:3000/api/products
# {"data":[{"id":1,"name":"Mechanical keyboard","priceInCents":34990,"status":1}]}

An invalid payload returns 422 Problem Details with the error for each field.

my-api/
├── index.php # configuration, providers, middleware, routes, listen()
├── bin/migrate # migration runner (pam composer migrate)
├── database/migrations/ # Arcano migrations
├── src/
│ ├── Domain/Products/ # CreateProductData DTO, ProductStatus enum
│ ├── Http/Controllers/ # PingController, ProductController
│ ├── Http/Requests/ # StoreProductRequest
│ ├── Http/Resources/ # PingResource, ProductResource
│ ├── Models/Product.php # #[Entity] mapped by Arcano
│ ├── Providers/AppServiceProvider.php
│ ├── Repositories/ # ProductRepository + ArcanoProductRepository
│ └── Services/ # ProductService, ReadinessService
├── tests/ApplicationTest.php # in-memory tests
└── .env.example

POST /api/products passes through each layer:

  1. index.php maps the route to [ProductController::class, 'store'].
  2. StoreProductRequest validates name and priceInCents and exposes data(), which hydrates the readonly CreateProductData DTO.
  3. ProductController stays thin: it calls ProductService::create().
  4. ProductService owns the use case and talks to the ProductRepository interface.
  5. AppServiceProvider binds ProductRepository to ArcanoProductRepository, which persists the Product entity.
  6. ProductResource turns the entity into JSON and the controller returns it with status 201.

Statuses are integer-backed enums (ProductStatus::Active = 1, Archived = 2), so the API exposes stable numbers.

index.php validates configuration at boot with Configuration and installs SecurityHeadersMiddleware. .env.example lists the variables:

.env.example
PAM_PORT=3000
PAM_WORKERS=4
DB_CONNECTION=sqlite
DB_DATABASE=storage/database.sqlite

Any database variable supported by DatabaseConfig::fromEnvironment() works. PostgreSQL is the default when DB_CONNECTION is not set.

Entities in src/Models are compiled into var/cache/arcano-schema.php. The cache is rebuilt when an entity changes, except when PAM_ENV=production.

Migrations never run while workers boot, so concurrent workers cannot race schema changes. Use the Composer script:

Terminal window
pam composer migrate # run pending migrations
pam composer migrate generate # write a migration for changed entities
pam composer migrate rollback 1 # revert the last migration
pam composer migrate status # list migrations and when they ran
pam composer migrate cache # rebuild the schema cache (deployments)

Running migrate again is safe; it reports that the database is already up to date.

Terminal window
pam composer test

The script runs PHPUnit inside PAM (pam test --phpunit -c phpunit.xml). tests/ApplicationTest.php checks the ping endpoint and the full product flow against a temporary SQLite database, including a 422 response. See HTTP Testing.

  • Build the schema cache with pam composer migrate cache and run pam composer migrate as a release step.
  • Set PAM_ENV=production so the schema is never rescanned at runtime.
  • Run the application with pam start index.php and configure listener limits, trusted proxies and TLS termination. See Production.
  • Run pam doctor after dependency changes.
Skeleton PAM HTTP ORM
2.1.0 ^2.2 Arcano (pushinbr/arcano)
2.0.x ^2.0 Eloquent

The skeleton requires PHP 8.5, pushinbr/pam-http, pushinbr/pam-http-psr, pushinbr/pam-socket and pushinbr/arcano, with pushinbr/pam-http-testing, PHPUnit and Laravel Pint for development. Files you copy from the skeleton are yours to use under any terms; the skeleton itself is licensed under the Apache License 2.0.