Search by

kode4 / slim-foundation

kode4

The foundation of a Slim 4 JSON API: Problem Details, configuration, persistence, security, contract, jobs and mail as modules

Package info

gitlab.com/kode4/packages/slim-foundation

Issues

pkg:composer/kode4/slim-foundation

Statistics

Installs: 23

Dependents: 2

Suggesters: 0

Stars: 0

v0.1.2 2026-12-02 13:26 UTC

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

ModuleNamespace Kode4\SlimFoundation\…Content
Core (always)Kernel, Config, Error, Http, Json, ConsoleKernel and module hooks, settings and .env, Problem Details, middleware, sessions, CSRF, JsonResponder, JsonView, contract:openapi, db:seed, db:reset
PersistencePersistenceMapping attributes, EntityRepository, Criteria, paging, transactions with deadlock retry, connections, migrations, seeders
Security, AuthSecurity, AuthGuards, permissions, rate limits, audit log; identity, session authentication, login, password hashing
InputInputJsonInput (a JSON body by dot paths, every error in one 422), ListQuery (q, sort, page, size)
ContractContract#[ApiOperation], #[ApiType], the OpenAPI 3.1 generator
FileFileFileStorage and a local driver
HealthModuleHealth/health/live, /health/ready
JobModuleJobThe job queue, job:work, job:recover, job:cleanup
MailModuleMailTwig templates, sending through the queue, a transport guard that keeps mail on development machines
AccountModuleAccountUsers and roles, login, logout, /me, password reset, user:create-admin

Documentation

DocumentContent
docs/INSTRUCTIONS.mdThe 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.mdThe HTTP conventions clients rely on; changing one is a breaking change
docs/adr/The architecture decisions
ROADMAP.mdWhat 0.1 leaves out
CHANGELOG.mdChanges per release
AGENTS.mdWorking 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 Connection and QueryBuilder must be a literal-string, so a value interpolated into SQL fails the analysis (persistence.md).
  • A project that uses an @internal class 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.