Search by

pivotphp / skeleton

CAFernandes

Skeleton project for PivotPHP v2.2.0 - The evolutionary PHP microframework

Package info

github.com/PivotPHP/pivotphp-skeleton

Type:project

pkg:composer/pivotphp/skeleton

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.1 2026-10-09 03:49 UTC

This package is auto-updated.

Last update: 2026-10-09 03:49:42 UTC


README

The fastest way to start building APIs with PivotPHP v2.2.0

PivotPHP PHP Version License

๐Ÿš€ "Route Syntax & DX Edition" - PivotPHP v2.2.0 Edition

โœจ What's Included

This skeleton provides everything you need to start building modern PHP APIs:

  • ๐ŸŽฏ PivotPHP v2.2.0 - Latest framework with educational focus
  • ๐Ÿ“š Optional OpenAPI/Swagger - Interactive API documentation at /swagger, opt-in (a few lines in public/index.php โ€” see Enabling API Documentation below)
  • ๐Ÿš€ Express.js Syntax - Familiar, intuitive routing patterns
  • ๐Ÿ—๏ธ MVC Structure - Controllers, middleware, and clean organization
  • โœ… PHPUnit Testing - Ready-to-use testing setup
  • ๐Ÿ”ง Development Tools - Built-in server, debugging, and more

๐Ÿš€ Quick Start

# Create a new project
composer create-project pivotphp/skeleton my-api

# Enter project directory and start server
cd my-api && composer serve

Your API is now running at http://localhost:8000! ๐ŸŽ‰

๐Ÿ“– Available Endpoints

Once running, you can access:

Endpoint Description
GET / Welcome message with API info
GET /health Health check endpoint
GET /api/status API status and metadata
GET /api/users List all users (CRUD example)
POST /api/users Create new user
GET /api/users/{id} Get user by ID
PUT /api/users/{id} Update user
DELETE /api/users/{id} Delete user

GET /swagger and GET /docs (interactive API documentation and its OpenAPI 3.0 JSON spec) are not available out of the box โ€” they require enabling ApiDocumentationMiddleware first. See Enabling API Documentation below.

๐Ÿ—๏ธ Project Structure

my-api/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ Controllers/          # API controllers
โ”‚   โ”‚   โ”œโ”€โ”€ ApiController.php
โ”‚   โ”‚   โ””โ”€โ”€ UserController.php
โ”‚   โ””โ”€โ”€ Middleware/           # Custom middleware
โ”‚       โ””โ”€โ”€ CorsMiddleware.php
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ app.php              # Application configuration
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ index.php            # Application entry point
โ”œโ”€โ”€ routes/
โ”‚   โ””โ”€โ”€ api.php              # API route definitions
โ”œโ”€โ”€ storage/
โ”‚   โ””โ”€โ”€ logs/                # Application logs
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ ApiTest.php          # Example tests
โ”œโ”€โ”€ .env                     # Environment configuration
โ”œโ”€โ”€ composer.json            # Dependencies and scripts
โ””โ”€โ”€ README.md               # This file

๐Ÿ› ๏ธ Development Commands

# Start development server
composer serve

# Run tests
composer test

# Run tests with coverage report
composer test:coverage

๐Ÿ“š Enabling API Documentation (optional)

The @route, @summary, @tags and @response PHPDoc comments you'll see above each route in routes/api.php are for human readers only โ€” pivotphp/core does not parse them, and this skeleton does not register anything that would. By default, /swagger and /docs are not available.

To enable them, register PivotPHP\Core\Middleware\Http\ApiDocumentationMiddleware in public/index.php, before $app->run():

use PivotPHP\Core\Middleware\Http\ApiDocumentationMiddleware;

$app->use(new ApiDocumentationMiddleware([
    'docs_path' => '/docs',       // JSON OpenAPI 3.0 spec (note: not /openapi.json)
    'swagger_path' => '/swagger', // Swagger UI
]));

Once registered, the middleware builds the OpenAPI spec from the routes actually registered on the Router at runtime โ€” the PHPDoc blocks above are not read by it, they are purely documentation for developers browsing routes/api.php.

After adding this, visit http://localhost:8000/swagger to see interactive API docs.

๐ŸŽฏ Express.js-Style Routing

Write routes that feel familiar:

// Simple route
$app->get('/', function($req, $res) {
    return $res->json(['message' => 'Hello World!']);
});

// Route parameters
$app->get('/users/{id}', function($req, $res) {
    $id = $req->param('id');
    return $res->json(['user_id' => $id]);
});

// Array callables (work from PHP 8.1+; the legacy 'Controller@method' string
// syntax is what breaks under PHP 8.4+, not array callables themselves)
$app->post('/users', [UserController::class, 'store']);

// Middleware โ€” CorsMiddleware ships as an example class in
// app/Middleware/CorsMiddleware.php but is NOT registered anywhere by
// default. Register it yourself in public/index.php before $app->run():
$app->use(new CorsMiddleware());

๐Ÿ”ง Configuration

Edit config/app.php to customize your application:

return [
    'name' => 'My Awesome API',
    'openapi' => [
        'title' => 'My API Documentation',
        'version' => '2.0.0'
    ],
    'performance' => [
        'cache_routes' => true,  // Enable in production
        'optimize_responses' => true
    ]
];

๐Ÿงช Testing

Write tests in the tests/ directory:

class MyApiTest extends TestCase
{
    public function testWelcomeEndpoint(): void
    {
        // Your API tests here
        $this->assertTrue(true);
    }
}

๐Ÿ“ˆ Performance

Historical PivotPHP v1.2.0 benchmark figures (Docker-validated at the time), not revalidated against this skeleton or the current pivotphp/core release line โ€” treat as indicative, not a guarantee:

  • 2,122 req/sec peak HTTP performance
  • 3.6M ops/sec OpenAPI generation
  • Docker validated benchmarks (as of the v1.2.0 release)

๐Ÿš€ Next Steps

  1. Customize your API - Edit routes in routes/api.php
  2. Add controllers - Create new controllers in app/Controllers/
  3. Build middleware - Add custom middleware in app/Middleware/
  4. Write tests - Add tests in tests/
  5. Deploy - Use your preferred deployment method

๐Ÿ“– Learn More

๐Ÿ“„ License

The PivotPHP Skeleton is open-sourced software licensed under the MIT license.

Built with โค๏ธ by the PivotPHP Team

"Making PHP development joyful again"