kode4 / slim-foundation-skeleton
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
Type:project
pkg:composer/kode4/slim-foundation-skeleton
Requires
- php: ^8.4
- ext-pcntl: *
- ext-pdo_mysql: *
- kode4/slim-foundation: ^0.1
- symfony/mailer: ^8.1
- symfony/mime: ^8.1
- twig/cssinliner-extra: ^3.21
- twig/twig: ^3.21
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- kode4/slim-foundation-testing: ^0.1
- 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: ^12.5.4 || ^13.0
- rector/rector: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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.
| What | Command |
|---|---|
| All gates without a database: validate, audit, code style, PHPStan max, unit tests | docker compose run --rm api composer check |
Integration tests (migrates app_test first) | docker compose run --rm api composer test:integration |
| Migrations | docker 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 login | docker compose run --rm api bin/console user:create-admin <email> |
| Code style fix, Rector dry run | composer 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 handler | docker compose restart worker |
| Xdebug | XDEBUG_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
| Path | Content |
|---|---|
config/module.php | The modules: the library's (Health, Job, Mail, Account) and src/AppModule.php |
config/setting.php, setting.<env>.php | Settings over the modules' defaults; APP_ENV is dev, test, qa or prod |
config/container.php | Container bindings (most classes are autowired) |
config/permissions.php | Roles as bundles of permissions (<resource>.<action>) |
config/route/*.php | Routes; 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.json | The generated contract (committed; ContractTest checks it is current) |
tests/Unit, tests/Http | Without 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):
- A migration
migrations/Version<YYYYMMDDhhmmss>.phpandcomposer migrate. - The entity (
#[Table], afinal readonlyclass), its repository (EntityRepository), the input (JsonInput) and the view (JsonView), the controller with#[ApiOperation]. - The routes in
config/route/<name>.phpand the permissions inconfig/permissions.php; add new public routes totests/Unit/AccessTest.php. bin/console contract:openapi, an HTTP test withContractAssert,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 majorin dev, CI and production). - [ ] Roles and permissions: default: one
adminrole 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.