PHPackages                             psx/psx - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. psx/psx

ActiveProject[Framework](/categories/framework)

psx/psx
=======

PHP REST API Framework

v7.0.1(2y ago)17112.6k133Apache-2.0PHPPHP &gt;=8.1CI failing

Since Dec 9Pushed 1y ago12 watchersCompare

[ Source](https://github.com/apioo/psx)[ Packagist](https://packagist.org/packages/psx/psx)[ Docs](https://phpsx.org)[ Fund](https://www.paypal.me/fusioapi)[ GitHub Sponsors](https://github.com/chriskapp)[ RSS](/packages/psx-psx/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (65)Used By (3)

About
-----

[](#about)

**PSX is an innovative PHP framework dedicated to build fully typed REST APIs.**

It helps to improve the API development process by providing the following features:

- Fully typed controller classes
- Client SDK generator
- [OpenAPI](https://www.openapis.org/) generator
- Generate model classes based on a [TypeSchema](https://typeschema.org/) specification
- Uses the Symfony [DI container](https://github.com/symfony/dependency-injection) component
- Works with Doctrine [DBAL](https://github.com/doctrine/dbal) and [migrations](https://github.com/doctrine/migrations)
- Type-safe database interaction
- Endpoint integration testing

More information about PSX at [phpsx.org](https://phpsx.org/).

Installation
------------

[](#installation)

To install the framework you can simply install this demo API project.

```
composer create-project psx/psx .

```

Getting started
---------------

[](#getting-started)

This repository contains already a fully working demo API build with PSX which you can use as a starting point and to better understand how PSX works. In the following we go based on the demo files through the important concepts of PSX.

Controller
----------

[](#controller)

A controller is the entrypoint of your app which gets invoked by the framework. A controller is a simple PHP class which contains attributes to make specific methods invokable. In the following example we have a simple controller with a `getAll` and `create` method which gets invoked if a `GET` or `POST` request arrives at the `/population` endpoint s.

```
class Population extends ControllerAbstract
{
    #[Get]
    #[Path('/population')]
    public function getAll(#[Query] ?int $startIndex = null, #[Query] ?int $count = null): Model\PopulationCollection
    {
        return $this->populationTable->getCollection($startIndex, $count);
    }

    #[Post]
    #[Path('/population')]
    public function create(#[Body] Model\Population $payload): Model\Message
    {
        $id = $this->populationService->create($payload);

        $message = new Model\Message();
        $message->setSuccess(true);
        $message->setMessage('Population record successfully created');
        $message->setId($id);
        return $message;
    }
}
```

One key concept of PSX is that the arguments of your exposed controller methods are mapped to values of the incoming HTTP request, at the `getAll` method the `$startIndex` and `$count` parameter are mapped to a query parameter from the HTTP request, at the `create` method the `$payload` parameter is mapped to the request body. If you are familiar with [Spring](https://spring.io/) or [NestJS](https://nestjs.com/) you already know this approach.

PSX uses the symfony DI container, all controller classes are automatically loaded through auto-wiring. This means you can simply define at the constructor all dependencies which are needed for your controller. Please take a look at the [container.php](https://github.com/apioo/psx/blob/master/resources/container.php) if you want to customize which classes are loaded.

SDK
---

[](#sdk)

One of the greatest feature of PSX is that it can automatically generate a client SDK for the API which you have build. To generate the client SDK simply run the following command.

```
php bin/psx generate:sdk

```

This writes the SDK to the `output/` folder. By default, the command generates the TypeScript SDK. Based on the controller defined above PSX would generate the following client SDK.

```
const client = new Client(...);

client.population().getAll(startIndex?: number, count?: number);
client.population().create(payload: Population);

```

The client then contains the same schemas which are also defined at the backend but converted to TypeScript. This means you are using exactly the same schema at the backend and frontend. If you change your schema at the backend you can then regenerate the SDK and you will directly see all problems with your new schema. In this sense PSX provides similar features like [tRPC](https://trpc.io/) but in a language neutral way.

The `generate:sdk` command accepts as argument a format which defines the type of SDK which is generated. The following list shows some supported formats.

- `client-php`
- `client-typescript`
- `spec-openapi`

Model
-----

[](#model)

To enable this SDK generation PSX needs to understand the structure of the incoming or outgoing JSON payload. This is done by using DTO models for every argument and return type. PSX contains a model generator which allows you to generate those models based on a [TypeSchema](https://typeschema.org/) specification. Please take a look at the [typeschema.json](https://github.com/apioo/psx/blob/master/resources/typeschema.json) file which contains the models for our demo API. You can generate all models using the following command s.

```
php bin/psx generate:model

```

The command writes all models to the `src/Model` folder. You can then use those models at the controller classes.

Service
-------

[](#service)

PSX recommends to move your actual business logic into a separate service class. The controller then simply invokes methods from your service. While this is not mandatory it improves your code quality since you can easily use this service also in another context. All classes under the `service/` folder are automatically loaded thus you can specify all dependencies through simple constructor injection.

Migrations
----------

[](#migrations)

PSX uses doctrine [migrations](https://github.com/doctrine/migrations/) which helps to manage your database schema. To generate a new migration you can simply run s.

```
php bin/psx migrations:generate

```

This would create a new migration file at `src/Migrations`. You can then model your table schema at this migration file. After this you can run the `migrate` command to execute all needed database changes s.

```
php bin/psx migrations:migrate

```

Please take a look at the doctrine [migrations](https://github.com/doctrine/migrations/) project for more information how the migration system works.

Table
-----

[](#table)

PSX provides a command which generates table and row classes to interact with your database in a type-safe way. This command should be executed after you have executed all your migrations.

```
php bin/psx generate:table

```

This command then writes all files to the `src/Table` folder.

Note in general we think that for API development an ORM is not needed, but it would be easy possible to integrate any existing ORM into PSX.

Tests
-----

[](#tests)

PSX provides a way to easily build an integration test for every controller endpoint. The following extract shows the test which requests the `/population` endpoint and simply compares the JSON payload with an existing JSON structure.

```
public function testGetAll(): void
{
    $response = $this->sendRequest('/population', 'GET');

    $actual = (string) $response->getBody();
    $expect = file_get_contents(__DIR__ . '/resources/collection.json');

    $this->assertEquals(200, $response->getStatusCode(), $actual);
    $this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
}
```

Through this you can easily build integration tests for every endpoint. Please take a look at the `tests/Controller/PopulationTest.php` file to see the complete test case.

Components
----------

[](#components)

Besides the framework PSX is build on various PHP components. These components are independent of the framework and can also be used in another context. The following list contains the most notable packages:

- [psx/api](https://github.com/apioo/psx-api)
    Parse and generate API specification formats
- [psx/schema](https://github.com/apioo/psx-schema)
    Parse and generate data schema formats
- [psx/data](https://github.com/apioo/psx-data)
    Data processing library to read and write POPOs in different formats
- [psx/sql](https://github.com/apioo/psx-sql)
    Generate type-safe PHP classes from your database

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~559 days

Total

64

Last Release

869d ago

Major Versions

v1.2.3 → v2.0.0-RC12016-04-29

v2.0.1 → v3.0.02016-12-24

v3.0.3 → v4.0.02017-12-31

v4.0.1 → v6.0.02021-12-28

v6.0.0 → v7.0.02023-04-08

PHP version history (7 changes)v0.4.7PHP &gt;=5.3

v0.9.0PHP &gt;=5.4

v2.0.0-RC1PHP &gt;=5.5

v3.0.0PHP &gt;=5.6

v3.0.3PHP &gt;=7.0

v6.0.0PHP &gt;=8.0

v7.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2505846?v=4)[Christoph Kappestein](/maintainers/chriskapp)[@chriskapp](https://github.com/chriskapp)

---

Top Contributors

[![chriskapp](https://avatars.githubusercontent.com/u/2505846?v=4)](https://github.com/chriskapp "chriskapp (1937 commits)")

---

Tags

apicode-generatorframeworkopenapiphprestapiframeworkrest

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/psx-psx/health.svg)

```
[![Health](https://phpackages.com/badges/psx-psx/health.svg)](https://phpackages.com/packages/psx-psx)
```

###  Alternatives

[gotzmann/comet

Modern PHP framework for building blazing fast REST APIs and microservices

68516.3k1](/packages/gotzmann-comet)[atk4/api

Agile API - Extensible API server in PHP for Agile Data

143.7k1](/packages/atk4-api)[patricksavalle/slim-rest-api

Production-grade REST-API App-class for PHP SLIM, in production on https://zaplog.pro (https://api.zaplog.pro/v1)

101.4k](/packages/patricksavalle-slim-rest-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
