kode4 / slim-foundation
The foundation of a Slim 4 JSON API: Problem Details, configuration, persistence, security, contract, jobs and mail as modules
Requires
- php: ^8.4
- ext-pdo_mysql: *
- doctrine/dbal: ^4.6
- doctrine/migrations: ^3.9
- guzzlehttp/psr7: ^3.4
- monolog/monolog: ^3.8
- php-di/php-di: ^7.0
- php-di/slim-bridge: ^3.4
- phpstan/phpdoc-parser: ^2.4
- psr/clock: ^1.0
- psr/container: ^2.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
- slim/slim: ^4.14
- symfony/cache: ^8.1
- symfony/clock: ^7.4 || ^8.0
- symfony/console: ^7.4 || ^8.0
- symfony/dotenv: ^7.4 || ^8.0
- symfony/lock: ^8.1
- symfony/rate-limiter: ^8.1
- symfony/uid: ^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- kode4/slim-foundation-testing: 0.1.x-dev
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1.13
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-doctrine: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.2
- symfony/mailer: ^8.1
- symfony/mime: ^8.1
- twig/cssinliner-extra: ^3.21
- twig/twig: ^3.21
Suggests
- ext-pcntl: job:work stops cleanly on SIGTERM
- phpstan/phpstan-doctrine: extension.neon: the literal-string SQL rule and the @internal boundary (^2.0, with phpstan/phpstan ^2.1.13)
- symfony/mailer: MailModule: sending mails (^8.1)
- symfony/mime: MailModule: building mails (^8.1)
- twig/cssinliner-extra: MailModule: inlined CSS in HTML mails (^3.21)
- twig/twig: MailModule: mail templates (^3.21)
Provides
None
Conflicts
- laravel/serializable-closure: <1.0.5
- phpstan/phpstan: <2.1.13
- symfony/polyfill-php83: <1.31
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 12:43:24 UTC
README
The foundation of a Slim 4 JSON API: a Kernel with opt-in modules, layered configuration, Problem Details,
server-side sessions with guards and permissions, persistence on Doctrine DBAL, a generated OpenAPI 3.1 contract, a
database job queue, mail and accounts. The backend sibling of @kode4/react-foundation.
PHP ^8.4, Slim 4, PHP-DI, Doctrine DBAL ^4.6, MariaDB or MySQL, Symfony components. MIT licence.
Start
A new project comes from the skeleton (Docker only, no PHP on the host):
docker run --rm -v "$PWD":/app -w /app composer:2 \
create-project --no-install --no-scripts kode4/slim-foundation-skeleton api
Then read docs/INSTRUCTIONS.md: the mental model, the rules, how to add a feature, one chapter per module.
In an existing project: composer require kode4/slim-foundation and composer require --dev
kode4/slim-foundation-testing; for the Mail module also symfony/mailer, symfony/mime, twig/twig and
twig/cssinliner-extra.
Modules
| Module | Namespace Kode4\SlimFoundation\… | Content |
|---|---|---|
| Core (always) | Kernel, Config, Error, Http, Json, Console | Kernel and module hooks, settings and .env, Problem Details, middleware, sessions, CSRF, JsonResponder, JsonView, contract:openapi, db:seed, db:reset |
| Persistence | Persistence | Mapping attributes, EntityRepository, Criteria, paging, transactions with deadlock retry, connections, migrations, seeders |
| Security, Auth | Security, Auth | Guards, permissions, rate limits, audit log; identity, session authentication, login, password hashing |
| Input | Input | JsonInput (a JSON body by dot paths, every error in one 422), ListQuery (q, sort, page, size) |
| Contract | Contract | #[ApiOperation], #[ApiType], the OpenAPI 3.1 generator |
| File | File | FileStorage and a local driver |
HealthModule | Health | /health/live, /health/ready |
JobModule | Job | The job queue, job:work, job:recover, job:cleanup |
MailModule | Mail | Twig templates, sending through the queue, a transport guard that keeps mail on development machines |
AccountModule | Account | Users and roles, login, logout, /me, password reset, user:create-admin |
Documentation
| Document | Content |
|---|---|
| docs/INSTRUCTIONS.md | The consumer guide for developers and coding agents |
| docs/reference/ | One chapter per area: kernel and modules, configuration, HTTP, persistence, input, security, accounts, contract, jobs, mail, files and health, testing |
| CONTRACT.md | The HTTP conventions clients rely on; changing one is a breaking change |
| docs/adr/ | The architecture decisions |
| ROADMAP.md | What 0.1 leaves out |
| CHANGELOG.md | Changes per release |
| AGENTS.md | Working on the library itself (for coding agents; CLAUDE.md imports it) |
PHPStan
Include vendor/kode4/slim-foundation/extension.neon (needs phpstan/phpstan-doctrine and phpstan/phpstan 2.1.13 or
later). It has two rules:
- SQL passed to DBAL's
ConnectionandQueryBuildermust be aliteral-string, so a value interpolated into SQL fails the analysis (persistence.md). - A project that uses an
@internalclass of the library, or a member of one, is reported (ADR 0014).
Status
Semver covers the types tagged @api; an @internal one may change in
any release (ADR 0014). Before 1.0 a minor release may break, always with a
### Breaking note and a migration path in the changelog. The packages are released together with the same version:
kode4/slim-foundation, kode4/slim-foundation-testing and kode4/slim-foundation-skeleton.
Source
Developed in the monorepo gitlab.com/kode4/slim-foundation (folder
slim-foundation/). The repository kode4/packages/slim-foundation is a read-only copy made on every release: open
issues and merge requests in the monorepo.