|
| 1 | +# Switon App Rules |
| 2 | + |
| 3 | +**TL;DR** — Setup: `create-project` creates `.env` and generates `MASTER_KEY`. CLI: `bash bin/console` (fallback: `php switon.php` on Windows when shell wrapper execution is unavailable). Dev HTTP: `php public/index.php` (`.env` sets `SERVER_TYPE=php`). |
| 4 | + |
| 5 | +**Framework:** Switon (PHP). **Scope:** `vendor/switon/*`. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Core Rules |
| 10 | + |
| 11 | +- Do not invent class names, interfaces, config keys, or commands. Verify machine-meaningful identifiers against the codebase or discovery commands. |
| 12 | +- Use `router:list --json` instead of a hand-written route list. |
| 13 | +- `vendor/switon/*` is read-only. |
| 14 | +- Do not run `composer require`, delete files, or make broad refactors without asking. |
| 15 | +- Do not commit or log `.env` or `--uri` output. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Project Structure |
| 20 | + |
| 21 | +| Path | Purpose | |
| 22 | +|------|---------| |
| 23 | +| `app/` | Application code (controllers, commands, entities, repositories, services, listeners). | |
| 24 | +| `switon.yml` | Main application config file. | |
| 25 | +| `config/` | Optional PHP-only configuration patches. | |
| 26 | +| `public/index.php` | HTTP entry. | |
| 27 | +| `switon.php` | CLI entry. | |
| 28 | +| `docs/` | Project docs. | |
| 29 | +| `skills/` | App skills only; use `app-` for project skills and `switon-` for built-in Switon app-facing skills. | |
| 30 | +| `vendor/switon/*` | Framework; read-only. | |
| 31 | + |
| 32 | +Routes: configure the prefix in `switon.yml`; actions live in `app/Controller/`. |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## CLI |
| 37 | + |
| 38 | +- Entrypoint: `bash bin/console` (fallback: `php switon.php` on Windows when shell wrapper execution is unavailable). |
| 39 | +- Options: `--name=value` or `--flag`. |
| 40 | +- Tool discovery: `tool:list` for the command list; `tool:description <invocation>` for one command. |
| 41 | +- For tool-only tasks, `tool:list` and `tool:description` are enough. |
| 42 | +- Prefer `class:*` and `event:*` tools to read framework code and events by FQCN instead of raw file reads. |
| 43 | +- Common tools: `router:resolve <path> [verb] --json`, `router:list [filter] --json`, `class:list [filter]`, `class:inspect <FQCN>`, `class:content <FQCN>` or `class:content <FQCN>::<method>`, `event:classes [filter] --json`, `event:class <FQCN> --json`, `event:category <class> --json`, `event:by-code <code> --json`. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Runtime |
| 48 | + |
| 49 | +- Run: `php public/index.php`. |
| 50 | +- Sample routes: `/`, `/time/current` (see `router:list --json`). |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## Switon package rules |
| 55 | + |
| 56 | +- Auto-registration: default bindings lowest; explicit overrides. |
| 57 | +- Config: prefer root `switon.yml`; use `config/*.php` only for PHP-only values or pre-built instances. |
| 58 | +- Events: use the component `Event/` namespace and FQCNs. |
| 59 | +- Exceptions: use `Switon\Core\Exception\*`, not PHP built-ins. |
| 60 | +- Runtime: package `composer.json` (including `ext-*`) is source of truth. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## Sword Templates |
| 65 | + |
| 66 | +- Prefer `@inject('name', FQCN::class)` for small template-level service access. |
| 67 | +- Do not inline `\Switon\Core\App::get(...)` when `@inject` can express the dependency. |
| 68 | +- Prefer upstream view vars for business data; use `@inject` only for light template wiring. |
| 69 | +- Use `json(...)` for JS/JSON literal output in templates. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Project Overrides |
| 74 | + |
| 75 | +Add app-specific or third-party rules here. Keep short and scoped. |
0 commit comments