Search by

kode4 / slim-foundation-skeleton

kode4

A new JSON API on kode4/slim-foundation: composer create-project kode4/slim-foundation-skeleton api

Package info

gitlab.com/kode4/packages/slim-foundation-skeleton

Issues

Type:project

pkg:composer/kode4/slim-foundation-skeleton

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.2 2026-12-01 19:29 UTC

This package is auto-updated.

Last update: 2026-12-02 12:42:15 UTC


README

A JSON API on kode4/slim-foundation (guide: vendor/kode4/slim-foundation/docs/INSTRUCTIONS.md): Slim 4, PHP 8.4, Doctrine DBAL, MariaDB, Problem Details, session login with roles and permissions, a generated OpenAPI 3.1 contract, a job queue and mail. Created from kode4/slim-foundation-skeleton; replace this paragraph with what the API is for.

Coding agents (Claude Code, Codex, Cursor, Copilot, …): the rules are in AGENTS.md.

Getting started

Docker is the only requirement: every tool runs in a container, nothing on the host.

docker run --rm -v "$PWD":/app -w /app composer:2 \
  create-project --no-install --no-scripts kode4/slim-foundation-skeleton api
cd api
docker compose run --rm api composer install
docker compose run --rm api bin/console db:reset --force   # schema + dev data (admin@example.test / pw)
docker compose up -d
curl http://localhost:8080/health/ready

Then commit composer.lock. Ports and user ids: .env.example.

WhatCommand
All gates without a database: validate, audit, code style, PHPStan max, unit testsdocker compose run --rm api composer check
Integration tests (migrates app_test first)docker compose run --rm api composer test:integration
Migrationsdocker compose run --rm api composer migrate
Rebuild the dev database (schema, then db:seed and the modules' reset steps)docker compose run --rm api bin/console db:reset --force
The contract, after every API change (commit it)docker compose run --rm api bin/console contract:openapi
An administrator logindocker compose run --rm api bin/console user:create-admin <email>
Code style fix, Rector dry runcomposer cs:fix, composer rector (in the container)
Mails of development (Mailpit; it forwards nothing)http://localhost:8025
Database UI (Adminer)docker compose --profile tools up -d, http://localhost:8081
The job worker after a change to a job handlerdocker compose restart worker
XdebugXDEBUG_MODE=debug docker compose up -d

No mail leaves a development machine: dev sends to Mailpit, the tests keep mails in memory; outside qa and prod the library refuses every other mail server. The production mail server is set only in production's environment.

Layout

PathContent
config/module.phpThe modules: the library's (Health, Job, Mail, Account) and src/AppModule.php
config/setting.php, setting.<env>.phpSettings over the modules' defaults; APP_ENV is dev, test, qa or prod
config/container.phpContainer bindings (most classes are autowired)
config/permissions.phpRoles as bundles of permissions (<resource>.<action>)
config/route/*.phpRoutes; every route has exactly one guard (Guard::public(), authenticated(), can('…'))
src/Feature/<Name>/One folder per feature: entity, repository, input, view, controller
migrations/The application's migrations; they run with the library's in timestamp order
resources/mail/<locale>/Mail templates (Twig): <name>.subject.txt.twig, .txt.twig, .html.twig
contract/openapi.jsonThe generated contract (committed; ContractTest checks it is current)
tests/Unit, tests/HttpWithout a database (in composer check) and against the test database

The first feature

src/Feature/Note is an example: a guarded CRUD with a paged, searchable, sortable list. Build your first feature next to it, then delete it (the folder, config/route/note.php, its migration, tests/Http/NoteTest.php, note.* in config/permissions.php, the notes in src/Seed/DevSeeder.php):

  1. A migration migrations/Version<YYYYMMDDhhmmss>.php and composer migrate.
  2. The entity (#[Table], a final readonly class), its repository (EntityRepository), the input (JsonInput) and the view (JsonView), the controller with #[ApiOperation].
  3. The routes in config/route/<name>.php and the permissions in config/permissions.php; add new public routes to tests/Unit/AccessTest.php.
  4. bin/console contract:openapi, an HTTP test with ContractAssert, composer check.

Step 0: decide before you build

Each item has a default, so nothing blocks the start; the first four shape the first migration and the infrastructure.

  • [ ] Domain and language: the entities, their statuses and ownership rules; the language of identifiers, tables and
    URLs.
    
  • [ ] Hosting and database: container platform or PHP-FPM host (Dockerfile.prod); MariaDB version (same major
    in dev, CI and production).
    
  • [ ] Roles and permissions: default: one admin role with * (config/permissions.php).
  • [ ] Accounts: who creates them (default: administrators, user:create-admin); the locales a user can choose
    (`account.localeList`); the page of the web app that opens the reset link (`account.passwordResetPath`).
    
  • [ ] Rate limits: default values in rateLimit.*; per flow of your own.
  • [ ] Audited events: the library records login, logout and the password reset; the rest per feature
    (`AuditLog::record()`, e.g. the example's `note.created`).
    
  • [ ] Paging: default size 100; the sortable fields per list.
  • [ ] Mail: sender (MAIL_FROM), the locales of the templates, the display time zone (mail.timeZone).
  • [ ] Files: where the local storage lives (storage.fileRoot), upload types and sizes.
  • [ ] Retention: jobs (job:cleanup), the audit log, logs, backups.
  • [ ] Monitoring: an uptime check on /health/ready, an alert on 5xx responses in the logs.
  • [ ] The frontend: which client uses the contract (types generated from contract/openapi.json).

Write each answer down; a short ADR for the ones that are hard to change later (language, hosting, database).

Production

Dockerfile.prod builds a PHP-FPM image without dev packages and with APP_ENV=prod; a web server in front serves public/ and passes PHP to port 9000. The worker runs the same image with php bin/console job:work. Set DATABASE_URL, MAILER_DSN, MAIL_FROM, APP_WEB_URL, APP_PUBLIC_URL and CORS_ALLOWED_ORIGINS in the environment; run bin/console migrations:migrate --no-interaction on each deployment.

CI (parked): ci/gitlab-ci.yml runs composer check and the integration tests against MariaDB. GitLab does not run it there; to activate it, git mv ci/gitlab-ci.yml .gitlab-ci.yml.