This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A CakePHP 5.x sandbox application showcasing CakePHP features, plugins, and tools. This is a live demo application (https://sandbox.dereuromark.de) with custom exception handling, DB logging, and extensive plugin examples.
The codebase uses a modular plugin architecture with three main plugins in /plugins/:
- Sandbox: Misc. examples and plugin showcases (most example code)
- AuthSandbox: Authentication examples
- StateMachineSandbox: State machine examples with Queue integration
The main application (/src/) contains core controllers, user management, and admin functionality.
- AppController (
src/Controller/AppController.php): Uses TinyAuth for authentication/authorization, Flash component, and Tools.Common component. ExtendsTools\Controller\ControllerwithRedirectOutOfBoundsTrait. - Authentication: TinyAuth with MultiColumn authenticator supporting username/email login.
- Routing: Uses DashedRoute by default. Admin routes use
/adminprefix. Plugins configured inconfig/plugins.php. - Middleware Stack: Custom ErrorHandlerMiddleware, MaintenanceMiddleware, CacheMiddleware, RedirectMiddleware.
Standard CakePHP conventions enforced:
- Tables: plural snake_case (e.g.,
sandbox_users,sandbox_posts) - Foreign keys:
{singular_table}_id - Auto-managed timestamps:
createdandmodifiedfields
Initial setup:
./install.sh # First-time install (runs migrations, seeds, assets)
./setup.sh # Subsequent setup (after pull, for dev env)Manual steps:
composer install
composer migrate # Runs migrations for app + all plugins
bin/cake seeds run # Seed demo data
composer assets # Install npm assets via package.jsoncomposer migrate # Run all migrations
bin/cake migrations migrate # Run app migrations
bin/cake migrations migrate -p Queue # Run plugin migrations
bin/cake seeds run # Seed all demo data
bin/cake seeds run Cities # Seed specific seeder
bin/cake seeds status # Show seed statuscomposer test # Run all tests via PHPUnit
vendor/bin/phpunit # Run all tests
vendor/bin/phpunit --filter testMethodName # Run specific test method
vendor/bin/phpunit --testsuite app # Run app tests
vendor/bin/phpunit --testsuite sandbox # Run Sandbox plugin tests
composer test-coverage # Generate coverage reportsTest suites: app, sandbox, auth-sandbox, state-machine-sandbox
composer cs-check # Check coding standards (PSR2R via phpcs.xml)
composer cs-fix # Auto-fix coding standard violations
composer stan # Run PHPStan level 8 analysis (phpstan.neon)
composer stan-tests # Run PHPStan on test filescomposer setup # Generate IDE helper files (code_completion + phpstorm)
composer annotate # Add annotations to app + all plugins
composer dto # Generate DTOs for Sandbox plugin
bin/cake bake model MyModel --theme Setup # Use Setup theme for bakingcomposer assets # Install/copy frontend assets from npm
bin/cake asset_compress build # Build compressed assets
bin/cake cache clear_all # Clear all caches
bin/cake schema_cache build # Rebuild schema cachebin/cake queue worker end all # Stop all queue workers
bin/cake maintenance_mode activate # Enable maintenance mode
bin/cake maintenance_mode deactivate # Disable maintenance modebin/cake user create username password # Create user (select role 1 for admin)- TinyAuth handles both authentication (MultiColumn) and authorization (Tiny adapter)
- Login fields:
login(username) andpassword, with fallback to email - User model:
Userstable - Admin access requires role_id = 1
- Avoid usernames
admin,mod,user(reserved for seed data)
- Uses
Shim\TestSuite\IntegrationTestCasefor controller tests - Fixture factories preferred over traditional fixtures (dereuromark/cakephp-fixture-factories)
- Test URLs must be arrays:
$this->get(['controller' => 'Overview', 'action' => 'index']) - Each test method should have only ONE
get()/post()call - Flash message tests: add
$this->enableRetainFlashMessages()in test setup
- Asset management via
markstory/asset_compressplugin - Frontend dependencies in
package.json(Bootstrap icons, Font Awesome, Feather icons, etc.) - Assets copied to
webroot/assets/and fonts towebroot/css/fonts/ - Compiled JS/CSS output:
webroot/js/cjs/andwebroot/css/ccss/
config/app_local.php: Local config (not version-controlled) - DB, email, API keys, saltconfig/plugins.php: Plugin loading configurationconfig/routes.php: Route definitionsphpcs.xml: Coding standards (PSR2R ruleset)phpstan.neon: Static analysis config (level 8)
- NEVER commit unrelated files, especially personal notes or planning
.mdfiles in the root directory - Before committing, always review
git statuscarefully to ensure only relevant files are staged - Files like
_*.mdshould remain local and untracked
See global CLAUDE.md for general CakePHP patterns. Project-specific notes:
- Query methods: Use
groupBy()andorderBy()(not deprecatedgroup()/order()) - Table loading: Prefer
fetchTable()overloadModel() - Result sets: Always call
->toArray()unless paginated - Baking: Use
--theme Setupfor consistency - Annotations: Run
composer annotateafter model changes - DTOs: Generated via
composer dto, stored inplugins/Sandbox/src/Dto/